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;
|
threadTs?: string;
|
||||||
integrationId?: string;
|
integrationId?: string;
|
||||||
channelId?: string;
|
channelId?: string;
|
||||||
|
slackBlocks?: SlackBlock[];
|
||||||
}
|
}
|
||||||
|
|
||||||
interface SlackBlock {
|
interface SlackBlock {
|
||||||
|
@ -201,6 +202,7 @@ export async function sendSlackNotification(
|
||||||
...(result.messageTs && { messageTs: result.messageTs }),
|
...(result.messageTs && { messageTs: result.messageTs }),
|
||||||
integrationId: integration.id,
|
integrationId: integration.id,
|
||||||
channelId: integration.defaultChannel.id,
|
channelId: integration.defaultChannel.id,
|
||||||
|
...(slackMessage.blocks && { slackBlocks: slackMessage.blocks }),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -270,6 +272,7 @@ export async function sendSlackReplyNotification(
|
||||||
threadTs: params.threadTs,
|
threadTs: params.threadTs,
|
||||||
integrationId: params.integrationId,
|
integrationId: params.integrationId,
|
||||||
channelId: params.channelId,
|
channelId: params.channelId,
|
||||||
|
...(slackMessage.blocks && { slackBlocks: slackMessage.blocks }),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -510,6 +513,7 @@ export async function trackSlackNotification(params: {
|
||||||
chatId: string;
|
chatId: string;
|
||||||
summaryTitle?: string;
|
summaryTitle?: string;
|
||||||
summaryMessage?: string;
|
summaryMessage?: string;
|
||||||
|
slackBlocks?: SlackBlock[];
|
||||||
}): Promise<void> {
|
}): Promise<void> {
|
||||||
const db = getDb();
|
const db = getDb();
|
||||||
|
|
||||||
|
@ -525,8 +529,9 @@ export async function trackSlackNotification(params: {
|
||||||
slackMessageTs: params.messageTs,
|
slackMessageTs: params.messageTs,
|
||||||
slackThreadTs: params.threadTs || null,
|
slackThreadTs: params.threadTs || null,
|
||||||
messageType: params.threadTs ? 'reply' : 'message',
|
messageType: params.threadTs ? 'reply' : 'message',
|
||||||
content:
|
content: params.slackBlocks
|
||||||
params.summaryTitle && params.summaryMessage
|
? JSON.stringify({ blocks: params.slackBlocks })
|
||||||
|
: params.summaryTitle && params.summaryMessage
|
||||||
? `${params.summaryTitle}\n\n${params.summaryMessage}`
|
? `${params.summaryTitle}\n\n${params.summaryMessage}`
|
||||||
: 'Notification sent',
|
: 'Notification sent',
|
||||||
senderInfo: {
|
senderInfo: {
|
||||||
|
|
|
@ -295,7 +295,12 @@ export const messagePostProcessingTask: ReturnType<
|
||||||
|
|
||||||
let slackResult: Awaited<ReturnType<typeof sendSlackNotification>>;
|
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', {
|
logger.log('Found existing Slack thread for chat, sending as reply', {
|
||||||
messageId: payload.messageId,
|
messageId: payload.messageId,
|
||||||
chatId: messageContext.chatId,
|
chatId: messageContext.chatId,
|
||||||
|
@ -365,6 +370,7 @@ export const messagePostProcessingTask: ReturnType<
|
||||||
chatId: messageContext.chatId,
|
chatId: messageContext.chatId,
|
||||||
summaryTitle: dbData.summary_title,
|
summaryTitle: dbData.summary_title,
|
||||||
summaryMessage: dbData.summary_message,
|
summaryMessage: dbData.summary_message,
|
||||||
|
...(slackResult.slackBlocks && { slackBlocks: slackResult.slackBlocks }),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue