@botonic/plugin-flow-builder 0.22.0-alpha.2 → 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 (256) hide show
  1. package/lib/cjs/action.js +14 -12
  2. package/lib/cjs/action.js.map +1 -1
  3. package/lib/cjs/api.d.ts +19 -0
  4. package/lib/cjs/api.js +108 -0
  5. package/lib/cjs/api.js.map +1 -0
  6. package/lib/cjs/content-fields/content-fields-base.d.ts +4 -4
  7. package/lib/cjs/content-fields/content-fields-base.js.map +1 -1
  8. package/lib/cjs/content-fields/flow-button.d.ts +6 -3
  9. package/lib/cjs/content-fields/flow-button.js +28 -21
  10. package/lib/cjs/content-fields/flow-button.js.map +1 -1
  11. package/lib/cjs/content-fields/flow-carousel.d.ts +3 -2
  12. package/lib/cjs/content-fields/flow-carousel.js +3 -10
  13. package/lib/cjs/content-fields/flow-carousel.js.map +1 -1
  14. package/lib/cjs/content-fields/flow-element.d.ts +6 -3
  15. package/lib/cjs/content-fields/flow-element.js +16 -5
  16. package/lib/cjs/content-fields/flow-element.js.map +1 -1
  17. package/lib/cjs/content-fields/flow-image.d.ts +2 -2
  18. package/lib/cjs/content-fields/flow-image.js.map +1 -1
  19. package/lib/cjs/content-fields/flow-text.d.ts +4 -3
  20. package/lib/cjs/content-fields/flow-text.js +9 -9
  21. package/lib/cjs/content-fields/flow-text.js.map +1 -1
  22. package/lib/cjs/content-fields/flow-video.d.ts +2 -2
  23. package/lib/cjs/content-fields/flow-video.js +0 -1
  24. package/lib/cjs/content-fields/flow-video.js.map +1 -1
  25. package/lib/cjs/content-fields/hubtype-fields/button.d.ts +9 -0
  26. package/lib/cjs/content-fields/hubtype-fields/button.js +3 -0
  27. package/lib/cjs/content-fields/hubtype-fields/button.js.map +1 -0
  28. package/lib/cjs/content-fields/hubtype-fields/carousel.d.ts +16 -0
  29. package/lib/cjs/content-fields/hubtype-fields/carousel.js +3 -0
  30. package/lib/cjs/content-fields/hubtype-fields/carousel.js.map +1 -0
  31. package/lib/cjs/content-fields/hubtype-fields/common.d.ts +55 -0
  32. package/lib/cjs/content-fields/hubtype-fields/common.js +3 -0
  33. package/lib/cjs/content-fields/hubtype-fields/common.js.map +1 -0
  34. package/lib/cjs/content-fields/hubtype-fields/fallback.d.ts +9 -0
  35. package/lib/cjs/content-fields/hubtype-fields/fallback.js +3 -0
  36. package/lib/cjs/content-fields/hubtype-fields/fallback.js.map +1 -0
  37. package/lib/cjs/content-fields/hubtype-fields/function.d.ts +28 -0
  38. package/lib/cjs/content-fields/hubtype-fields/function.js +10 -0
  39. package/lib/cjs/content-fields/hubtype-fields/function.js.map +1 -0
  40. package/lib/cjs/content-fields/hubtype-fields/handoff.d.ts +10 -0
  41. package/lib/cjs/content-fields/hubtype-fields/handoff.js +3 -0
  42. package/lib/cjs/content-fields/hubtype-fields/handoff.js.map +1 -0
  43. package/lib/cjs/content-fields/hubtype-fields/image.d.ts +8 -0
  44. package/lib/cjs/content-fields/{types.js → hubtype-fields/image.js} +1 -1
  45. package/lib/cjs/content-fields/hubtype-fields/image.js.map +1 -0
  46. package/lib/cjs/content-fields/hubtype-fields/index.d.ts +17 -0
  47. package/lib/cjs/content-fields/hubtype-fields/index.js +21 -0
  48. package/lib/cjs/content-fields/hubtype-fields/index.js.map +1 -0
  49. package/lib/cjs/content-fields/hubtype-fields/intent.d.ts +10 -0
  50. package/lib/cjs/content-fields/hubtype-fields/intent.js +3 -0
  51. package/lib/cjs/content-fields/hubtype-fields/intent.js.map +1 -0
  52. package/lib/cjs/content-fields/hubtype-fields/keyword.d.ts +9 -0
  53. package/lib/cjs/content-fields/hubtype-fields/keyword.js +3 -0
  54. package/lib/cjs/content-fields/hubtype-fields/keyword.js.map +1 -0
  55. package/lib/cjs/content-fields/hubtype-fields/node-types.d.ts +23 -0
  56. package/lib/cjs/content-fields/hubtype-fields/node-types.js +31 -0
  57. package/lib/cjs/content-fields/hubtype-fields/node-types.js.map +1 -0
  58. package/lib/cjs/content-fields/hubtype-fields/nodes.d.ts +16 -0
  59. package/lib/cjs/content-fields/hubtype-fields/nodes.js +3 -0
  60. package/lib/cjs/content-fields/hubtype-fields/nodes.js.map +1 -0
  61. package/lib/cjs/content-fields/hubtype-fields/payload.d.ts +8 -0
  62. package/lib/cjs/content-fields/hubtype-fields/payload.js +3 -0
  63. package/lib/cjs/content-fields/hubtype-fields/payload.js.map +1 -0
  64. package/lib/cjs/content-fields/hubtype-fields/start.d.ts +7 -0
  65. package/lib/cjs/content-fields/hubtype-fields/start.js +3 -0
  66. package/lib/cjs/content-fields/hubtype-fields/start.js.map +1 -0
  67. package/lib/cjs/content-fields/hubtype-fields/text.d.ts +11 -0
  68. package/lib/cjs/content-fields/hubtype-fields/text.js +3 -0
  69. package/lib/cjs/content-fields/hubtype-fields/text.js.map +1 -0
  70. package/lib/cjs/content-fields/hubtype-fields/url.d.ts +8 -0
  71. package/lib/cjs/content-fields/hubtype-fields/url.js +3 -0
  72. package/lib/cjs/content-fields/hubtype-fields/url.js.map +1 -0
  73. package/lib/cjs/content-fields/hubtype-fields/video.d.ts +8 -0
  74. package/lib/cjs/content-fields/hubtype-fields/video.js +3 -0
  75. package/lib/cjs/content-fields/hubtype-fields/video.js.map +1 -0
  76. package/lib/cjs/content-fields/hubtype-fields/whatsapp-button-list.d.ts +21 -0
  77. package/lib/cjs/content-fields/hubtype-fields/whatsapp-button-list.js +3 -0
  78. package/lib/cjs/content-fields/hubtype-fields/whatsapp-button-list.js.map +1 -0
  79. package/lib/cjs/content-fields/index.d.ts +7 -5
  80. package/lib/cjs/content-fields/index.js +11 -9
  81. package/lib/cjs/content-fields/index.js.map +1 -1
  82. package/lib/cjs/content-fields/whatsapp-button-list/flow-whatsapp-button-list-row.d.ts +10 -0
  83. package/lib/cjs/content-fields/whatsapp-button-list/flow-whatsapp-button-list-row.js +32 -0
  84. package/lib/cjs/content-fields/whatsapp-button-list/flow-whatsapp-button-list-row.js.map +1 -0
  85. package/lib/cjs/content-fields/whatsapp-button-list/flow-whatsapp-button-list-section.d.ts +10 -0
  86. package/lib/cjs/content-fields/whatsapp-button-list/flow-whatsapp-button-list-section.js +29 -0
  87. package/lib/cjs/content-fields/whatsapp-button-list/flow-whatsapp-button-list-section.js.map +1 -0
  88. package/lib/cjs/content-fields/whatsapp-button-list/flow-whatsapp-button-list.d.ts +12 -0
  89. package/lib/cjs/content-fields/whatsapp-button-list/flow-whatsapp-button-list.js +33 -0
  90. package/lib/cjs/content-fields/whatsapp-button-list/flow-whatsapp-button-list.js.map +1 -0
  91. package/lib/cjs/functions/conditional-queue-status.js +1 -3
  92. package/lib/cjs/functions/conditional-queue-status.js.map +1 -1
  93. package/lib/cjs/handoff.d.ts +2 -2
  94. package/lib/cjs/handoff.js +13 -7
  95. package/lib/cjs/handoff.js.map +1 -1
  96. package/lib/cjs/helpers.d.ts +2 -1
  97. package/lib/cjs/helpers.js +5 -13
  98. package/lib/cjs/helpers.js.map +1 -1
  99. package/lib/cjs/index.d.ts +8 -21
  100. package/lib/cjs/index.js +34 -150
  101. package/lib/cjs/index.js.map +1 -1
  102. package/lib/cjs/types.d.ts +6 -2
  103. package/lib/cjs/types.js.map +1 -1
  104. package/lib/esm/action.js +14 -12
  105. package/lib/esm/action.js.map +1 -1
  106. package/lib/esm/api.d.ts +19 -0
  107. package/lib/esm/api.js +103 -0
  108. package/lib/esm/api.js.map +1 -0
  109. package/lib/esm/content-fields/content-fields-base.d.ts +4 -4
  110. package/lib/esm/content-fields/content-fields-base.js.map +1 -1
  111. package/lib/esm/content-fields/flow-button.d.ts +6 -3
  112. package/lib/esm/content-fields/flow-button.js +28 -21
  113. package/lib/esm/content-fields/flow-button.js.map +1 -1
  114. package/lib/esm/content-fields/flow-carousel.d.ts +3 -2
  115. package/lib/esm/content-fields/flow-carousel.js +4 -11
  116. package/lib/esm/content-fields/flow-carousel.js.map +1 -1
  117. package/lib/esm/content-fields/flow-element.d.ts +6 -3
  118. package/lib/esm/content-fields/flow-element.js +15 -5
  119. package/lib/esm/content-fields/flow-element.js.map +1 -1
  120. package/lib/esm/content-fields/flow-image.d.ts +2 -2
  121. package/lib/esm/content-fields/flow-image.js.map +1 -1
  122. package/lib/esm/content-fields/flow-text.d.ts +4 -3
  123. package/lib/esm/content-fields/flow-text.js +9 -9
  124. package/lib/esm/content-fields/flow-text.js.map +1 -1
  125. package/lib/esm/content-fields/flow-video.d.ts +2 -2
  126. package/lib/esm/content-fields/flow-video.js +0 -1
  127. package/lib/esm/content-fields/flow-video.js.map +1 -1
  128. package/lib/esm/content-fields/hubtype-fields/button.d.ts +9 -0
  129. package/lib/esm/content-fields/hubtype-fields/button.js +2 -0
  130. package/lib/esm/content-fields/hubtype-fields/button.js.map +1 -0
  131. package/lib/esm/content-fields/hubtype-fields/carousel.d.ts +16 -0
  132. package/lib/esm/content-fields/hubtype-fields/carousel.js +2 -0
  133. package/lib/esm/content-fields/hubtype-fields/carousel.js.map +1 -0
  134. package/lib/esm/content-fields/hubtype-fields/common.d.ts +55 -0
  135. package/lib/esm/content-fields/hubtype-fields/common.js +2 -0
  136. package/lib/esm/content-fields/hubtype-fields/common.js.map +1 -0
  137. package/lib/esm/content-fields/hubtype-fields/fallback.d.ts +9 -0
  138. package/lib/esm/content-fields/hubtype-fields/fallback.js +2 -0
  139. package/lib/esm/content-fields/hubtype-fields/fallback.js.map +1 -0
  140. package/lib/esm/content-fields/hubtype-fields/function.d.ts +28 -0
  141. package/lib/esm/content-fields/hubtype-fields/function.js +7 -0
  142. package/lib/esm/content-fields/hubtype-fields/function.js.map +1 -0
  143. package/lib/esm/content-fields/hubtype-fields/handoff.d.ts +10 -0
  144. package/lib/esm/content-fields/hubtype-fields/handoff.js +2 -0
  145. package/lib/esm/content-fields/hubtype-fields/handoff.js.map +1 -0
  146. package/lib/esm/content-fields/hubtype-fields/image.d.ts +8 -0
  147. package/lib/esm/content-fields/hubtype-fields/image.js +2 -0
  148. package/lib/esm/content-fields/hubtype-fields/image.js.map +1 -0
  149. package/lib/esm/content-fields/hubtype-fields/index.d.ts +17 -0
  150. package/lib/esm/content-fields/hubtype-fields/index.js +18 -0
  151. package/lib/esm/content-fields/hubtype-fields/index.js.map +1 -0
  152. package/lib/esm/content-fields/hubtype-fields/intent.d.ts +10 -0
  153. package/lib/esm/content-fields/hubtype-fields/intent.js +2 -0
  154. package/lib/esm/content-fields/hubtype-fields/intent.js.map +1 -0
  155. package/lib/esm/content-fields/hubtype-fields/keyword.d.ts +9 -0
  156. package/lib/esm/content-fields/hubtype-fields/keyword.js +2 -0
  157. package/lib/esm/content-fields/hubtype-fields/keyword.js.map +1 -0
  158. package/lib/esm/content-fields/hubtype-fields/node-types.d.ts +23 -0
  159. package/lib/esm/content-fields/hubtype-fields/node-types.js +28 -0
  160. package/lib/esm/content-fields/hubtype-fields/node-types.js.map +1 -0
  161. package/lib/esm/content-fields/hubtype-fields/nodes.d.ts +16 -0
  162. package/lib/esm/content-fields/hubtype-fields/nodes.js +2 -0
  163. package/lib/esm/content-fields/hubtype-fields/nodes.js.map +1 -0
  164. package/lib/esm/content-fields/hubtype-fields/payload.d.ts +8 -0
  165. package/lib/esm/content-fields/hubtype-fields/payload.js +2 -0
  166. package/lib/esm/content-fields/hubtype-fields/payload.js.map +1 -0
  167. package/lib/esm/content-fields/hubtype-fields/start.d.ts +7 -0
  168. package/lib/esm/content-fields/hubtype-fields/start.js +2 -0
  169. package/lib/esm/content-fields/hubtype-fields/start.js.map +1 -0
  170. package/lib/esm/content-fields/hubtype-fields/text.d.ts +11 -0
  171. package/lib/esm/content-fields/hubtype-fields/text.js +2 -0
  172. package/lib/esm/content-fields/hubtype-fields/text.js.map +1 -0
  173. package/lib/esm/content-fields/hubtype-fields/url.d.ts +8 -0
  174. package/lib/esm/content-fields/hubtype-fields/url.js +2 -0
  175. package/lib/esm/content-fields/hubtype-fields/url.js.map +1 -0
  176. package/lib/esm/content-fields/hubtype-fields/video.d.ts +8 -0
  177. package/lib/esm/content-fields/hubtype-fields/video.js +2 -0
  178. package/lib/esm/content-fields/hubtype-fields/video.js.map +1 -0
  179. package/lib/esm/content-fields/hubtype-fields/whatsapp-button-list.d.ts +21 -0
  180. package/lib/esm/content-fields/hubtype-fields/whatsapp-button-list.js +2 -0
  181. package/lib/esm/content-fields/hubtype-fields/whatsapp-button-list.js.map +1 -0
  182. package/lib/esm/content-fields/index.d.ts +7 -5
  183. package/lib/esm/content-fields/index.js +6 -4
  184. package/lib/esm/content-fields/index.js.map +1 -1
  185. package/lib/esm/content-fields/whatsapp-button-list/flow-whatsapp-button-list-row.d.ts +10 -0
  186. package/lib/esm/content-fields/whatsapp-button-list/flow-whatsapp-button-list-row.js +28 -0
  187. package/lib/esm/content-fields/whatsapp-button-list/flow-whatsapp-button-list-row.js.map +1 -0
  188. package/lib/esm/content-fields/whatsapp-button-list/flow-whatsapp-button-list-section.d.ts +10 -0
  189. package/lib/esm/content-fields/whatsapp-button-list/flow-whatsapp-button-list-section.js +25 -0
  190. package/lib/esm/content-fields/whatsapp-button-list/flow-whatsapp-button-list-section.js.map +1 -0
  191. package/lib/esm/content-fields/whatsapp-button-list/flow-whatsapp-button-list.d.ts +12 -0
  192. package/lib/esm/content-fields/whatsapp-button-list/flow-whatsapp-button-list.js +28 -0
  193. package/lib/esm/content-fields/whatsapp-button-list/flow-whatsapp-button-list.js.map +1 -0
  194. package/lib/esm/functions/conditional-queue-status.js +1 -3
  195. package/lib/esm/functions/conditional-queue-status.js.map +1 -1
  196. package/lib/esm/handoff.d.ts +2 -2
  197. package/lib/esm/handoff.js +13 -7
  198. package/lib/esm/handoff.js.map +1 -1
  199. package/lib/esm/helpers.d.ts +2 -1
  200. package/lib/esm/helpers.js +3 -11
  201. package/lib/esm/helpers.js.map +1 -1
  202. package/lib/esm/index.d.ts +8 -21
  203. package/lib/esm/index.js +36 -152
  204. package/lib/esm/index.js.map +1 -1
  205. package/lib/esm/types.d.ts +6 -2
  206. package/lib/esm/types.js.map +1 -1
  207. package/package.json +4 -5
  208. package/src/action.tsx +19 -12
  209. package/src/api.ts +162 -0
  210. package/src/content-fields/content-fields-base.ts +7 -7
  211. package/src/content-fields/flow-button.tsx +40 -19
  212. package/src/content-fields/flow-carousel.tsx +10 -18
  213. package/src/content-fields/flow-element.tsx +26 -9
  214. package/src/content-fields/flow-image.tsx +2 -2
  215. package/src/content-fields/flow-text.tsx +15 -12
  216. package/src/content-fields/flow-video.tsx +2 -3
  217. package/src/content-fields/hubtype-fields/button.ts +15 -0
  218. package/src/content-fields/hubtype-fields/carousel.ts +18 -0
  219. package/src/content-fields/hubtype-fields/common.ts +65 -0
  220. package/src/content-fields/hubtype-fields/fallback.ts +10 -0
  221. package/src/content-fields/hubtype-fields/function.ts +33 -0
  222. package/src/content-fields/hubtype-fields/handoff.ts +11 -0
  223. package/src/content-fields/hubtype-fields/image.ts +9 -0
  224. package/src/content-fields/hubtype-fields/index.ts +17 -0
  225. package/src/content-fields/hubtype-fields/intent.ts +11 -0
  226. package/src/content-fields/hubtype-fields/keyword.ts +10 -0
  227. package/src/content-fields/hubtype-fields/node-types.ts +26 -0
  228. package/src/content-fields/hubtype-fields/nodes.ts +32 -0
  229. package/src/content-fields/hubtype-fields/payload.ts +9 -0
  230. package/src/content-fields/hubtype-fields/start.ts +8 -0
  231. package/src/content-fields/hubtype-fields/text.ts +12 -0
  232. package/src/content-fields/hubtype-fields/url.ts +9 -0
  233. package/src/content-fields/hubtype-fields/video.ts +9 -0
  234. package/src/content-fields/hubtype-fields/whatsapp-button-list.ts +25 -0
  235. package/src/content-fields/index.ts +14 -5
  236. package/src/content-fields/whatsapp-button-list/flow-whatsapp-button-list-row.tsx +33 -0
  237. package/src/content-fields/whatsapp-button-list/flow-whatsapp-button-list-section.tsx +35 -0
  238. package/src/content-fields/whatsapp-button-list/flow-whatsapp-button-list.tsx +46 -0
  239. package/src/functions/conditional-queue-status.ts +1 -3
  240. package/src/handoff.ts +16 -10
  241. package/src/helpers.ts +8 -19
  242. package/src/index.ts +47 -196
  243. package/src/types.ts +8 -2
  244. package/lib/cjs/content-fields/types.d.ts +0 -5
  245. package/lib/cjs/content-fields/types.js.map +0 -1
  246. package/lib/cjs/flow-builder-models.d.ts +0 -197
  247. package/lib/cjs/flow-builder-models.js +0 -24
  248. package/lib/cjs/flow-builder-models.js.map +0 -1
  249. package/lib/esm/content-fields/types.d.ts +0 -5
  250. package/lib/esm/content-fields/types.js +0 -2
  251. package/lib/esm/content-fields/types.js.map +0 -1
  252. package/lib/esm/flow-builder-models.d.ts +0 -197
  253. package/lib/esm/flow-builder-models.js +0 -21
  254. package/lib/esm/flow-builder-models.js.map +0 -1
  255. package/src/content-fields/types.ts +0 -6
  256. package/src/flow-builder-models.ts +0 -249
