From e67f3bc9e9780e4407aa405906070c7d3a88b0f8 Mon Sep 17 00:00:00 2001 From: Baptiste Arnaud Date: Tue, 20 Aug 2024 15:11:41 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=91=EF=B8=8F=20Fix=20audio=20clip=20no?= =?UTF-8?q?t=20saving=20properly?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/bot-engine/continueBotFlow.ts | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/packages/bot-engine/continueBotFlow.ts b/packages/bot-engine/continueBotFlow.ts index 89a2d1266..2300987d9 100644 --- a/packages/bot-engine/continueBotFlow.ts +++ b/packages/bot-engine/continueBotFlow.ts @@ -107,14 +107,16 @@ export const continueBotFlow = async ( } formattedReply = - 'reply' in parsedReplyResult ? parsedReplyResult.reply : undefined + 'reply' in parsedReplyResult && reply?.type === 'text' + ? parsedReplyResult.reply + : undefined newSessionState = await processAndSaveAnswer( state, block )( isDefined(formattedReply) ? { ...reply, type: 'text', text: formattedReply } - : undefined + : reply ) } @@ -312,9 +314,12 @@ const processAndSaveAnswer = const saveVariablesValueIfAny = (state: SessionState, block: InputBlock) => (reply: Message): SessionState => { - if (!block.options?.variableId) return state let newSessionState = saveAttachmentsVarIfAny({ block, reply, state }) - newSessionState = saveAudioClipVarIfAny({ block, reply, state }) + newSessionState = saveAudioClipVarIfAny({ + block, + reply, + state: newSessionState, + }) return saveInputVarIfAny({ block, reply, state: newSessionState }) } @@ -379,7 +384,7 @@ const saveAudioClipVarIfAny = ({ return state const variable = state.typebotsQueue[0].typebot.variables.find( - (variable) => variable.id === block.options?.attachments?.saveVariableId + (variable) => variable.id === block.options?.audioClip?.saveVariableId ) if (!variable) return state @@ -408,7 +413,7 @@ const saveInputVarIfAny = ({ reply: Message state: SessionState }): SessionState => { - if (reply.type !== 'text') return state + if (reply.type !== 'text' || !block.options?.variableId) return state const foundVariable = state.typebotsQueue[0].typebot.variables.find( (variable) => variable.id === block.options?.variableId