2023-01-26 15:26:42 +01:00
|
|
|
import { executeChatwoot } from '@/features/blocks/integrations/chatwoot'
|
|
|
|
|
import { executeGoogleAnalyticsBlock } from '@/features/blocks/integrations/googleAnalytics/utils/executeGoogleAnalytics'
|
|
|
|
|
import { executeRedirect } from '@/features/blocks/logic/redirect'
|
2023-01-27 15:58:05 +01:00
|
|
|
import { executeScript } from '@/features/blocks/logic/script/executeScript'
|
2023-01-26 18:23:09 +01:00
|
|
|
import { executeWait } from '@/features/blocks/logic/wait/utils/executeWait'
|
2023-03-15 08:35:16 +01:00
|
|
|
import type { ChatReply } from '@typebot.io/schemas'
|
2023-01-26 15:26:42 +01:00
|
|
|
|
|
|
|
|
export const executeClientSideAction = async (
|
|
|
|
|
clientSideAction: NonNullable<ChatReply['clientSideActions']>[0]
|
2023-02-20 08:36:48 +01:00
|
|
|
): Promise<{ blockedPopupUrl: string } | void> => {
|
2023-01-26 15:26:42 +01:00
|
|
|
if ('chatwoot' in clientSideAction) {
|
2023-02-20 08:36:48 +01:00
|
|
|
return executeChatwoot(clientSideAction.chatwoot)
|
2023-01-26 15:26:42 +01:00
|
|
|
}
|
|
|
|
|
if ('googleAnalytics' in clientSideAction) {
|
2023-02-20 08:36:48 +01:00
|
|
|
return executeGoogleAnalyticsBlock(clientSideAction.googleAnalytics)
|
2023-01-26 15:26:42 +01:00
|
|
|
}
|
2023-01-27 15:58:05 +01:00
|
|
|
if ('scriptToExecute' in clientSideAction) {
|
2023-02-20 08:36:48 +01:00
|
|
|
return executeScript(clientSideAction.scriptToExecute)
|
2023-01-26 15:26:42 +01:00
|
|
|
}
|
|
|
|
|
if ('redirect' in clientSideAction) {
|
2023-02-20 08:36:48 +01:00
|
|
|
return executeRedirect(clientSideAction.redirect)
|
2023-01-26 15:26:42 +01:00
|
|
|
}
|
2023-01-26 18:23:09 +01:00
|
|
|
if ('wait' in clientSideAction) {
|
2023-02-20 08:36:48 +01:00
|
|
|
return executeWait(clientSideAction.wait)
|
2023-01-26 18:23:09 +01:00
|
|
|
}
|
2023-01-26 15:26:42 +01:00
|
|
|
}
|