diff --git a/package-lock.json b/package-lock.json index 4774388aa..6b729c1f0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "botonic", - "version": "0.27.0", + "version": "0.30.4", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "botonic", - "version": "0.27.0", + "version": "0.30.4", "license": "MIT", "workspaces": [ "packages/*" @@ -25327,7 +25327,7 @@ }, "packages/botonic-plugin-flow-builder": { "name": "@botonic/plugin-flow-builder", - "version": "0.30.3", + "version": "0.30.4-alpha.0", "dependencies": { "@botonic/react": "^0.30.3", "axios": "^1.7.2", diff --git a/package.json b/package.json index a4228502c..86ddaca78 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "private": true, "name": "botonic", - "version": "0.27.0", + "version": "0.30.4", "scripts": { "clean": "rimraf packages/**/lib" }, diff --git a/packages/botonic-plugin-flow-builder/package.json b/packages/botonic-plugin-flow-builder/package.json index 7a06c0873..7005cef66 100644 --- a/packages/botonic-plugin-flow-builder/package.json +++ b/packages/botonic-plugin-flow-builder/package.json @@ -1,6 +1,6 @@ { "name": "@botonic/plugin-flow-builder", - "version": "0.30.3", + "version": "0.30.4-alpha.0", "main": "./lib/cjs/index.js", "module": "./lib/esm/index.js", "description": "Use Flow Builder to show your contents", diff --git a/packages/botonic-plugin-flow-builder/src/index.ts b/packages/botonic-plugin-flow-builder/src/index.ts index 744851a0f..1af336c6d 100644 --- a/packages/botonic-plugin-flow-builder/src/index.ts +++ b/packages/botonic-plugin-flow-builder/src/index.ts @@ -21,6 +21,7 @@ import { FlowWhatsappCtaUrlButtonNode, } from './content-fields' import { + HtBotActionNode, HtFlowBuilderData, HtFunctionArgument, HtFunctionArguments, @@ -108,16 +109,29 @@ export default class BotonicPluginFlowBuilder implements Plugin { this.updateRequestBeforeRoutes(request) } - private updateRequestBeforeRoutes(request: PluginPreRequest) { + private updateRequestBeforeRoutes(request: PluginPreRequest): void { if (request.input.payload) { request.input.payload = this.removeSourceSufix(request.input.payload) } + + if (request.input.payload && this.isBotAction(request.input.payload)) { + const cmsBotAction = this.cmsApi.getNodeById( + request.input.payload + ) + + request.input.payload = this.cmsApi.createPayloadWithParams(cmsBotAction) + } } private removeSourceSufix(payload: string): string { return payload.split(SOURCE_INFO_SEPARATOR)[0] } + private isBotAction(payload: string): boolean { + const node = this.cmsApi.getNodeById(payload) + return node?.type === HtNodeWithContentType.BOT_ACTION + } + async getContentsByContentID( contentID: string, locale: string, diff --git a/packages/botonic-plugin-flow-builder/tests/bot-action.test.ts b/packages/botonic-plugin-flow-builder/tests/bot-action.test.ts index 06a19508b..a324fe0bd 100644 --- a/packages/botonic-plugin-flow-builder/tests/bot-action.test.ts +++ b/packages/botonic-plugin-flow-builder/tests/bot-action.test.ts @@ -1,4 +1,4 @@ -import { BotonicAction, INPUT } from '@botonic/core' +import { INPUT } from '@botonic/core' import { describe, test } from '@jest/globals' import { FlowText } from '../src/index' @@ -7,6 +7,7 @@ import { basicFlow } from './helpers/flows/basic' import { createFlowBuilderPlugin, createFlowBuilderPluginAndGetContents, + createRequest, } from './helpers/utils' describe('The user clicks on a button that is connected to a BotActionNode', () => { @@ -33,21 +34,28 @@ describe('The user clicks on a button that is connected to a BotActionNode', () expect(nextPaylod).toBe(botActionUuid) }) - test('The request.session._botonic_action have redirect:nextPayload', async () => { - const { contents, request } = await createFlowBuilderPluginAndGetContents({ - flowBuilderOptions: { flow: basicFlow }, - requestArgs: { - input: { - type: INPUT.POSTBACK, - payload: botActionUuid, - }, + test('When the request.input.payload is a UUID of a bot action node it is replaced by the payload with parameters defined in the node', async () => { + const flowBuilderPlugin = createFlowBuilderPlugin({ + flow: basicFlow, + }) + + const requestArgs = { + input: { + type: INPUT.POSTBACK, + payload: botActionUuid, + }, + } + + const request = createRequest({ + ...requestArgs, + plugins: { + // @ts-ignore + flowBuilderPlugin, }, }) + await flowBuilderPlugin.pre(request) - expect(contents.length).toBe(1) - expect(request.session._botonic_action).toBe( - `${BotonicAction.Redirect}:${ratingPayloadWithParams}` - ) + expect(request.input.payload).toBe(ratingPayloadWithParams) }) test('In the custom action the payloadParmas defined in the BotActionNode are obtained', async () => {