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'
|
2023-06-05 17:33:43 +02:00
|
|
|
import { executeCondition } from './executeCondition'
|
|
|
|
|
|
|
|
|
|
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-06-05 17:33:43 +02:00
|
|
|
const passedCondition = block.items.find((item) =>
|
|
|
|
|
executeCondition(variables)(item.content)
|
|
|
|
|
)
|
|
|
|
|
return {
|
|
|
|
|
outgoingEdgeId: passedCondition
|
|
|
|
|
? passedCondition.outgoingEdgeId
|
|
|
|
|
: block.outgoingEdgeId,
|
|
|
|
|
}
|
|
|
|
|
}
|