Skip to content

Commit

Permalink
Add: slackbot will re-create a conversation if needed, url is now vis…
Browse files Browse the repository at this point in the history
…ibile to the model. (#8154)
  • Loading branch information
Fraggle authored Oct 22, 2024
1 parent 6f183cc commit e564ee9
Showing 1 changed file with 40 additions and 22 deletions.
62 changes: 40 additions & 22 deletions connectors/src/connectors/slack/bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -588,34 +588,48 @@ async function answerMessage(
if (buildContentFragmentRes.isErr()) {
return buildSlackMessageError(buildContentFragmentRes);
}

let conversation: ConversationType | undefined = undefined;
let userMessage: UserMessageType | undefined = undefined;

if (lastSlackChatBotMessage?.conversationId) {
if (buildContentFragmentRes.value) {
const contentFragmentRes = await dustAPI.postContentFragment({
// Check conversation existence (it might have been deleted between two messages).
const existsRes = await dustAPI.getConversation({
conversationId: lastSlackChatBotMessage.conversationId,
});

// If it doesn't exists, we will create a new one later.
if (existsRes.isOk()) {
if (buildContentFragmentRes.value) {
const contentFragmentRes = await dustAPI.postContentFragment({
conversationId: lastSlackChatBotMessage.conversationId,
contentFragment: buildContentFragmentRes.value,
});
if (contentFragmentRes.isErr()) {
return buildSlackMessageError(contentFragmentRes);
}
}

const messageRes = await dustAPI.postUserMessage({
conversationId: lastSlackChatBotMessage.conversationId,
contentFragment: buildContentFragmentRes.value,
message: messageReqBody,
});
if (contentFragmentRes.isErr()) {
return buildSlackMessageError(contentFragmentRes);
if (messageRes.isErr()) {
return buildSlackMessageError(messageRes);
}
userMessage = messageRes.value;

const conversationRes = await dustAPI.getConversation({
conversationId: lastSlackChatBotMessage.conversationId,
});
if (conversationRes.isErr()) {
return buildSlackMessageError(conversationRes);
}
conversation = conversationRes.value;
}
const messageRes = await dustAPI.postUserMessage({
conversationId: lastSlackChatBotMessage.conversationId,
message: messageReqBody,
});
if (messageRes.isErr()) {
return buildSlackMessageError(messageRes);
}
userMessage = messageRes.value;
const conversationRes = await dustAPI.getConversation({
conversationId: lastSlackChatBotMessage.conversationId,
});
if (conversationRes.isErr()) {
return buildSlackMessageError(conversationRes);
}
conversation = conversationRes.value;
} else {
}

if (!conversation || !userMessage) {
const convRes = await dustAPI.createConversation({
title: null,
visibility: "unlisted",
Expand Down Expand Up @@ -756,9 +770,13 @@ async function makeContentFragment(
}
url = permalinkRes.permalink;
}

// Prepend $url to the content to make it available to the model.
const section = `$url: ${url}\n${sectionFullText(content)}`;

return new Ok({
title: `Thread content from #${channel.channel.name}`,
content: sectionFullText(content),
content: section,
url: url,
contentType: "dust-application/slack",
context: null,
Expand Down

0 comments on commit e564ee9

Please sign in to comment.