Skip to content

Commit

Permalink
⚡️ Update session handling to continue bot flow when start message is…
Browse files Browse the repository at this point in the history
… present and no messages to display

Closes #1831
  • Loading branch information
baptisteArno committed Oct 11, 2024
1 parent a6db54c commit 5ab08b5
Showing 1 changed file with 18 additions and 33 deletions.
51 changes: 18 additions & 33 deletions packages/bot-engine/src/startSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,41 +182,26 @@ export const startSession = async ({
textBubbleContentFormat: startParams.textBubbleContentFormat,
});

// If params has message and first block is an input block, we can directly continue the bot flow
if (startParams.message) {
const firstEdgeId = getFirstEdgeId({
typebot: chatReply.newSessionState.typebotsQueue[0].typebot,
startEventId:
startParams.type === "preview" &&
startParams.startFrom?.type === "event"
? startParams.startFrom.eventId
: undefined,
});
const nextGroup = await getNextGroup({
// Has start message and has no messages to display first
if (
startParams.message &&
chatReply.messages.length === 0 &&
(chatReply.clientSideActions?.filter((c) => c.expectsDedicatedReply)
.length ?? 0) === 0
) {
const resultId = chatReply.newSessionState.typebotsQueue[0].resultId;
if (resultId)
await upsertResult({
hasStarted: true,
isCompleted: false,
resultId,
typebot: chatReply.newSessionState.typebotsQueue[0].typebot,
});
chatReply = await continueBotFlow(startParams.message, {
version,
state: chatReply.newSessionState,
edgeId: firstEdgeId,
isOffDefaultPath: false,
textBubbleContentFormat: startParams.textBubbleContentFormat,
});
const newSessionState = nextGroup.newSessionState;
const firstBlock = nextGroup.group?.blocks.at(0);
if (firstBlock && isInputBlock(firstBlock)) {
const resultId = newSessionState.typebotsQueue[0].resultId;
if (resultId)
await upsertResult({
hasStarted: true,
isCompleted: false,
resultId,
typebot: newSessionState.typebotsQueue[0].typebot,
});
chatReply = await continueBotFlow(startParams.message, {
version,
state: {
...newSessionState,
currentBlockId: firstBlock.id,
},
textBubbleContentFormat: startParams.textBubbleContentFormat,
});
}
}

const {
Expand Down

0 comments on commit 5ab08b5

Please sign in to comment.