@botonic/plugin-flow-builder 0.22.0-beta.3 → 0.22.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 (268) hide show
  1. package/lib/cjs/action.d.ts +16 -2
  2. package/lib/cjs/action.js +21 -19
  3. package/lib/cjs/action.js.map +1 -1
  4. package/lib/cjs/api.d.ts +19 -0
  5. package/lib/cjs/api.js +108 -0
  6. package/lib/cjs/api.js.map +1 -0
  7. package/lib/cjs/content-fields/content-fields-base.d.ts +4 -4
  8. package/lib/cjs/content-fields/content-fields-base.js.map +1 -1
  9. package/lib/cjs/content-fields/flow-button.d.ts +6 -3
  10. package/lib/cjs/content-fields/flow-button.js +28 -21
  11. package/lib/cjs/content-fields/flow-button.js.map +1 -1
  12. package/lib/cjs/content-fields/flow-carousel.d.ts +3 -2
  13. package/lib/cjs/content-fields/flow-carousel.js +3 -10
  14. package/lib/cjs/content-fields/flow-carousel.js.map +1 -1
  15. package/lib/cjs/content-fields/flow-element.d.ts +6 -3
  16. package/lib/cjs/content-fields/flow-element.js +16 -5
  17. package/lib/cjs/content-fields/flow-element.js.map +1 -1
  18. package/lib/cjs/content-fields/flow-image.d.ts +2 -2
  19. package/lib/cjs/content-fields/flow-image.js.map +1 -1
  20. package/lib/cjs/content-fields/flow-text.d.ts +4 -3
  21. package/lib/cjs/content-fields/flow-text.js +9 -9
  22. package/lib/cjs/content-fields/flow-text.js.map +1 -1
  23. package/lib/cjs/content-fields/flow-video.d.ts +2 -2
  24. package/lib/cjs/content-fields/flow-video.js +0 -1
  25. package/lib/cjs/content-fields/flow-video.js.map +1 -1
  26. package/lib/cjs/content-fields/hubtype-fields/button.d.ts +9 -0
  27. package/lib/cjs/content-fields/hubtype-fields/button.js +3 -0
  28. package/lib/cjs/content-fields/hubtype-fields/button.js.map +1 -0
  29. package/lib/cjs/content-fields/hubtype-fields/carousel.d.ts +16 -0
  30. package/lib/cjs/content-fields/hubtype-fields/carousel.js +3 -0
  31. package/lib/cjs/content-fields/hubtype-fields/carousel.js.map +1 -0
  32. package/lib/cjs/content-fields/hubtype-fields/common.d.ts +55 -0
  33. package/lib/cjs/content-fields/hubtype-fields/common.js +3 -0
  34. package/lib/cjs/content-fields/hubtype-fields/common.js.map +1 -0
  35. package/lib/cjs/content-fields/hubtype-fields/fallback.d.ts +9 -0
  36. package/lib/cjs/content-fields/hubtype-fields/fallback.js +3 -0
  37. package/lib/cjs/content-fields/hubtype-fields/fallback.js.map +1 -0
  38. package/lib/cjs/content-fields/hubtype-fields/function.d.ts +28 -0
  39. package/lib/cjs/content-fields/hubtype-fields/function.js +10 -0
  40. package/lib/cjs/content-fields/hubtype-fields/function.js.map +1 -0
  41. package/lib/cjs/content-fields/hubtype-fields/handoff.d.ts +10 -0
  42. package/lib/cjs/content-fields/hubtype-fields/handoff.js +3 -0
  43. package/lib/cjs/content-fields/hubtype-fields/handoff.js.map +1 -0
  44. package/lib/cjs/content-fields/hubtype-fields/image.d.ts +8 -0
  45. package/lib/cjs/content-fields/{types.js → hubtype-fields/image.js} +1 -1
  46. package/lib/cjs/content-fields/hubtype-fields/image.js.map +1 -0
  47. package/lib/cjs/content-fields/hubtype-fields/index.d.ts +17 -0
  48. package/lib/cjs/content-fields/hubtype-fields/index.js +21 -0
  49. package/lib/cjs/content-fields/hubtype-fields/index.js.map +1 -0
  50. package/lib/cjs/content-fields/hubtype-fields/intent.d.ts +10 -0
  51. package/lib/cjs/content-fields/hubtype-fields/intent.js +3 -0
  52. package/lib/cjs/content-fields/hubtype-fields/intent.js.map +1 -0
  53. package/lib/cjs/content-fields/hubtype-fields/keyword.d.ts +9 -0
  54. package/lib/cjs/content-fields/hubtype-fields/keyword.js +3 -0
  55. package/lib/cjs/content-fields/hubtype-fields/keyword.js.map +1 -0
  56. package/lib/cjs/content-fields/hubtype-fields/node-types.d.ts +23 -0
  57. package/lib/cjs/content-fields/hubtype-fields/node-types.js +31 -0
  58. package/lib/cjs/content-fields/hubtype-fields/node-types.js.map +1 -0
  59. package/lib/cjs/content-fields/hubtype-fields/nodes.d.ts +16 -0
  60. package/lib/cjs/content-fields/hubtype-fields/nodes.js +3 -0
  61. package/lib/cjs/content-fields/hubtype-fields/nodes.js.map +1 -0
  62. package/lib/cjs/content-fields/hubtype-fields/payload.d.ts +8 -0
  63. package/lib/cjs/content-fields/hubtype-fields/payload.js +3 -0
  64. package/lib/cjs/content-fields/hubtype-fields/payload.js.map +1 -0
  65. package/lib/cjs/content-fields/hubtype-fields/start.d.ts +7 -0
  66. package/lib/cjs/content-fields/hubtype-fields/start.js +3 -0
  67. package/lib/cjs/content-fields/hubtype-fields/start.js.map +1 -0
  68. package/lib/cjs/content-fields/hubtype-fields/text.d.ts +11 -0
  69. package/lib/cjs/content-fields/hubtype-fields/text.js +3 -0
  70. package/lib/cjs/content-fields/hubtype-fields/text.js.map +1 -0
  71. package/lib/cjs/content-fields/hubtype-fields/url.d.ts +8 -0
  72. package/lib/cjs/content-fields/hubtype-fields/url.js +3 -0
  73. package/lib/cjs/content-fields/hubtype-fields/url.js.map +1 -0
  74. package/lib/cjs/content-fields/hubtype-fields/video.d.ts +8 -0
  75. package/lib/cjs/content-fields/hubtype-fields/video.js +3 -0
  76. package/lib/cjs/content-fields/hubtype-fields/video.js.map +1 -0
  77. package/lib/cjs/content-fields/hubtype-fields/whatsapp-button-list.d.ts +21 -0
  78. package/lib/cjs/content-fields/hubtype-fields/whatsapp-button-list.js +3 -0
  79. package/lib/cjs/content-fields/hubtype-fields/whatsapp-button-list.js.map +1 -0
  80. package/lib/cjs/content-fields/index.d.ts +7 -5
  81. package/lib/cjs/content-fields/index.js +11 -9
  82. package/lib/cjs/content-fields/index.js.map +1 -1
  83. package/lib/cjs/content-fields/whatsapp-button-list/flow-whatsapp-button-list-row.d.ts +10 -0
  84. package/lib/cjs/content-fields/whatsapp-button-list/flow-whatsapp-button-list-row.js +32 -0
  85. package/lib/cjs/content-fields/whatsapp-button-list/flow-whatsapp-button-list-row.js.map +1 -0
  86. package/lib/cjs/content-fields/whatsapp-button-list/flow-whatsapp-button-list-section.d.ts +10 -0
  87. package/lib/cjs/content-fields/whatsapp-button-list/flow-whatsapp-button-list-section.js +29 -0
  88. package/lib/cjs/content-fields/whatsapp-button-list/flow-whatsapp-button-list-section.js.map +1 -0
  89. package/lib/cjs/content-fields/whatsapp-button-list/flow-whatsapp-button-list.d.ts +12 -0
  90. package/lib/cjs/content-fields/whatsapp-button-list/flow-whatsapp-button-list.js +33 -0
  91. package/lib/cjs/content-fields/whatsapp-button-list/flow-whatsapp-button-list.js.map +1 -0
  92. package/lib/cjs/functions/conditional-provider.d.ts +2 -2
  93. package/lib/cjs/functions/conditional-provider.js +2 -2
  94. package/lib/cjs/functions/conditional-provider.js.map +1 -1
  95. package/lib/cjs/functions/conditional-queue-status.d.ts +7 -2
  96. package/lib/cjs/functions/conditional-queue-status.js +11 -1
  97. package/lib/cjs/functions/conditional-queue-status.js.map +1 -1
  98. package/lib/cjs/handoff.d.ts +2 -2
  99. package/lib/cjs/handoff.js +17 -9
  100. package/lib/cjs/handoff.js.map +1 -1
  101. package/lib/cjs/helpers.d.ts +2 -1
  102. package/lib/cjs/helpers.js +5 -13
  103. package/lib/cjs/helpers.js.map +1 -1
  104. package/lib/cjs/index.d.ts +10 -21
  105. package/lib/cjs/index.js +36 -151
  106. package/lib/cjs/index.js.map +1 -1
  107. package/lib/cjs/types.d.ts +8 -2
  108. package/lib/cjs/types.js.map +1 -1
  109. package/lib/esm/action.d.ts +16 -2
  110. package/lib/esm/action.js +21 -19
  111. package/lib/esm/action.js.map +1 -1
  112. package/lib/esm/api.d.ts +19 -0
  113. package/lib/esm/api.js +103 -0
  114. package/lib/esm/api.js.map +1 -0
  115. package/lib/esm/content-fields/content-fields-base.d.ts +4 -4
  116. package/lib/esm/content-fields/content-fields-base.js.map +1 -1
  117. package/lib/esm/content-fields/flow-button.d.ts +6 -3
  118. package/lib/esm/content-fields/flow-button.js +28 -21
  119. package/lib/esm/content-fields/flow-button.js.map +1 -1
  120. package/lib/esm/content-fields/flow-carousel.d.ts +3 -2
  121. package/lib/esm/content-fields/flow-carousel.js +4 -11
  122. package/lib/esm/content-fields/flow-carousel.js.map +1 -1
  123. package/lib/esm/content-fields/flow-element.d.ts +6 -3
  124. package/lib/esm/content-fields/flow-element.js +15 -5
  125. package/lib/esm/content-fields/flow-element.js.map +1 -1
  126. package/lib/esm/content-fields/flow-image.d.ts +2 -2
  127. package/lib/esm/content-fields/flow-image.js.map +1 -1
  128. package/lib/esm/content-fields/flow-text.d.ts +4 -3
  129. package/lib/esm/content-fields/flow-text.js +9 -9
  130. package/lib/esm/content-fields/flow-text.js.map +1 -1
  131. package/lib/esm/content-fields/flow-video.d.ts +2 -2
  132. package/lib/esm/content-fields/flow-video.js +0 -1
  133. package/lib/esm/content-fields/flow-video.js.map +1 -1
  134. package/lib/esm/content-fields/hubtype-fields/button.d.ts +9 -0
  135. package/lib/esm/content-fields/hubtype-fields/button.js +2 -0
  136. package/lib/esm/content-fields/hubtype-fields/button.js.map +1 -0
  137. package/lib/esm/content-fields/hubtype-fields/carousel.d.ts +16 -0
  138. package/lib/esm/content-fields/hubtype-fields/carousel.js +2 -0
  139. package/lib/esm/content-fields/hubtype-fields/carousel.js.map +1 -0
  140. package/lib/esm/content-fields/hubtype-fields/common.d.ts +55 -0
  141. package/lib/esm/content-fields/hubtype-fields/common.js +2 -0
  142. package/lib/esm/content-fields/hubtype-fields/common.js.map +1 -0
  143. package/lib/esm/content-fields/hubtype-fields/fallback.d.ts +9 -0
  144. package/lib/esm/content-fields/hubtype-fields/fallback.js +2 -0
  145. package/lib/esm/content-fields/hubtype-fields/fallback.js.map +1 -0
  146. package/lib/esm/content-fields/hubtype-fields/function.d.ts +28 -0
  147. package/lib/esm/content-fields/hubtype-fields/function.js +7 -0
  148. package/lib/esm/content-fields/hubtype-fields/function.js.map +1 -0
  149. package/lib/esm/content-fields/hubtype-fields/handoff.d.ts +10 -0
  150. package/lib/esm/content-fields/hubtype-fields/handoff.js +2 -0
  151. package/lib/esm/content-fields/hubtype-fields/handoff.js.map +1 -0
  152. package/lib/esm/content-fields/hubtype-fields/image.d.ts +8 -0
  153. package/lib/esm/content-fields/hubtype-fields/image.js +2 -0
  154. package/lib/esm/content-fields/hubtype-fields/image.js.map +1 -0
  155. package/lib/esm/content-fields/hubtype-fields/index.d.ts +17 -0
  156. package/lib/esm/content-fields/hubtype-fields/index.js +18 -0
  157. package/lib/esm/content-fields/hubtype-fields/index.js.map +1 -0
  158. package/lib/esm/content-fields/hubtype-fields/intent.d.ts +10 -0
  159. package/lib/esm/content-fields/hubtype-fields/intent.js +2 -0
  160. package/lib/esm/content-fields/hubtype-fields/intent.js.map +1 -0
  161. package/lib/esm/content-fields/hubtype-fields/keyword.d.ts +9 -0
  162. package/lib/esm/content-fields/hubtype-fields/keyword.js +2 -0
  163. package/lib/esm/content-fields/hubtype-fields/keyword.js.map +1 -0
  164. package/lib/esm/content-fields/hubtype-fields/node-types.d.ts +23 -0
  165. package/lib/esm/content-fields/hubtype-fields/node-types.js +28 -0
  166. package/lib/esm/content-fields/hubtype-fields/node-types.js.map +1 -0
  167. package/lib/esm/content-fields/hubtype-fields/nodes.d.ts +16 -0
  168. package/lib/esm/content-fields/hubtype-fields/nodes.js +2 -0
  169. package/lib/esm/content-fields/hubtype-fields/nodes.js.map +1 -0
  170. package/lib/esm/content-fields/hubtype-fields/payload.d.ts +8 -0
  171. package/lib/esm/content-fields/hubtype-fields/payload.js +2 -0
  172. package/lib/esm/content-fields/hubtype-fields/payload.js.map +1 -0
  173. package/lib/esm/content-fields/hubtype-fields/start.d.ts +7 -0
  174. package/lib/esm/content-fields/hubtype-fields/start.js +2 -0
  175. package/lib/esm/content-fields/hubtype-fields/start.js.map +1 -0
  176. package/lib/esm/content-fields/hubtype-fields/text.d.ts +11 -0
  177. package/lib/esm/content-fields/hubtype-fields/text.js +2 -0
  178. package/lib/esm/content-fields/hubtype-fields/text.js.map +1 -0
  179. package/lib/esm/content-fields/hubtype-fields/url.d.ts +8 -0
  180. package/lib/esm/content-fields/hubtype-fields/url.js +2 -0
  181. package/lib/esm/content-fields/hubtype-fields/url.js.map +1 -0
  182. package/lib/esm/content-fields/hubtype-fields/video.d.ts +8 -0
  183. package/lib/esm/content-fields/hubtype-fields/video.js +2 -0
  184. package/lib/esm/content-fields/hubtype-fields/video.js.map +1 -0
  185. package/lib/esm/content-fields/hubtype-fields/whatsapp-button-list.d.ts +21 -0
  186. package/lib/esm/content-fields/hubtype-fields/whatsapp-button-list.js +2 -0
  187. package/lib/esm/content-fields/hubtype-fields/whatsapp-button-list.js.map +1 -0
  188. package/lib/esm/content-fields/index.d.ts +7 -5
  189. package/lib/esm/content-fields/index.js +6 -4
  190. package/lib/esm/content-fields/index.js.map +1 -1
  191. package/lib/esm/content-fields/whatsapp-button-list/flow-whatsapp-button-list-row.d.ts +10 -0
  192. package/lib/esm/content-fields/whatsapp-button-list/flow-whatsapp-button-list-row.js +28 -0
  193. package/lib/esm/content-fields/whatsapp-button-list/flow-whatsapp-button-list-row.js.map +1 -0
  194. package/lib/esm/content-fields/whatsapp-button-list/flow-whatsapp-button-list-section.d.ts +10 -0
  195. package/lib/esm/content-fields/whatsapp-button-list/flow-whatsapp-button-list-section.js +25 -0
  196. package/lib/esm/content-fields/whatsapp-button-list/flow-whatsapp-button-list-section.js.map +1 -0
  197. package/lib/esm/content-fields/whatsapp-button-list/flow-whatsapp-button-list.d.ts +12 -0
  198. package/lib/esm/content-fields/whatsapp-button-list/flow-whatsapp-button-list.js +28 -0
  199. package/lib/esm/content-fields/whatsapp-button-list/flow-whatsapp-button-list.js.map +1 -0
  200. package/lib/esm/functions/conditional-provider.d.ts +2 -2
  201. package/lib/esm/functions/conditional-provider.js +2 -2
  202. package/lib/esm/functions/conditional-provider.js.map +1 -1
  203. package/lib/esm/functions/conditional-queue-status.d.ts +7 -2
  204. package/lib/esm/functions/conditional-queue-status.js +11 -1
  205. package/lib/esm/functions/conditional-queue-status.js.map +1 -1
  206. package/lib/esm/handoff.d.ts +2 -2
  207. package/lib/esm/handoff.js +17 -9
  208. package/lib/esm/handoff.js.map +1 -1
  209. package/lib/esm/helpers.d.ts +2 -1
  210. package/lib/esm/helpers.js +3 -11
  211. package/lib/esm/helpers.js.map +1 -1
  212. package/lib/esm/index.d.ts +10 -21
  213. package/lib/esm/index.js +38 -153
  214. package/lib/esm/index.js.map +1 -1
  215. package/lib/esm/types.d.ts +8 -2
  216. package/lib/esm/types.js.map +1 -1
  217. package/package.json +4 -5
  218. package/src/action.tsx +31 -22
  219. package/src/api.ts +162 -0
  220. package/src/content-fields/content-fields-base.ts +7 -7
  221. package/src/content-fields/flow-button.tsx +40 -19
  222. package/src/content-fields/flow-carousel.tsx +10 -18
  223. package/src/content-fields/flow-element.tsx +26 -9
  224. package/src/content-fields/flow-image.tsx +2 -2
  225. package/src/content-fields/flow-text.tsx +15 -12
  226. package/src/content-fields/flow-video.tsx +2 -3
  227. package/src/content-fields/hubtype-fields/button.ts +15 -0
  228. package/src/content-fields/hubtype-fields/carousel.ts +18 -0
  229. package/src/content-fields/hubtype-fields/common.ts +65 -0
  230. package/src/content-fields/hubtype-fields/fallback.ts +10 -0
  231. package/src/content-fields/hubtype-fields/function.ts +33 -0
  232. package/src/content-fields/hubtype-fields/handoff.ts +11 -0
  233. package/src/content-fields/hubtype-fields/image.ts +9 -0
  234. package/src/content-fields/hubtype-fields/index.ts +17 -0
  235. package/src/content-fields/hubtype-fields/intent.ts +11 -0
  236. package/src/content-fields/hubtype-fields/keyword.ts +10 -0
  237. package/src/content-fields/hubtype-fields/node-types.ts +26 -0
  238. package/src/content-fields/hubtype-fields/nodes.ts +32 -0
  239. package/src/content-fields/hubtype-fields/payload.ts +9 -0
  240. package/src/content-fields/hubtype-fields/start.ts +8 -0
  241. package/src/content-fields/hubtype-fields/text.ts +12 -0
  242. package/src/content-fields/hubtype-fields/url.ts +9 -0
  243. package/src/content-fields/hubtype-fields/video.ts +9 -0
  244. package/src/content-fields/hubtype-fields/whatsapp-button-list.ts +25 -0
  245. package/src/content-fields/index.ts +14 -5
  246. package/src/content-fields/whatsapp-button-list/flow-whatsapp-button-list-row.tsx +33 -0
  247. package/src/content-fields/whatsapp-button-list/flow-whatsapp-button-list-section.tsx +35 -0
  248. package/src/content-fields/whatsapp-button-list/flow-whatsapp-button-list.tsx +46 -0
  249. package/src/functions/conditional-provider.ts +2 -2
  250. package/src/functions/conditional-queue-status.ts +22 -3
  251. package/src/handoff.ts +27 -14
  252. package/src/helpers.ts +8 -19
  253. package/src/index.ts +55 -197
  254. package/src/types.ts +14 -2
  255. package/lib/cjs/content-fields/types.d.ts +0 -5
  256. package/lib/cjs/content-fields/types.js.map +0 -1
  257. package/lib/cjs/flow-builder-models.d.ts +0 -196
  258. package/lib/cjs/flow-builder-models.js +0 -24
  259. package/lib/cjs/flow-builder-models.js.map +0 -1
  260. package/lib/esm/content-fields/types.d.ts +0 -5
  261. package/lib/esm/content-fields/types.js +0 -2
  262. package/lib/esm/content-fields/types.js.map +0 -1
  263. package/lib/esm/flow-builder-models.d.ts +0 -196
  264. package/lib/esm/flow-builder-models.js +0 -21
  265. package/lib/esm/flow-builder-models.js.map +0 -1
  266. package/src/.DS_Store +0 -0
  267. package/src/content-fields/types.ts +0 -6
  268. package/src/flow-builder-models.ts +0 -249
