diff --git a/apps/trigger/src/tasks/message-post-processing/helpers/slack-notifier.ts b/apps/trigger/src/tasks/message-post-processing/helpers/slack-notifier.ts index b34255650..7e3c09cde 100644 --- a/apps/trigger/src/tasks/message-post-processing/helpers/slack-notifier.ts +++ b/apps/trigger/src/tasks/message-post-processing/helpers/slack-notifier.ts @@ -36,6 +36,7 @@ export interface SlackNotificationResult { threadTs?: string; integrationId?: string; channelId?: string; + slackBlocks?: SlackBlock[]; } interface SlackBlock { @@ -201,6 +202,7 @@ export async function sendSlackNotification( ...(result.messageTs && { messageTs: result.messageTs }), integrationId: integration.id, channelId: integration.defaultChannel.id, + ...(slackMessage.blocks && { slackBlocks: slackMessage.blocks }), }; } @@ -270,6 +272,7 @@ export async function sendSlackReplyNotification( threadTs: params.threadTs, integrationId: params.integrationId, channelId: params.channelId, + ...(slackMessage.blocks && { slackBlocks: slackMessage.blocks }), }; } @@ -510,6 +513,7 @@ export async function trackSlackNotification(params: { chatId: string; summaryTitle?: string; summaryMessage?: string; + slackBlocks?: SlackBlock[]; }): Promise { const db = getDb(); @@ -525,8 +529,9 @@ export async function trackSlackNotification(params: { slackMessageTs: params.messageTs, slackThreadTs: params.threadTs || null, messageType: params.threadTs ? 'reply' : 'message', - content: - params.summaryTitle && params.summaryMessage + content: params.slackBlocks + ? JSON.stringify({ blocks: params.slackBlocks }) + : params.summaryTitle && params.summaryMessage ? `${params.summaryTitle}\n\n${params.summaryMessage}` : 'Notification sent', senderInfo: { diff --git a/apps/trigger/src/tasks/message-post-processing/message-post-processing.ts b/apps/trigger/src/tasks/message-post-processing/message-post-processing.ts index 4e13e26b8..23964fc1e 100644 --- a/apps/trigger/src/tasks/message-post-processing/message-post-processing.ts +++ b/apps/trigger/src/tasks/message-post-processing/message-post-processing.ts @@ -295,7 +295,12 @@ export const messagePostProcessingTask: ReturnType< let slackResult: Awaited>; - if (existingSlackMessage?.exists && existingSlackMessage.slackThreadTs && existingSlackMessage.channelId && existingSlackMessage.integrationId) { + if ( + existingSlackMessage?.exists && + existingSlackMessage.slackThreadTs && + existingSlackMessage.channelId && + existingSlackMessage.integrationId + ) { logger.log('Found existing Slack thread for chat, sending as reply', { messageId: payload.messageId, chatId: messageContext.chatId, @@ -365,6 +370,7 @@ export const messagePostProcessingTask: ReturnType< chatId: messageContext.chatId, summaryTitle: dbData.summary_title, summaryMessage: dbData.summary_message, + ...(slackResult.slackBlocks && { slackBlocks: slackResult.slackBlocks }), }); } } else {