@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
@@ -1,42 +1,63 @@
1
1
  import { Button, Reply } from '@botonic/react'
2
2
  import React from 'react'
3
3
 
4
- import { Button as FbButton, ButtonStyle } from '../flow-builder-models'
4
+ import { FlowBuilderApi } from '../api'
5
5
  import { ContentFieldsBase } from './content-fields-base'
6
+ import {
7
+ HtButton,
8
+ HtButtonStyle,
9
+ HtPayloadNode,
10
+ HtUrlNode,
11
+ } from './hubtype-fields'
6
12
 
7
13
  export class FlowButton extends ContentFieldsBase {
8
14
  public text = ''
9
15
  public url?: string
10
16
  public payload?: string
11
17
 
12
- static fromHubtypeCMS(component: FbButton, locale: string): FlowButton {
13
- const newButton = new FlowButton(component.id)
14
- newButton.text = FlowButton.getTextByLocale(locale, component.text)
15
- newButton.payload = component.target
16
- ? component.target.id
17
- : component.payload?.find(payload => payload.locale === locale)?.id
18
- if (component.url) {
19
- const urlButton = (component.url as any).find(
20
- url => url.locale === locale
21
- )
22
- if (urlButton) newButton.url = urlButton.content.url
18
+ static fromHubtypeCMS(
19
+ cmsButton: HtButton,
20
+ locale: string,
21
+ cmsApi: FlowBuilderApi
22
+ ): FlowButton {
23
+ const payloadId = this.getPayloadId(cmsButton, locale)
24
+ const urlId = this.getUrlId(cmsButton, locale)
25
+
26
+ const newButton = new FlowButton(cmsButton.id)
27
+ newButton.text = this.getTextByLocale(locale, cmsButton.text)
28
+ if (cmsButton.target) {
29
+ newButton.payload = cmsButton.target.id
30
+ }
31
+ if (cmsButton.payload && payloadId) {
32
+ const payloadNode = cmsApi.getNode(payloadId) as HtPayloadNode
33
+ newButton.payload = payloadNode.content.payload
23
34
  }
35
+ if (cmsButton.url && urlId) {
36
+ const payloadNode = cmsApi.getNode(urlId) as HtUrlNode
37
+ newButton.url = payloadNode.content.url
38
+ }
39
+
24
40
  return newButton
25
41
  }
26
42
 
27
- renderButton(id: string, buttonStyle: ButtonStyle): JSX.Element {
28
- if (buttonStyle === ButtonStyle.QUICK_REPLY) {
43
+ static getPayloadId(cmsButton, locale): string | undefined {
44
+ return cmsButton.payload.find(payload => payload.locale === locale)?.id
45
+ }
46
+
47
+ static getUrlId(cmsButton, locale): string | undefined {
48
+ return cmsButton.url.find(url => url.locale === locale)?.id
49
+ }
50
+
51
+ renderButton(buttonStyle?: HtButtonStyle): JSX.Element {
52
+ if (buttonStyle === HtButtonStyle.QUICK_REPLY) {
29
53
  return (
30
- <Reply key={id} payload={this.payload}>
54
+ <Reply key={this.id} payload={this.payload}>
31
55
  {this.text}
32
56
  </Reply>
33
57
  )
34
58
  }
35
- let props = {}
36
- if (this.url) props = { url: this.url }
37
59
  return (
38
- // @ts-ignore
39
- <Button key={id} payload={this.payload} {...props}>
60
+ <Button key={this.id} payload={this.payload} url={this.url}>
40
61
  {this.text}
41
62
  </Button>
42
63
  )
@@ -1,19 +1,24 @@
1
- import { Button, Carousel, Element, Pic, Subtitle, Title } from '@botonic/react'
1
+ import { Carousel } from '@botonic/react'
2
2
  import React from 'react'
3
3
 
4
- import { CarouselNode } from '../flow-builder-models'
4
+ import { FlowBuilderApi } from '../api'
5
5
  import { ContentFieldsBase } from './content-fields-base'
6
6
  import { FlowElement } from './flow-element'
7
+ import { HtCarouselNode } from './hubtype-fields'
7
8
 
8
9
  export class FlowCarousel extends ContentFieldsBase {
9
10
  public code = ''
10
11
  public elements: FlowElement[] = []
11
12
 
12
- static fromHubtypeCMS(component: CarouselNode, locale: string): FlowCarousel {
13
+ static fromHubtypeCMS(
14
+ component: HtCarouselNode,
15
+ locale: string,
16
+ cmsApi: FlowBuilderApi
17
+ ): FlowCarousel {
13
18
  const newCarousel = new FlowCarousel(component.id)
14
19
  newCarousel.code = component.code
15
20
  newCarousel.elements = component.content.elements.map(element =>
16
- FlowElement.fromHubtypeCMS(element, locale)
21
+ FlowElement.fromHubtypeCMS(element, locale, cmsApi)
17
22
  )
18
23
  return newCarousel
19
24
  }
@@ -21,20 +26,7 @@ export class FlowCarousel extends ContentFieldsBase {
21
26
  toBotonic(id: string): JSX.Element {
22
27
  return (
23
28
  <Carousel key={id}>
24
- {this.elements.map(element => (
25
- <Element key={`${id}-${element.id}`}>
26
- <Pic src={element.image} />
27
- <Title style=''>{element.title}</Title>
28
- <Subtitle style=''>{element.subtitle}</Subtitle>
29
- {/* @ts-ignore */}
30
- <Button
31
- payload={element.buttons?.payload}
32
- url={element.buttons?.url}
33
- >
34
- {element.buttons?.text}
35
- </Button>
36
- </Element>
37
- ))}
29
+ {this.elements.map(element => element.toBotonic(id))}
38
30
  </Carousel>
39
31
  )
40
32
  }
@@ -1,26 +1,43 @@
1
- import { CarouselElementNode } from '../flow-builder-models'
1
+ import { Element, Pic, Subtitle, Title } from '@botonic/react'
2
+ import React from 'react'
3
+
4
+ import { FlowBuilderApi } from '../api'
2
5
  import { ContentFieldsBase } from './content-fields-base'
3
6
  import { FlowButton } from './flow-button'
7
+ import { HtCarouselElement } from './hubtype-fields'
4
8
 
5
9
  export class FlowElement extends ContentFieldsBase {
6
10
  public title = ''
7
11
  public subtitle = ''
8
- public buttons: FlowButton | undefined
12
+ public button: FlowButton | undefined
9
13
  public image = ''
10
14
  public hidden = false
11
15
 
12
16
  static fromHubtypeCMS(
13
- component: CarouselElementNode,
14
- locale: string
17
+ component: HtCarouselElement,
18
+ locale: string,
19
+ cmsApi: FlowBuilderApi
15
20
  ): FlowElement {
16
21
  const newElement = new FlowElement(component.id)
17
- newElement.title = FlowElement.getTextByLocale(locale, component.title)
18
- newElement.subtitle = FlowElement.getTextByLocale(
22
+ newElement.title = this.getTextByLocale(locale, component.title)
23
+ newElement.subtitle = this.getTextByLocale(locale, component.subtitle)
24
+ newElement.image = this.getImageByLocale(locale, component.image)
25
+ newElement.button = FlowButton.fromHubtypeCMS(
26
+ component.button,
19
27
  locale,
20
- component.subtitle
28
+ cmsApi
21
29
  )
22
- newElement.image = FlowElement.getImageByLocale(locale, component.image)
23
- newElement.buttons = FlowButton.fromHubtypeCMS(component.button, locale)
24
30
  return newElement
25
31
  }
32
+
33
+ toBotonic(parentId: string): JSX.Element {
34
+ return (
35
+ <Element key={`${parentId}-${this.id}`}>
36
+ <Pic src={this.image} />
37
+ <Title>{this.title}</Title>
38
+ <Subtitle>{this.subtitle}</Subtitle>
39
+ {this.button?.renderButton()}
40
+ </Element>
41
+ )
42
+ }
26
43
  }
@@ -1,14 +1,14 @@
1
1
  import { Image } from '@botonic/react'
2
2
  import React from 'react'
3
3
 
4
- import { ImageNode } from '../flow-builder-models'
5
4
  import { ContentFieldsBase } from './content-fields-base'
5
+ import { HtImageNode } from './hubtype-fields'
6
6
 
7
7
  export class FlowImage extends ContentFieldsBase {
8
8
  public src = ''
9
9
  public code = ''
10
10
 
11
- static fromHubtypeCMS(component: ImageNode, locale: string): FlowImage {
11
+ static fromHubtypeCMS(component: HtImageNode, locale: string): FlowImage {
12
12
  const newImage = new FlowImage(component.id)
13
13
  newImage.code = component.code
14
14
  newImage.src = this.getImageByLocale(locale, component.content.image)
@@ -1,23 +1,28 @@
1
1
  import { Text } from '@botonic/react'
2
2
  import React from 'react'
3
3
 
4
- import { ButtonStyle, TextNode } from '../flow-builder-models'
4
+ import { FlowBuilderApi } from '../api'
5
5
  import { ContentFieldsBase } from './content-fields-base'
6
6
  import { FlowButton } from './flow-button'
7
+ import { HtButtonStyle, HtTextNode } from './hubtype-fields'
7
8
 
8
9
  export class FlowText extends ContentFieldsBase {
9
10
  public text = ''
10
11
  public code = ''
11
12
  public buttons: FlowButton[] = []
12
- public buttonStyle = ButtonStyle.BUTTON
13
+ public buttonStyle = HtButtonStyle.BUTTON
13
14
 
14
- static fromHubtypeCMS(component: TextNode, locale: string): FlowText {
15
- const newText = new FlowText(component.id)
16
- newText.code = component.code
17
- newText.buttonStyle = component.content.buttons_style || ButtonStyle.BUTTON
18
- newText.text = FlowText.getTextByLocale(locale, component.content.text)
19
- newText.buttons = component.content.buttons.map(button =>
20
- FlowButton.fromHubtypeCMS(button, locale)
15
+ static fromHubtypeCMS(
16
+ cmsText: HtTextNode,
17
+ locale: string,
18
+ cmsApi: FlowBuilderApi
19
+ ): FlowText {
20
+ const newText = new FlowText(cmsText.id)
21
+ newText.code = cmsText.code
22
+ newText.buttonStyle = cmsText.content.buttons_style || HtButtonStyle.BUTTON
23
+ newText.text = this.getTextByLocale(locale, cmsText.content.text)
24
+ newText.buttons = cmsText.content.buttons.map(button =>
25
+ FlowButton.fromHubtypeCMS(button, locale, cmsApi)
21
26
  )
22
27
  return newText
23
28
  }
@@ -26,9 +31,7 @@ export class FlowText extends ContentFieldsBase {
26
31
  return (
27
32
  <Text key={id}>
28
33
  {this.text}
29
- {this.buttons.map(button =>
30
- button.renderButton(button.id, this.buttonStyle)
31
- )}
34
+ {this.buttons.map(button => button.renderButton(this.buttonStyle))}
32
35
  </Text>
33
36
  )
34
37
  }
@@ -1,14 +1,14 @@
1
1
  import { Video } from '@botonic/react'
2
2
  import React from 'react'
3
3
 
4
- import { VideoNode } from '../flow-builder-models'
5
4
  import { ContentFieldsBase } from './content-fields-base'
5
+ import { HtVideoNode } from './hubtype-fields'
6
6
 
7
7
  export class FlowVideo extends ContentFieldsBase {
8
8
  public src = ''
9
9
  public code = ''
10
10
 
11
- static fromHubtypeCMS(component: VideoNode, locale: string): FlowVideo {
11
+ static fromHubtypeCMS(component: HtVideoNode, locale: string): FlowVideo {
12
12
  const newVideo = new FlowVideo(component.id)
13
13
  newVideo.code = component.code
14
14
  newVideo.src = this.getVideoByLocale(locale, component.content.video)
@@ -16,7 +16,6 @@ export class FlowVideo extends ContentFieldsBase {
16
16
  }
17
17
 
18
18
  toBotonic(id: string): JSX.Element {
19
- // @ts-ignore
20
19
  return <Video key={id} src={this.src} />
21
20
  }
22
21
  }
@@ -0,0 +1,15 @@
1
+ import {
2
+ HtNodeLink,
3
+ HtPayloadLocale,
4
+ HtTextLocale,
5
+ HtUrlLocale,
6
+ } from './common'
7
+
8
+ export interface HtButton {
9
+ id: string
10
+ text: HtTextLocale[]
11
+ url: HtUrlLocale[]
12
+ payload: HtPayloadLocale[]
13
+ target?: HtNodeLink
14
+ hidden: string[]
15
+ }
@@ -0,0 +1,18 @@
1
+ import { HtButton } from './button'
2
+ import { HtBaseNode, HtMediaFileLocale, HtTextLocale } from './common'
3
+ import { HtNodeWithContentType } from './node-types'
4
+
5
+ export interface HtCarouselElement {
6
+ id: string
7
+ title: HtTextLocale[]
8
+ subtitle: HtTextLocale[]
9
+ image: HtMediaFileLocale[]
10
+ button: HtButton
11
+ }
12
+
13
+ export interface HtCarouselNode extends HtBaseNode {
14
+ type: HtNodeWithContentType.CAROUSEL
15
+ content: {
16
+ elements: HtCarouselElement[]
17
+ }
18
+ }
@@ -0,0 +1,65 @@
1
+ import { HtNodeWithContentType, HtNodeWithoutContentType } from './node-types'
2
+ import { HtNodeComponent } from './nodes'
3
+
4
+ export interface HtFlowBuilderData {
5
+ version: string
6
+ name: string
7
+ locales: string[]
8
+ start_node_id?: string
9
+ ai_model_id?: string
10
+ nodes: HtNodeComponent[]
11
+ }
12
+
13
+ export interface HtNodeLink {
14
+ id: string
15
+ type: HtNodeWithContentType | HtNodeWithoutContentType
16
+ }
17
+
18
+ export interface HtBaseNode {
19
+ id: string
20
+ code: string
21
+ meta: {
22
+ x: number
23
+ y: number
24
+ }
25
+ follow_up?: HtNodeLink
26
+ target?: HtNodeLink
27
+ }
28
+
29
+ export interface HtTextLocale {
30
+ message: string
31
+ locale: string
32
+ }
33
+
34
+ export interface HtMediaFileLocale {
35
+ id: string
36
+ file: string
37
+ locale: string
38
+ }
39
+
40
+ export interface HtVideoLocale {
41
+ url: string
42
+ is_embedded: boolean
43
+ locale: string
44
+ }
45
+
46
+ export interface HtQueueLocale {
47
+ id: string
48
+ name: string
49
+ locale: string
50
+ }
51
+
52
+ export interface HtInputLocale {
53
+ values: string[]
54
+ locale: string
55
+ }
56
+
57
+ export interface HtUrlLocale {
58
+ id: string
59
+ locale: string
60
+ }
61
+
62
+ export interface HtPayloadLocale {
63
+ id: string
64
+ locale: string
65
+ }
@@ -0,0 +1,10 @@
1
+ import { HtBaseNode, HtNodeLink } from './common'
2
+ import { HtNodeWithContentType } from './node-types'
3
+
4
+ export interface HtFallbackNode extends HtBaseNode {
5
+ type: HtNodeWithContentType.FALLBACK
6
+ content: {
7
+ first_message?: HtNodeLink
8
+ second_message?: HtNodeLink
9
+ }
10
+ }
@@ -0,0 +1,33 @@
1
+ import { HtBaseNode, HtNodeLink } from './common'
2
+ import { HtNodeWithContentType } from './node-types'
3
+
4
+ export enum HtArgumentType {
5
+ NUMBER = 'number',
6
+ STRING = 'string',
7
+ JSON = 'json',
8
+ }
9
+
10
+ export interface HtFunctionArgument {
11
+ type: HtArgumentType
12
+ name: string
13
+ value: string
14
+ }
15
+
16
+ export interface HtFunctionArgumentLocale {
17
+ locale: string
18
+ values: HtFunctionArgument[]
19
+ }
20
+
21
+ export interface HtFunctionResult {
22
+ result: string
23
+ target?: HtNodeLink
24
+ }
25
+
26
+ export interface HtFunctionNode extends HtBaseNode {
27
+ type: HtNodeWithContentType.FUNCTION
28
+ content: {
29
+ action: string
30
+ arguments: HtFunctionArgumentLocale[]
31
+ result_mapping: HtFunctionResult[]
32
+ }
33
+ }
@@ -0,0 +1,11 @@
1
+ import { HtBaseNode, HtPayloadLocale, HtQueueLocale } from './common'
2
+ import { HtNodeWithContentType } from './node-types'
3
+
4
+ export interface HtHandoffNode extends HtBaseNode {
5
+ type: HtNodeWithContentType.HANDOFF
6
+ content: {
7
+ queue: HtQueueLocale[]
8
+ payload: HtPayloadLocale[]
9
+ has_auto_assign: boolean
10
+ }
11
+ }
@@ -0,0 +1,9 @@
1
+ import { HtBaseNode, HtMediaFileLocale } from './common'
2
+ import { HtNodeWithContentType } from './node-types'
3
+
4
+ export interface HtImageNode extends HtBaseNode {
5
+ type: HtNodeWithContentType.IMAGE
6
+ content: {
7
+ image: HtMediaFileLocale[]
8
+ }
9
+ }
@@ -0,0 +1,17 @@
1
+ export * from './button'
2
+ export * from './carousel'
3
+ export * from './common'
4
+ export * from './fallback'
5
+ export * from './function'
6
+ export * from './handoff'
7
+ export * from './image'
8
+ export * from './intent'
9
+ export * from './keyword'
10
+ export * from './node-types'
11
+ export * from './nodes'
12
+ export * from './payload'
13
+ export * from './start'
14
+ export * from './text'
15
+ export * from './url'
16
+ export * from './video'
17
+ export * from './whatsapp-button-list'
@@ -0,0 +1,11 @@
1
+ import { HtBaseNode, HtInputLocale, HtTextLocale } from './common'
2
+ import { HtNodeWithContentType } from './node-types'
3
+
4
+ export interface HtIntentNode extends HtBaseNode {
5
+ type: HtNodeWithContentType.INTENT
6
+ content: {
7
+ title: HtTextLocale[]
8
+ intents: HtInputLocale[]
9
+ confidence: number
10
+ }
11
+ }
@@ -0,0 +1,10 @@
1
+ import { HtBaseNode, HtInputLocale, HtTextLocale } from './common'
2
+ import { HtNodeWithContentType } from './node-types'
3
+
4
+ export interface HtKeywordNode extends HtBaseNode {
5
+ type: HtNodeWithContentType.KEYWORD
6
+ content: {
7
+ title: HtTextLocale[]
8
+ keywords: HtInputLocale[]
9
+ }
10
+ }
@@ -0,0 +1,26 @@
1
+ export enum HtNodeWithContentType {
2
+ CAROUSEL = 'carousel',
3
+ HANDOFF = 'handoff',
4
+ IMAGE = 'image',
5
+ TEXT = 'text',
6
+ KEYWORD = 'keyword',
7
+ INTENT = 'intent',
8
+ FUNCTION = 'function',
9
+ FALLBACK = 'fallback',
10
+ VIDEO = 'video',
11
+ WHATSAPP_BUTTON_LIST = 'whatsapp-button-list',
12
+ }
13
+
14
+ export enum HtNodeStartType {
15
+ STARTUP = 'start-up',
16
+ }
17
+
18
+ export enum HtNodeWithoutContentType {
19
+ URL = 'url',
20
+ PAYLOAD = 'payload',
21
+ }
22
+
23
+ export enum HtButtonStyle {
24
+ BUTTON = 'button',
25
+ QUICK_REPLY = 'quick-reply',
26
+ }
@@ -0,0 +1,32 @@
1
+ import { HtCarouselNode } from './carousel'
2
+ import { HtFallbackNode } from './fallback'
3
+ import { HtFunctionNode } from './function'
4
+ import { HtHandoffNode } from './handoff'
5
+ import { HtImageNode } from './image'
6
+ import { HtIntentNode } from './intent'
7
+ import { HtKeywordNode } from './keyword'
8
+ import { HtPayloadNode } from './payload'
9
+ import { HtStartNode } from './start'
10
+ import { HtTextNode } from './text'
11
+ import { HtUrlNode } from './url'
12
+ import { HtVideoNode } from './video'
13
+ import { HtWhatsappButtonListNode } from './whatsapp-button-list'
14
+
15
+ export type HtNodeWithContent =
16
+ | HtTextNode
17
+ | HtImageNode
18
+ | HtVideoNode
19
+ | HtCarouselNode
20
+ | HtHandoffNode
21
+ | HtKeywordNode
22
+ | HtIntentNode
23
+ | HtFunctionNode
24
+ | HtFallbackNode
25
+ | HtWhatsappButtonListNode
26
+
27
+ export type HtNodeWithoutContent = HtUrlNode | HtPayloadNode
28
+
29
+ export type HtNodeComponent =
30
+ | HtNodeWithContent
31
+ | HtNodeWithoutContent
32
+ | HtStartNode
@@ -0,0 +1,9 @@
1
+ import { HtNodeWithoutContentType } from './node-types'
2
+
3
+ export interface HtPayloadNode {
4
+ id: string
5
+ type: HtNodeWithoutContentType.PAYLOAD
6
+ content: {
7
+ payload: string
8
+ }
9
+ }
@@ -0,0 +1,8 @@
1
+ import { HtNodeLink } from './common'
2
+ import { HtNodeStartType } from './node-types'
3
+
4
+ export interface HtStartNode {
5
+ id: string
6
+ type: HtNodeStartType.STARTUP
7
+ target: HtNodeLink
8
+ }
@@ -0,0 +1,12 @@
1
+ import { HtButton } from './button'
2
+ import { HtBaseNode, HtTextLocale } from './common'
3
+ import { HtButtonStyle, HtNodeWithContentType } from './node-types'
4
+
5
+ export interface HtTextNode extends HtBaseNode {
6
+ type: HtNodeWithContentType.TEXT
7
+ content: {
8
+ text: HtTextLocale[]
9
+ buttons_style?: HtButtonStyle
10
+ buttons: HtButton[]
11
+ }
12
+ }
@@ -0,0 +1,9 @@
1
+ import { HtNodeWithoutContentType } from './node-types'
2
+
3
+ export interface HtUrlNode {
4
+ id: string
5
+ type: HtNodeWithoutContentType.URL
6
+ content: {
7
+ url: string
8
+ }
9
+ }
@@ -0,0 +1,9 @@
1
+ import { HtBaseNode, HtVideoLocale } from './common'
2
+ import { HtNodeWithContentType } from './node-types'
3
+
4
+ export interface HtVideoNode extends HtBaseNode {
5
+ type: HtNodeWithContentType.VIDEO
6
+ content: {
7
+ video: HtVideoLocale[]
8
+ }
9
+ }
@@ -0,0 +1,25 @@
1
+ /* eslint-disable @typescript-eslint/naming-convention */
2
+ import { HtBaseNode, HtNodeLink, HtTextLocale } from './common'
3
+ import { HtNodeWithContentType } from './node-types'
4
+
5
+ export interface HtWhatsappButtonListRow {
6
+ id: string
7
+ text: HtTextLocale[]
8
+ description: HtTextLocale[]
9
+ target?: HtNodeLink
10
+ }
11
+
12
+ export interface HtWhatsappButtonListSection {
13
+ id: string
14
+ title: HtTextLocale[]
15
+ rows: HtWhatsappButtonListRow[]
16
+ }
17
+
18
+ export interface HtWhatsappButtonListNode extends HtBaseNode {
19
+ type: HtNodeWithContentType.WHATSAPP_BUTTON_LIST
20
+ content: {
21
+ text: HtTextLocale[]
22
+ button_text: HtTextLocale[]
23
+ sections: HtWhatsappButtonListSection[]
24
+ }
25
+ }
@@ -1,8 +1,17 @@
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
+ import { FlowWhatsappButtonList } from './whatsapp-button-list/flow-whatsapp-button-list'
6
+
1
7
  export { ContentFieldsBase } from './content-fields-base'
2
8
  export { FlowButton } from './flow-button'
3
- export { FlowCarousel } from './flow-carousel'
4
9
  export { FlowElement } from './flow-element'
5
- export { FlowImage } from './flow-image'
6
- export { FlowText } from './flow-text'
7
- export { FlowVideo } from './flow-video'
8
- export type { FlowContent } from './types'
10
+ export { FlowCarousel, FlowImage, FlowText, FlowVideo, FlowWhatsappButtonList }
11
+
12
+ export type FlowContent =
13
+ | FlowCarousel
14
+ | FlowImage
15
+ | FlowText
16
+ | FlowVideo
17
+ | FlowWhatsappButtonList