2023-06-05 17:33:43 +02:00
|
|
|
import { ConditionBlock, SessionState } from '@typebot.io/schemas'
|
2023-09-20 15:26:52 +02:00
|
|
|
import { ExecuteLogicResponse } from '../../../types'
|
2024-05-15 14:24:55 +02:00
|
|
|
import { executeCondition } from '@typebot.io/logic/executeCondition'
|
2023-06-05 17:33:43 +02:00
|
|
|
export const executeConditionBlock = (
|
2023-08-24 07:48:30 +02:00
|
|
|
state: SessionState,
|
2023-06-05 17:33:43 +02:00
|
|
|
block: ConditionBlock
|
|
|
|
|
): ExecuteLogicResponse => {
|
2023-08-24 07:48:30 +02:00
|
|
|
const { variables } = state.typebotsQueue[0].typebot
|
2023-11-08 15:34:16 +01:00
|
|
|
const passedCondition = block.items.find(
|
2024-05-15 14:24:55 +02:00
|
|
|
(item) =>
|
|
|
|
|
item.content && executeCondition({ variables, condition: item.content })
|
2023-06-05 17:33:43 +02:00
|
|
|
)
|
|
|
|
|
return {
|
|
|
|
|
outgoingEdgeId: passedCondition
|
|
|
|
|
? passedCondition.outgoingEdgeId
|
|
|
|
|
: block.outgoingEdgeId,
|
|
|
|
|
}
|
|
|
|
|
}
|