@@ -0,0 +1,33 @@
1
+ import { WhatsappButtonListRowProps } from '@botonic/react/lib/cjs/components/whatsapp-button-list'
2
+
3
+ import { ContentFieldsBase } from '../content-fields-base'
4
+ import { HtWhatsappButtonListRow } from '../hubtype-fields'
5
+
6
+ export class FlowWhatsappButtonListRow extends ContentFieldsBase {
7
+ public title = ''
8
+ public description = ''
9
+ public targetId?: string
10
+
11
+ static fromHubtypeCMS(
12
+ component: HtWhatsappButtonListRow,
13
+ locale: string
14
+ ): FlowWhatsappButtonListRow {
15
+ const newRow = new FlowWhatsappButtonListRow(component.id)
16
+ newRow.title = this.getTextByLocale(locale, component.text)
17
+ newRow.description = this.getTextByLocale(locale, component.description)
18
+ newRow.targetId = component.target?.id
19
+ return newRow
20
+ }
21
+
22
+ toBotonic(): WhatsappButtonListRowProps | undefined {
23
+ if (!this.targetId) {
24
+ console.error(`Row with title: '${this.title}' has no target`)
25
+ return undefined
26
+ }
27
+ return {
28
+ id: this.targetId,
29
+ title: this.title,
30
+ description: this.description,
31
+ }
32
+ }
33
+ }
@@ -0,0 +1,35 @@
1
+ import {
2
+ WhatsappButtonListRowProps,
3
+ WhatsappButtonListSectionProps,
4
+ } from '@botonic/react/lib/cjs/components/whatsapp-button-list'
5
+
6
+ import { HtWhatsappButtonListSection } from '../hubtype-fields'
7
+ import { ContentFieldsBase } from './../content-fields-base'
8
+ import { FlowWhatsappButtonListRow } from './flow-whatsapp-button-list-row'
9
+
10
+ export class FlowWhatsappButtonListSection extends ContentFieldsBase {
11
+ public title = ''
12
+ public rows: FlowWhatsappButtonListRow[] = []
13
+
14
+ static fromHubtypeCMS(
15
+ component: HtWhatsappButtonListSection,
16
+ locale: string
17
+ ): FlowWhatsappButtonListSection {
18
+ const newButton = new FlowWhatsappButtonListSection(component.id)
19
+ newButton.title = this.getTextByLocale(locale, component.title)
20
+ newButton.rows = component.rows.map(row =>
21
+ FlowWhatsappButtonListRow.fromHubtypeCMS(row, locale)
22
+ )
23
+ return newButton
24
+ }
25
+
26
+ toBotonic(): WhatsappButtonListSectionProps {
27
+ const rows = this.rows.reduce((acc: WhatsappButtonListRowProps[], row) => {
28
+ const botonicRow = row.toBotonic()
29
+ if (botonicRow) acc.push(botonicRow)
30
+ return acc
31
+ }, [])
32
+
33
+ return { title: this.title, rows }
34
+ }
35
+ }
@@ -0,0 +1,46 @@
1
+ import { WhatsappButtonList } from '@botonic/react'
2
+ import React from 'react'
3
+
4
+ import { HtWhatsappButtonListNode } from '../hubtype-fields'
5
+ import { ContentFieldsBase } from './../content-fields-base'
6
+ import { FlowWhatsappButtonListSection } from './flow-whatsapp-button-list-section'
7
+
8
+ export class FlowWhatsappButtonList extends ContentFieldsBase {
9
+ public code = ''
10
+ public text = ''
11
+ public listButtonText = ''
12
+ public sections: FlowWhatsappButtonListSection[] = []
13
+
14
+ static fromHubtypeCMS(
15
+ component: HtWhatsappButtonListNode,
16
+ locale: string
17
+ ): FlowWhatsappButtonList {
18
+ const newWhatsappButtonList = new FlowWhatsappButtonList(component.id)
19
+ newWhatsappButtonList.code = component.code
20
+ newWhatsappButtonList.text = this.getTextByLocale(
21
+ locale,
22
+ component.content.text
23
+ )
24
+ newWhatsappButtonList.listButtonText = this.getTextByLocale(
25
+ locale,
26
+ component.content.button_text
27
+ )
28
+ newWhatsappButtonList.sections = component.content.sections.map(section =>
29
+ FlowWhatsappButtonListSection.fromHubtypeCMS(section, locale)
30
+ )
31
+ return newWhatsappButtonList
32
+ }
33
+
34
+ toBotonic(id: string): JSX.Element {
35
+ return (
36
+ <WhatsappButtonList
37
+ key={id}
38
+ body={this.text}
39
+ action={{
40
+ button: this.listButtonText,
41
+ sections: this.sections.map(section => section.toBotonic()),
42
+ }}
43
+ ></WhatsappButtonList>
44
+ )
45
+ }
46
+ }
@@ -35,14 +35,12 @@ export async function conditionalQueueStatus({
35
35
  )
36
36
  const isAvailable = response.data.available
37
37
 
38
- console.log('conditionalQueueStatus', { data: response.data })
39
38
  const flowBuilderPlugin = getFlowBuilderPlugin(request.plugins)
40
39
  if (flowBuilderPlugin.trackEvent) {
41
- const eventName = 'QUEUE_STATUS'
40
+ const eventName = `QUEUE_${isAvailable ? 'OPEN' : 'CLOSED'}`
42
41
  const args = {
43
42
  queue_id,
44
43
  queue_name,
45
- status: isAvailable ? 'open' : 'closed',
46
44
  }
47
45
  await flowBuilderPlugin.trackEvent(request, eventName, args)
48
46
  }
package/src/handoff.ts CHANGED
@@ -1,14 +1,14 @@
1
1
  import { HandOffBuilder } from '@botonic/core'
2
2
  import { ActionRequest } from '@botonic/react'
3
3
 
4
- import { HandoffNode, PayloadNode } from './flow-builder-models'
4
+ import { HtHandoffNode, HtPayloadNode } from './content-fields/hubtype-fields'
5
5
  import { getFlowBuilderPlugin } from './helpers'
6
6
  import BotonicPluginFlowBuilder from './index'
7
7
 
8
8
  export async function doHandoff(
9
9
  request: ActionRequest,
10
10
  locale: string,
11
- handoffNode: HandoffNode
11
+ handoffNode: HtHandoffNode
12
12
  ): Promise<void> {
13
13
  const flowBuilderPlugin = getFlowBuilderPlugin(request.plugins)
14
14
  // @ts-ignore
@@ -23,6 +23,9 @@ export async function doHandoff(
23
23
  locale
24
24
  )
25
25
  if (onFinishPayload) handOffBuilder.withOnFinishPayload(onFinishPayload)
26
+ if (handoffNode.content.has_auto_assign) {
27
+ handOffBuilder.withAutoAssignOnWaiting(true)
28
+ }
26
29
 
27
30
  // TODO: Retrieve params from FlowBuilder
28
31
  // const handoffParams = {
@@ -42,20 +45,23 @@ export async function doHandoff(
42
45
 
43
46
  if (flowBuilderPlugin.trackEvent) {
44
47
  await flowBuilderPlugin.trackEvent(request, 'HANDOFF_SUCCESSFULL', {
45
- queueName: queueFound?.name,
48
+ queue_id: queueFound?.id,
49
+ queue_name: queueFound?.name,
46
50
  })
47
51
  }
48
52
  }
49
53
 
50
54
  async function getOnFinishPayload(
51
55
  flowBuilderPlugin: BotonicPluginFlowBuilder,
52
- handoffNode: HandoffNode,
56
+ handoffNode: HtHandoffNode,
53
57
  locale: string
54
58
  ): Promise<string | undefined> {
55
- const handoffTargetNode = await flowBuilderPlugin.getHandoffContent(
56
- handoffNode.target?.id
57
- )
58
- if (handoffTargetNode?.id) return handoffTargetNode?.id
59
+ if (handoffNode.target?.id) {
60
+ const handoffTargetNode = flowBuilderPlugin.cmsApi.getNode<HtHandoffNode>(
61
+ handoffNode.target?.id
62
+ )
63
+ if (handoffTargetNode?.id) return handoffTargetNode?.id
64
+ }
59
65
 
60
66
  const payloadId = handoffNode.content.payload.find(
61
67
  payload => payload.locale === locale
@@ -63,7 +69,7 @@ async function getOnFinishPayload(
63
69
 
64
70
  if (!payloadId) return undefined
65
71
 
66
- const actionPayload = await flowBuilderPlugin.getContent(payloadId)
72
+ const actionPayload = flowBuilderPlugin.cmsApi.getNode(payloadId)
67
73
 
68
- return (actionPayload as PayloadNode).content.payload
74
+ return (actionPayload as HtPayloadNode).content.payload
69
75
  }
package/src/helpers.ts CHANGED
@@ -1,6 +1,11 @@
1
1
  import { Plugin } from '@botonic/core'
2
+
3
+ import {
4
+ HtHandoffNode,
5
+ HtNodeWithContent,
6
+ HtNodeWithContentType,
7
+ } from './content-fields/hubtype-fields'
2
8
  import BotonicPluginFlowBuilder from './index'
3
- import { NodeComponent } from './flow-builder-models'
4
9
 
5
10
  const FLOW_BUILDER_PLUGIN_NAME = 'BotonicPluginFlowBuilder'
6
11
 
@@ -18,22 +23,6 @@ export function getFlowBuilderPlugin(plugins: {
18
23
  return flowBuilderPlugin
19
24
  }
20
25
 
21
- export async function updateButtonUrls(
22
- hubtypeContent: any,
23
- contentKey: string,
24
- getContentFn: any
25
- ): Promise<void> {
26
- if (hubtypeContent.content[contentKey]) {
27
- for (const i in hubtypeContent.content[contentKey]) {
28
- const button = hubtypeContent.content[contentKey][i].button
29
- if (button?.url) {
30
- for (const j in button.url) {
31
- button.url[j] = {
32
- ...button.url[j],
33
- ...(await getContentFn(button.url[j].id)),
34
- }
35
- }
36
- }
37
- }
38
- }
26
+ export function isHandoffNode(node: HtNodeWithContent): node is HtHandoffNode {
27
+ return node.type === HtNodeWithContentType.HANDOFF
39
28
  }
package/src/index.ts CHANGED
@@ -1,39 +1,34 @@
1
1
  import {
2
- Input,
3
2
  Plugin,
4
3
  PluginPostRequest,
5
4
  PluginPreRequest,
6
5
  Session,
7
6
  } from '@botonic/core'
8
7
  import { ActionRequest } from '@botonic/react'
9
- import axios from 'axios'
10
8
 
9
+ import { FlowBuilderApi } from './api'
11
10
  import {
12
11
  FlowCarousel,
13
12
  FlowContent,
14
13
  FlowImage,
15
14
  FlowText,
16
15
  FlowVideo,
16
+ FlowWhatsappButtonList,
17
17
  } from './content-fields'
18
18
  import {
19
- FallbackNode,
20
- FlowBuilderData,
21
- FunctionNode,
22
- HandoffNode,
23
- IntentNode,
24
- KeywordNode,
25
- NodeComponent,
26
- NodeType,
27
- StartNode,
28
- } from './flow-builder-models'
19
+ HtFunctionNode,
20
+ HtHandoffNode,
21
+ HtNodeComponent,
22
+ HtNodeWithContent,
23
+ HtNodeWithContentType,
24
+ } from './content-fields/hubtype-fields'
29
25
  import { DEFAULT_FUNCTIONS } from './functions'
30
- import { updateButtonUrls } from './helpers'
26
+ import { isHandoffNode } from './helpers'
31
27
  import { BotonicPluginFlowBuilderOptions } from './types'
32
28
  import { resolveGetAccessToken } from './utils'
33
29
 
34
30
  export default class BotonicPluginFlowBuilder implements Plugin {
35
- private flowUrl: string
36
- private flow: Promise<FlowBuilderData> | FlowBuilderData
31
+ public cmsApi: FlowBuilderApi
37
32
  private functions: Record<any, any>
38
33
  private currentRequest: PluginPreRequest
39
34
  private getAccessToken: (session: Session) => string
@@ -45,217 +40,73 @@ export default class BotonicPluginFlowBuilder implements Plugin {
45
40
  ) => Promise<void>
46
41
 
47
42
  constructor(readonly options: BotonicPluginFlowBuilderOptions) {
43
+ this.cmsApi = new FlowBuilderApi({
44
+ url: options.flowUrl,
45
+ flow: options.flow,
46
+ })
48
47
  this.getLocale = options.getLocale
49
48
  this.getAccessToken = resolveGetAccessToken(options)
50
49
  this.trackEvent = options.trackEvent
51
- this.flowUrl = options.flowUrl
52
- if (options.flow) this.flow = options.flow
53
50
  const customFunctions = options.customFunctions || {}
54
51
  this.functions = { ...DEFAULT_FUNCTIONS, ...customFunctions }
55
52
  }
56
53
 
57
- async readFlowContent(session: Session): Promise<FlowBuilderData> {
58
- const { data } = await axios.get(this.flowUrl, {
59
- headers: { Authorization: `Bearer ${this.getAccessToken(session)}` },
60
- })
61
- return data
62
- }
63
-
64
54
  async pre(request: PluginPreRequest): Promise<void> {
65
55
  this.currentRequest = request
66
- this.flow = await this.readFlowContent(this.currentRequest.session)
56
+ await this.cmsApi.init(this.getAccessToken(request.session))
67
57
  }
68
58
 
69
59
  async post(_request: PluginPostRequest): Promise<void> {}
70
60
 
71
- async getContent(id: string): Promise<NodeComponent> {
72
- const flow = await this.flow
73
- const content = flow.nodes.find(node => node.id === id)
74
- if (!content) throw Error(`Node with id: '${id}' not found`)
75
- return content
76
- }
77
-
78
- async getContentByCode(code: string): Promise<NodeComponent> {
79
- const flow = await this.flow
80
- const content = flow.nodes.find(node => {
81
- if ('code' in node) return node.code === code
82
- return undefined
83
- })
84
- if (!content) throw Error(`Node with code: '${code}' not found`)
85
- return content
86
- }
87
-
88
- async getHandoffContent(
89
- handoffTargetId: string | undefined
90
- ): Promise<HandoffNode | undefined> {
91
- if (!handoffTargetId) return undefined
92
- return (await this.getContent(handoffTargetId)) as HandoffNode
93
- }
94
-
95
- getFlowContent(
96
- hubtypeContent: NodeComponent,
97
- locale: string
98
- ): FlowContent | undefined {
99
- switch (hubtypeContent.type) {
100
- case NodeType.TEXT:
101
- return FlowText.fromHubtypeCMS(hubtypeContent, locale)
102
- case NodeType.IMAGE:
103
- return FlowImage.fromHubtypeCMS(hubtypeContent, locale)
104
- case NodeType.CAROUSEL:
105
- return FlowCarousel.fromHubtypeCMS(hubtypeContent, locale)
106
- case NodeType.VIDEO:
107
- return FlowVideo.fromHubtypeCMS(hubtypeContent, locale)
108
- default:
109
- return undefined
110
- }
111
- }
112
-
113
- async getStartId(): Promise<string> {
114
- const flow = await this.flow
115
- const startNode = flow.nodes.find(
116
- node => node.type === NodeType.START_UP
117
- ) as StartNode | undefined
118
- if (!startNode) throw new Error('start-up id must be defined')
119
- return startNode.target.id
120
- }
121
-
122
- async getFallbackId(alternate: boolean): Promise<string> {
123
- const flow = await this.flow
124
- const fallbackNode = flow.nodes.find(
125
- node => node.type === NodeType.FALLBACK
126
- ) as FallbackNode | undefined
127
- if (!fallbackNode) throw new Error('fallback node must be defined')
128
- const fallbackFirstMessage = fallbackNode.content.first_message
129
- const fallbackSecondMessage = fallbackNode.content.second_message
130
- if (!fallbackSecondMessage) return fallbackFirstMessage.id
131
- return alternate ? fallbackFirstMessage.id : fallbackSecondMessage.id
132
- }
133
- async getContents(
134
- id: string,
61
+ async getContent(
62
+ nodeOrId: HtNodeWithContent | string,
135
63
  locale: string,
136
64
  prevContents?: FlowContent[]
137
- ): Promise<{ contents: FlowContent[]; handoffNode: HandoffNode }> {
65
+ ): Promise<{ contents: FlowContent[]; handoffNode?: HtHandoffNode }> {
138
66
  const contents = prevContents || []
139
- const hubtypeContent: any = await this.getContent(id)
140
- const isHandoff = hubtypeContent.type === NodeType.HANDOFF
141
- // TODO: Create function to populate these buttons
142
- await updateButtonUrls(hubtypeContent, 'elements', this.getContent)
143
- await updateButtonUrls(hubtypeContent, 'buttons', this.getContent)
144
- 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
+ }
145
71
 
146
- this.replaceButtonPayload(content)
72
+ const content = await this.getFlowContent(node, locale)
147
73
 
148
- if (hubtypeContent.type === NodeType.FUNCTION) {
149
- const targetId = await this.callFunction(hubtypeContent, locale)
150
- 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)
151
77
  } else {
152
78
  if (content) contents.push(content)
153
79
  // TODO: prevent infinite recursive calls
154
80
 
155
- if (hubtypeContent.follow_up)
156
- return this.getContents(hubtypeContent.follow_up.id, locale, contents)
81
+ if (node.follow_up)
82
+ return this.getContent(node.follow_up.id, locale, contents)
157
83
  }
158
- // execute function
159
- // return this.getContents(function result_mapping target, locale, contents)
160
- return { contents, handoffNode: isHandoff && hubtypeContent }
161
- }
162
84
 
163
- private async replaceButtonPayload(content: FlowContent | undefined) {
164
- if (content && 'buttons' in content) {
165
- for (const button of content.buttons) {
166
- if (button.payload) {
167
- const contentButton = await this.getContent(button.payload)
168
- if (contentButton?.type === NodeType.PAYLOAD) {
169
- button.payload = contentButton.content.payload
170
- }
171
- }
172
- }
173
- }
85
+ return { contents, handoffNode: isHandoffNode(node) ? node : undefined }
174
86
  }
175
87
 
176
- async getPayloadByIntent(
177
- input: Input,
88
+ private getFlowContent(
89
+ hubtypeContent: HtNodeComponent,
178
90
  locale: string
179
- ): Promise<string | undefined> {
180
- try {
181
- const flow = await this.flow
182
- const intents = flow.nodes.filter(
183
- node => node.type === NodeType.INTENT
184
- ) as IntentNode[]
185
- const inputIntent = input.intent
186
- const inputConfidence = input.confidence
187
- if (inputIntent) {
188
- const matchedIntentNode = intents.find(
189
- node =>
190
- inputIntent &&
191
- this.hasIntent(node, inputIntent, locale) &&
192
- inputConfidence &&
193
- this.hasMetConfidenceThreshold(node, inputConfidence)
194
- )
195
- return matchedIntentNode?.target?.id
196
- }
197
- } catch (error) {
198
- console.error('Error getting payload by input: ', error)
199
- }
200
-
201
- return undefined
202
- }
203
-
204
- hasIntent(node: IntentNode, intent: string, locale: string): boolean {
205
- return node.content.intents.some(
206
- i => i.locale === locale && i.values.includes(intent)
207
- )
208
- }
209
-
210
- hasMetConfidenceThreshold(
211
- node: IntentNode,
212
- predictedConfidence: number
213
- ): boolean {
214
- const nodeConfidence = node.content.confidence / 100
215
- return predictedConfidence >= nodeConfidence
216
- }
217
-
218
- async getPayloadByKeyword(
219
- input: Input,
220
- locale: string
221
- ): Promise<string | undefined> {
222
- try {
223
- const flow = await this.flow
224
- const keywordNodes = flow.nodes.filter(
225
- node => node.type == NodeType.KEYWORD
226
- ) as KeywordNode[]
227
- const matchedKeywordNodes = keywordNodes.filter(node =>
228
- //@ts-ignore
229
- this.matchKeywords(node, input.data, locale)
230
- )
231
- if (matchedKeywordNodes.length > 0) {
232
- return matchedKeywordNodes[0].target?.id
233
- }
234
- } catch (error) {
235
- console.error('Error getting payload by input: ', error)
236
- }
237
-
238
- return undefined
239
- }
240
-
241
- matchKeywords(node: KeywordNode, input: string, locale: string): boolean {
242
- const result = node.content.keywords.find(
243
- i => i.locale === locale && this.containsAnyKeywords(input, i.values)
244
- )
245
- return Boolean(result)
246
- }
247
-
248
- containsAnyKeywords(input: string, keywords: string[]): boolean {
249
- for (let i = 0; i < keywords.length; i++) {
250
- if (input.includes(keywords[i])) {
251
- return true
252
- }
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
253
105
  }
254
- return false
255
106
  }
256
107
 
257
108
  async callFunction(
258
- functionNode: FunctionNode,
109
+ functionNode: HtFunctionNode,
259
110
  locale: string
260
111
  ): Promise<string> {
261
112
  const functionNodeId = functionNode.id
@@ -278,7 +129,7 @@ export default class BotonicPluginFlowBuilder implements Plugin {
278
129
  const result = functionNode.content.result_mapping.find(
279
130
  r => r.result === functionResult
280
131
  )
281
- if (!result) {
132
+ if (!result?.target) {
282
133
  throw new Error(
283
134
  `No result found for result_mapping for node with id: ${functionNodeId}`
284
135
  )
package/src/types.ts CHANGED
@@ -1,11 +1,12 @@
1
1
  import { Session } from '@botonic/core'
2
2
  import { ActionRequest } from '@botonic/react'
3
3
 
4
- import { FlowBuilderData } from './flow-builder-models'
4
+ import { FlowBuilderApi } from './api'
5
+ import { HtFlowBuilderData } from './content-fields/hubtype-fields'
5
6
 
6
7
  export interface BotonicPluginFlowBuilderOptions {
7
8
  flowUrl: string
8
- flow?: FlowBuilderData
9
+ flow?: HtFlowBuilderData
9
10
  customFunctions?: Record<any, any>
10
11
  getLocale: (session: Session) => string
11
12
  getAccessToken: () => string
@@ -16,6 +17,11 @@ export interface BotonicPluginFlowBuilderOptions {
16
17
  ) => Promise<void>
17
18
  }
18
19
 
20
+ export interface FlowBuilderApiOptions {
21
+ url: string
22
+ flow?: HtFlowBuilderData
23
+ }
24
+
19
25
  export enum ProcessEnvNodeEnvs {
20
26
  PRODUCTION = 'production',
21
27
  DEVELOPMENT = 'development',
@@ -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":""}