@botonic/plugin-flow-builder 0.24.0 → 0.24.2-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (95) hide show
  1. package/lib/cjs/action/index.js +10 -6
  2. package/lib/cjs/action/index.js.map +1 -1
  3. package/lib/cjs/action/intent.d.ts +2 -2
  4. package/lib/cjs/action/intent.js +4 -4
  5. package/lib/cjs/action/intent.js.map +1 -1
  6. package/lib/cjs/action/keyword.d.ts +2 -2
  7. package/lib/cjs/action/keyword.js +3 -3
  8. package/lib/cjs/action/keyword.js.map +1 -1
  9. package/lib/cjs/action/user-input.d.ts +2 -2
  10. package/lib/cjs/action/user-input.js +4 -10
  11. package/lib/cjs/action/user-input.js.map +1 -1
  12. package/lib/cjs/api.d.ts +5 -2
  13. package/lib/cjs/api.js +31 -2
  14. package/lib/cjs/api.js.map +1 -1
  15. package/lib/cjs/constants.d.ts +2 -1
  16. package/lib/cjs/constants.js +3 -2
  17. package/lib/cjs/constants.js.map +1 -1
  18. package/lib/cjs/content-fields/flow-button.js +2 -1
  19. package/lib/cjs/content-fields/flow-button.js.map +1 -1
  20. package/lib/cjs/content-fields/flow-handoff.js +8 -9
  21. package/lib/cjs/content-fields/flow-handoff.js.map +1 -1
  22. package/lib/cjs/content-fields/hubtype-fields/bot-action.d.ts +10 -0
  23. package/lib/cjs/content-fields/hubtype-fields/bot-action.js +3 -0
  24. package/lib/cjs/content-fields/hubtype-fields/bot-action.js.map +1 -0
  25. package/lib/cjs/content-fields/hubtype-fields/common.d.ts +6 -0
  26. package/lib/cjs/content-fields/hubtype-fields/go-to-flow.d.ts +8 -0
  27. package/lib/cjs/content-fields/hubtype-fields/go-to-flow.js +3 -0
  28. package/lib/cjs/content-fields/hubtype-fields/go-to-flow.js.map +1 -0
  29. package/lib/cjs/content-fields/hubtype-fields/index.d.ts +2 -0
  30. package/lib/cjs/content-fields/hubtype-fields/index.js +2 -0
  31. package/lib/cjs/content-fields/hubtype-fields/index.js.map +1 -1
  32. package/lib/cjs/content-fields/hubtype-fields/node-types.d.ts +3 -1
  33. package/lib/cjs/content-fields/hubtype-fields/node-types.js +2 -0
  34. package/lib/cjs/content-fields/hubtype-fields/node-types.js.map +1 -1
  35. package/lib/cjs/content-fields/hubtype-fields/nodes.d.ts +3 -1
  36. package/lib/cjs/index.d.ts +3 -2
  37. package/lib/cjs/index.js +12 -0
  38. package/lib/cjs/index.js.map +1 -1
  39. package/lib/cjs/types.d.ts +3 -0
  40. package/lib/esm/action/index.js +10 -6
  41. package/lib/esm/action/index.js.map +1 -1
  42. package/lib/esm/action/intent.d.ts +2 -2
  43. package/lib/esm/action/intent.js +2 -2
  44. package/lib/esm/action/intent.js.map +1 -1
  45. package/lib/esm/action/keyword.d.ts +2 -2
  46. package/lib/esm/action/keyword.js +1 -1
  47. package/lib/esm/action/keyword.js.map +1 -1
  48. package/lib/esm/action/user-input.d.ts +2 -2
  49. package/lib/esm/action/user-input.js +6 -12
  50. package/lib/esm/action/user-input.js.map +1 -1
  51. package/lib/esm/api.d.ts +5 -2
  52. package/lib/esm/api.js +32 -3
  53. package/lib/esm/api.js.map +1 -1
  54. package/lib/esm/constants.d.ts +2 -1
  55. package/lib/esm/constants.js +2 -1
  56. package/lib/esm/constants.js.map +1 -1
  57. package/lib/esm/content-fields/flow-button.js +2 -1
  58. package/lib/esm/content-fields/flow-button.js.map +1 -1
  59. package/lib/esm/content-fields/flow-handoff.js +8 -9
  60. package/lib/esm/content-fields/flow-handoff.js.map +1 -1
  61. package/lib/esm/content-fields/hubtype-fields/bot-action.d.ts +10 -0
  62. package/lib/esm/content-fields/hubtype-fields/bot-action.js +2 -0
  63. package/lib/esm/content-fields/hubtype-fields/bot-action.js.map +1 -0
  64. package/lib/esm/content-fields/hubtype-fields/common.d.ts +6 -0
  65. package/lib/esm/content-fields/hubtype-fields/go-to-flow.d.ts +8 -0
  66. package/lib/esm/content-fields/hubtype-fields/go-to-flow.js +2 -0
  67. package/lib/esm/content-fields/hubtype-fields/go-to-flow.js.map +1 -0
  68. package/lib/esm/content-fields/hubtype-fields/index.d.ts +2 -0
  69. package/lib/esm/content-fields/hubtype-fields/index.js +2 -0
  70. package/lib/esm/content-fields/hubtype-fields/index.js.map +1 -1
  71. package/lib/esm/content-fields/hubtype-fields/node-types.d.ts +3 -1
  72. package/lib/esm/content-fields/hubtype-fields/node-types.js +2 -0
  73. package/lib/esm/content-fields/hubtype-fields/node-types.js.map +1 -1
  74. package/lib/esm/content-fields/hubtype-fields/nodes.d.ts +3 -1
  75. package/lib/esm/index.d.ts +3 -2
  76. package/lib/esm/index.js +13 -1
  77. package/lib/esm/index.js.map +1 -1
  78. package/lib/esm/types.d.ts +3 -0
  79. package/package.json +5 -5
  80. package/src/action/index.tsx +11 -14
  81. package/src/action/intent.ts +4 -7
  82. package/src/action/keyword.ts +3 -3
  83. package/src/action/user-input.ts +7 -14
  84. package/src/api.ts +41 -5
  85. package/src/constants.ts +2 -1
  86. package/src/content-fields/flow-button.tsx +5 -3
  87. package/src/content-fields/flow-handoff.tsx +7 -26
  88. package/src/content-fields/hubtype-fields/bot-action.ts +11 -0
  89. package/src/content-fields/hubtype-fields/common.ts +7 -0
  90. package/src/content-fields/hubtype-fields/go-to-flow.ts +9 -0
  91. package/src/content-fields/hubtype-fields/index.ts +2 -0
  92. package/src/content-fields/hubtype-fields/node-types.ts +2 -0
  93. package/src/content-fields/hubtype-fields/nodes.ts +7 -1
  94. package/src/index.ts +28 -3
  95. package/src/types.ts +4 -0
