diff --git a/packages/bot-engine/blocks/logic/setVariable/executeSetVariable.ts b/packages/bot-engine/blocks/logic/setVariable/executeSetVariable.ts index 560b4ec36..5963c3c53 100644 --- a/packages/bot-engine/blocks/logic/setVariable/executeSetVariable.ts +++ b/packages/bot-engine/blocks/logic/setVariable/executeSetVariable.ts @@ -27,16 +27,19 @@ import { stringifyError } from '@typebot.io/lib/stringifyError' export const executeSetVariable = async ( state: SessionState, - block: SetVariableBlock + block: SetVariableBlock, + setVariableHistory: SetVariableHistoryItem[] ): Promise => { const { variables } = state.typebotsQueue[0].typebot if (!block.options?.variableId) return { outgoingEdgeId: block.outgoingEdgeId, } + const expressionToEvaluate = await getExpressionToEvaluate(state)( block.options, - block.id + block.id, + setVariableHistory ) const isCustomValue = !block.options.type || block.options.type === 'Custom' const isCode = @@ -139,7 +142,8 @@ const getExpressionToEvaluate = (state: SessionState) => async ( options: SetVariableBlock['options'], - blockId: string + blockId: string, + setVariableHistory: SetVariableHistoryItem[] ): Promise => { switch (options?.type) { case 'Contact name': @@ -227,6 +231,8 @@ const getExpressionToEvaluate = typebot: typebotWithEmptyVariables, stopAtBlockId: blockId, ...props, + setVariableHistory: + props.setVariableHistory.concat(setVariableHistory), }) return ( 'return `' + diff --git a/packages/bot-engine/executeGroup.ts b/packages/bot-engine/executeGroup.ts index 0ba6c1423..b86a37814 100644 --- a/packages/bot-engine/executeGroup.ts +++ b/packages/bot-engine/executeGroup.ts @@ -6,7 +6,7 @@ import { SessionState, SetVariableHistoryItem, } from '@typebot.io/schemas' -import { isEmpty, isNotEmpty } from '@typebot.io/lib' +import { isNotEmpty } from '@typebot.io/lib' import { isBubbleBlock, isInputBlock, @@ -139,7 +139,7 @@ export const executeGroup = async ( } const executionResponse = ( isLogicBlock(block) - ? await executeLogic(newSessionState)(block) + ? await executeLogic(newSessionState)(block, setVariableHistory) : isIntegrationBlock(block) ? await executeIntegration(newSessionState)(block) : null diff --git a/packages/bot-engine/executeLogic.ts b/packages/bot-engine/executeLogic.ts index 5cb1b1d21..dc2643b5b 100644 --- a/packages/bot-engine/executeLogic.ts +++ b/packages/bot-engine/executeLogic.ts @@ -1,5 +1,9 @@ import { executeWait } from './blocks/logic/wait/executeWait' -import { LogicBlock, SessionState } from '@typebot.io/schemas' +import { + LogicBlock, + SessionState, + SetVariableHistoryItem, +} from '@typebot.io/schemas' import { ExecuteLogicResponse } from './types' import { executeScript } from './blocks/logic/script/executeScript' import { executeJumpBlock } from './blocks/logic/jump/executeJumpBlock' @@ -12,10 +16,13 @@ import { LogicBlockType } from '@typebot.io/schemas/features/blocks/logic/consta export const executeLogic = (state: SessionState) => - async (block: LogicBlock): Promise => { + async ( + block: LogicBlock, + setVariableHistory: SetVariableHistoryItem[] + ): Promise => { switch (block.type) { case LogicBlockType.SET_VARIABLE: - return executeSetVariable(state, block) + return executeSetVariable(state, block, setVariableHistory) case LogicBlockType.CONDITION: return executeConditionBlock(state, block) case LogicBlockType.REDIRECT: diff --git a/packages/logic/computeResultTranscript.ts b/packages/logic/computeResultTranscript.ts index 40f47b6eb..8d7177f64 100644 --- a/packages/logic/computeResultTranscript.ts +++ b/packages/logic/computeResultTranscript.ts @@ -73,8 +73,8 @@ export const computeResultTranscript = ({ typebotsQueue: [{ typebot }], nextGroup: firstGroup, currentTranscript: [], - answers, - setVariableHistory, + answers: [...answers], + setVariableHistory: [...setVariableHistory], visitedEdges, stopAtBlockId, })