From 67bcd0729aecc0479c5a7e7636291c94173eb876 Mon Sep 17 00:00:00 2001 From: Oriol Raventos Date: Mon, 4 Nov 2024 13:55:48 +0100 Subject: [PATCH 1/6] refactor(botonic-react): replace bot action id for payload with params in pre function --- .../botonic-plugin-flow-builder/src/index.ts | 16 +++++++++- .../tests/bot-action.test.ts | 32 ++++++++++++------- 2 files changed, 35 insertions(+), 13 deletions(-) diff --git a/packages/botonic-plugin-flow-builder/src/index.ts b/packages/botonic-plugin-flow-builder/src/index.ts index 744851a0f0..cb85bae93c 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 botActionNode = this.cmsApi.getNodeById(payload) + return botActionNode?.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 06a19508b6..3b841ab6ec 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', () => { @@ -34,20 +35,27 @@ describe('The user clicks on a button that is connected to a BotActionNode', () }) 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, - }, + 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 () => { From bb90422a480f36dbbfb76d23df648690436d299d Mon Sep 17 00:00:00 2001 From: Oriol Raventos Date: Mon, 4 Nov 2024 13:59:09 +0100 Subject: [PATCH 2/6] refactor(botonic-react): change text of test --- packages/botonic-plugin-flow-builder/tests/bot-action.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 3b841ab6ec..bf4736f2be 100644 --- a/packages/botonic-plugin-flow-builder/tests/bot-action.test.ts +++ b/packages/botonic-plugin-flow-builder/tests/bot-action.test.ts @@ -34,7 +34,7 @@ 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 () => { + test('The request.input.payload after execute pre function of the plugin is nextPayload with params', async () => { const flowBuilderPlugin = createFlowBuilderPlugin({ flow: basicFlow, }) From 8bc02ec712ac1c5e370e1323b0fea92a7a3d50ad Mon Sep 17 00:00:00 2001 From: Oriol Raventos Date: Mon, 4 Nov 2024 15:18:13 +0100 Subject: [PATCH 3/6] 0.30.4 --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 4774388aa0..95e7eb1273 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/*" diff --git a/package.json b/package.json index a4228502cf..86ddaca784 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" }, From 4491712488cfd472e69ff5f2ae2b18c1816cb3c2 Mon Sep 17 00:00:00 2001 From: Oriol Raventos Date: Mon, 4 Nov 2024 15:43:18 +0100 Subject: [PATCH 4/6] chore(plugin-flow-builder): publish 0.30.4-alpha.0 --- package-lock.json | 2 +- packages/botonic-plugin-flow-builder/package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index 95e7eb1273..6b729c1f0f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -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/packages/botonic-plugin-flow-builder/package.json b/packages/botonic-plugin-flow-builder/package.json index 7a06c0873a..7005cef66f 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", From 0f3aec2f34adfba478c85709c9f791f0b9001ba2 Mon Sep 17 00:00:00 2001 From: Oriol Raventos Date: Mon, 11 Nov 2024 10:27:04 +0100 Subject: [PATCH 5/6] refactor(plugin-flow-builder): rename variable to node --- packages/botonic-plugin-flow-builder/src/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/botonic-plugin-flow-builder/src/index.ts b/packages/botonic-plugin-flow-builder/src/index.ts index cb85bae93c..1af336c6d5 100644 --- a/packages/botonic-plugin-flow-builder/src/index.ts +++ b/packages/botonic-plugin-flow-builder/src/index.ts @@ -128,8 +128,8 @@ export default class BotonicPluginFlowBuilder implements Plugin { } private isBotAction(payload: string): boolean { - const botActionNode = this.cmsApi.getNodeById(payload) - return botActionNode?.type === HtNodeWithContentType.BOT_ACTION + const node = this.cmsApi.getNodeById(payload) + return node?.type === HtNodeWithContentType.BOT_ACTION } async getContentsByContentID( From b88b38e6564eef51c2eda69eff6c77504ebb0d4e Mon Sep 17 00:00:00 2001 From: Oriol Raventos Date: Mon, 11 Nov 2024 10:31:20 +0100 Subject: [PATCH 6/6] refactor(plugin-flow-builder): change test description --- packages/botonic-plugin-flow-builder/tests/bot-action.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 bf4736f2be..a324fe0bd0 100644 --- a/packages/botonic-plugin-flow-builder/tests/bot-action.test.ts +++ b/packages/botonic-plugin-flow-builder/tests/bot-action.test.ts @@ -34,7 +34,7 @@ describe('The user clicks on a button that is connected to a BotActionNode', () expect(nextPaylod).toBe(botActionUuid) }) - test('The request.input.payload after execute pre function of the plugin is nextPayload with params', async () => { + 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, })