2023-09-20 15:26:52 +02:00
|
|
|
import { executeWait } from './blocks/logic/wait/executeWait'
|
2024-08-13 16:01:22 +02:00
|
|
|
import {
|
|
|
|
LogicBlock,
|
|
|
|
SessionState,
|
|
|
|
SetVariableHistoryItem,
|
|
|
|
} from '@typebot.io/schemas'
|
2023-09-20 15:26:52 +02:00
|
|
|
import { ExecuteLogicResponse } from './types'
|
|
|
|
import { executeScript } from './blocks/logic/script/executeScript'
|
|
|
|
import { executeJumpBlock } from './blocks/logic/jump/executeJumpBlock'
|
|
|
|
import { executeRedirect } from './blocks/logic/redirect/executeRedirect'
|
|
|
|
import { executeConditionBlock } from './blocks/logic/condition/executeConditionBlock'
|
|
|
|
import { executeSetVariable } from './blocks/logic/setVariable/executeSetVariable'
|
|
|
|
import { executeTypebotLink } from './blocks/logic/typebotLink/executeTypebotLink'
|
|
|
|
import { executeAbTest } from './blocks/logic/abTest/executeAbTest'
|
2023-11-08 15:34:16 +01:00
|
|
|
import { LogicBlockType } from '@typebot.io/schemas/features/blocks/logic/constants'
|
2022-11-29 10:02:40 +01:00
|
|
|
|
|
|
|
export const executeLogic =
|
2023-05-26 09:20:22 +02:00
|
|
|
(state: SessionState) =>
|
2024-08-13 16:01:22 +02:00
|
|
|
async (
|
|
|
|
block: LogicBlock,
|
|
|
|
setVariableHistory: SetVariableHistoryItem[]
|
|
|
|
): Promise<ExecuteLogicResponse> => {
|
2022-11-29 10:02:40 +01:00
|
|
|
switch (block.type) {
|
|
|
|
case LogicBlockType.SET_VARIABLE:
|
2024-08-13 16:01:22 +02:00
|
|
|
return executeSetVariable(state, block, setVariableHistory)
|
2022-11-29 10:02:40 +01:00
|
|
|
case LogicBlockType.CONDITION:
|
2023-06-05 17:33:43 +02:00
|
|
|
return executeConditionBlock(state, block)
|
2022-11-29 10:02:40 +01:00
|
|
|
case LogicBlockType.REDIRECT:
|
2023-05-26 09:20:22 +02:00
|
|
|
return executeRedirect(state, block)
|
2023-01-27 15:58:05 +01:00
|
|
|
case LogicBlockType.SCRIPT:
|
2023-05-26 09:20:22 +02:00
|
|
|
return executeScript(state, block)
|
2022-11-29 10:02:40 +01:00
|
|
|
case LogicBlockType.TYPEBOT_LINK:
|
|
|
|
return executeTypebotLink(state, block)
|
2023-01-26 18:23:09 +01:00
|
|
|
case LogicBlockType.WAIT:
|
2023-05-26 09:20:22 +02:00
|
|
|
return executeWait(state, block)
|
2023-03-03 15:03:31 +01:00
|
|
|
case LogicBlockType.JUMP:
|
|
|
|
return executeJumpBlock(state, block.options)
|
2023-04-17 16:47:17 +02:00
|
|
|
case LogicBlockType.AB_TEST:
|
|
|
|
return executeAbTest(state, block)
|
2022-11-29 10:02:40 +01:00
|
|
|
}
|
|
|
|
}
|