@botonic/plugin-flow-builder 0.38.1 → 0.39.0-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 (76) hide show
  1. package/lib/cjs/action/payload.js +1 -7
  2. package/lib/cjs/action/payload.js.map +1 -1
  3. package/lib/cjs/api.d.ts +2 -1
  4. package/lib/cjs/api.js +3 -0
  5. package/lib/cjs/api.js.map +1 -1
  6. package/lib/cjs/content-fields/flow-button.d.ts +5 -0
  7. package/lib/cjs/content-fields/flow-button.js +38 -2
  8. package/lib/cjs/content-fields/flow-button.js.map +1 -1
  9. package/lib/cjs/content-fields/flow-webview.d.ts +10 -0
  10. package/lib/cjs/content-fields/flow-webview.js +24 -0
  11. package/lib/cjs/content-fields/flow-webview.js.map +1 -0
  12. package/lib/cjs/content-fields/hubtype-fields/common.d.ts +6 -0
  13. package/lib/cjs/content-fields/hubtype-fields/index.d.ts +1 -0
  14. package/lib/cjs/content-fields/hubtype-fields/index.js +1 -0
  15. package/lib/cjs/content-fields/hubtype-fields/index.js.map +1 -1
  16. package/lib/cjs/content-fields/hubtype-fields/node-types.d.ts +2 -1
  17. package/lib/cjs/content-fields/hubtype-fields/node-types.js +1 -0
  18. package/lib/cjs/content-fields/hubtype-fields/node-types.js.map +1 -1
  19. package/lib/cjs/content-fields/hubtype-fields/nodes.d.ts +2 -1
  20. package/lib/cjs/content-fields/hubtype-fields/webview.d.ts +16 -0
  21. package/lib/cjs/content-fields/hubtype-fields/webview.js +3 -0
  22. package/lib/cjs/content-fields/hubtype-fields/webview.js.map +1 -0
  23. package/lib/cjs/index.d.ts +4 -2
  24. package/lib/cjs/index.js +12 -1
  25. package/lib/cjs/index.js.map +1 -1
  26. package/lib/cjs/types.d.ts +5 -1
  27. package/lib/cjs/types.js.map +1 -1
  28. package/lib/cjs/webview/types.d.ts +1 -1
  29. package/lib/cjs/webview/use-webview-contents.d.ts +1 -1
  30. package/lib/cjs/webview/use-webview-contents.js +2 -4
  31. package/lib/cjs/webview/use-webview-contents.js.map +1 -1
  32. package/lib/esm/action/payload.js +2 -8
  33. package/lib/esm/action/payload.js.map +1 -1
  34. package/lib/esm/api.d.ts +2 -1
  35. package/lib/esm/api.js +3 -0
  36. package/lib/esm/api.js.map +1 -1
  37. package/lib/esm/content-fields/flow-button.d.ts +5 -0
  38. package/lib/esm/content-fields/flow-button.js +39 -3
  39. package/lib/esm/content-fields/flow-button.js.map +1 -1
  40. package/lib/esm/content-fields/flow-webview.d.ts +10 -0
  41. package/lib/esm/content-fields/flow-webview.js +20 -0
  42. package/lib/esm/content-fields/flow-webview.js.map +1 -0
  43. package/lib/esm/content-fields/hubtype-fields/common.d.ts +6 -0
  44. package/lib/esm/content-fields/hubtype-fields/index.d.ts +1 -0
  45. package/lib/esm/content-fields/hubtype-fields/index.js +1 -0
  46. package/lib/esm/content-fields/hubtype-fields/index.js.map +1 -1
  47. package/lib/esm/content-fields/hubtype-fields/node-types.d.ts +2 -1
  48. package/lib/esm/content-fields/hubtype-fields/node-types.js +1 -0
  49. package/lib/esm/content-fields/hubtype-fields/node-types.js.map +1 -1
  50. package/lib/esm/content-fields/hubtype-fields/nodes.d.ts +2 -1
  51. package/lib/esm/content-fields/hubtype-fields/webview.d.ts +16 -0
  52. package/lib/esm/content-fields/hubtype-fields/webview.js +2 -0
  53. package/lib/esm/content-fields/hubtype-fields/webview.js.map +1 -0
  54. package/lib/esm/index.d.ts +4 -2
  55. package/lib/esm/index.js +10 -0
  56. package/lib/esm/index.js.map +1 -1
  57. package/lib/esm/types.d.ts +5 -1
  58. package/lib/esm/types.js.map +1 -1
  59. package/lib/esm/webview/types.d.ts +1 -1
  60. package/lib/esm/webview/use-webview-contents.d.ts +1 -1
  61. package/lib/esm/webview/use-webview-contents.js +2 -4
  62. package/lib/esm/webview/use-webview-contents.js.map +1 -1
  63. package/package.json +2 -2
  64. package/src/action/payload.ts +3 -8
  65. package/src/api.ts +5 -0
  66. package/src/content-fields/flow-button.tsx +62 -2
  67. package/src/content-fields/flow-webview.tsx +20 -0
  68. package/src/content-fields/hubtype-fields/common.ts +7 -0
  69. package/src/content-fields/hubtype-fields/index.ts +1 -0
  70. package/src/content-fields/hubtype-fields/node-types.ts +1 -0
  71. package/src/content-fields/hubtype-fields/nodes.ts +2 -0
  72. package/src/content-fields/hubtype-fields/webview.ts +18 -0
  73. package/src/index.ts +23 -0
  74. package/src/types.ts +9 -5
  75. package/src/webview/types.ts +1 -1
  76. package/src/webview/use-webview-contents.ts +2 -3
