2
0
Files
bot/apps/viewer/src/features/blocks/logic/wait/executeWait.ts

32 lines
923 B
TypeScript
Raw Normal View History

import { ExecuteLogicResponse } from '@/features/chat/types'
import { parseVariables } from '@/features/variables/parseVariables'
import { SessionState, WaitBlock } from '@typebot.io/schemas'
2023-01-26 18:23:09 +01:00
export const executeWait = (
state: SessionState,
block: WaitBlock
): ExecuteLogicResponse => {
const { variables } = state.typebotsQueue[0].typebot
2023-01-26 18:23:09 +01:00
if (!block.options.secondsToWaitFor)
return { outgoingEdgeId: block.outgoingEdgeId }
const parsedSecondsToWaitFor = safeParseInt(
parseVariables(variables)(block.options.secondsToWaitFor)
2023-01-26 18:23:09 +01:00
)
return {
outgoingEdgeId: block.outgoingEdgeId,
clientSideActions: parsedSecondsToWaitFor
? [
{
wait: { secondsToWaitFor: parsedSecondsToWaitFor },
},
]
: undefined,
2023-01-26 18:23:09 +01:00
}
}
const safeParseInt = (value: string) => {
const parsedValue = parseInt(value)
return isNaN(parsedValue) ? undefined : parsedValue
}