2023-06-28 09:52:03 +02:00
|
|
|
import { PixelBlock, SessionState } from '@typebot.io/schemas'
|
2023-09-20 15:26:52 +02:00
|
|
|
import { ExecuteIntegrationResponse } from '../../../types'
|
2023-12-13 10:22:02 +01:00
|
|
|
import { deepParseVariables } from '@typebot.io/variables/deepParseVariables'
|
2023-06-28 09:52:03 +02:00
|
|
|
|
|
|
|
export const executePixelBlock = (
|
2023-08-24 07:48:30 +02:00
|
|
|
state: SessionState,
|
2023-06-28 09:52:03 +02:00
|
|
|
block: PixelBlock
|
|
|
|
): ExecuteIntegrationResponse => {
|
2023-08-24 07:48:30 +02:00
|
|
|
const { typebot, resultId } = state.typebotsQueue[0]
|
2023-08-29 10:01:28 +02:00
|
|
|
if (
|
|
|
|
!resultId ||
|
2023-11-08 15:34:16 +01:00
|
|
|
!block.options?.pixelId ||
|
2023-08-29 10:01:28 +02:00
|
|
|
!block.options.eventType ||
|
|
|
|
state.whatsApp
|
|
|
|
)
|
2023-06-28 10:29:58 +02:00
|
|
|
return { outgoingEdgeId: block.outgoingEdgeId }
|
2023-08-24 07:48:30 +02:00
|
|
|
const pixel = deepParseVariables(typebot.variables, {
|
2023-06-28 09:52:03 +02:00
|
|
|
guessCorrectTypes: true,
|
|
|
|
removeEmptyStrings: true,
|
|
|
|
})(block.options)
|
|
|
|
return {
|
|
|
|
outgoingEdgeId: block.outgoingEdgeId,
|
|
|
|
clientSideActions: [
|
|
|
|
{
|
|
|
|
pixel: {
|
|
|
|
...pixel,
|
|
|
|
pixelId: block.options.pixelId,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
}
|
|
|
|
}
|