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 @@
export { executeWait } from './utils/executeWait'

View File

@ -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
}

View File

@ -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) }
}
}