-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
plugin-flow-builder: bot action limit characters (#2817)
## Description When using a Bot Action node with parameters that is connected to a follow up. It is easy to exceed the character limit allowed by Telegram (64bytes = 64 characters). ## Context When connecting a BotActionNode to a button the payload will be ba|BotActionNodeUUID|source_x In the pre function of the plugin: first the |source_x is removed, then if a payload starting with ba| is detected the BotActionNode is obtained using the botActionNodeUUID and the payload is replaced by the payload plus the parameters defined in the BotActionNode. When we get to the bot routes we have the payload with the parameters. In the action we can continue using the getPayloadParams function as we did before. ## Testing Add config for jest and github action Add test for first interaction Add test for bot action node
- Loading branch information
Showing
18 changed files
with
620 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
name: Botonic plugin flow builder tests | ||
|
||
on: | ||
push: | ||
paths: | ||
- 'packages/botonic-plugin-flow-builder/**' | ||
- '.github/workflows/botonic-plugin-flow-builder-tests.yml' | ||
workflow_dispatch: | ||
|
||
jobs: | ||
botonic-react-tests: | ||
uses: ./.github/workflows/botonic-common-workflow.yml | ||
secrets: inherit #pragma: allowlist secret | ||
with: | ||
PACKAGE_NAME: Botonic plugin flow builder tests | ||
PACKAGE: botonic-plugin-flow-builder | ||
BUILD_COMMAND: 'cd ../botonic-core && npm run build && cd ../botonic-react && npm run build && cd ../botonic-plugin-flow-builder && npm run build' | ||
NEEDS_CODECOV_UPLOAD: 'yes' |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* | ||
* This babel configuration is used along with Jest for execute tests, | ||
* do not modify to avoid conflicts with webpack.config.js. | ||
*/ | ||
// require("@babel/register"); | ||
|
||
/* | ||
* This babel configuration is used along with Jest for execute tests, | ||
* do not modify to avoid conflicts with webpack.config.js. | ||
*/ | ||
|
||
module.exports = { | ||
sourceType: 'unambiguous', | ||
// .map files are not generated unless babel invoked with --source-maps | ||
sourceMaps: true, | ||
presets: ['@babel/preset-env', '@babel/preset-react'], | ||
plugins: [ | ||
require('@babel/plugin-transform-modules-commonjs'), | ||
require('@babel/plugin-transform-runtime'), | ||
], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// eslint-disable-next-line @typescript-eslint/no-var-requires | ||
const path = require('path') | ||
|
||
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */ | ||
module.exports = { | ||
roots: ['src/', 'tests/'], | ||
transform: { | ||
'^.+\\.tsx?$': [ | ||
'ts-jest', | ||
{ | ||
tsconfig: '<rootDir>/tsconfig.tests.json', | ||
}, | ||
], | ||
'^.+\\.jsx?$': [ | ||
'babel-jest', | ||
{ configFile: path.resolve(__dirname, 'babel.config.js') }, | ||
], | ||
}, | ||
preset: 'ts-jest', | ||
testRegex: '(/tests/.*|(\\.|/)(test|spec))\\.([jt]sx?)$', | ||
testPathIgnorePatterns: [ | ||
'dist', | ||
'lib', | ||
'.*.d.ts', | ||
'tests/helpers', | ||
'tests/mocks', | ||
'.*json.*', | ||
'__mocks__', | ||
], | ||
collectCoverageFrom: ['src/**/*.{js,jsx,ts,tsx}', '!/node_modules/'], | ||
transformIgnorePatterns: [ | ||
'node_modules/(?!@botonic|axios|escape-string-regexp).+\\.(js|jsx)$', | ||
], | ||
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json'], | ||
snapshotSerializers: [], | ||
setupFilesAfterEnv: [ | ||
// 'jest-expect-message', // to display a message when an assert fails | ||
// 'jest-extended', // more assertions | ||
'<rootDir>/jest.setup.js', | ||
], | ||
modulePaths: ['node_modules', 'src'], | ||
moduleNameMapper: { | ||
'\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$': | ||
'@botonic/dx/baseline/tests/__mocks__/file-mock.js', | ||
'\\.(css|less|scss|sass)$': 'identity-obj-proxy', | ||
}, | ||
testEnvironment: 'node', | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 1 addition & 7 deletions
8
packages/botonic-plugin-flow-builder/src/content-fields/hubtype-fields/button.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,9 @@ | ||
import { | ||
HtNodeLink, | ||
HtPayloadLocale, | ||
HtTextLocale, | ||
HtUrlLocale, | ||
} from './common' | ||
import { HtNodeLink, HtTextLocale, HtUrlLocale } from './common' | ||
|
||
export interface HtButton { | ||
id: string | ||
text: HtTextLocale[] | ||
url: HtUrlLocale[] | ||
payload: HtPayloadLocale[] | ||
target?: HtNodeLink | ||
hidden: string[] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
packages/botonic-plugin-flow-builder/tests/bot-action.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import { INPUT } from '@botonic/core' | ||
import { describe, test } from '@jest/globals' | ||
|
||
import { BOT_ACTION_PAYLOAD_PREFIX } from '../src/constants' | ||
import { FlowText } from '../src/index' | ||
import { ProcessEnvNodeEnvs } from '../src/types' | ||
import { testFlow } from './helpers/flows' | ||
import { | ||
createFlowBuilderPlugin, | ||
createRequest, | ||
getContentsAfterPreAndBotonicInit, | ||
} from './helpers/utils' | ||
|
||
describe('Check the contents returned by the plugin', () => { | ||
process.env.NODE_ENV = ProcessEnvNodeEnvs.PRODUCTION | ||
const flowBuilderPlugin = createFlowBuilderPlugin(testFlow) | ||
|
||
test('The starting content is displayed on the first interaction', async () => { | ||
const request = createRequest({ | ||
input: { data: 'Hola', type: INPUT.TEXT }, | ||
isFirstInteraction: true, | ||
plugins: { | ||
// @ts-ignore | ||
flowBuilderPlugin, | ||
}, | ||
}) | ||
|
||
const { contents } = await getContentsAfterPreAndBotonicInit( | ||
request, | ||
flowBuilderPlugin | ||
) | ||
|
||
expect((contents[0] as FlowText).text).toBe('Welcome message') | ||
}) | ||
}) | ||
|
||
describe('The user clicks on a button that is connected to a BotActionNode', () => { | ||
process.env.NODE_ENV = ProcessEnvNodeEnvs.PRODUCTION | ||
const flowBuilderPlugin = createFlowBuilderPlugin(testFlow) | ||
const messageUUidWithButtonConectedToBotAction = | ||
'386ba508-a3b3-49a2-94d0-5e239ba63106' | ||
const botActionUuid = '8b0c87c0-77b2-4b05-bae0-3b353240caaa' | ||
test('The button has the payload = ba|botActionUuid', async () => { | ||
const request = createRequest({ | ||
input: { | ||
type: INPUT.POSTBACK, | ||
payload: messageUUidWithButtonConectedToBotAction, | ||
}, | ||
plugins: { | ||
// @ts-ignore | ||
flowBuilderPlugin, | ||
}, | ||
}) | ||
|
||
const { contents } = await getContentsAfterPreAndBotonicInit( | ||
request, | ||
flowBuilderPlugin | ||
) | ||
|
||
const nextPaylod = (contents[0] as FlowText).buttons[0].payload | ||
expect(nextPaylod).toBe(`${BOT_ACTION_PAYLOAD_PREFIX}${botActionUuid}`) | ||
}) | ||
|
||
test('The bot routes receive the correct payload, in the custom action the payloadParmas defined in the BotActionNode are obtained', async () => { | ||
const request = createRequest({ | ||
input: { | ||
type: INPUT.POSTBACK, | ||
payload: `${BOT_ACTION_PAYLOAD_PREFIX}${botActionUuid}`, | ||
}, | ||
plugins: { | ||
// @ts-ignore | ||
flowBuilderPlugin, | ||
}, | ||
}) | ||
|
||
await flowBuilderPlugin.pre(request) | ||
expect(request.input.payload).toBe( | ||
'rating|{"value":1,"followUpContentID":"SORRY"}' | ||
) | ||
|
||
const payloadParams = flowBuilderPlugin.getPayloadParams( | ||
request.input.payload as string | ||
) | ||
expect(payloadParams).toEqual( | ||
JSON.parse('{"value":1,"followUpContentID":"SORRY"}') | ||
) | ||
}) | ||
}) |
Oops, something went wrong.