package/src/index.ts CHANGED
@@ -1,254 +1,112 @@
1
1
  import {
2
- Input,
3
2
  Plugin,
4
3
  PluginPostRequest,
5
4
  PluginPreRequest,
6
5
  Session,
7
6
  } from '@botonic/core'
8
- import axios from 'axios'
7
+ import { ActionRequest } from '@botonic/react'
9
8
 
9
+ import { FlowBuilderApi } from './api'
10
10
  import {
11
11
  FlowCarousel,
12
12
  FlowContent,
13
13
  FlowImage,
14
14
  FlowText,
15
15
  FlowVideo,
16
+ FlowWhatsappButtonList,
16
17
  } from './content-fields'
17
18
  import {
18
- FallbackNode,
19
- FlowBuilderData,
20
- FunctionNode,
21
- HandoffNode,
22
- IntentNode,
23
- KeywordNode,
24
- NodeComponent,
25
- NodeType,
26
- StartNode,
27
- } from './flow-builder-models'
19
+ HtFunctionNode,
20
+ HtHandoffNode,
21
+ HtNodeComponent,
22
+ HtNodeWithContent,
23
+ HtNodeWithContentType,
24
+ } from './content-fields/hubtype-fields'
28
25
  import { DEFAULT_FUNCTIONS } from './functions'
