From 7942ae4751703ef0599366f257a690bae9d15818 Mon Sep 17 00:00:00 2001 From: Baptiste Arnaud Date: Mon, 24 Jul 2023 09:21:55 +0200 Subject: [PATCH] :bug: (sendMessage) Return updated session in all cases --- .../src/features/chat/helpers/continueBotFlow.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/apps/viewer/src/features/chat/helpers/continueBotFlow.ts b/apps/viewer/src/features/chat/helpers/continueBotFlow.ts index 81dd92706..308bd8b72 100644 --- a/apps/viewer/src/features/chat/helpers/continueBotFlow.ts +++ b/apps/viewer/src/features/chat/helpers/continueBotFlow.ts @@ -31,7 +31,7 @@ export const continueBotFlow = (state: SessionState) => async ( reply?: string - ): Promise => { + ): Promise => { let newSessionState = { ...state } const group = state.typebot.groups.find( (group) => group.id === state.currentBlock?.groupId @@ -87,12 +87,13 @@ export const continueBotFlow = let formattedReply = null if (isInputBlock(block)) { - if (reply && !isReplyValid(reply, block)) return parseRetryMessage(block) + if (reply && !isReplyValid(reply, block)) + return { ...parseRetryMessage(block), newSessionState } formattedReply = formatReply(reply, block.type) if (!formattedReply && !canSkip(block.type)) { - return parseRetryMessage(block) + return { ...parseRetryMessage(block), newSessionState } } const nextEdgeId = getOutgoingEdgeId(newSessionState)( @@ -121,11 +122,11 @@ export const continueBotFlow = } if (!nextEdgeId && state.linkedTypebots.queue.length === 0) - return { messages: [] } + return { messages: [], newSessionState } const nextGroup = getNextGroup(newSessionState)(nextEdgeId) - if (!nextGroup) return { messages: [] } + if (!nextGroup) return { messages: [], newSessionState } return executeGroup(newSessionState)(nextGroup.group) }