2
0

Add Wait block

Closes #142
This commit is contained in:
Baptiste Arnaud
2023-01-26 18:23:09 +01:00
parent ee864d9729
commit fa9e4b7b67
29 changed files with 621 additions and 313 deletions

View File

@ -0,0 +1,22 @@
import { ExecuteLogicResponse } from '@/features/chat'
import { parseVariables } from '@/features/variables'
import { SessionState, WaitBlock } from 'models'
export const executeWait = async (
{ typebot: { variables } }: SessionState,
block: WaitBlock
): Promise<ExecuteLogicResponse> => {
if (!block.options.secondsToWaitFor)
return { outgoingEdgeId: block.outgoingEdgeId }
const parsedSecondsToWaitFor = parseVariables(variables)(
block.options.secondsToWaitFor
)
return {
outgoingEdgeId: block.outgoingEdgeId,
// @ts-expect-error isNaN can be used with strings
clientSideActions: isNaN(parsedSecondsToWaitFor)
? undefined
: [{ wait: { secondsToWaitFor: parsedSecondsToWaitFor } }],
}
}

View File

@ -3,6 +3,7 @@ import { executeCondition } from '@/features/blocks/logic/condition/api'
import { executeRedirect } from '@/features/blocks/logic/redirect/api'
import { executeSetVariable } from '@/features/blocks/logic/setVariable/api'
import { executeTypebotLink } from '@/features/blocks/logic/typebotLink/api'
import { executeWait } from '@/features/blocks/logic/wait/api/utils/executeWait'
import { LogicBlock, LogicBlockType, SessionState } from 'models'
import { ExecuteLogicResponse } from '../../types'
@ -20,5 +21,7 @@ export const executeLogic =
return executeCode(state, block)
case LogicBlockType.TYPEBOT_LINK:
return executeTypebotLink(state, block)
case LogicBlockType.WAIT:
return executeWait(state, block)
}
}