@@ -7,7 +7,6 @@ import { HtNodeWithContent } from '../content-fields/hubtype-fields'
7
7
  import { getFlowBuilderPlugin } from '../helpers'
8
8
  import { createNodeFromKnowledgeBase } from './knowledge-bases'
9
9
  import { EventName, trackEvent } from './tracking'
10
- import { getNodeByUserInput } from './user-input'
11
10
 
12
11
  export type FlowBuilderActionProps = {
13
12
  contents: FlowContent[]
@@ -22,11 +21,7 @@ export class FlowBuilderAction extends React.Component<FlowBuilderActionProps> {
22
21
  const flowBuilderPlugin = getFlowBuilderPlugin(request.plugins)
23
22
  const locale = flowBuilderPlugin.getLocale(request.session)
24
23
 
25
- const targetNode = await getTargetNode(
26
- flowBuilderPlugin.cmsApi,
27
- locale,
28
- request
29
- )
24
+ const targetNode = await getTargetNode(flowBuilderPlugin.cmsApi, request)
30
25
 
31
26
  const contents = await flowBuilderPlugin.getContentsByNode(
32
27
  targetNode,
@@ -58,15 +53,17 @@ export class FlowBuilderMultichannelAction extends FlowBuilderAction {
58
53
  }
59
54
  }
60
55
 
61
- async function getTargetNode(
62
- cmsApi: FlowBuilderApi,
63
- locale: string,
64
- request: ActionRequest
65
- ) {
56
+ async function getTargetNode(cmsApi: FlowBuilderApi, request: ActionRequest) {
57
+ if (request.session.is_first_interaction) {
58
+ const startNode = cmsApi.getStartNode()
59
+ await trackEvent(request, EventName.botStart)
60
+ return startNode
61
+ }
66
62
  const contentId = request.input.payload
67
- const targetNode = !contentId
68
- ? await getNodeByUserInput(cmsApi, locale, request)
69
- : (cmsApi.getNodeById(contentId) as HtNodeWithContent)
63
+
64
+ const targetNode = contentId
65
+ ? cmsApi.getNodeById<HtNodeWithContent>(contentId)
66
+ : undefined
70
67
 
71
68
  if (targetNode) {
72
69
  const eventArgs = {
@@ -1,17 +1,14 @@
1
1
  import { ActionRequest } from '@botonic/react'
2
2
 
3
3
  import { FlowBuilderApi } from '../api'
4
- import {
5
- HtIntentNode,
6
- HtNodeWithContent,
7
- } from '../content-fields/hubtype-fields'
4
+ import { HtIntentNode } from '../content-fields/hubtype-fields'
8
5
  import { EventName, trackEvent } from './tracking'
9
6
 
10
- export async function getNodeByIntent(
7
+ export async function getIntentNodeByInput(
11
8
  cmsApi: FlowBuilderApi,
12
9
  locale: string,
13
10
  request: ActionRequest
14
- ): Promise<HtNodeWithContent | undefined> {
11
+ ): Promise<HtIntentNode | undefined> {
15
12
  const intentNode = cmsApi.getIntentNode(request.input, locale)
16
13
  const eventArgs = {
17
14
  intent: request.input.intent as string,
@@ -20,7 +17,7 @@ export async function getNodeByIntent(
20
17
  }
21
18
  if (isIntentValid(intentNode, request, cmsApi) && intentNode?.target?.id) {
22
19
  await trackEvent(request, EventName.botAiModel, eventArgs)
23
- return cmsApi.getNodeById<HtNodeWithContent>(intentNode.target.id)
20
+ return intentNode
24
21
  } else {
25
22
  eventArgs.confidence_successful = false
26
23
  await trackEvent(request, EventName.botAiModel, eventArgs)
@@ -1,15 +1,15 @@
1
1
  import { ActionRequest } from '@botonic/react'
2
2
 
3
3
  import { FlowBuilderApi } from '../api'
4
- import { HtNodeWithContent } from '../content-fields/hubtype-fields'
4
+ import { HtKeywordNode } from '../content-fields/hubtype-fields'
5
5
  import { EventName, trackEvent } from './tracking'
6
6
 
7
- export async function getNodeByKeyword(
7
+ export async function getKeywordNodeByInput(
8
8
  cmsApi: FlowBuilderApi,
9
9
  locale: string,
10
10
  request: ActionRequest,
11
11
  userInput: string
12
- ): Promise<HtNodeWithContent | undefined> {
12
+ ): Promise<HtKeywordNode | undefined> {
13
13
  const keywordNode = cmsApi.getNodeByKeyword(userInput, locale)
14
14
  if (!keywordNode) {
15
15
  return undefined
@@ -1,27 +1,20 @@
1
1
  import { ActionRequest } from '@botonic/react'
2
2
 
3
3
  import { FlowBuilderApi } from '../api'
4
- import { HtNodeWithContent } from '../content-fields/hubtype-fields'
5
- import { getNodeByIntent } from './intent'
6
- import { getNodeByKeyword } from './keyword'
7
- import { EventName, trackEvent } from './tracking'
4
+ import { HtIntentNode, HtKeywordNode } from '../content-fields/hubtype-fields'
5
+ import { getIntentNodeByInput } from './intent'
6
+ import { getKeywordNodeByInput } from './keyword'
8
7
 
9
8
  export async function getNodeByUserInput(
10
9
  cmsApi: FlowBuilderApi,
11
10
  locale: string,
12
11
  request: ActionRequest
13
- ): Promise<HtNodeWithContent | undefined> {
14
- if (request.session.is_first_interaction) {
15
- const startNode = cmsApi.getStartNode()
16
- await trackEvent(request, EventName.botStart)
17
- return startNode
18
- }
19
-
12
+ ): Promise<HtIntentNode | HtKeywordNode | undefined> {
20
13
  if (request.input.data) {
21
- const nodeByIntent = await getNodeByIntent(cmsApi, locale, request)
22
- if (nodeByIntent) return nodeByIntent
14
+ const intentNode = await getIntentNodeByInput(cmsApi, locale, request)
15
+ if (intentNode) return intentNode
23
16
 
24
- const keywordNode = await getNodeByKeyword(
17
+ const keywordNode = await getKeywordNodeByInput(
25
18
  cmsApi,
26
19
  locale,
27
20
  request,
package/src/api.ts CHANGED
@@ -1,7 +1,9 @@
1
1
  import { Input, PluginPreRequest } from '@botonic/core'
2
2
  import axios from 'axios'
3
3
 
4
+ import { SEPARATOR } from './constants'
4
5
  import {
6
+ HtBotActionNode,
5
7
  HtFallbackNode,
6
8
  HtFlowBuilderData,
7
9
  HtIntentNode,
@@ -10,6 +12,8 @@ import {
10
12
  HtNodeLink,
11
13
  HtNodeWithContent,
12
14
  HtNodeWithContentType,
15
+ HtNodeWithoutContentType,
16
+ HtPayloadNode,
13
17
  } from './content-fields/hubtype-fields'
14
18
  import { FlowBuilderApiOptions } from './types'
15
19
 
@@ -37,9 +41,18 @@ export class FlowBuilderApi {
37
41
  return data as HtFlowBuilderData
38
42
  }
39
43
 
44
+ getNodeByFlowId(id: string): HtNodeWithContent {
45
+ const subFlow = this.flow.flows.find(subFlow => subFlow.id === id)
46
+ if (!subFlow) throw Error(`SubFlow with id: '${id}' not found`)
47
+ return this.getNodeById<HtNodeWithContent>(subFlow.start_node_id)
48
+ }
49
+
40
50
  getNodeById<T extends HtNodeComponent>(id: string): T {
41
51
  const node = this.flow.nodes.find(node => node.id === id)
42
52
  if (!node) throw Error(`Node with id: '${id}' not found`)
53
+ if (node.type === HtNodeWithoutContentType.GO_TO_FLOW) {
54
+ return this.getNodeByFlowId(node.content.flow_id) as T
55
+ }
43
56
  return node as T
44
57
  }
45
58
 
@@ -132,18 +145,16 @@ export class FlowBuilderApi {
132
145
  getNodeByKeyword(
133
146
  userInput: string,
134
147
  locale: string
135
- ): HtNodeWithContent | undefined {
148
+ ): HtKeywordNode | undefined {
136
149
  try {
137
150
  const keywordNodes = this.flow.nodes.filter(
138
- node => node.type == HtNodeWithContentType.KEYWORD
151
+ node => node.type === HtNodeWithContentType.KEYWORD
139
152
  ) as HtKeywordNode[]
140
153
  const matchedKeywordNodes = keywordNodes.filter(node =>
141
154
  this.matchKeywords(node, userInput, locale)
142
155
  )
143
156
  if (matchedKeywordNodes.length > 0 && matchedKeywordNodes[0].target) {
144
- return this.getNodeById<HtNodeWithContent>(
145
- matchedKeywordNodes[0].target.id
146
- )
157
+ return matchedKeywordNodes[0]
147
158
  }
148
159
  } catch (error) {
149
160
  console.error(`Error getting node by keyword '${userInput}': `, error)
@@ -166,4 +177,29 @@ export class FlowBuilderApi {
166
177
  private containsAnyKeywords(input: string, keywords: string[]): boolean {
167
178
  return keywords.some(keyword => input.includes(keyword))
168
179
  }
180
+
181
+ getPayload(target?: HtNodeLink): string | undefined {
182
+ if (target) {
183
+ if (target.type === HtNodeWithoutContentType.BOT_ACTION) {
184
+ const botActionNode = this.getNodeById<HtBotActionNode>(target.id)
185
+ return this.createPayloadWithParams(botActionNode)
186
+ }
187
+ const targetNode = this.getNodeById(target.id)
188
+ return targetNode.id
189
+ }
190
+ return undefined
191
+ }
192
+
193
+ private createPayloadWithParams(botActionNode: HtBotActionNode): string {
194
+ const payloadId = botActionNode.content.payload_id
195
+ const payloadNode = this.getNodeById<HtPayloadNode>(payloadId)
196
+ const customParams = JSON.parse(
197
+ botActionNode.content.payload_params || '{}'
198
+ )
199
+ const payloadJson = JSON.stringify({
200
+ ...customParams,
201
+ followUpId: botActionNode.follow_up?.id,
202
+ })
203
+ return `${payloadNode.content.payload}${SEPARATOR}${payloadJson}`
204
+ }
169
205
  }
package/src/constants.ts CHANGED
@@ -1,2 +1,3 @@
1
- export const SOURCE_INFO_SEPARATOR = '|source_'
1
+ export const SEPARATOR = '|'
2
+ export const SOURCE_INFO_SEPARATOR = `${SEPARATOR}source_`
2
3
  export const VARIABLE_REGEX = /{([^}]+)}/g
@@ -27,14 +27,16 @@ export class FlowButton extends ContentFieldsBase {
27
27
  const newButton = new FlowButton(cmsButton.id)
28
28
  newButton.text = this.getTextByLocale(locale, cmsButton.text)
29
29
  if (cmsButton.target) {
30
- newButton.payload = cmsButton.target.id
30
+ newButton.payload = cmsApi.getPayload(cmsButton.target)
31
31
  }
32
+
33
+ // OLD PAYLOAD
32
34
  if (cmsButton.payload && payloadId) {
33
- const payloadNode = cmsApi.getNodeById(payloadId) as HtPayloadNode
35
+ const payloadNode = cmsApi.getNodeById<HtPayloadNode>(payloadId)
34
36
  newButton.payload = payloadNode.content.payload
35
37
  }
36
38
  if (cmsButton.url && urlId) {
37
- const payloadNode = cmsApi.getNodeById(urlId) as HtUrlNode
39
+ const payloadNode = cmsApi.getNodeById<HtUrlNode>(urlId)
38
40
  newButton.url = payloadNode.content.url
39
41
  }
40
42
 
@@ -6,23 +6,7 @@ import { EventName, trackEvent } from '../action/tracking'
6
6
  import { FlowBuilderApi } from '../api'
7
7
  import { getQueueAvailability } from '../functions/conditional-queue-status'
8
8
  import { ContentFieldsBase } from './content-fields-base'
9
- import {
10
- HtCarouselNode,
11
- HtHandoffNode,
12
- HtImageNode,
13
- HtPayloadNode,
14
- HtQueueLocale,
15
- HtTextNode,
16
- HtVideoNode,
17
- HtWhatsappButtonListNode,
18
- } from './hubtype-fields'
19
-
20
- type HtAfterHandoff =
21
- | HtTextNode
22
- | HtImageNode
23
- | HtVideoNode
24
- | HtCarouselNode
25
- | HtWhatsappButtonListNode
9
+ import { HtHandoffNode, HtPayloadNode, HtQueueLocale } from './hubtype-fields'
26
10
 
27
11
  export class FlowHandoff extends ContentFieldsBase {
28
12
  public code: string
@@ -54,21 +38,18 @@ export class FlowHandoff extends ContentFieldsBase {
54
38
  cmsApi: FlowBuilderApi
55
39
  ): string | undefined {
56
40
  if (cmsHandoff.target?.id) {
57
- const handoffTargetNode = cmsApi.getNodeById<HtAfterHandoff>(
58
- cmsHandoff.target?.id
59
- )
60
- if (handoffTargetNode?.id) return handoffTargetNode?.id
41
+ return cmsApi.getPayload(cmsHandoff.target)
61
42
  }
62
43
 
44
+ // OLD PAYLOAD
63
45
  const payloadId = cmsHandoff.content.payload.find(
64
46
  payload => payload.locale === locale
65
47
  )?.id
48
+ if (payloadId) {
49
+ return cmsApi.getNodeById<HtPayloadNode>(payloadId).content.payload
50
+ }
66
51
 
67
- if (!payloadId) return undefined
68
-
69
- const actionPayload = cmsApi.getNodeById(payloadId)
70
-
71
- return (actionPayload as HtPayloadNode).content.payload
52
+ return undefined
72
53
  }
73
54
 
74
55
  async doHandoff(request: ActionRequest): Promise<void> {
@@ -0,0 +1,11 @@
1
+ import { HtBaseNode } from './common'
2
+ import { HtNodeWithoutContentType } from './node-types'
3
+
4
+ export interface HtBotActionNode extends HtBaseNode {
5
+ id: string
6
+ type: HtNodeWithoutContentType.BOT_ACTION
7
+ content: {
8
+ payload_id: string
9
+ payload_params?: string
10
+ }
11
+ }
@@ -8,6 +8,13 @@ export interface HtFlowBuilderData {
8
8
  start_node_id?: string
9
9
  ai_model_id?: string
10
10
  nodes: HtNodeComponent[]
11
+ flows: HtFlows[]
12
+ }
13
+
14
+ export interface HtFlows {
15
+ id: string
16
+ name: string
17
+ start_node_id: string
11
18
  }
12
19
 
13
20
  export interface HtNodeLink {
@@ -0,0 +1,9 @@
1
+ import { HtNodeWithoutContentType } from './node-types'
2
+
3
+ export interface HtGoToFlow {
4
+ id: string
5
+ type: HtNodeWithoutContentType.GO_TO_FLOW
6
+ content: {
7
+ flow_id: string
8
+ }
9
+ }
@@ -1,8 +1,10 @@
1
+ export * from './bot-action'
1
2
  export * from './button'
2
3
  export * from './carousel'
3
4
  export * from './common'
4
5
  export * from './fallback'
5
6
  export * from './function'
7
+ export * from './go-to-flow'
6
8
  export * from './handoff'
7
9
  export * from './image'
8
10
  export * from './intent'
@@ -14,6 +14,8 @@ export enum HtNodeWithContentType {
14
14
  export enum HtNodeWithoutContentType {
15
15
  URL = 'url',
16
16
  PAYLOAD = 'payload',
17
+ GO_TO_FLOW = 'go-to-flow',
18
+ BOT_ACTION = 'bot-action',
17
19
  }
18
20
 
19
21
  export enum HtButtonStyle {
@@ -1,6 +1,8 @@
1
+ import { HtBotActionNode } from './bot-action'
1
2
  import { HtCarouselNode } from './carousel'
2
3
  import { HtFallbackNode } from './fallback'
3
4
  import { HtFunctionNode } from './function'
5
+ import { HtGoToFlow } from './go-to-flow'
4
6
  import { HtHandoffNode } from './handoff'
5
7
  import { HtImageNode } from './image'
6
8
  import { HtIntentNode } from './intent'
@@ -23,6 +25,10 @@ export type HtNodeWithContent =
23
25
  | HtFallbackNode
24
26
  | HtWhatsappButtonListNode
25
27
 
26
- export type HtNodeWithoutContent = HtUrlNode | HtPayloadNode
28
+ export type HtNodeWithoutContent =
29
+ | HtUrlNode
30
+ | HtPayloadNode
31
+ | HtGoToFlow
32
+ | HtBotActionNode
27
33
 
28
34
  export type HtNodeComponent = HtNodeWithContent | HtNodeWithoutContent
package/src/index.ts CHANGED
@@ -1,8 +1,9 @@
1
1
  import { Plugin, PluginPreRequest, Session } from '@botonic/core'
2
2
  import { ActionRequest } from '@botonic/react'
3
3
 
4
+ import { getNodeByUserInput } from './action/user-input'
4
5
  import { FlowBuilderApi } from './api'
5
- import { SOURCE_INFO_SEPARATOR } from './constants'
6
+ import { SEPARATOR, SOURCE_INFO_SEPARATOR } from './constants'
6
7
  import {
7
8
  FlowCarousel,
8
9
  FlowContent,
@@ -20,7 +21,11 @@ import {
20
21
  HtNodeWithContentType,
21
22
  } from './content-fields/hubtype-fields'
22
23
  import { DEFAULT_FUNCTIONS } from './functions'
23
- import { BotonicPluginFlowBuilderOptions, KnowledgeBaseResponse } from './types'
24
+ import {
25
+ BotonicPluginFlowBuilderOptions,
26
+ KnowledgeBaseResponse,
27
+ PayloadParamsBase,
28
+ } from './types'
24
29
  import { resolveGetAccessToken } from './utils'
25
30
 
26
31
  export default class BotonicPluginFlowBuilder implements Plugin {
@@ -59,6 +64,21 @@ export default class BotonicPluginFlowBuilder implements Plugin {
59
64
  accessToken: this.getAccessToken(request.session),
60
65
  request: this.currentRequest,
61
66
  })
67
+
68
+ const checkUserTextInput =
69
+ request.input.data &&
70
+ !request.input.payload &&
71
+ !request.session.is_first_interaction
72
+
73
+ if (checkUserTextInput) {
74
+ const nodeByUserInput = await getNodeByUserInput(
75
+ this.cmsApi,
76
+ this.getLocale(request.session),
77
+ request as unknown as ActionRequest
78
+ )
79
+ request.input.payload = this.cmsApi.getPayload(nodeByUserInput?.target)
80
+ }
81
+
62
82
  if (request.input.payload) {
63
83
  request.input.payload = request.input.payload?.split(
64
84
  SOURCE_INFO_SEPARATOR
@@ -165,8 +185,13 @@ export default class BotonicPluginFlowBuilder implements Plugin {
165
185
  }
166
186
  return result.target.id
167
187
  }
188
+
189
+ getPayloadParams<T extends PayloadParamsBase>(payload: string): T {
190
+ const payloadParams = JSON.parse(payload.split(SEPARATOR)[1] || '{}')
191
+ return payloadParams
192
+ }
168
193
  }
169
194
 
170
195
  export * from './action'
171
196
  export * from './content-fields'
172
- export { BotonicPluginFlowBuilderOptions } from './types'
197
+ export { BotonicPluginFlowBuilderOptions, PayloadParamsBase } from './types'
package/src/types.ts CHANGED
@@ -39,3 +39,7 @@ export interface KnowledgeBaseResponse {
39
39
  page?: number
40
40
  }[]
41
41
  }
42
+
43
+ export interface PayloadParamsBase {
44
+ followUpId?: string
45
+ }