diff --git a/packages/botonic-plugin-flow-builder/src/api.ts b/packages/botonic-plugin-flow-builder/src/api.ts index 782de397d0..90922845e5 100644 --- a/packages/botonic-plugin-flow-builder/src/api.ts +++ b/packages/botonic-plugin-flow-builder/src/api.ts @@ -2,7 +2,7 @@ import { Input, PluginPreRequest } from '@botonic/core' import axios from 'axios' import { - BOT_ACTION_PAYLOAD_SEPARATOR, + BOT_ACTION_PAYLOAD_PREFIX, REG_EXP_PATTERN, SEPARATOR, } from './constants' @@ -213,7 +213,7 @@ export class FlowBuilderApi { } if (target.type === HtNodeWithoutContentType.BOT_ACTION) { - return `${BOT_ACTION_PAYLOAD_SEPARATOR}${target.id}` + return `${BOT_ACTION_PAYLOAD_PREFIX}${target.id}` } return target.id diff --git a/packages/botonic-plugin-flow-builder/src/constants.ts b/packages/botonic-plugin-flow-builder/src/constants.ts index d5a33f585d..18c4b14b57 100644 --- a/packages/botonic-plugin-flow-builder/src/constants.ts +++ b/packages/botonic-plugin-flow-builder/src/constants.ts @@ -2,7 +2,7 @@ export const FLOW_BUILDER_API_URL_PROD = 'https://api.ent0.flowbuilder.prod.hubtype.com' export const SEPARATOR = '|' export const SOURCE_INFO_SEPARATOR = `${SEPARATOR}source_` -export const BOT_ACTION_PAYLOAD_SEPARATOR = `ba${SEPARATOR}` +export const BOT_ACTION_PAYLOAD_PREFIX = `ba${SEPARATOR}` export const VARIABLE_PATTERN = /{([^}]+)}/g export const ACCESS_TOKEN_VARIABLE_KEY = '_access_token' export const REG_EXP_PATTERN = /^\/(.*)\/([gimyus]*)$/ diff --git a/packages/botonic-plugin-flow-builder/src/index.ts b/packages/botonic-plugin-flow-builder/src/index.ts index 0b09a07c6f..89a2e257ca 100644 --- a/packages/botonic-plugin-flow-builder/src/index.ts +++ b/packages/botonic-plugin-flow-builder/src/index.ts @@ -3,7 +3,7 @@ import { ActionRequest } from '@botonic/react' import { FlowBuilderApi } from './api' import { - BOT_ACTION_PAYLOAD_SEPARATOR, + BOT_ACTION_PAYLOAD_PREFIX, FLOW_BUILDER_API_URL_PROD, SEPARATOR, SOURCE_INFO_SEPARATOR, @@ -101,22 +101,23 @@ export default class BotonicPluginFlowBuilder implements Plugin { request.input.payload = this.removeSourceSeparatorFromPayload( request.input.payload ) - request.input.payload = this.updateBotActionPayload(request.input.payload) + + if (request.input.payload.startsWith(BOT_ACTION_PAYLOAD_PREFIX)) { + request.input.payload = this.updateBotActionPayload( + request.input.payload + ) + } } } private removeSourceSeparatorFromPayload(payload: string): string { - return payload?.split(SOURCE_INFO_SEPARATOR)[0] + return payload.split(SOURCE_INFO_SEPARATOR)[0] } private updateBotActionPayload(payload: string): string { - if (payload.startsWith(BOT_ACTION_PAYLOAD_SEPARATOR)) { - const botActionId = payload.split(SEPARATOR)[1] - const botActionNode = - this.cmsApi.getNodeById(botActionId) - return this.cmsApi.createPayloadWithParams(botActionNode) - } - return payload + const botActionId = payload.split(SEPARATOR)[1] + const botActionNode = this.cmsApi.getNodeById(botActionId) + return this.cmsApi.createPayloadWithParams(botActionNode) } async getContentsByContentID(