Skip to content

Commit 1cfd9fa

Browse files
authored
feat(plugin-flow-builder): always adds match contents with some nlu (#3018)
## Description plugin-flow-builder always adds match contents with some nlu when bot pass from conversation start node. Until now it only added contents of a match with NLU when it was the first interaction. ## Tests Update basicFlow, now smart intents titles are in snake_case. Add a test to check that executeConversationStart always add match of keywords or smart intents in all interactions.
1 parent 78cebc1 commit 1cfd9fa

File tree

9 files changed

+320
-129
lines changed

9 files changed

+320
-129
lines changed

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/botonic-plugin-flow-builder/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ All notable changes to Botonic will be documented in this file.
2020

2121
</details>
2222

23+
## [0.35.1] - 2025-05-13
24+
25+
### Changed
26+
27+
- [PR-3018](https://github.com/hubtype/botonic/pull/3018): FlowBuilder.executeConversationStart always add match with keywords or smart-intent.
28+
2329
## [0.35.0] - 2025-05-06
2430

2531
### Added

packages/botonic-plugin-flow-builder/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@botonic/plugin-flow-builder",
3-
"version": "0.35.0",
3+
"version": "0.35.1",
44
"main": "./lib/cjs/index.js",
55
"module": "./lib/esm/index.js",
66
"description": "Use Flow Builder to show your contents",

packages/botonic-plugin-flow-builder/src/action/index.tsx

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,10 @@ export class FlowBuilderAction extends React.Component<FlowBuilderActionProps> {
2727
): Promise<FlowBuilderActionProps> {
2828
const context = getContext(request)
2929
const contents = await getContentsByFirstInteraction(context)
30-
const contentID = contents[0]?.code
31-
return await FlowBuilderAction.botonicInit(request, contentID)
30+
await trackFlowContent(request, contents)
31+
await FlowBuilderAction.doHandoffAndBotActions(request, contents)
32+
33+
return { contents }
3234
}
3335

3436
static async botonicInit(
@@ -37,7 +39,15 @@ export class FlowBuilderAction extends React.Component<FlowBuilderActionProps> {
3739
): Promise<FlowBuilderActionProps> {
3840
const contents = await getContents(request, contentID)
3941
await trackFlowContent(request, contents)
42+
await FlowBuilderAction.doHandoffAndBotActions(request, contents)
4043

44+
return { contents }
45+
}
46+
47+
private static async doHandoffAndBotActions(
48+
request: ActionRequest,
49+
contents: FlowContent[]
50+
) {
4151
const handoffContent = contents.find(
4252
content => content instanceof FlowHandoff
4353
) as FlowHandoff
@@ -51,8 +61,6 @@ export class FlowBuilderAction extends React.Component<FlowBuilderActionProps> {
5161
if (botActionContent) {
5262
botActionContent.doBotAction(request)
5363
}
54-
55-
return { contents }
5664
}
5765

5866
render(): JSX.Element | JSX.Element[] {
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import { INPUT, InputType } from '@botonic/core'
2+
import { describe, test } from '@jest/globals'
3+
4+
import { FlowBuilderAction, FlowText } from '../src'
5+
import { ProcessEnvNodeEnvs } from '../src/types'
6+
// eslint-disable-next-line jest/no-mocks-import
7+
import { mockSmartIntent } from './__mocks__/smart-intent'
8+
import { basicFlow } from './helpers/flows/basic'
9+
import {
10+
createFlowBuilderPlugin,
11+
createRequest,
12+
getActionRequest,
13+
} from './helpers/utils'
14+
15+
describe('FlowBuilderAction.executeConversationStart', () => {
16+
process.env.NODE_ENV = ProcessEnvNodeEnvs.PRODUCTION
17+
18+
beforeEach(() => mockSmartIntent('add_a_bag'))
19+
20+
test.each([
21+
{
22+
firstMessage: 'Welcome message',
23+
isFirstInteraction: true,
24+
},
25+
{
26+
firstMessage: 'Welcome back',
27+
isFirstInteraction: false,
28+
},
29+
])(
30+
'executeConversationStart adds match of keywords or smart intents after contents connected to start node in all interactions',
31+
async ({ firstMessage, isFirstInteraction }) => {
32+
const flowBuilderPlugin = createFlowBuilderPlugin({ flow: basicFlow })
33+
const requestArgs = {
34+
input: { data: 'Hello', type: INPUT.TEXT as InputType },
35+
isFirstInteraction,
36+
}
37+
const request = createRequest({
38+
...requestArgs,
39+
plugins: {
40+
// @ts-ignore
41+
flowBuilderPlugin,
42+
},
43+
})
44+
await flowBuilderPlugin.pre(request)
45+
const actionRequest = getActionRequest(request)
46+
const { contents } =
47+
await FlowBuilderAction.executeConversationStart(actionRequest)
48+
49+
expect((contents[0] as FlowText).text).toBe(firstMessage)
50+
expect(contents.length).toBe(3)
51+
expect((contents[2] as FlowText).text).toBe(
52+
'Message explaining how to add a bag'
53+
)
54+
}
55+
)
56+
})

packages/botonic-plugin-flow-builder/tests/first-interaction.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ describe('Check the contents returned by the plugin in first interaction', () =>
5959
describe('Check the contents returned by the plugin in first interaction with smart intent', () => {
6060
process.env.NODE_ENV = ProcessEnvNodeEnvs.PRODUCTION
6161

62-
beforeEach(() => mockSmartIntent('add a bag'))
62+
beforeEach(() => mockSmartIntent('add_a_bag'))
6363

6464
test('The start contents are displayed followed by more contents obtained by matching a smart-intent', async () => {
6565
const { contents } = await createFlowBuilderPluginAndGetContents({

0 commit comments

Comments
 (0)