Skip to content

Commit

Permalink
[Slack bot] Show which assistant is chosen + link to help (#7921)
Browse files Browse the repository at this point in the history
* [Slack bot] Show which assistant is chosen + link to help

Description
---
Fixes dust-tt/tasks#1417

Risks
---
a little bit slower to show the thinking message, but should be fine

Deploy
---
connectors

* fix
  • Loading branch information
philipperolet authored Oct 7, 2024
1 parent 72168e4 commit 889a7c1
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 14 deletions.
20 changes: 12 additions & 8 deletions connectors/src/connectors/slack/bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,14 +276,6 @@ async function botAnswerMessage(
}
);

const mainMessage = await slackClient.chat.postMessage({
...makeMessageUpdateBlocksAndText(null, {
isThinking: true,
}),
channel: slackChannel,
thread_ts: slackMessageTs,
});

// Slack sends the message with user ids when someone is mentionned (bot or user).
// Here we remove the bot id from the message and we replace user ids by their display names.
// Example: <@U01J9JZQZ8Z> What is the command to upgrade a workspace in production (cc
Expand Down Expand Up @@ -415,6 +407,18 @@ async function botAnswerMessage(
}
}

const mainMessage = await slackClient.chat.postMessage({
...makeMessageUpdateBlocksAndText(
null,
{
isThinking: true,
},
mention?.assistantName
),
channel: slackChannel,
thread_ts: slackMessageTs,
});

const messageReqBody = {
content: message,
mentions: mentions.map((m) => {
Expand Down
17 changes: 12 additions & 5 deletions connectors/src/connectors/slack/chat/blocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ import type { SlackMessageFootnotes } from "@connectors/connectors/slack/chat/ci
*/
export const MAX_SLACK_MESSAGE_LENGTH = 2950;

export const SLACK_CHOOSE_BOT_HELP_URL =
"https://docs.dust.tt/docs/slack#calling-an-assistant-in-slack";

function makeConversationLinkContextBlock(conversationUrl: string) {
return {
type: "context",
Expand All @@ -23,13 +26,16 @@ function makeConversationLinkContextBlock(conversationUrl: string) {
};
}

export function makeThinkingBlock() {
export function makeThinkingBlock(assistantName: string | undefined) {
const thinkingText =
(assistantName ? `@${assistantName} is thinking...` : "Thinking...") +
` <${SLACK_CHOOSE_BOT_HELP_URL}| Select which assistant replies>`;
return {
type: "context",
elements: [
{
type: "plain_text",
text: "Thinking...",
type: "mrkdwn",
text: thinkingText,
},
],
};
Expand Down Expand Up @@ -98,13 +104,14 @@ export type SlackMessageUpdate =

export function makeMessageUpdateBlocksAndText(
conversationUrl: string | null,
messageUpdate: SlackMessageUpdate
messageUpdate: SlackMessageUpdate,
assistantName: string | undefined
) {
const { isThinking, text, footnotes } = messageUpdate;

return {
blocks: [
isThinking ? makeThinkingBlock() : makeMarkdownBlock(text),
isThinking ? makeThinkingBlock(assistantName) : makeMarkdownBlock(text),
...makeContextSectionBlocks(conversationUrl, footnotes),
],
// TODO(2024-06-17 flav) We should not return markdown here.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,11 @@ export async function streamConversationToSlack(
}

const response = await slackClient.chat.update({
...makeMessageUpdateBlocksAndText(conversationUrl, messageUpdate),
...makeMessageUpdateBlocksAndText(
conversationUrl,
messageUpdate,
assistantName
),
channel: slackChannelId,
thread_ts: slackMessageTs,
ts: mainMessage.ts as string,
Expand Down

0 comments on commit 889a7c1

Please sign in to comment.