⚡ Improve new bot engine client side actions
We make sure to save client side actions in an array that will be executed sequentially
This commit is contained in:
22
packages/js/src/utils/executeClientSideActions.ts
Normal file
22
packages/js/src/utils/executeClientSideActions.ts
Normal file
@ -0,0 +1,22 @@
|
||||
import { executeChatwoot } from '@/features/blocks/integrations/chatwoot'
|
||||
import { executeGoogleAnalyticsBlock } from '@/features/blocks/integrations/googleAnalytics/utils/executeGoogleAnalytics'
|
||||
import { executeCode } from '@/features/blocks/logic/code'
|
||||
import { executeRedirect } from '@/features/blocks/logic/redirect'
|
||||
import type { ChatReply } from 'models'
|
||||
|
||||
export const executeClientSideAction = async (
|
||||
clientSideAction: NonNullable<ChatReply['clientSideActions']>[0]
|
||||
) => {
|
||||
if ('chatwoot' in clientSideAction) {
|
||||
executeChatwoot(clientSideAction.chatwoot)
|
||||
}
|
||||
if ('googleAnalytics' in clientSideAction) {
|
||||
executeGoogleAnalyticsBlock(clientSideAction.googleAnalytics)
|
||||
}
|
||||
if ('codeToExecute' in clientSideAction) {
|
||||
await executeCode(clientSideAction.codeToExecute)
|
||||
}
|
||||
if ('redirect' in clientSideAction) {
|
||||
executeRedirect(clientSideAction.redirect)
|
||||
}
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
import { executeChatwoot } from '@/features/blocks/integrations/chatwoot'
|
||||
import { executeGoogleAnalyticsBlock } from '@/features/blocks/integrations/googleAnalytics/utils/executeGoogleAnalytics'
|
||||
import type { ChatReply } from 'models'
|
||||
|
||||
export const executeIntegrations = async (
|
||||
integrations: ChatReply['integrations']
|
||||
) => {
|
||||
if (integrations?.chatwoot?.codeToExecute) {
|
||||
executeChatwoot(integrations.chatwoot)
|
||||
}
|
||||
if (integrations?.googleAnalytics) {
|
||||
executeGoogleAnalyticsBlock(integrations.googleAnalytics)
|
||||
}
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
import { executeCode } from '@/features/blocks/logic/code'
|
||||
import { executeRedirect } from '@/features/blocks/logic/redirect'
|
||||
import type { ChatReply } from 'models'
|
||||
|
||||
export const executeLogic = async (logic: ChatReply['logic']) => {
|
||||
if (logic?.codeToExecute) {
|
||||
await executeCode(logic.codeToExecute)
|
||||
}
|
||||
if (logic?.redirect) {
|
||||
executeRedirect(logic.redirect)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user