🐛 (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 (
|
export const executeSetVariable = async (
|
||||||
state: SessionState,
|
state: SessionState,
|
||||||
block: SetVariableBlock
|
block: SetVariableBlock,
|
||||||
|
setVariableHistory: SetVariableHistoryItem[]
|
||||||
): Promise<ExecuteLogicResponse> => {
|
): Promise<ExecuteLogicResponse> => {
|
||||||
const { variables } = state.typebotsQueue[0].typebot
|
const { variables } = state.typebotsQueue[0].typebot
|
||||||
if (!block.options?.variableId)
|
if (!block.options?.variableId)
|
||||||
return {
|
return {
|
||||||
outgoingEdgeId: block.outgoingEdgeId,
|
outgoingEdgeId: block.outgoingEdgeId,
|
||||||
}
|
}
|
||||||
|
|
||||||
const expressionToEvaluate = await getExpressionToEvaluate(state)(
|
const expressionToEvaluate = await getExpressionToEvaluate(state)(
|
||||||
block.options,
|
block.options,
|
||||||
block.id
|
block.id,
|
||||||
|
setVariableHistory
|
||||||
)
|
)
|
||||||
const isCustomValue = !block.options.type || block.options.type === 'Custom'
|
const isCustomValue = !block.options.type || block.options.type === 'Custom'
|
||||||
const isCode =
|
const isCode =
|
||||||
@ -139,7 +142,8 @@ const getExpressionToEvaluate =
|
|||||||
(state: SessionState) =>
|
(state: SessionState) =>
|
||||||
async (
|
async (
|
||||||
options: SetVariableBlock['options'],
|
options: SetVariableBlock['options'],
|
||||||
blockId: string
|
blockId: string,
|
||||||
|
setVariableHistory: SetVariableHistoryItem[]
|
||||||
): Promise<string | null> => {
|
): Promise<string | null> => {
|
||||||
switch (options?.type) {
|
switch (options?.type) {
|
||||||
case 'Contact name':
|
case 'Contact name':
|
||||||
@ -227,6 +231,8 @@ const getExpressionToEvaluate =
|
|||||||
typebot: typebotWithEmptyVariables,
|
typebot: typebotWithEmptyVariables,
|
||||||
stopAtBlockId: blockId,
|
stopAtBlockId: blockId,
|
||||||
...props,
|
...props,
|
||||||
|
setVariableHistory:
|
||||||
|
props.setVariableHistory.concat(setVariableHistory),
|
||||||
})
|
})
|
||||||
return (
|
return (
|
||||||
'return `' +
|
'return `' +
|
||||||
|
@ -6,7 +6,7 @@ import {
|
|||||||
SessionState,
|
SessionState,
|
||||||
SetVariableHistoryItem,
|
SetVariableHistoryItem,
|
||||||
} from '@typebot.io/schemas'
|
} from '@typebot.io/schemas'
|
||||||
import { isEmpty, isNotEmpty } from '@typebot.io/lib'
|
import { isNotEmpty } from '@typebot.io/lib'
|
||||||
import {
|
import {
|
||||||
isBubbleBlock,
|
isBubbleBlock,
|
||||||
isInputBlock,
|
isInputBlock,
|
||||||
@ -139,7 +139,7 @@ export const executeGroup = async (
|
|||||||
}
|
}
|
||||||
const executionResponse = (
|
const executionResponse = (
|
||||||
isLogicBlock(block)
|
isLogicBlock(block)
|
||||||
? await executeLogic(newSessionState)(block)
|
? await executeLogic(newSessionState)(block, setVariableHistory)
|
||||||
: isIntegrationBlock(block)
|
: isIntegrationBlock(block)
|
||||||
? await executeIntegration(newSessionState)(block)
|
? await executeIntegration(newSessionState)(block)
|
||||||
: null
|
: null
|
||||||
|
@ -1,5 +1,9 @@
|
|||||||
import { executeWait } from './blocks/logic/wait/executeWait'
|
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 { ExecuteLogicResponse } from './types'
|
||||||
import { executeScript } from './blocks/logic/script/executeScript'
|
import { executeScript } from './blocks/logic/script/executeScript'
|
||||||
import { executeJumpBlock } from './blocks/logic/jump/executeJumpBlock'
|
import { executeJumpBlock } from './blocks/logic/jump/executeJumpBlock'
|
||||||
@ -12,10 +16,13 @@ import { LogicBlockType } from '@typebot.io/schemas/features/blocks/logic/consta
|
|||||||
|
|
||||||
export const executeLogic =
|
export const executeLogic =
|
||||||
(state: SessionState) =>
|
(state: SessionState) =>
|
||||||
async (block: LogicBlock): Promise<ExecuteLogicResponse> => {
|
async (
|
||||||
|
block: LogicBlock,
|
||||||
|
setVariableHistory: SetVariableHistoryItem[]
|
||||||
|
): Promise<ExecuteLogicResponse> => {
|
||||||
switch (block.type) {
|
switch (block.type) {
|
||||||
case LogicBlockType.SET_VARIABLE:
|
case LogicBlockType.SET_VARIABLE:
|
||||||
return executeSetVariable(state, block)
|
return executeSetVariable(state, block, setVariableHistory)
|
||||||
case LogicBlockType.CONDITION:
|
case LogicBlockType.CONDITION:
|
||||||
return executeConditionBlock(state, block)
|
return executeConditionBlock(state, block)
|
||||||
case LogicBlockType.REDIRECT:
|
case LogicBlockType.REDIRECT:
|
||||||
|
@ -73,8 +73,8 @@ export const computeResultTranscript = ({
|
|||||||
typebotsQueue: [{ typebot }],
|
typebotsQueue: [{ typebot }],
|
||||||
nextGroup: firstGroup,
|
nextGroup: firstGroup,
|
||||||
currentTranscript: [],
|
currentTranscript: [],
|
||||||
answers,
|
answers: [...answers],
|
||||||
setVariableHistory,
|
setVariableHistory: [...setVariableHistory],
|
||||||
visitedEdges,
|
visitedEdges,
|
||||||
stopAtBlockId,
|
stopAtBlockId,
|
||||||
})
|
})
|
||||||
|
Reference in New Issue
Block a user