@@ -4,7 +4,14 @@ import React from 'react'
4
4
  import { FlowBuilderApi } from '../api'
5
5
  import { SOURCE_INFO_SEPARATOR } from '../constants'
6
6
  import { ContentFieldsBase } from './content-fields-base'
7
- import { HtButton, HtButtonStyle, HtUrlNode } from './hubtype-fields'
7
+ import { FlowWebview } from './flow-webview'
8
+ import {
9
+ HtButton,
10
+ HtButtonStyle,
11
+ HtNodeWithContent,
12
+ HtNodeWithContentType,
13
+ HtUrlNode,
14
+ } from './hubtype-fields'
8
15
  import { HtRatingButton } from './hubtype-fields/rating'
9
16
 
10
17
  export class FlowButton extends ContentFieldsBase {
@@ -13,6 +20,7 @@ export class FlowButton extends ContentFieldsBase {
13
20
  public payload?: string
14
21
  public target?: string
15
22
  public webview?: Webview
23
+ public params?: Record<string, string>
16
24
 
17
25
  static fromHubtypeCMS(
18
26
  cmsButton: HtButton,
@@ -24,7 +32,14 @@ export class FlowButton extends ContentFieldsBase {
24
32
  const newButton = new FlowButton(cmsButton.id)
25
33
  newButton.text = this.getTextByLocale(locale, cmsButton.text)
26
34
  if (cmsButton.target) {
27
- newButton.payload = cmsApi.getPayload(cmsButton.target)
35
+ const webview = this.getTargetWebview(cmsApi, cmsButton.target.id)
36
+ if (webview) {
37
+ const params = this.getWebviewParams(webview, cmsApi)
38
+ newButton.webview = { name: webview.webviewComponentName }
39
+ newButton.params = params
40
+ } else {
41
+ newButton.payload = cmsApi.getPayload(cmsButton.target)
42
+ }
28
43
  }
29
44
 
30
45
  if (cmsButton.url && urlId) {
@@ -35,6 +50,38 @@ export class FlowButton extends ContentFieldsBase {
35
50
  return newButton
36
51
  }
37
52
 
53
+ private static getWebviewParams(
54
+ webview: FlowWebview,
55
+ cmsApi: FlowBuilderApi
56
+ ) {
57
+ const params: Record<string, string> = {
58
+ webviewId: webview.webviewTargetId,
59
+ }
60
+ const exitSuccessContentID = this.getExitSuccessContentID(webview, cmsApi)
61
+
62
+ if (exitSuccessContentID) {
63
+ params.exitSuccessContentID = exitSuccessContentID
64
+ }
65
+
66
+ return params
67
+ }
68
+
69
+ private static getExitSuccessContentID(
70
+ webview: FlowWebview,
71
+ cmsApi: FlowBuilderApi
72
+ ) {
73
+ const webviewSuccessExit = webview.exits?.find(
74
+ exit => exit.name === 'Success'
75
+ )
76
+ const exitSuccessId = webviewSuccessExit?.target?.id
77
+ if (!exitSuccessId) {
78
+ return undefined
79
+ }
80
+ const exitNode = cmsApi.getNodeById<HtNodeWithContent>(exitSuccessId)
81
+
82
+ return exitNode.code
83
+ }
84
+
38
85
  static fromAIAgent(button: {
39
86
  id: string
40
87
  text: string
@@ -60,6 +107,17 @@ export class FlowButton extends ContentFieldsBase {
60
107
  return cmsButton.url.find(url => url.locale === locale)?.id
61
108
  }
62
109
 
110
+ static getTargetWebview(
111
+ cmsApi: FlowBuilderApi,
112
+ targetId: string
113
+ ): FlowWebview | undefined {
114
+ const targetNode = cmsApi.getNodeById(targetId)
115
+ if (targetNode.type !== HtNodeWithContentType.WEBVIEW) {
116
+ return undefined
117
+ }
118
+ return FlowWebview.fromHubtypeCMS(targetNode)
119
+ }
120
+
63
121
  renderButton(buttonIndex: number, buttonStyle?: HtButtonStyle): JSX.Element {
64
122
  if (buttonStyle === HtButtonStyle.QUICK_REPLY) {
65
123
  return (
@@ -68,6 +126,7 @@ export class FlowButton extends ContentFieldsBase {
68
126
  </Reply>
69
127
  )
70
128
  }
129
+
71
130
  return (
72
131
  <Button
73
132
  key={this.id}
@@ -75,6 +134,7 @@ export class FlowButton extends ContentFieldsBase {
75
134
  payload={this.getButtonPayload(buttonIndex)}
76
135
  target={this.target}
77
136
  webview={this.webview}
137
+ params={this.params}
78
138
  >
79
139
  {this.text}
80
140
  </Button>
@@ -0,0 +1,20 @@
1
+ import { ContentFieldsBase } from './content-fields-base'
2
+ import { HtWebviewExits, HtWebviewNode } from './hubtype-fields'
3
+
4
+ export class FlowWebview extends ContentFieldsBase {
5
+ public code: string = ''
6
+ public webviewTargetId: string = ''
7
+ public webviewName: string = ''
8
+ public webviewComponentName: string = ''
9
+ public exits: HtWebviewExits[] = []
10
+
11
+ static fromHubtypeCMS(component: HtWebviewNode): FlowWebview {
12
+ const newWebview = new FlowWebview(component.id)
13
+ newWebview.webviewTargetId = component.content.webview_target_id
14
+ newWebview.webviewName = component.content.webview_name
15
+ newWebview.webviewComponentName = component.content.webview_component_name
16
+ newWebview.exits = component.content.exits
17
+
18
+ return newWebview
19
+ }
20
+ }
@@ -12,6 +12,7 @@ export interface HtFlowBuilderData {
12
12
  is_ai_agent_active?: boolean
13
13
  nodes: HtNodeComponent[]
14
14
  flows: HtFlows[]
15
+ webviews: HtFlowWebview[]
15
16
  }
16
17
 
17
18
  export interface HtFlows {
@@ -20,6 +21,12 @@ export interface HtFlows {
20
21
  start_node_id: string
21
22
  }
22
23
 
24
+ export interface HtFlowWebview {
25
+ id: string
26
+ name: string
27
+ component_name: string
28
+ }
29
+
23
30
  export interface HtNodeLink {
24
31
  id: string
25
32
  type: HtNodeWithContentType | HtNodeWithoutContentType
@@ -17,5 +17,6 @@ export * from './smart-intent'
17
17
  export * from './text'
18
18
  export * from './url'
19
19
  export * from './video'
20
+ export * from './webview'
20
21
  export * from './whatsapp-button-list'
21
22
  export * from './whatsapp-cta-url-button'
@@ -14,6 +14,7 @@ export enum HtNodeWithContentType {
14
14
  BOT_ACTION = 'bot-action',
15
15
  AI_AGENT = 'ai-agent',
16
16
  RATING = 'rating',
17
+ WEBVIEW = 'webview',
17
18
  }
18
19
 
19
20
  export enum HtNodeWithoutContentType {
@@ -14,6 +14,7 @@ import { HtSmartIntentNode } from './smart-intent'
14
14
  import { HtTextNode } from './text'
15
15
  import { HtUrlNode } from './url'
16
16
  import { HtVideoNode } from './video'
17
+ import { HtWebviewNode } from './webview'
17
18
  import { HtWhatsappButtonListNode } from './whatsapp-button-list'
18
19
  import { HtWhatsappCTAUrlButtonNode } from './whatsapp-cta-url-button'
19
20
 
@@ -33,6 +34,7 @@ export type HtNodeWithContent =
33
34
  | HtBotActionNode
34
35
  | HtAiAgentNode
35
36
  | HtRatingNode
37
+ | HtWebviewNode
36
38
 
37
39
  export type HtNodeWithoutContent = HtUrlNode | HtPayloadNode | HtGoToFlow
38
40
 
@@ -0,0 +1,18 @@
1
+ import { HtBaseNode, HtNodeLink } from './common'
2
+ import { HtNodeWithContentType } from './node-types'
3
+
4
+ export interface HtWebviewExits {
5
+ id: string
6
+ name: string
7
+ target?: HtNodeLink
8
+ }
9
+
10
+ export interface HtWebviewNode extends HtBaseNode {
11
+ type: HtNodeWithContentType.WEBVIEW
12
+ content: {
13
+ webview_target_id: string
14
+ webview_name: string
15
+ webview_component_name: string
16
+ exits: HtWebviewExits[]
17
+ }
18
+ }
package/src/index.ts CHANGED
@@ -36,6 +36,7 @@ import {
36
36
  HtNodeComponent,
37
37
  HtNodeWithContent,
38
38
  HtNodeWithContentType,
39
+ HtRatingButton,
39
40
  } from './content-fields/hubtype-fields'
40
41
  import { DEFAULT_FUNCTIONS } from './functions'
41
42
  import {
@@ -46,6 +47,7 @@ import {
46
47
  InShadowingConfig,
47
48
  KnowledgeBaseFunction,
48
49
  PayloadParamsBase,
50
+ RatingSubmittedInfo,
49
51
  TrackEventFunction,
50
52
  } from './types'
51
53
  import { getNodeByUserInput } from './user-input'
@@ -314,9 +316,29 @@ export default class BotonicPluginFlowBuilder implements Plugin {
314
316
  getFlowName(flowId: string): string {
315
317
  return this.cmsApi.getFlowName(flowId)
316
318
  }
319
+
320
+ getRatingSubmittedInfo(payload: string): RatingSubmittedInfo {
321
+ const buttonId = payload?.split(SEPARATOR)[1]
322
+ const ratingNode = this.cmsApi.getRatingNodeByButtonId(buttonId)
323
+
324
+ const ratingButton = this.cmsApi.getRatingButtonById(ratingNode, buttonId)
325
+ const possibleOptions = ratingNode.content.buttons.map(
326
+ button => button.text
327
+ )
328
+ const possibleValues = ratingNode.content.buttons.map(
329
+ button => button.value
330
+ )
331
+
332
+ return {
333
+ ...ratingButton,
334
+ possibleOptions,
335
+ possibleValues,
336
+ }
337
+ }
317
338
  }
318
339
 
319
340
  export * from './action'
341
+ export { AGENT_RATING_PAYLOAD } from './constants'
320
342
  export * from './content-fields'
321
343
  export { HtBotActionNode } from './content-fields/hubtype-fields'
322
344
  export { trackFlowContent } from './tracking'
@@ -325,5 +347,6 @@ export {
325
347
  ContentFilter,
326
348
  FlowBuilderJSONVersion,
327
349
  PayloadParamsBase,
350
+ RatingSubmittedInfo,
328
351
  } from './types'
329
352
  export * from './webview'
package/src/types.ts CHANGED
@@ -1,17 +1,16 @@
1
1
  import {
2
- AgenticOutputMessage,
3
2
  BotContext,
4
- CarouselMessage,
5
3
  InferenceResponse,
6
4
  KnowledgeBasesResponse,
7
5
  PluginPreRequest,
8
6
  ResolvedPlugins,
9
- TextMessage,
10
- TextWithButtonsMessage,
11
7
  } from '@botonic/core'
12
8
 
13
9
  import { FlowContent } from './content-fields'
14
- import { HtFlowBuilderData } from './content-fields/hubtype-fields'
10
+ import {
11
+ HtFlowBuilderData,
12
+ HtRatingButton,
13
+ } from './content-fields/hubtype-fields'
15
14
 
16
15
  export interface InShadowingConfig {
17
16
  allowKeywords: boolean
@@ -116,3 +115,8 @@ export interface SmartIntentResponse {
116
115
  export interface PayloadParamsBase {
117
116
  followUpContentID?: string
118
117
  }
118
+
119
+ export interface RatingSubmittedInfo extends HtRatingButton {
120
+ possibleOptions: string[]
121
+ possibleValues: number[]
122
+ }
@@ -31,9 +31,9 @@ export type MapContentsType = Record<string, string>
31
31
  export interface UseWebviewContentsProps<T extends MapContentsType> {
32
32
  apiUrl?: string
33
33
  version?: FlowBuilderJSONVersion
34
- orgId: string
35
34
  botId: string
36
35
  webviewId: string
36
+ providerId: string
37
37
  locale: string
38
38
  mapContents: Record<keyof T, string>
39
39
  }
@@ -16,10 +16,9 @@ import {
16
16
  export function useWebviewContents<T extends MapContentsType>({
17
17
  apiUrl = FLOW_BUILDER_API_URL_PROD,
18
18
  version = FlowBuilderJSONVersion.LATEST,
19
- // @ts-ignore
20
- orgId,
21
19
  botId,
22
20
  webviewId,
21
+ providerId,
23
22
  locale,
24
23
  mapContents,
25
24
  }: UseWebviewContentsProps<T>): UseWebviewContents<T> {
@@ -85,7 +84,7 @@ export function useWebviewContents<T extends MapContentsType>({
85
84
 
86
85
  useEffect(() => {
87
86
  const getResponseContents = async () => {
88
- const url = `${apiUrl}/v1/bot_flows/${botId}/versions/${version}/webviews/${webviewId}/`
87
+ const url = `${apiUrl}/v1/bot_flows/${botId}/versions/${version}/webviews/${webviewId}/?provider_id=${providerId}`
89
88
  try {
90
89
  const response = await axios.get<WebviewContentsResponse>(url)
91
90