@ -0,0 +1 @@
|
||||
export { executeWait } from './utils/executeWait'
|
@ -0,0 +1,19 @@
|
||||
import { parseVariables } from '@/features/variables'
|
||||
import { LogicState } from '@/types'
|
||||
import { WaitBlock } from 'models'
|
||||
|
||||
export const executeWait = async (
|
||||
block: WaitBlock,
|
||||
{ typebot: { variables } }: LogicState
|
||||
) => {
|
||||
if (!block.options.secondsToWaitFor) return block.outgoingEdgeId
|
||||
const parsedSecondsToWaitFor = parseVariables(variables)(
|
||||
block.options.secondsToWaitFor
|
||||
)
|
||||
// @ts-expect-error isNaN can be used with strings
|
||||
if (isNaN(parsedSecondsToWaitFor)) return block.outgoingEdgeId
|
||||
await new Promise((resolve) =>
|
||||
setTimeout(resolve, parseInt(parsedSecondsToWaitFor) * 1000)
|
||||
)
|
||||
return block.outgoingEdgeId
|
||||
}
|
@ -4,6 +4,7 @@ import { executeCondition } from '@/features/blocks/logic/condition'
|
||||
import { executeRedirect } from '@/features/blocks/logic/redirect'
|
||||
import { executeSetVariable } from '@/features/blocks/logic/setVariable'
|
||||
import { executeTypebotLink } from '@/features/blocks/logic/typebotLink'
|
||||
import { executeWait } from '@/features/blocks/logic/wait'
|
||||
import { LinkedTypebot } from '@/providers/TypebotProvider'
|
||||
import { EdgeId, LogicState } from '@/types'
|
||||
import { LogicBlock, LogicBlockType } from 'models'
|
||||
@ -26,5 +27,7 @@ export const executeLogic = async (
|
||||
return { nextEdgeId: await executeCode(block, context) }
|
||||
case LogicBlockType.TYPEBOT_LINK:
|
||||
return executeTypebotLink(block, context)
|
||||
case LogicBlockType.WAIT:
|
||||
return { nextEdgeId: await executeWait(block, context) }
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user