mirror of https://github.com/buster-so/buster.git
Enhance Slack notification handling by adding support for slackBlocks in message tracking and notification functions. Refactor conditional checks for existing Slack messages for improved readability.
This commit is contained in:
parent
0aae37e2ef
commit
fa53ae1111
|
@ -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<void> {
|
||||
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: {
|
||||
|
|
|
@ -295,7 +295,12 @@ export const messagePostProcessingTask: ReturnType<
|
|||
|
||||
let slackResult: Awaited<ReturnType<typeof sendSlackNotification>>;
|
||||
|
||||
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 {
|
||||
|
|
Loading…
Reference in New Issue