2
0

Add AB test block

Closes #449
This commit is contained in:
Baptiste Arnaud
2023-04-17 16:47:17 +02:00
parent b416c6e373
commit 7e937e1c7c
28 changed files with 443 additions and 21 deletions

View File

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

View File

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