29
- import { updateButtonUrls } from './helpers'
26
+ import { isHandoffNode } from './helpers'
30
27
  import { BotonicPluginFlowBuilderOptions } from './types'
31
28
  import { resolveGetAccessToken } from './utils'
32
29
 
33
30
  export default class BotonicPluginFlowBuilder implements Plugin {
34
- private flowUrl: string
35
- private flow: Promise<FlowBuilderData> | FlowBuilderData
31
+ public cmsApi: FlowBuilderApi
36
32
  private functions: Record<any, any>
37
33
  private currentRequest: PluginPreRequest
38
34
  private getAccessToken: (session: Session) => string
39
35
  public getLocale: (session: Session) => string
36
+ public trackEvent?: (
37
+ request: ActionRequest,
38
+ eventName: string,
39
+ args?: Record<string, any>
40
+ ) => Promise<void>
40
41
 
41
42
  constructor(readonly options: BotonicPluginFlowBuilderOptions) {
43
+ this.cmsApi = new FlowBuilderApi({
44
+ url: options.flowUrl,
45
+ flow: options.flow,
46
+ })
42
47
  this.getLocale = options.getLocale
43
48
  this.getAccessToken = resolveGetAccessToken(options)
44
- this.flowUrl = options.flowUrl
45
- if (options.flow) this.flow = options.flow
49
+ this.trackEvent = options.trackEvent
46
50
  const customFunctions = options.customFunctions || {}
47
51
  this.functions = { ...DEFAULT_FUNCTIONS, ...customFunctions }
48
52
  }
49
53
 
50
- async readFlowContent(session: Session): Promise<FlowBuilderData> {
51
- const { data } = await axios.get(this.flowUrl, {
52
- headers: { Authorization: `Bearer ${this.getAccessToken(session)}` },
53
- })
54
- return data
55
- }
56
-
57
54
  async pre(request: PluginPreRequest): Promise<void> {
58
55
  this.currentRequest = request
59
- this.flow = await this.readFlowContent(this.currentRequest.session)
56
+ await this.cmsApi.init(this.getAccessToken(request.session))
60
57
  }
61
58
 
62
59
  async post(_request: PluginPostRequest): Promise<void> {}
63
60
 
64
- async getContent(id: string): Promise<NodeComponent> {
65
- const flow = await this.flow
66
- const content = flow.nodes.find(node => node.id === id)
67
- if (!content) throw Error(`Node with id: '${id}' not found`)
68
- return content
69
- }
70
-
71
- async getContentByCode(code: string): Promise<NodeComponent> {
72
- const flow = await this.flow
73
- const content = flow.nodes.find(node => {
74
- if ('code' in node) return node.code === code
75
- return undefined
76
- })
77
- if (!content) throw Error(`Node with code: '${code}' not found`)
78
- return content
79
- }
80
-
81
- async getHandoffContent(
82
- handoffTargetId: string | undefined
83
- ): Promise<HandoffNode | undefined> {
84
- if (!handoffTargetId) return undefined
85
- return (await this.getContent(handoffTargetId)) as HandoffNode
86
- }
87
-
88
- getFlowContent(
89
- hubtypeContent: NodeComponent,
90
- locale: string
91
- ): FlowContent | undefined {
92
- switch (hubtypeContent.type) {
93
- case NodeType.TEXT:
94
- return FlowText.fromHubtypeCMS(hubtypeContent, locale)
95
- case NodeType.IMAGE:
96
- return FlowImage.fromHubtypeCMS(hubtypeContent, locale)
97
- case NodeType.CAROUSEL:
98
- return FlowCarousel.fromHubtypeCMS(hubtypeContent, locale)
99
- case NodeType.VIDEO:
100
- return FlowVideo.fromHubtypeCMS(hubtypeContent, locale)
101
- default:
102
- return undefined
103
- }
104
- }
105
-
106
- async getStartId(): Promise<string> {
107
- const flow = await this.flow
108
- const startNode = flow.nodes.find(
109
- node => node.type === NodeType.START_UP
110
- ) as StartNode | undefined
111
- if (!startNode) throw new Error('start-up id must be defined')
112
- return startNode.target.id
113
- }
114
-
115
- async getFallbackId(alternate: boolean): Promise<string> {
116
- const flow = await this.flow
117
- const fallbackNode = flow.nodes.find(
118
- node => node.type === NodeType.FALLBACK
119
- ) as FallbackNode | undefined
120
- if (!fallbackNode) throw new Error('fallback node must be defined')
121
- const fallbackFirstMessage = fallbackNode.content.first_message
122
- const fallbackSecondMessage = fallbackNode.content.second_message
123
- if (!fallbackSecondMessage) return fallbackFirstMessage.id
124
- return alternate ? fallbackFirstMessage.id : fallbackSecondMessage.id
125
- }
126
- async getContents(
127
- id: string,
61
+ async getContent(
62
+ nodeOrId: HtNodeWithContent | string,
128
63
  locale: string,
129
64
  prevContents?: FlowContent[]
130
- ): Promise<{ contents: FlowContent[]; handoffNode: HandoffNode }> {
65
+ ): Promise<{ contents: FlowContent[]; handoffNode?: HtHandoffNode }> {
131
66
  const contents = prevContents || []
132
- const hubtypeContent: any = await this.getContent(id)
133
- const isHandoff = hubtypeContent.type === NodeType.HANDOFF
134
- // TODO: Create function to populate these buttons
135
- await updateButtonUrls(hubtypeContent, 'elements', this.getContent)
136
- await updateButtonUrls(hubtypeContent, 'buttons', this.getContent)
137
- const content = this.getFlowContent(hubtypeContent, locale)
67
+ let node = nodeOrId as HtNodeWithContent
68
+ if (typeof nodeOrId === 'string') {
69
+ node = this.cmsApi.getNode(nodeOrId) as HtNodeWithContent
70
+ }
138
71
 
139
- this.replaceButtonPayload(content)
72
+ const content = await this.getFlowContent(node, locale)
140
73
 
141
- if (hubtypeContent.type === NodeType.FUNCTION) {
142
- const targetId = await this.callFunction(hubtypeContent, locale)
143
- return this.getContents(targetId, locale, contents)
74
+ if (node.type === HtNodeWithContentType.FUNCTION) {
75
+ const targetId = await this.callFunction(node, locale)
76
+ return this.getContent(targetId, locale, contents)
144
77
  } else {
145
78
  if (content) contents.push(content)
146
79
  // TODO: prevent infinite recursive calls
147
80
 
148
- if (hubtypeContent.follow_up)
149
- return this.getContents(hubtypeContent.follow_up.id, locale, contents)
81
+ if (node.follow_up)
82
+ return this.getContent(node.follow_up.id, locale, contents)
150
83
  }
151
- // execute function
152
- // return this.getContents(function result_mapping target, locale, contents)
153
- return { contents, handoffNode: isHandoff && hubtypeContent }
154
- }
155
84
 
156
- private async replaceButtonPayload(content: FlowContent | undefined) {
157
- if (content && 'buttons' in content) {
158
- for (const button of content.buttons) {
159
- if (button.payload) {
160
- const contentButton = await this.getContent(button.payload)
161
- if (contentButton?.type === NodeType.PAYLOAD) {
162
- button.payload = contentButton.content.payload
163
- }
164
- }
165
- }
166
- }
85
+ return { contents, handoffNode: isHandoffNode(node) ? node : undefined }
167
86
  }
168
87
 
169
- async getPayloadByIntent(
170
- input: Input,
88
+ private getFlowContent(
89
+ hubtypeContent: HtNodeComponent,
171
90
  locale: string
172
- ): Promise<string | undefined> {
173
- try {
174
- const flow = await this.flow
175
- const intents = flow.nodes.filter(
176
- node => node.type === NodeType.INTENT
177
- ) as IntentNode[]
178
- const inputIntent = input.intent
179
- const inputConfidence = input.confidence
180
- if (inputIntent) {
181
- const matchedIntentNode = intents.find(
182
- node =>
183
- inputIntent &&
184
- this.hasIntent(node, inputIntent, locale) &&
185
- inputConfidence &&
186
- this.hasMetConfidenceThreshold(node, inputConfidence)
187
- )
188
- return matchedIntentNode?.target?.id
189
- }
190
- } catch (error) {
191
- console.error('Error getting payload by input: ', error)
192
- }
193
-
194
- return undefined
195
- }
196
-
197
- hasIntent(node: IntentNode, intent: string, locale: string): boolean {
198
- return node.content.intents.some(
199
- i => i.locale === locale && i.values.includes(intent)
200
- )
201
- }
202
-
203
- hasMetConfidenceThreshold(
204
- node: IntentNode,
205
- predictedConfidence: number
206
- ): boolean {
207
- const nodeConfidence = node.content.confidence / 100
208
- return predictedConfidence >= nodeConfidence
209
- }
210
-
211
- async getPayloadByKeyword(
212
- input: Input,
213
- locale: string
214
- ): Promise<string | undefined> {
215
- try {
216
- const flow = await this.flow
217
- const keywordNodes = flow.nodes.filter(
218
- node => node.type == NodeType.KEYWORD
219
- ) as KeywordNode[]
220
- const matchedKeywordNodes = keywordNodes.filter(node =>
221
- //@ts-ignore
222
- this.matchKeywords(node, input.data, locale)
223
- )
224
- if (matchedKeywordNodes.length > 0) {
225
- return matchedKeywordNodes[0].target?.id
226
- }
227
- } catch (error) {
228
- console.error('Error getting payload by input: ', error)
229
- }
230
-
231
- return undefined
232
- }
233
-
234
- matchKeywords(node: KeywordNode, input: string, locale: string): boolean {
235
- const result = node.content.keywords.find(
236
- i => i.locale === locale && this.containsAnyKeywords(input, i.values)
237
- )
238
- return Boolean(result)
239
- }
240
-
241
- containsAnyKeywords(input: string, keywords: string[]): boolean {
242
- for (let i = 0; i < keywords.length; i++) {
243
- if (input.includes(keywords[i])) {
244
- return true
245
- }
91
+ ): FlowContent | undefined {
92
+ switch (hubtypeContent.type) {
93
+ case HtNodeWithContentType.TEXT:
94
+ return FlowText.fromHubtypeCMS(hubtypeContent, locale, this.cmsApi)
95
+ case HtNodeWithContentType.IMAGE:
96
+ return FlowImage.fromHubtypeCMS(hubtypeContent, locale)
97
+ case HtNodeWithContentType.CAROUSEL:
98
+ return FlowCarousel.fromHubtypeCMS(hubtypeContent, locale, this.cmsApi)
99
+ case HtNodeWithContentType.VIDEO:
100
+ return FlowVideo.fromHubtypeCMS(hubtypeContent, locale)
101
+ case HtNodeWithContentType.WHATSAPP_BUTTON_LIST:
102
+ return FlowWhatsappButtonList.fromHubtypeCMS(hubtypeContent, locale)
103
+ default:
104
+ return undefined
246
105
  }
247
- return false
248
106
  }
249
107
 
250
108
  async callFunction(
251
- functionNode: FunctionNode,
109
+ functionNode: HtFunctionNode,
252
110
  locale: string
253
111
  ): Promise<string> {
254
112
  const functionNodeId = functionNode.id
@@ -259,7 +117,7 @@ export default class BotonicPluginFlowBuilder implements Plugin {
259
117
 
260
118
  const args = Object.assign(
261
119
  {
262
- session: this.currentRequest.session,
120
+ request: this.currentRequest,
263
121
  results: [functionNode.content.result_mapping.map(r => r.result)],
264
122
  },
265
123
  ...nameValues
@@ -271,7 +129,7 @@ export default class BotonicPluginFlowBuilder implements Plugin {
271
129
  const result = functionNode.content.result_mapping.find(
272
130
  r => r.result === functionResult
273
131
  )
274
- if (!result) {
132
+ if (!result?.target) {
275
133
  throw new Error(
276
134
  `No result found for result_mapping for node with id: ${functionNodeId}`
277
135
  )
package/src/types.ts CHANGED
@@ -1,13 +1,25 @@
1
1
  import { Session } from '@botonic/core'
2
+ import { ActionRequest } from '@botonic/react'
2
3
 
3
- import { FlowBuilderData } from './flow-builder-models'
4
+ import { FlowBuilderApi } from './api'
5
+ import { HtFlowBuilderData } from './content-fields/hubtype-fields'
4
6
 
5
7
  export interface BotonicPluginFlowBuilderOptions {
6
8
  flowUrl: string
7
- flow?: FlowBuilderData
9
+ flow?: HtFlowBuilderData
8
10
  customFunctions?: Record<any, any>
9
11
  getLocale: (session: Session) => string
10
12
  getAccessToken: () => string
13
+ trackEvent?: (
14
+ request: ActionRequest,
15
+ eventName: string,
16
+ args?: Record<string, any>
17
+ ) => Promise<void>
18
+ }
19
+
20
+ export interface FlowBuilderApiOptions {
21
+ url: string
22
+ flow?: HtFlowBuilderData
11
23
  }
12
24
 
13
25
  export enum ProcessEnvNodeEnvs {
@@ -1,5 +0,0 @@
1
- import { FlowCarousel } from './flow-carousel';
2
- import { FlowImage } from './flow-image';
3
- import { FlowText } from './flow-text';
4
- import { FlowVideo } from './flow-video';
5
- export type FlowContent = FlowText | FlowImage | FlowCarousel | FlowVideo;
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/content-fields/types.ts"],"names":[],"mappings":""}
@@ -1,196 +0,0 @@
1
- export interface FlowBuilderData {
2
- version: string;
3
- name: string;
4
- locales: string[];
5
- start_node_id?: string;
6
- ai_model_id?: string;
7
- nodes: NodeComponent[];
8
- }
9
- export declare enum NodeType {
10
- TEXT = "text",
11
- IMAGE = "image",
12
- CAROUSEL = "carousel",
13
- HANDOFF = "handoff",
14
- KEYWORD = "keyword",
15
- INTENT = "intent",
16
- START_UP = "start-up",
17
- URL = "url",
18
- PAYLOAD = "payload",
19
- FUNCTION = "function",
20
- FALLBACK = "fallback",
21
- VIDEO = "video"
22
- }
23
- export interface BaseNode {
24
- id: string;
25
- type: NodeType;
26
- }
27
- export interface Meta {
28
- x: number;
29
- y: number;
30
- }
31
- export interface Node extends BaseNode {
32
- code: string;
33
- meta: Meta;
34
- follow_up?: NodeLink;
35
- target?: NodeLink;
36
- }
37
- export interface NodeLink {
38
- id: string;
39
- type: NodeType;
40
- }
41
- export interface TextLocale {
42
- message: string;
43
- locale: string;
44
- }
45
- export declare enum ButtonStyle {
46
- BUTTON = "button",
47
- QUICK_REPLY = "quick-reply"
48
- }
49
- export interface UrlLocale {
50
- id: string;
51
- locale: string;
52
- }
53
- export interface PayloadLocale {
54
- id: string;
55
- locale: string;
56
- }
57
- export interface Button {
58
- id: string;
59
- text: TextLocale[];
60
- target?: NodeLink;
61
- hidden: string;
62
- url?: UrlLocale[];
63
- payload?: PayloadLocale[];
64
- }
65
- export interface TextNodeContent {
66
- text: TextLocale[];
67
- buttons_style?: ButtonStyle;
68
- buttons: Button[];
69
- }
70
- export interface TextNode extends Node {
71
- type: NodeType.TEXT;
72
- content: TextNodeContent;
73
- }
74
- export interface MediaFileLocale {
75
- id: string;
76
- file: string;
77
- locale: string;
78
- }
79
- export interface ImageNodeContent {
80
- image: MediaFileLocale[];
81
- }
82
- export interface ImageNode extends Node {
83
- type: NodeType.IMAGE;
84
- content: ImageNodeContent;
85
- }
86
- export interface CarouselElementNode {
87
- id: string;
88
- title: TextLocale[];
89
- subtitle: TextLocale[];
90
- image: MediaFileLocale[];
91
- button: Button;
92
- }
93
- export interface CarouselNodeContent {
94
- elements: CarouselElementNode[];
95
- }
96
- export interface CarouselNode extends Node {
97
- type: NodeType.CAROUSEL;
98
- content: CarouselNodeContent;
99
- }
100
- export interface QueueLocale {
101
- id: string;
102
- name: string;
103
- locale: string;
104
- }
105
- export interface HandoffNodeContent {
106
- queue: QueueLocale[];
107
- payload: PayloadLocale[];
108
- has_auto_assign: boolean;
109
- }
110
- export interface HandoffNode extends Node {
111
- type: NodeType.HANDOFF;
112
- content: HandoffNodeContent;
113
- }
114
- export interface InputLocale {
115
- values: string[];
116
- locale: string;
117
- }
118
- export interface KeywordNodeContent {
119
- title: TextLocale[];
120
- keywords: InputLocale[];
121
- }
122
- export interface KeywordNode extends Node {
123
- type: NodeType.KEYWORD;
124
- content: KeywordNodeContent;
125
- }
126
- export interface IntentNodeContent {
127
- title: TextLocale[];
128
- intents: InputLocale[];
129
- confidence: number;
130
- }
131
- export interface IntentNode extends Node {
132
- type: NodeType.INTENT;
133
- content: IntentNodeContent;
134
- }
135
- export interface StartNode extends BaseNode {
136
- type: NodeType.START_UP;
137
- target: NodeLink;
138
- }
139
- export interface UrlNodeContent {
140
- url: string;
141
- }
142
- export interface UrlNode extends BaseNode {
143
- type: NodeType.URL;
144
- content: UrlNodeContent;
145
- }
146
- export interface PayloadNodeContent {
147
- payload: string;
148
- }
149
- export interface PayloadNode extends BaseNode {
150
- type: NodeType.PAYLOAD;
151
- content: PayloadNodeContent;
152
- }
153
- export type ArgumentType = number | string | Record<any, any>;
154
- export interface FunctionNodeArgument {
155
- type: ArgumentType;
156
- name: string;
157
- value: string;
158
- }
159
- export interface FunctionNodeArgumentLocale {
160
- locale: string;
161
- values: FunctionNodeArgument[];
162
- }
163
- export interface FunctionNodeResult {
164
- result: string;
165
- target: NodeLink;
166
- }
167
- export interface FunctionNodeContent {
168
- action: string;
169
- arguments: FunctionNodeArgumentLocale[];
170
- result_mapping: FunctionNodeResult[];
171
- }
172
- export interface FunctionNode extends Node {
173
- type: NodeType.FUNCTION;
174
- content: FunctionNodeContent;
175
- }
176
- export interface FallbackNodeContent {
177
- first_message: NodeLink;
178
- second_message: NodeLink;
179
- }
180
- export interface FallbackNode extends Node {
181
- type: NodeType.FALLBACK;
182
- content: FallbackNodeContent;
183
- }
184
- export interface VideoLocale {
185
- url: string;
186
- is_embedded?: boolean;
187
- locale: string;
188
- }
189
- export interface VideoNodeContent {
190
- video: VideoLocale[];
191
- }
192
- export interface VideoNode extends Node {
193
- type: NodeType.VIDEO;
194
- content: VideoNodeContent;
195
- }
196
- export type NodeComponent = TextNode | ImageNode | CarouselNode | HandoffNode | KeywordNode | IntentNode | UrlNode | StartNode | PayloadNode | FunctionNode | FallbackNode | VideoNode;
@@ -1,24 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ButtonStyle = exports.NodeType = void 0;
4
- var NodeType;
5
- (function (NodeType) {
6
- NodeType["TEXT"] = "text";
7
- NodeType["IMAGE"] = "image";
8
- NodeType["CAROUSEL"] = "carousel";
9
- NodeType["HANDOFF"] = "handoff";
10
- NodeType["KEYWORD"] = "keyword";
11
- NodeType["INTENT"] = "intent";
12
- NodeType["START_UP"] = "start-up";
13
- NodeType["URL"] = "url";
14
- NodeType["PAYLOAD"] = "payload";
15
- NodeType["FUNCTION"] = "function";
16
- NodeType["FALLBACK"] = "fallback";
17
- NodeType["VIDEO"] = "video";
18
- })(NodeType = exports.NodeType || (exports.NodeType = {}));
19
- var ButtonStyle;
20
- (function (ButtonStyle) {
21
- ButtonStyle["BUTTON"] = "button";
22
- ButtonStyle["QUICK_REPLY"] = "quick-reply";
23
- })(ButtonStyle = exports.ButtonStyle || (exports.ButtonStyle = {}));
24
- //# sourceMappingURL=flow-builder-models.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"flow-builder-models.js","sourceRoot":"","sources":["../../src/flow-builder-models.ts"],"names":[],"mappings":";;;AAUA,IAAY,QAaX;AAbD,WAAY,QAAQ;IAClB,yBAAa,CAAA;IACb,2BAAe,CAAA;IACf,iCAAqB,CAAA;IACrB,+BAAmB,CAAA;IACnB,+BAAmB,CAAA;IACnB,6BAAiB,CAAA;IACjB,iCAAqB,CAAA;IACrB,uBAAW,CAAA;IACX,+BAAmB,CAAA;IACnB,iCAAqB,CAAA;IACrB,iCAAqB,CAAA;IACrB,2BAAe,CAAA;AACjB,CAAC,EAbW,QAAQ,GAAR,gBAAQ,KAAR,gBAAQ,QAanB;AA6BD,IAAY,WAGX;AAHD,WAAY,WAAW;IACrB,gCAAiB,CAAA;IACjB,0CAA2B,CAAA;AAC7B,CAAC,EAHW,WAAW,GAAX,mBAAW,KAAX,mBAAW,QAGtB"}
@@ -1,5 +0,0 @@
1
- import { FlowCarousel } from './flow-carousel';
2
- import { FlowImage } from './flow-image';
3
- import { FlowText } from './flow-text';
4
- import { FlowVideo } from './flow-video';
5
- export type FlowContent = FlowText | FlowImage | FlowCarousel | FlowVideo;
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=types.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/content-fields/types.ts"],"names":[],"mappings":""}