From c26ab77786ff77140dfd373eae100d60d8ae2682 Mon Sep 17 00:00:00 2001 From: Baptiste Arnaud Date: Thu, 12 Sep 2024 19:50:59 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20(setVariable)=20Fix=20transcript?= =?UTF-8?q?ion=20in=20loop?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Closes #1774 --- .../blocks/logic/setVariable/executeSetVariable.ts | 7 ++++++- packages/logic/computeResultTranscript.ts | 9 ++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/packages/bot-engine/blocks/logic/setVariable/executeSetVariable.ts b/packages/bot-engine/blocks/logic/setVariable/executeSetVariable.ts index 8e96e376f..4fee21b8a 100644 --- a/packages/bot-engine/blocks/logic/setVariable/executeSetVariable.ts +++ b/packages/bot-engine/blocks/logic/setVariable/executeSetVariable.ts @@ -384,7 +384,12 @@ const parseTranscriptProps = async ( const parsePreviewTranscriptProps = async ( state: SessionState ): Promise => { - if (!state.previewMetadata) return + if (!state.previewMetadata) + return { + answers: [], + setVariableHistory: [], + visitedEdges: [], + } return { answers: state.previewMetadata.answers ?? [], setVariableHistory: state.previewMetadata.setVariableHistory ?? [], diff --git a/packages/logic/computeResultTranscript.ts b/packages/logic/computeResultTranscript.ts index aff2e0d30..2abf15dc8 100644 --- a/packages/logic/computeResultTranscript.ts +++ b/packages/logic/computeResultTranscript.ts @@ -131,7 +131,14 @@ const executeGroup = ({ for (const block of nextGroup?.group.blocks.slice( nextGroup.blockIndex ?? 0 )) { - if (stopAtBlockId && block.id === stopAtBlockId) return currentTranscript + if ( + stopAtBlockId && + block.id === stopAtBlockId && + answers.length === 0 && + setVariableHistory.length === 0 && + visitedEdges.length === 0 + ) + return currentTranscript if (setVariableHistory.at(0)?.blockId === block.id) typebotsQueue[0].typebot.variables = applySetVariable( setVariableHistory.shift(),