create checks if CLI or SLack, so don't process/return both formats every time

This commit is contained in:
Charlotte Croce 2025-04-20 20:59:12 -04:00
parent 964eaa8ae9
commit b98502284a
4 changed files with 123 additions and 102 deletions

View file

@ -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;
try {
// This is for Slack - get the Block Kit UI components
blocks = getSigmaRuleDetailsBlocks(sigmaRuleDetailsResult.explanation);
} catch (blockError) {
await handleError(blockError, `${FILE_NAME}: Block generation`, respond, {
responseType: 'ephemeral',
customMessage: 'Error generating rule details view'
// Create response based on interface type
if (isCliRequest) {
// For CLI, just return the raw data
await respond({
responseData: sigmaRuleDetailsResult.explanation,
response_type: 'cli'
});
return;
} else {
// For Slack, generate and return Block Kit blocks
try {
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 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'