create checks if CLI or SLack, so don't process/return both formats every time
This commit is contained in:
parent
964eaa8ae9
commit
b98502284a
4 changed files with 123 additions and 102 deletions
|
@ -2,7 +2,6 @@
|
|||
* sigma_create_handler.js
|
||||
*
|
||||
* Handles Sigma rule conversion requests from Slack commands
|
||||
* Action handlers moved to sigma_action_core.js
|
||||
*/
|
||||
const logger = require('../../utils/logger');
|
||||
const { handleError } = require('../../utils/error_handler');
|
||||
|
|
|
@ -22,6 +22,9 @@ const handleCommand = async (command, respond) => {
|
|||
try {
|
||||
logger.debug(`${FILE_NAME}: Processing sigma-details command: ${command.text}`);
|
||||
|
||||
// Determine if request is from CLI
|
||||
const isCliRequest = command.channel_id === 'cli' || command.channel_name === 'cli';
|
||||
|
||||
if (!command || !command.text) {
|
||||
logger.warn(`${FILE_NAME}: Empty command received for sigma-details`);
|
||||
await respond({
|
||||
|
@ -61,25 +64,28 @@ const handleCommand = async (command, respond) => {
|
|||
return;
|
||||
}
|
||||
|
||||
// For Slack responses, generate Block Kit blocks
|
||||
let blocks;
|
||||
// Create response based on interface type
|
||||
if (isCliRequest) {
|
||||
// For CLI, just return the raw data
|
||||
await respond({
|
||||
responseData: sigmaRuleDetailsResult.explanation,
|
||||
response_type: 'cli'
|
||||
});
|
||||
} else {
|
||||
// For Slack, generate and return Block Kit blocks
|
||||
try {
|
||||
// This is for Slack - get the Block Kit UI components
|
||||
blocks = getSigmaRuleDetailsBlocks(sigmaRuleDetailsResult.explanation);
|
||||
const blocks = getSigmaRuleDetailsBlocks(sigmaRuleDetailsResult.explanation);
|
||||
await respond({
|
||||
blocks: blocks,
|
||||
response_type: 'in_channel'
|
||||
});
|
||||
} catch (blockError) {
|
||||
await handleError(blockError, `${FILE_NAME}: Block generation`, respond, {
|
||||
responseType: 'ephemeral',
|
||||
customMessage: 'Error generating rule details view'
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
// Return the response with both blocks for Slack and responseData for CLI
|
||||
await respond({
|
||||
blocks: blocks, // For Slack interface
|
||||
responseData: sigmaRuleDetailsResult.explanation, // For CLI interface
|
||||
response_type: 'in_channel'
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
await handleError(error, `${FILE_NAME}: Details command handler`, respond, {
|
||||
responseType: 'ephemeral'
|
||||
|
|
|
@ -110,7 +110,16 @@ const handleCommand = async (command, respond) => {
|
|||
return;
|
||||
}
|
||||
|
||||
// Generate blocks with pagination support
|
||||
const isCliRequest = command.channel_id === 'cli' || command.channel_name === 'cli';
|
||||
|
||||
if (isCliRequest) {
|
||||
// For CLI, just return the raw data
|
||||
await respond({
|
||||
responseData: searchResult.results,
|
||||
response_type: 'cli'
|
||||
});
|
||||
} else {
|
||||
// For Slack, generate and return Block Kit blocks
|
||||
let blocks;
|
||||
try {
|
||||
logger.debug(`${FILE_NAME}: Calling getSearchResultBlocks with ${searchResult.results.length} results`);
|
||||
|
@ -129,27 +138,27 @@ const handleCommand = async (command, respond) => {
|
|||
blocks = getSearchResultBlocks(keyword, searchResult.results, searchResult.pagination);
|
||||
}
|
||||
logger.debug(`${FILE_NAME}: Successfully generated ${blocks?.length || 0} blocks`);
|
||||
|
||||
// Determine if this should be visible to everyone or just the user
|
||||
const isEphemeral = totalCount > 20;
|
||||
|
||||
// Add debug log before sending response
|
||||
logger.debug(`${FILE_NAME}: About to send response with ${blocks?.length || 0} blocks`);
|
||||
|
||||
// Respond with the search results
|
||||
// Respond with the search results
|
||||
await respond({
|
||||
blocks: blocks,
|
||||
response_type: isEphemeral ? 'ephemeral' : 'in_channel'
|
||||
});
|
||||
} catch (blockError) {
|
||||
// Use error handler for block generation errors
|
||||
await handleError(blockError, `${FILE_NAME}: Block generation`, respond, {
|
||||
responseType: 'in_channel',
|
||||
customMessage: `Found ${searchResult.results.length} of ${totalCount} rules matching "${keyword}" (page ${page} of ${searchResult.pagination?.totalPages || 1}). Use /sigma-details [id] to view details.`
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
// Add debug log before sending response
|
||||
logger.debug(`${FILE_NAME}: About to send response with ${blocks?.length || 0} blocks`);
|
||||
|
||||
// Determine if this should be visible to everyone or just the user
|
||||
const isEphemeral = totalCount > 20;
|
||||
|
||||
// Respond with the search results
|
||||
await respond({
|
||||
blocks: blocks,
|
||||
responseData: searchResult.results,
|
||||
response_type: isEphemeral ? 'ephemeral' : 'in_channel'
|
||||
});
|
||||
}
|
||||
|
||||
// Add debug log after sending response
|
||||
logger.debug(`${FILE_NAME}: Response sent successfully`);
|
||||
|
|
|
@ -22,6 +22,9 @@ const handleCommand = async (command, respond) => {
|
|||
try {
|
||||
logger.info(`${FILE_NAME}: Processing sigma-stats command`);
|
||||
|
||||
// Determine if request is from CLI by checking channel properties
|
||||
const isCliRequest = command.channel_id === 'cli' || command.channel_name === 'cli';
|
||||
|
||||
await respond({
|
||||
text: 'Gathering Sigma rule statistics... This may take a moment.',
|
||||
response_type: 'ephemeral'
|
||||
|
@ -39,24 +42,28 @@ const handleCommand = async (command, respond) => {
|
|||
return;
|
||||
}
|
||||
|
||||
// For Slack responses, generate Block Kit blocks
|
||||
let blocks;
|
||||
// For CLI, only include responseData
|
||||
if (isCliRequest) {
|
||||
await respond({
|
||||
responseData: statsResult.stats,
|
||||
response_type: 'cli'
|
||||
});
|
||||
}
|
||||
// For Slack, only generate Block Kit blocks
|
||||
else {
|
||||
try {
|
||||
blocks = getStatsBlocks(statsResult.stats);
|
||||
const blocks = getStatsBlocks(statsResult.stats);
|
||||
await respond({
|
||||
blocks: blocks,
|
||||
response_type: 'in_channel'
|
||||
});
|
||||
} catch (blockError) {
|
||||
await handleError(blockError, `${FILE_NAME}: Block generation`, respond, {
|
||||
responseType: 'ephemeral',
|
||||
customMessage: 'Error generating statistics view'
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
// Return the response with both blocks for Slack and responseData for CLI
|
||||
await respond({
|
||||
blocks: blocks,
|
||||
responseData: statsResult.stats, // Include raw data for CLI
|
||||
response_type: 'in_channel'
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
await handleError(error, `${FILE_NAME}: Stats command handler`, respond, {
|
||||
responseType: 'ephemeral'
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue