2
0

🐛 (sendMessage) Return updated session in all cases

This commit is contained in:
Baptiste Arnaud
2023-07-24 09:21:55 +02:00
parent defe00155d
commit 7942ae4751

View File

@ -31,7 +31,7 @@ export const continueBotFlow =
(state: SessionState) => (state: SessionState) =>
async ( async (
reply?: string reply?: string
): Promise<ChatReply & { newSessionState?: SessionState }> => { ): Promise<ChatReply & { newSessionState: SessionState }> => {
let newSessionState = { ...state } let newSessionState = { ...state }
const group = state.typebot.groups.find( const group = state.typebot.groups.find(
(group) => group.id === state.currentBlock?.groupId (group) => group.id === state.currentBlock?.groupId
@ -87,12 +87,13 @@ export const continueBotFlow =
let formattedReply = null let formattedReply = null
if (isInputBlock(block)) { 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) formattedReply = formatReply(reply, block.type)
if (!formattedReply && !canSkip(block.type)) { if (!formattedReply && !canSkip(block.type)) {
return parseRetryMessage(block) return { ...parseRetryMessage(block), newSessionState }
} }
const nextEdgeId = getOutgoingEdgeId(newSessionState)( const nextEdgeId = getOutgoingEdgeId(newSessionState)(
@ -121,11 +122,11 @@ export const continueBotFlow =
} }
if (!nextEdgeId && state.linkedTypebots.queue.length === 0) if (!nextEdgeId && state.linkedTypebots.queue.length === 0)
return { messages: [] } return { messages: [], newSessionState }
const nextGroup = getNextGroup(newSessionState)(nextEdgeId) const nextGroup = getNextGroup(newSessionState)(nextEdgeId)
if (!nextGroup) return { messages: [] } if (!nextGroup) return { messages: [], newSessionState }
return executeGroup(newSessionState)(nextGroup.group) return executeGroup(newSessionState)(nextGroup.group)
} }