🐛 (transcript) Fix shift answers is not immutable
This commit is contained in:
@ -27,16 +27,19 @@ import { stringifyError } from '@typebot.io/lib/stringifyError'
|
||||
|
||||
export const executeSetVariable = async (
|
||||
state: SessionState,
|
||||
block: SetVariableBlock
|
||||
block: SetVariableBlock,
|
||||
setVariableHistory: SetVariableHistoryItem[]
|
||||
): Promise<ExecuteLogicResponse> => {
|
||||
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<string | null> => {
|
||||
switch (options?.type) {
|
||||
case 'Contact name':
|
||||
@ -227,6 +231,8 @@ const getExpressionToEvaluate =
|
||||
typebot: typebotWithEmptyVariables,
|
||||
stopAtBlockId: blockId,
|
||||
...props,
|
||||
setVariableHistory:
|
||||
props.setVariableHistory.concat(setVariableHistory),
|
||||
})
|
||||
return (
|
||||
'return `' +
|
||||
|
@ -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
|
||||
|
@ -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<ExecuteLogicResponse> => {
|
||||
async (
|
||||
block: LogicBlock,
|
||||
setVariableHistory: SetVariableHistoryItem[]
|
||||
): Promise<ExecuteLogicResponse> => {
|
||||
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:
|
||||
|
@ -73,8 +73,8 @@ export const computeResultTranscript = ({
|
||||
typebotsQueue: [{ typebot }],
|
||||
nextGroup: firstGroup,
|
||||
currentTranscript: [],
|
||||
answers,
|
||||
setVariableHistory,
|
||||
answers: [...answers],
|
||||
setVariableHistory: [...setVariableHistory],
|
||||
visitedEdges,
|
||||
stopAtBlockId,
|
||||
})
|
||||
|
Reference in New Issue
Block a user