@@ -0,0 +1,16 @@
|
||||
import { AbTestBlock, SessionState } from '@typebot.io/schemas'
|
||||
import { ExecuteLogicResponse } from '@/features/chat/types'
|
||||
|
||||
export const executeAbTest = (
|
||||
_: SessionState,
|
||||
block: AbTestBlock
|
||||
): ExecuteLogicResponse => {
|
||||
const aEdgeId = block.items[0].outgoingEdgeId
|
||||
const random = Math.random() * 100
|
||||
if (random < block.options.aPercent && aEdgeId) {
|
||||
return { outgoingEdgeId: aEdgeId }
|
||||
}
|
||||
const bEdgeId = block.items[1].outgoingEdgeId
|
||||
if (bEdgeId) return { outgoingEdgeId: bEdgeId }
|
||||
return { outgoingEdgeId: block.outgoingEdgeId }
|
||||
}
|
||||
@@ -7,6 +7,7 @@ import { executeRedirect } from '@/features/blocks/logic/redirect/executeRedirec
|
||||
import { executeCondition } from '@/features/blocks/logic/condition/executeCondition'
|
||||
import { executeSetVariable } from '@/features/blocks/logic/setVariable/executeSetVariable'
|
||||
import { executeTypebotLink } from '@/features/blocks/logic/typebotLink/executeTypebotLink'
|
||||
import { executeAbTest } from '@/features/blocks/logic/abTest/executeAbTest'
|
||||
|
||||
export const executeLogic =
|
||||
(state: SessionState, lastBubbleBlockId?: string) =>
|
||||
@@ -26,5 +27,7 @@ export const executeLogic =
|
||||
return executeWait(state, block, lastBubbleBlockId)
|
||||
case LogicBlockType.JUMP:
|
||||
return executeJumpBlock(state, block.options)
|
||||
case LogicBlockType.AB_TEST:
|
||||
return executeAbTest(state, block)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user