@botonic/react 0.22.0-alpha.0 → 0.22.0-alpha.1

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 (693) hide show
  1. package/lib/cjs/app.d.ts +2 -0
  2. package/lib/cjs/app.js +10 -0
  3. package/lib/cjs/app.js.map +1 -0
  4. package/lib/cjs/botonic-tester.d.ts +18 -0
  5. package/lib/cjs/botonic-tester.js +70 -0
  6. package/lib/cjs/botonic-tester.js.map +1 -0
  7. package/lib/cjs/components/audio.d.ts +8 -0
  8. package/lib/cjs/components/audio.js +27 -0
  9. package/lib/cjs/components/audio.js.map +1 -0
  10. package/lib/cjs/components/button.d.ts +15 -0
  11. package/lib/cjs/components/button.js +156 -0
  12. package/lib/cjs/components/button.js.map +1 -0
  13. package/lib/cjs/components/buttons-disabler.d.ts +24 -0
  14. package/lib/cjs/components/buttons-disabler.js +88 -0
  15. package/lib/cjs/components/buttons-disabler.js.map +1 -0
  16. package/lib/cjs/components/carousel.d.ts +10 -0
  17. package/lib/cjs/components/carousel.js +120 -0
  18. package/lib/cjs/components/carousel.js.map +1 -0
  19. package/lib/cjs/components/components.d.ts +12 -0
  20. package/lib/{components → cjs/components}/components.js +6 -11
  21. package/lib/cjs/components/components.js.map +1 -0
  22. package/lib/cjs/components/custom-message.d.ts +43 -0
  23. package/lib/cjs/components/custom-message.js +65 -0
  24. package/lib/cjs/components/custom-message.js.map +1 -0
  25. package/lib/cjs/components/document.d.ts +8 -0
  26. package/lib/cjs/components/document.js +50 -0
  27. package/lib/cjs/components/document.js.map +1 -0
  28. package/lib/cjs/components/element.d.ts +4 -0
  29. package/lib/cjs/components/element.js +55 -0
  30. package/lib/cjs/components/element.js.map +1 -0
  31. package/lib/cjs/components/handoff.d.ts +1 -0
  32. package/lib/cjs/components/handoff.js +58 -0
  33. package/lib/cjs/components/handoff.js.map +1 -0
  34. package/lib/cjs/components/image.d.ts +8 -0
  35. package/lib/cjs/components/image.js +42 -0
  36. package/lib/cjs/components/image.js.map +1 -0
  37. package/lib/cjs/components/index.d.ts +20 -0
  38. package/lib/cjs/components/index.js +44 -0
  39. package/lib/cjs/components/index.js.map +1 -0
  40. package/lib/cjs/components/location.d.ts +11 -0
  41. package/lib/cjs/components/location.js +38 -0
  42. package/lib/cjs/components/location.js.map +1 -0
  43. package/lib/cjs/components/markdown.d.ts +7 -0
  44. package/lib/cjs/components/markdown.js +162 -0
  45. package/lib/cjs/components/markdown.js.map +1 -0
  46. package/lib/cjs/components/message-template.d.ts +1 -0
  47. package/lib/cjs/components/message-template.js +15 -0
  48. package/lib/cjs/components/message-template.js.map +1 -0
  49. package/lib/cjs/components/message.d.ts +1 -0
  50. package/lib/cjs/components/message.js +206 -0
  51. package/lib/cjs/components/message.js.map +1 -0
  52. package/lib/cjs/components/multichannel/facebook/facebook.d.ts +17 -0
  53. package/lib/cjs/components/multichannel/facebook/facebook.js +47 -0
  54. package/lib/cjs/components/multichannel/facebook/facebook.js.map +1 -0
  55. package/lib/cjs/components/multichannel/index.d.ts +6 -0
  56. package/lib/cjs/components/multichannel/index.js +14 -0
  57. package/lib/cjs/components/multichannel/index.js.map +1 -0
  58. package/lib/cjs/components/multichannel/multichannel-button.d.ts +1 -0
  59. package/lib/cjs/components/multichannel/multichannel-button.js +77 -0
  60. package/lib/cjs/components/multichannel/multichannel-button.js.map +1 -0
  61. package/lib/cjs/components/multichannel/multichannel-carousel.d.ts +1 -0
  62. package/lib/cjs/components/multichannel/multichannel-carousel.js +95 -0
  63. package/lib/cjs/components/multichannel/multichannel-carousel.js.map +1 -0
  64. package/lib/cjs/components/multichannel/multichannel-context.d.ts +11 -0
  65. package/lib/cjs/components/multichannel/multichannel-context.js +16 -0
  66. package/lib/cjs/components/multichannel/multichannel-context.js.map +1 -0
  67. package/lib/cjs/components/multichannel/multichannel-reply.d.ts +1 -0
  68. package/lib/cjs/components/multichannel/multichannel-reply.js +24 -0
  69. package/lib/cjs/components/multichannel/multichannel-reply.js.map +1 -0
  70. package/lib/cjs/components/multichannel/multichannel-text.d.ts +1 -0
  71. package/lib/cjs/components/multichannel/multichannel-text.js +147 -0
  72. package/lib/cjs/components/multichannel/multichannel-text.js.map +1 -0
  73. package/lib/cjs/components/multichannel/multichannel-utils.d.ts +24 -0
  74. package/lib/cjs/components/multichannel/multichannel-utils.js +83 -0
  75. package/lib/cjs/components/multichannel/multichannel-utils.js.map +1 -0
  76. package/lib/cjs/components/multichannel/multichannel.d.ts +1 -0
  77. package/lib/cjs/components/multichannel/multichannel.js +72 -0
  78. package/lib/cjs/components/multichannel/multichannel.js.map +1 -0
  79. package/lib/cjs/components/pic.d.ts +6 -0
  80. package/lib/cjs/components/pic.js +29 -0
  81. package/lib/cjs/components/pic.js.map +1 -0
  82. package/lib/cjs/components/raw.d.ts +9 -0
  83. package/lib/cjs/components/raw.js +53 -0
  84. package/lib/cjs/components/raw.js.map +1 -0
  85. package/lib/cjs/components/reply.d.ts +9 -0
  86. package/lib/cjs/components/reply.js +57 -0
  87. package/lib/cjs/components/reply.js.map +1 -0
  88. package/lib/cjs/components/share-button.d.ts +1 -0
  89. package/lib/cjs/components/share-button.js +15 -0
  90. package/lib/cjs/components/share-button.js.map +1 -0
  91. package/lib/cjs/components/subtitle.d.ts +6 -0
  92. package/lib/cjs/components/subtitle.js +25 -0
  93. package/lib/cjs/components/subtitle.js.map +1 -0
  94. package/lib/cjs/components/text.d.ts +8 -0
  95. package/lib/cjs/components/text.js +50 -0
  96. package/lib/cjs/components/text.js.map +1 -0
  97. package/lib/cjs/components/timestamps.d.ts +10 -0
  98. package/lib/cjs/components/timestamps.js +54 -0
  99. package/lib/cjs/components/timestamps.js.map +1 -0
  100. package/lib/cjs/components/title.d.ts +6 -0
  101. package/lib/cjs/components/title.js +21 -0
  102. package/lib/cjs/components/title.js.map +1 -0
  103. package/lib/cjs/components/video.d.ts +8 -0
  104. package/lib/cjs/components/video.js +34 -0
  105. package/lib/cjs/components/video.js.map +1 -0
  106. package/lib/cjs/components/webchat-settings.d.ts +10 -0
  107. package/lib/cjs/components/webchat-settings.js +78 -0
  108. package/lib/cjs/components/webchat-settings.js.map +1 -0
  109. package/lib/cjs/components/whatsapp-template.d.ts +1 -0
  110. package/lib/cjs/components/whatsapp-template.js +26 -0
  111. package/lib/cjs/components/whatsapp-template.js.map +1 -0
  112. package/lib/cjs/constants.d.ts +168 -0
  113. package/lib/cjs/constants.js +190 -0
  114. package/lib/cjs/constants.js.map +1 -0
  115. package/lib/cjs/contexts.d.ts +69 -0
  116. package/lib/cjs/contexts.js +38 -0
  117. package/lib/cjs/contexts.js.map +1 -0
  118. package/lib/cjs/dev-app.d.ts +30 -0
  119. package/lib/cjs/dev-app.js +71 -0
  120. package/lib/cjs/dev-app.js.map +1 -0
  121. package/lib/cjs/index.d.ts +10 -0
  122. package/lib/cjs/index.js +28 -0
  123. package/lib/cjs/index.js.map +1 -0
  124. package/lib/cjs/message-utils.d.ts +19 -0
  125. package/lib/cjs/message-utils.js +61 -0
  126. package/lib/cjs/message-utils.js.map +1 -0
  127. package/lib/cjs/msg-to-botonic.d.ts +18 -0
  128. package/lib/cjs/msg-to-botonic.js +160 -0
  129. package/lib/cjs/msg-to-botonic.js.map +1 -0
  130. package/lib/cjs/node-app.d.ts +12 -0
  131. package/lib/cjs/node-app.js +25 -0
  132. package/lib/cjs/node-app.js.map +1 -0
  133. package/lib/cjs/react-bot.d.ts +8 -0
  134. package/lib/cjs/react-bot.js +35 -0
  135. package/lib/cjs/react-bot.js.map +1 -0
  136. package/lib/cjs/util/dom.d.ts +13 -0
  137. package/lib/cjs/util/dom.js +55 -0
  138. package/lib/cjs/util/dom.js.map +1 -0
  139. package/lib/cjs/util/environment.d.ts +6 -0
  140. package/lib/cjs/util/environment.js +68 -0
  141. package/lib/cjs/util/environment.js.map +1 -0
  142. package/lib/cjs/util/error-boundary.d.ts +40 -0
  143. package/lib/cjs/util/error-boundary.js +46 -0
  144. package/lib/cjs/util/error-boundary.js.map +1 -0
  145. package/lib/cjs/util/index.d.ts +0 -0
  146. package/lib/cjs/util/index.js +2 -0
  147. package/lib/cjs/util/index.js.map +1 -0
  148. package/lib/cjs/util/logs.d.ts +2 -0
  149. package/lib/cjs/util/logs.js +20 -0
  150. package/lib/cjs/util/logs.js.map +1 -0
  151. package/lib/cjs/util/objects.d.ts +3 -0
  152. package/lib/cjs/util/objects.js +44 -0
  153. package/lib/cjs/util/objects.js.map +1 -0
  154. package/lib/cjs/util/react.d.ts +12 -0
  155. package/lib/cjs/util/react.js +42 -0
  156. package/lib/cjs/util/react.js.map +1 -0
  157. package/lib/cjs/util/regexs.d.ts +2 -0
  158. package/lib/cjs/util/regexs.js +23 -0
  159. package/lib/cjs/util/regexs.js.map +1 -0
  160. package/lib/cjs/util/webchat.d.ts +11 -0
  161. package/lib/cjs/util/webchat.js +62 -0
  162. package/lib/cjs/util/webchat.js.map +1 -0
  163. package/lib/cjs/webchat/actions.d.ts +23 -0
  164. package/lib/cjs/webchat/actions.js +27 -0
  165. package/lib/cjs/webchat/actions.js.map +1 -0
  166. package/lib/cjs/webchat/components/attachment.d.ts +5 -0
  167. package/lib/cjs/webchat/components/attachment.js +32 -0
  168. package/lib/cjs/webchat/components/attachment.js.map +1 -0
  169. package/lib/cjs/webchat/components/common.d.ts +1 -0
  170. package/lib/cjs/webchat/components/common.js +13 -0
  171. package/lib/cjs/webchat/components/common.js.map +1 -0
  172. package/lib/cjs/webchat/components/conditional-animation.d.ts +1 -0
  173. package/lib/cjs/webchat/components/conditional-animation.js +18 -0
  174. package/lib/cjs/webchat/components/conditional-animation.js.map +1 -0
  175. package/lib/cjs/webchat/components/emoji-picker.d.ts +5 -0
  176. package/lib/cjs/webchat/components/emoji-picker.js +52 -0
  177. package/lib/cjs/webchat/components/emoji-picker.js.map +1 -0
  178. package/lib/cjs/webchat/components/persistent-menu.d.ts +10 -0
  179. package/lib/cjs/webchat/components/persistent-menu.js +59 -0
  180. package/lib/cjs/webchat/components/persistent-menu.js.map +1 -0
  181. package/lib/cjs/webchat/components/send-button.d.ts +3 -0
  182. package/lib/cjs/webchat/components/send-button.js +24 -0
  183. package/lib/cjs/webchat/components/send-button.js.map +1 -0
  184. package/lib/cjs/webchat/components/styled-scrollbar.d.ts +1 -0
  185. package/lib/cjs/webchat/components/styled-scrollbar.js +54 -0
  186. package/lib/cjs/webchat/components/styled-scrollbar.js.map +1 -0
  187. package/lib/cjs/webchat/components/typing-indicator.d.ts +1 -0
  188. package/lib/cjs/webchat/components/typing-indicator.js +14 -0
  189. package/lib/cjs/webchat/components/typing-indicator.js.map +1 -0
  190. package/lib/cjs/webchat/devices/device-adapter.d.ts +12 -0
  191. package/lib/cjs/webchat/devices/device-adapter.js +47 -0
  192. package/lib/cjs/webchat/devices/device-adapter.js.map +1 -0
  193. package/lib/cjs/webchat/devices/index.d.ts +11 -0
  194. package/lib/cjs/webchat/devices/index.js +23 -0
  195. package/lib/cjs/webchat/devices/index.js.map +1 -0
  196. package/lib/cjs/webchat/devices/scrollbar-controller.d.ts +12 -0
  197. package/lib/cjs/webchat/devices/scrollbar-controller.js +103 -0
  198. package/lib/cjs/webchat/devices/scrollbar-controller.js.map +1 -0
  199. package/lib/cjs/webchat/devices/webchat-resizer.d.ts +9 -0
  200. package/lib/cjs/webchat/devices/webchat-resizer.js +47 -0
  201. package/lib/cjs/webchat/devices/webchat-resizer.js.map +1 -0
  202. package/lib/cjs/webchat/header.d.ts +3 -0
  203. package/lib/cjs/webchat/header.js +95 -0
  204. package/lib/cjs/webchat/header.js.map +1 -0
  205. package/lib/cjs/webchat/hooks.d.ts +80 -0
  206. package/lib/cjs/webchat/hooks.js +218 -0
  207. package/lib/cjs/webchat/hooks.js.map +1 -0
  208. package/lib/cjs/webchat/index.d.ts +6 -0
  209. package/lib/cjs/webchat/index.js +17 -0
  210. package/lib/cjs/webchat/index.js.map +1 -0
  211. package/lib/cjs/webchat/message-list.d.ts +1 -0
  212. package/lib/cjs/webchat/message-list.js +46 -0
  213. package/lib/cjs/webchat/message-list.js.map +1 -0
  214. package/lib/cjs/webchat/messages-reducer.d.ts +1 -0
  215. package/lib/cjs/webchat/messages-reducer.js +58 -0
  216. package/lib/cjs/webchat/messages-reducer.js.map +1 -0
  217. package/lib/cjs/webchat/replies.d.ts +1 -0
  218. package/lib/cjs/webchat/replies.js +46 -0
  219. package/lib/cjs/webchat/replies.js.map +1 -0
  220. package/lib/cjs/webchat/session-view.d.ts +1 -0
  221. package/lib/cjs/webchat/session-view.js +124 -0
  222. package/lib/cjs/webchat/session-view.js.map +1 -0
  223. package/lib/cjs/webchat/use-storage-state-hook.d.ts +1 -0
  224. package/lib/cjs/webchat/use-storage-state-hook.js +32 -0
  225. package/lib/cjs/webchat/use-storage-state-hook.js.map +1 -0
  226. package/lib/cjs/webchat/webchat-dev.d.ts +7 -0
  227. package/lib/cjs/webchat/webchat-dev.js +64 -0
  228. package/lib/cjs/webchat/webchat-dev.js.map +1 -0
  229. package/lib/cjs/webchat/webchat-reducer.d.ts +1 -0
  230. package/lib/cjs/webchat/webchat-reducer.js +48 -0
  231. package/lib/cjs/webchat/webchat-reducer.js.map +1 -0
  232. package/lib/cjs/webchat/webchat.d.ts +3 -0
  233. package/lib/cjs/webchat/webchat.js +704 -0
  234. package/lib/cjs/webchat/webchat.js.map +1 -0
  235. package/lib/cjs/webchat/webview.d.ts +2 -0
  236. package/lib/cjs/webchat/webview.js +92 -0
  237. package/lib/cjs/webchat/webview.js.map +1 -0
  238. package/lib/cjs/webchat-app.d.ts +99 -0
  239. package/lib/cjs/webchat-app.js +269 -0
  240. package/lib/cjs/webchat-app.js.map +1 -0
  241. package/lib/cjs/webview-app.d.ts +7 -0
  242. package/lib/cjs/webview-app.js +103 -0
  243. package/lib/cjs/webview-app.js.map +1 -0
  244. package/lib/esm/app.d.ts +2 -0
  245. package/lib/esm/app.js +6 -0
  246. package/lib/esm/app.js.map +1 -0
  247. package/lib/esm/assets/attachment-icon.svg +7 -0
  248. package/lib/esm/assets/audio.svg +4 -0
  249. package/lib/esm/assets/botonic_react_logo100x100.png +0 -0
  250. package/lib/esm/assets/document.svg +3 -0
  251. package/lib/esm/assets/emojiButton.svg +6 -0
  252. package/lib/esm/assets/image.svg +4 -0
  253. package/lib/esm/assets/leftArrow.svg +3 -0
  254. package/lib/esm/assets/menuButton.svg +3 -0
  255. package/lib/esm/assets/rightArrow.svg +3 -0
  256. package/lib/esm/assets/send-button.svg +1 -0
  257. package/lib/esm/assets/video.svg +3 -0
  258. package/lib/esm/botonic-tester.d.ts +18 -0
  259. package/lib/esm/botonic-tester.js +64 -0
  260. package/lib/esm/botonic-tester.js.map +1 -0
  261. package/lib/esm/components/audio.d.ts +8 -0
  262. package/lib/esm/components/audio.js +22 -0
  263. package/lib/esm/components/audio.js.map +1 -0
  264. package/lib/esm/components/button.d.ts +15 -0
  265. package/lib/esm/components/button.js +151 -0
  266. package/lib/esm/components/button.js.map +1 -0
  267. package/lib/esm/components/buttons-disabler.d.ts +24 -0
  268. package/lib/esm/components/buttons-disabler.js +84 -0
  269. package/lib/esm/components/buttons-disabler.js.map +1 -0
  270. package/lib/esm/components/carousel.d.ts +9 -0
  271. package/lib/esm/components/carousel.js +115 -0
  272. package/lib/esm/components/carousel.js.map +1 -0
  273. package/lib/esm/components/components.d.ts +12 -0
  274. package/lib/esm/components/components.js +17 -0
  275. package/lib/esm/components/components.js.map +1 -0
  276. package/lib/esm/components/custom-message.d.ts +43 -0
  277. package/lib/esm/components/custom-message.js +61 -0
  278. package/lib/esm/components/custom-message.js.map +1 -0
  279. package/lib/esm/components/document.d.ts +8 -0
  280. package/lib/esm/components/document.js +45 -0
  281. package/lib/esm/components/document.js.map +1 -0
  282. package/lib/esm/components/element.d.ts +4 -0
  283. package/lib/esm/components/element.js +50 -0
  284. package/lib/esm/components/element.js.map +1 -0
  285. package/lib/esm/components/handoff.d.ts +1 -0
  286. package/lib/esm/components/handoff.js +53 -0
  287. package/lib/esm/components/handoff.js.map +1 -0
  288. package/lib/esm/components/image.d.ts +8 -0
  289. package/lib/esm/components/image.js +37 -0
  290. package/lib/esm/components/image.js.map +1 -0
  291. package/lib/esm/components/index.d.ts +19 -0
  292. package/lib/esm/components/index.js +21 -0
  293. package/lib/esm/components/index.js.map +1 -0
  294. package/lib/esm/components/location.d.ts +11 -0
  295. package/lib/esm/components/location.js +33 -0
  296. package/lib/esm/components/location.js.map +1 -0
  297. package/lib/esm/components/markdown.d.ts +7 -0
  298. package/lib/esm/components/markdown.js +152 -0
  299. package/lib/esm/components/markdown.js.map +1 -0
  300. package/lib/esm/components/message-template.d.ts +1 -0
  301. package/lib/esm/components/message-template.js +10 -0
  302. package/lib/esm/components/message-template.js.map +1 -0
  303. package/lib/esm/components/message.d.ts +1 -0
  304. package/lib/esm/components/message.js +202 -0
  305. package/lib/esm/components/message.js.map +1 -0
  306. package/lib/esm/components/multichannel/facebook/facebook.d.ts +17 -0
  307. package/lib/esm/components/multichannel/facebook/facebook.js +43 -0
  308. package/lib/esm/components/multichannel/facebook/facebook.js.map +1 -0
  309. package/lib/esm/components/multichannel/index.d.ts +6 -0
  310. package/lib/esm/components/multichannel/index.js +11 -0
  311. package/lib/esm/components/multichannel/index.js.map +1 -0
  312. package/lib/esm/components/multichannel/multichannel-button.d.ts +1 -0
  313. package/lib/esm/components/multichannel/multichannel-button.js +72 -0
  314. package/lib/esm/components/multichannel/multichannel-button.js.map +1 -0
  315. package/lib/esm/components/multichannel/multichannel-carousel.d.ts +1 -0
  316. package/lib/esm/components/multichannel/multichannel-carousel.js +90 -0
  317. package/lib/esm/components/multichannel/multichannel-carousel.js.map +1 -0
  318. package/lib/esm/components/multichannel/multichannel-context.d.ts +11 -0
  319. package/lib/esm/components/multichannel/multichannel-context.js +12 -0
  320. package/lib/esm/components/multichannel/multichannel-context.js.map +1 -0
  321. package/lib/esm/components/multichannel/multichannel-reply.d.ts +1 -0
  322. package/lib/esm/components/multichannel/multichannel-reply.js +19 -0
  323. package/lib/esm/components/multichannel/multichannel-reply.js.map +1 -0
  324. package/lib/esm/components/multichannel/multichannel-text.d.ts +1 -0
  325. package/lib/esm/components/multichannel/multichannel-text.js +142 -0
  326. package/lib/esm/components/multichannel/multichannel-text.js.map +1 -0
  327. package/lib/esm/components/multichannel/multichannel-utils.d.ts +24 -0
  328. package/lib/esm/components/multichannel/multichannel-utils.js +67 -0
  329. package/lib/esm/components/multichannel/multichannel-utils.js.map +1 -0
  330. package/lib/esm/components/multichannel/multichannel.d.ts +1 -0
  331. package/lib/esm/components/multichannel/multichannel.js +67 -0
  332. package/lib/esm/components/multichannel/multichannel.js.map +1 -0
  333. package/lib/esm/components/pic.d.ts +6 -0
  334. package/lib/esm/components/pic.js +24 -0
  335. package/lib/esm/components/pic.js.map +1 -0
  336. package/lib/esm/components/raw.d.ts +9 -0
  337. package/lib/esm/components/raw.js +48 -0
  338. package/lib/esm/components/raw.js.map +1 -0
  339. package/lib/esm/components/reply.d.ts +9 -0
  340. package/lib/esm/components/reply.js +52 -0
  341. package/lib/esm/components/reply.js.map +1 -0
  342. package/lib/esm/components/share-button.d.ts +1 -0
  343. package/lib/esm/components/share-button.js +10 -0
  344. package/lib/esm/components/share-button.js.map +1 -0
  345. package/lib/esm/components/subtitle.d.ts +6 -0
  346. package/lib/esm/components/subtitle.js +20 -0
  347. package/lib/esm/components/subtitle.js.map +1 -0
  348. package/lib/esm/components/text.d.ts +8 -0
  349. package/lib/esm/components/text.js +45 -0
  350. package/lib/esm/components/text.js.map +1 -0
  351. package/lib/esm/components/timestamps.d.ts +10 -0
  352. package/lib/esm/components/timestamps.js +48 -0
  353. package/lib/esm/components/timestamps.js.map +1 -0
  354. package/lib/esm/components/title.d.ts +6 -0
  355. package/lib/esm/components/title.js +16 -0
  356. package/lib/esm/components/title.js.map +1 -0
  357. package/lib/esm/components/video.d.ts +8 -0
  358. package/lib/esm/components/video.js +29 -0
  359. package/lib/esm/components/video.js.map +1 -0
  360. package/lib/esm/components/webchat-settings.d.ts +10 -0
  361. package/lib/esm/components/webchat-settings.js +72 -0
  362. package/lib/esm/components/webchat-settings.js.map +1 -0
  363. package/lib/esm/components/whatsapp-template.d.ts +1 -0
  364. package/lib/esm/components/whatsapp-template.js +21 -0
  365. package/lib/esm/components/whatsapp-template.js.map +1 -0
  366. package/lib/esm/constants.d.ts +168 -0
  367. package/lib/esm/constants.js +186 -0
  368. package/lib/esm/constants.js.map +1 -0
  369. package/lib/esm/contexts.d.ts +69 -0
  370. package/lib/esm/contexts.js +34 -0
  371. package/lib/esm/contexts.js.map +1 -0
  372. package/lib/esm/dev-app.d.ts +30 -0
  373. package/lib/esm/dev-app.js +67 -0
  374. package/lib/esm/dev-app.js.map +1 -0
  375. package/lib/esm/index.d.ts +9 -0
  376. package/lib/esm/index.js +11 -0
  377. package/lib/esm/index.js.map +1 -0
  378. package/lib/esm/message-utils.d.ts +18 -0
  379. package/lib/esm/message-utils.js +41 -0
  380. package/lib/esm/message-utils.js.map +1 -0
  381. package/lib/esm/msg-to-botonic.d.ts +18 -0
  382. package/lib/esm/msg-to-botonic.js +154 -0
  383. package/lib/esm/msg-to-botonic.js.map +1 -0
  384. package/lib/esm/node-app.d.ts +12 -0
  385. package/lib/esm/node-app.js +21 -0
  386. package/lib/esm/node-app.js.map +1 -0
  387. package/lib/esm/react-bot.d.ts +7 -0
  388. package/lib/esm/react-bot.js +30 -0
  389. package/lib/esm/react-bot.js.map +1 -0
  390. package/lib/esm/util/dom.d.ts +13 -0
  391. package/lib/esm/util/dom.js +46 -0
  392. package/lib/esm/util/dom.js.map +1 -0
  393. package/lib/esm/util/environment.d.ts +6 -0
  394. package/lib/esm/util/environment.js +61 -0
  395. package/lib/esm/util/environment.js.map +1 -0
  396. package/lib/esm/util/error-boundary.d.ts +40 -0
  397. package/lib/esm/util/error-boundary.js +41 -0
  398. package/lib/esm/util/error-boundary.js.map +1 -0
  399. package/lib/esm/util/index.d.ts +0 -0
  400. package/lib/esm/util/index.js +2 -0
  401. package/lib/esm/util/index.js.map +1 -0
  402. package/lib/esm/util/logs.d.ts +2 -0
  403. package/lib/esm/util/logs.js +15 -0
  404. package/lib/esm/util/logs.js.map +1 -0
  405. package/lib/esm/util/objects.d.ts +3 -0
  406. package/lib/esm/util/objects.js +38 -0
  407. package/lib/esm/util/objects.js.map +1 -0
  408. package/lib/esm/util/react.d.ts +12 -0
  409. package/lib/esm/util/react.js +34 -0
  410. package/lib/esm/util/react.js.map +1 -0
  411. package/lib/esm/util/regexs.d.ts +2 -0
  412. package/lib/esm/util/regexs.js +18 -0
  413. package/lib/esm/util/regexs.js.map +1 -0
  414. package/lib/esm/util/webchat.d.ts +11 -0
  415. package/lib/esm/util/webchat.js +53 -0
  416. package/lib/esm/util/webchat.js.map +1 -0
  417. package/lib/esm/webchat/actions.d.ts +23 -0
  418. package/lib/esm/webchat/actions.js +24 -0
  419. package/lib/esm/webchat/actions.js.map +1 -0
  420. package/lib/esm/webchat/components/attachment.d.ts +5 -0
  421. package/lib/esm/webchat/components/attachment.js +27 -0
  422. package/lib/esm/webchat/components/attachment.js.map +1 -0
  423. package/lib/esm/webchat/components/common.d.ts +1 -0
  424. package/lib/esm/webchat/components/common.js +8 -0
  425. package/lib/esm/webchat/components/common.js.map +1 -0
  426. package/lib/esm/webchat/components/conditional-animation.d.ts +1 -0
  427. package/lib/esm/webchat/components/conditional-animation.js +13 -0
  428. package/lib/esm/webchat/components/conditional-animation.js.map +1 -0
  429. package/lib/esm/webchat/components/emoji-picker.d.ts +5 -0
  430. package/lib/esm/webchat/components/emoji-picker.js +46 -0
  431. package/lib/esm/webchat/components/emoji-picker.js.map +1 -0
  432. package/lib/esm/webchat/components/persistent-menu.d.ts +10 -0
  433. package/lib/esm/webchat/components/persistent-menu.js +53 -0
  434. package/lib/esm/webchat/components/persistent-menu.js.map +1 -0
  435. package/lib/esm/webchat/components/send-button.d.ts +3 -0
  436. package/lib/esm/webchat/components/send-button.js +19 -0
  437. package/lib/esm/webchat/components/send-button.js.map +1 -0
  438. package/lib/esm/webchat/components/styled-scrollbar.d.ts +1 -0
  439. package/lib/esm/webchat/components/styled-scrollbar.js +50 -0
  440. package/lib/esm/webchat/components/styled-scrollbar.js.map +1 -0
  441. package/lib/esm/webchat/components/styled-scrollbar.scss +12 -0
  442. package/lib/esm/webchat/components/typing-indicator.d.ts +1 -0
  443. package/lib/esm/webchat/components/typing-indicator.js +9 -0
  444. package/lib/esm/webchat/components/typing-indicator.js.map +1 -0
  445. package/lib/esm/webchat/components/typing-indicator.scss +38 -0
  446. package/lib/esm/webchat/devices/device-adapter.d.ts +12 -0
  447. package/lib/esm/webchat/devices/device-adapter.js +43 -0
  448. package/lib/esm/webchat/devices/device-adapter.js.map +1 -0
  449. package/lib/esm/webchat/devices/index.d.ts +11 -0
  450. package/lib/esm/webchat/devices/index.js +18 -0
  451. package/lib/esm/webchat/devices/index.js.map +1 -0
  452. package/lib/esm/webchat/devices/scrollbar-controller.d.ts +12 -0
  453. package/lib/esm/webchat/devices/scrollbar-controller.js +99 -0
  454. package/lib/esm/webchat/devices/scrollbar-controller.js.map +1 -0
  455. package/lib/esm/webchat/devices/webchat-resizer.d.ts +9 -0
  456. package/lib/esm/webchat/devices/webchat-resizer.js +43 -0
  457. package/lib/esm/webchat/devices/webchat-resizer.js.map +1 -0
  458. package/lib/esm/webchat/header.d.ts +3 -0
  459. package/lib/esm/webchat/header.js +89 -0
  460. package/lib/esm/webchat/header.js.map +1 -0
  461. package/lib/esm/webchat/hooks.d.ts +80 -0
  462. package/lib/esm/webchat/hooks.js +210 -0
  463. package/lib/esm/webchat/hooks.js.map +1 -0
  464. package/lib/esm/webchat/index.d.ts +6 -0
  465. package/lib/esm/webchat/index.js +11 -0
  466. package/lib/esm/webchat/index.js.map +1 -0
  467. package/lib/esm/webchat/message-list.d.ts +1 -0
  468. package/lib/esm/webchat/message-list.js +41 -0
  469. package/lib/esm/webchat/message-list.js.map +1 -0
  470. package/lib/esm/webchat/messages-reducer.d.ts +1 -0
  471. package/lib/esm/webchat/messages-reducer.js +54 -0
  472. package/lib/esm/webchat/messages-reducer.js.map +1 -0
  473. package/lib/esm/webchat/replies.d.ts +1 -0
  474. package/lib/esm/webchat/replies.js +41 -0
  475. package/lib/esm/webchat/replies.js.map +1 -0
  476. package/lib/esm/webchat/session-view.d.ts +1 -0
  477. package/lib/esm/webchat/session-view.js +119 -0
  478. package/lib/esm/webchat/session-view.js.map +1 -0
  479. package/lib/esm/webchat/use-storage-state-hook.d.ts +1 -0
  480. package/lib/esm/webchat/use-storage-state-hook.js +28 -0
  481. package/lib/esm/webchat/use-storage-state-hook.js.map +1 -0
  482. package/lib/esm/webchat/webchat-dev.d.ts +7 -0
  483. package/lib/esm/webchat/webchat-dev.js +60 -0
  484. package/lib/esm/webchat/webchat-dev.js.map +1 -0
  485. package/lib/esm/webchat/webchat-reducer.d.ts +1 -0
  486. package/lib/esm/webchat/webchat-reducer.js +44 -0
  487. package/lib/esm/webchat/webchat-reducer.js.map +1 -0
  488. package/lib/esm/webchat/webchat.d.ts +3 -0
  489. package/lib/esm/webchat/webchat.js +699 -0
  490. package/lib/esm/webchat/webchat.js.map +1 -0
  491. package/lib/esm/webchat/webview.d.ts +2 -0
  492. package/lib/esm/webchat/webview.js +86 -0
  493. package/lib/esm/webchat/webview.js.map +1 -0
  494. package/lib/esm/webchat-app.d.ts +98 -0
  495. package/lib/esm/webchat-app.js +265 -0
  496. package/lib/esm/webchat-app.js.map +1 -0
  497. package/lib/esm/webchat.template.html +37 -0
  498. package/lib/esm/webview-app.d.ts +7 -0
  499. package/lib/esm/webview-app.js +98 -0
  500. package/lib/esm/webview-app.js.map +1 -0
  501. package/lib/esm/webview.template.html +39 -0
  502. package/package.json +27 -20
  503. package/src/components/audio.jsx +2 -0
  504. package/src/components/document.jsx +2 -0
  505. package/src/components/image.jsx +2 -0
  506. package/src/components/location.jsx +2 -2
  507. package/src/components/pic.jsx +3 -1
  508. package/src/components/video.jsx +2 -0
  509. package/src/index.js +1 -1
  510. package/src/msg-to-botonic.jsx +1 -1
  511. package/src/util/environment.js +31 -2
  512. package/src/{webview.jsx → webview-app.tsx} +7 -1
  513. package/lib/app.js +0 -19
  514. package/lib/app.js.map +0 -1
  515. package/lib/botonic-tester.js +0 -224
  516. package/lib/botonic-tester.js.map +0 -1
  517. package/lib/components/audio.js +0 -48
  518. package/lib/components/audio.js.map +0 -1
  519. package/lib/components/button.js +0 -224
  520. package/lib/components/button.js.map +0 -1
  521. package/lib/components/buttons-disabler.js +0 -133
  522. package/lib/components/buttons-disabler.js.map +0 -1
  523. package/lib/components/carousel.js +0 -194
  524. package/lib/components/carousel.js.map +0 -1
  525. package/lib/components/components.js.map +0 -1
  526. package/lib/components/custom-message.js +0 -131
  527. package/lib/components/custom-message.js.map +0 -1
  528. package/lib/components/document.js +0 -76
  529. package/lib/components/document.js.map +0 -1
  530. package/lib/components/element.js +0 -69
  531. package/lib/components/element.js.map +0 -1
  532. package/lib/components/handoff.js +0 -69
  533. package/lib/components/handoff.js.map +0 -1
  534. package/lib/components/image.js +0 -91
  535. package/lib/components/image.js.map +0 -1
  536. package/lib/components/index.d.ts +0 -228
  537. package/lib/components/index.js +0 -193
  538. package/lib/components/index.js.map +0 -1
  539. package/lib/components/location.js +0 -69
  540. package/lib/components/location.js.map +0 -1
  541. package/lib/components/markdown.js +0 -108
  542. package/lib/components/markdown.js.map +0 -1
  543. package/lib/components/message-template.js +0 -36
  544. package/lib/components/message-template.js.map +0 -1
  545. package/lib/components/message.js +0 -351
  546. package/lib/components/message.js.map +0 -1
  547. package/lib/components/multichannel/facebook/facebook.js +0 -96
  548. package/lib/components/multichannel/facebook/facebook.js.map +0 -1
  549. package/lib/components/multichannel/index.d.ts +0 -65
  550. package/lib/components/multichannel/index.js +0 -46
  551. package/lib/components/multichannel/index.js.map +0 -1
  552. package/lib/components/multichannel/multichannel-button.js +0 -119
  553. package/lib/components/multichannel/multichannel-button.js.map +0 -1
  554. package/lib/components/multichannel/multichannel-carousel.js +0 -143
  555. package/lib/components/multichannel/multichannel-carousel.js.map +0 -1
  556. package/lib/components/multichannel/multichannel-context.js +0 -24
  557. package/lib/components/multichannel/multichannel-context.js.map +0 -1
  558. package/lib/components/multichannel/multichannel-reply.js +0 -46
  559. package/lib/components/multichannel/multichannel-reply.js.map +0 -1
  560. package/lib/components/multichannel/multichannel-text.js +0 -222
  561. package/lib/components/multichannel/multichannel-text.js.map +0 -1
  562. package/lib/components/multichannel/multichannel-utils.js +0 -126
  563. package/lib/components/multichannel/multichannel-utils.js.map +0 -1
  564. package/lib/components/multichannel/multichannel.js +0 -111
  565. package/lib/components/multichannel/multichannel.js.map +0 -1
  566. package/lib/components/pic.js +0 -50
  567. package/lib/components/pic.js.map +0 -1
  568. package/lib/components/raw.js +0 -70
  569. package/lib/components/raw.js.map +0 -1
  570. package/lib/components/reply.js +0 -107
  571. package/lib/components/reply.js.map +0 -1
  572. package/lib/components/share-button.js +0 -36
  573. package/lib/components/share-button.js.map +0 -1
  574. package/lib/components/subtitle.js +0 -54
  575. package/lib/components/subtitle.js.map +0 -1
  576. package/lib/components/text.js +0 -80
  577. package/lib/components/text.js.map +0 -1
  578. package/lib/components/timestamps.js +0 -69
  579. package/lib/components/timestamps.js.map +0 -1
  580. package/lib/components/title.js +0 -52
  581. package/lib/components/title.js.map +0 -1
  582. package/lib/components/video.js +0 -51
  583. package/lib/components/video.js.map +0 -1
  584. package/lib/components/webchat-settings.js +0 -118
  585. package/lib/components/webchat-settings.js.map +0 -1
  586. package/lib/components/whatsapp-template.js +0 -53
  587. package/lib/components/whatsapp-template.js.map +0 -1
  588. package/lib/constants.js +0 -203
  589. package/lib/constants.js.map +0 -1
  590. package/lib/contexts.js +0 -57
  591. package/lib/contexts.js.map +0 -1
  592. package/lib/dev-app.js +0 -241
  593. package/lib/dev-app.js.map +0 -1
  594. package/lib/index.d.ts +0 -238
  595. package/lib/index.js +0 -131
  596. package/lib/index.js.map +0 -1
  597. package/lib/message-utils.js +0 -149
  598. package/lib/message-utils.js.map +0 -1
  599. package/lib/msg-to-botonic.js +0 -199
  600. package/lib/msg-to-botonic.js.map +0 -1
  601. package/lib/node-app.js +0 -97
  602. package/lib/node-app.js.map +0 -1
  603. package/lib/react-bot.js +0 -167
  604. package/lib/react-bot.js.map +0 -1
  605. package/lib/util/dom.js +0 -84
  606. package/lib/util/dom.js.map +0 -1
  607. package/lib/util/environment.js +0 -42
  608. package/lib/util/environment.js.map +0 -1
  609. package/lib/util/error-boundary.js +0 -105
  610. package/lib/util/error-boundary.js.map +0 -1
  611. package/lib/util/index.d.ts +0 -9
  612. package/lib/util/index.js +0 -2
  613. package/lib/util/index.js.map +0 -1
  614. package/lib/util/logs.js +0 -28
  615. package/lib/util/logs.js.map +0 -1
  616. package/lib/util/objects.js +0 -60
  617. package/lib/util/objects.js.map +0 -1
  618. package/lib/util/react.js +0 -75
  619. package/lib/util/react.js.map +0 -1
  620. package/lib/util/regexs.js +0 -31
  621. package/lib/util/regexs.js.map +0 -1
  622. package/lib/util/webchat.js +0 -92
  623. package/lib/util/webchat.js.map +0 -1
  624. package/lib/webchat/actions.js +0 -53
  625. package/lib/webchat/actions.js.map +0 -1
  626. package/lib/webchat/components/attachment.js +0 -68
  627. package/lib/webchat/components/attachment.js.map +0 -1
  628. package/lib/webchat/components/common.js +0 -29
  629. package/lib/webchat/components/common.js.map +0 -1
  630. package/lib/webchat/components/conditional-animation.js +0 -42
  631. package/lib/webchat/components/conditional-animation.js.map +0 -1
  632. package/lib/webchat/components/emoji-picker.js +0 -89
  633. package/lib/webchat/components/emoji-picker.js.map +0 -1
  634. package/lib/webchat/components/persistent-menu.js +0 -104
  635. package/lib/webchat/components/persistent-menu.js.map +0 -1
  636. package/lib/webchat/components/send-button.js +0 -45
  637. package/lib/webchat/components/send-button.js.map +0 -1
  638. package/lib/webchat/components/styled-scrollbar.js +0 -55
  639. package/lib/webchat/components/styled-scrollbar.js.map +0 -1
  640. package/lib/webchat/components/typing-indicator.js +0 -27
  641. package/lib/webchat/components/typing-indicator.js.map +0 -1
  642. package/lib/webchat/devices/device-adapter.js +0 -82
  643. package/lib/webchat/devices/device-adapter.js.map +0 -1
  644. package/lib/webchat/devices/index.js +0 -32
  645. package/lib/webchat/devices/index.js.map +0 -1
  646. package/lib/webchat/devices/scrollbar-controller.js +0 -152
  647. package/lib/webchat/devices/scrollbar-controller.js.map +0 -1
  648. package/lib/webchat/devices/webchat-resizer.js +0 -76
  649. package/lib/webchat/devices/webchat-resizer.js.map +0 -1
  650. package/lib/webchat/header.js +0 -116
  651. package/lib/webchat/header.js.map +0 -1
  652. package/lib/webchat/hooks.js +0 -359
  653. package/lib/webchat/hooks.js.map +0 -1
  654. package/lib/webchat/index.d.ts +0 -62
  655. package/lib/webchat/index.js +0 -32
  656. package/lib/webchat/index.js.map +0 -1
  657. package/lib/webchat/message-list.js +0 -88
  658. package/lib/webchat/message-list.js.map +0 -1
  659. package/lib/webchat/messages-reducer.js +0 -93
  660. package/lib/webchat/messages-reducer.js.map +0 -1
  661. package/lib/webchat/replies.js +0 -78
  662. package/lib/webchat/replies.js.map +0 -1
  663. package/lib/webchat/session-view.js +0 -106
  664. package/lib/webchat/session-view.js.map +0 -1
  665. package/lib/webchat/use-storage-state-hook.js +0 -60
  666. package/lib/webchat/use-storage-state-hook.js.map +0 -1
  667. package/lib/webchat/webchat-dev.js +0 -109
  668. package/lib/webchat/webchat-dev.js.map +0 -1
  669. package/lib/webchat/webchat-reducer.js +0 -108
  670. package/lib/webchat/webchat-reducer.js.map +0 -1
  671. package/lib/webchat/webchat.js +0 -1108
  672. package/lib/webchat/webchat.js.map +0 -1
  673. package/lib/webchat/webview.js +0 -122
  674. package/lib/webchat/webview.js.map +0 -1
  675. package/lib/webchat-app.js +0 -660
  676. package/lib/webchat-app.js.map +0 -1
  677. package/lib/webview.js +0 -231
  678. package/lib/webview.js.map +0 -1
  679. /package/lib/{assets → cjs/assets}/attachment-icon.svg +0 -0
  680. /package/lib/{assets → cjs/assets}/audio.svg +0 -0
  681. /package/lib/{assets → cjs/assets}/botonic_react_logo100x100.png +0 -0
  682. /package/lib/{assets → cjs/assets}/document.svg +0 -0
  683. /package/lib/{assets → cjs/assets}/emojiButton.svg +0 -0
  684. /package/lib/{assets → cjs/assets}/image.svg +0 -0
  685. /package/lib/{assets → cjs/assets}/leftArrow.svg +0 -0
  686. /package/lib/{assets → cjs/assets}/menuButton.svg +0 -0
  687. /package/lib/{assets → cjs/assets}/rightArrow.svg +0 -0
  688. /package/lib/{assets → cjs/assets}/send-button.svg +0 -0
  689. /package/lib/{assets → cjs/assets}/video.svg +0 -0
  690. /package/lib/{webchat → cjs/webchat}/components/styled-scrollbar.scss +0 -0
  691. /package/lib/{webchat → cjs/webchat}/components/typing-indicator.scss +0 -0
  692. /package/lib/{webchat.template.html → cjs/webchat.template.html} +0 -0
  693. /package/lib/{webview.template.html → cjs/webview.template.html} +0 -0
@@ -0,0 +1,699 @@
1
+ import { INPUT, isMobile, params2queryString } from '@botonic/core';
2
+ import { motion } from 'framer-motion';
3
+ import merge from 'lodash.merge';
4
+ import React, { forwardRef, useEffect, useImperativeHandle, useRef, useState, } from 'react';
5
+ import Textarea from 'react-textarea-autosize';
6
+ import styled, { StyleSheetManager } from 'styled-components';
7
+ import { useAsyncEffect } from 'use-async-effect';
8
+ import { v4 as uuidv4 } from 'uuid';
9
+ import { Audio, Document, Image, Text, Video } from '../components';
10
+ import { Handoff } from '../components/handoff';
11
+ import { normalizeWebchatSettings } from '../components/webchat-settings';
12
+ import { COLORS, MAX_ALLOWED_SIZE_MB, ROLES, SENDERS, WEBCHAT, } from '../constants';
13
+ import { RequestContext, WebchatContext } from '../contexts';
14
+ import { getFullMimeWhitelist, getMediaType, isAllowedSize, isAudio, isDocument, isImage, isMedia, isText, isVideo, readDataURL, } from '../message-utils';
15
+ import { msgToBotonic } from '../msg-to-botonic';
16
+ import { scrollToBottom } from '../util/dom';
17
+ import { isDev, resolveImage } from '../util/environment';
18
+ import { deserializeRegex, stringifyWithRegexs } from '../util/regexs';
19
+ import { _getThemeProperty, getServerErrorMessage, initSession, shouldKeepSessionOnReload, } from '../util/webchat';
20
+ import { Attachment } from './components/attachment';
21
+ import { EmojiPicker, OpenedEmojiPicker } from './components/emoji-picker';
22
+ import { OpenedPersistentMenu, PersistentMenu, } from './components/persistent-menu';
23
+ import { SendButton } from './components/send-button';
24
+ import { TypingIndicator } from './components/typing-indicator';
25
+ import { DeviceAdapter } from './devices/device-adapter';
26
+ import { StyledWebchatHeader } from './header';
27
+ import { useComponentWillMount, usePrevious, useTyping, useWebchat, } from './hooks';
28
+ import { WebchatMessageList } from './message-list';
29
+ import { WebchatReplies } from './replies';
30
+ import { useStorageState } from './use-storage-state-hook';
31
+ import { WebviewContainer } from './webview';
32
+ export const getParsedAction = botonicAction => {
33
+ const splittedAction = botonicAction.split('create_case:');
34
+ if (splittedAction.length <= 1)
35
+ return undefined;
36
+ return JSON.parse(splittedAction[1]);
37
+ };
38
+ const StyledWebchat = styled.div `
39
+ position: fixed;
40
+ right: 20px;
41
+ bottom: 20px;
42
+ width: ${props => props.width}px;
43
+ height: ${props => props.height}px;
44
+ margin: auto;
45
+ background-color: ${COLORS.SOLID_WHITE};
46
+ border-radius: 10px;
47
+ box-shadow: ${COLORS.SOLID_BLACK_ALPHA_0_2} 0px 0px 12px;
48
+ display: flex;
49
+ flex-direction: column;
50
+ `;
51
+ const StyledTriggerButton = styled.div `
52
+ cursor: pointer;
53
+ position: fixed;
54
+ background: ${COLORS.SOLID_WHITE};
55
+ border-radius: 50%;
56
+ display: flex;
57
+ align-items: center;
58
+ justify-content: center;
59
+ overflow: hidden;
60
+ width: 65px;
61
+ height: 65px;
62
+ bottom: 20px;
63
+ right: 10px;
64
+ padding: 8px;
65
+ `;
66
+ const UserInputContainer = styled.div `
67
+ min-height: 52px;
68
+ position: relative;
69
+ display: flex;
70
+ align-items: center;
71
+ justify-content: flex-start;
72
+ gap: 16px;
73
+ padding: 0px 16px;
74
+ z-index: 1;
75
+ border-top: 1px solid ${COLORS.SOLID_BLACK_ALPHA_0_5};
76
+ `;
77
+ const TextAreaContainer = styled.div `
78
+ display: flex;
79
+ flex: 1 1 auto;
80
+ align-items: center;
81
+ `;
82
+ const TriggerImage = styled.img `
83
+ max-width: 100%;
84
+ max-height: 100%;
85
+ `;
86
+ const ErrorMessageContainer = styled.div `
87
+ position: relative;
88
+ display: flex;
89
+ z-index: 1;
90
+ justify-content: center;
91
+ width: 100%;
92
+ `;
93
+ const ErrorMessage = styled.div `
94
+ position: absolute;
95
+ top: 10px;
96
+ font-size: 14px;
97
+ line-height: 20px;
98
+ padding: 4px 11px;
99
+ display: flex;
100
+ background-color: ${COLORS.ERROR_RED};
101
+ color: ${COLORS.CONCRETE_WHITE};
102
+ border-radius: 5px;
103
+ align-items: center;
104
+ justify-content: center;
105
+ font-family: ${WEBCHAT.DEFAULTS.FONT_FAMILY};
106
+ `;
107
+ const DarkBackgroundMenu = styled.div `
108
+ background: ${COLORS.SOLID_BLACK};
109
+ opacity: 0.3;
110
+ z-index: 1;
111
+ right: 0;
112
+ bottom: 0;
113
+ border-radius: 10px;
114
+ position: absolute;
115
+ width: 100%;
116
+ height: 100%;
117
+ `;
118
+ // eslint-disable-next-line complexity
119
+ export const Webchat = forwardRef((props, ref) => {
120
+ const { webchatState, addMessage, addMessageComponent, updateMessage, updateReplies, updateLatestInput, updateTyping, updateWebview, updateSession, updateLastRoutePath, updateHandoff, updateTheme, updateDevSettings, toggleWebchat, toggleEmojiPicker, togglePersistentMenu, toggleCoverComponent, doRenderCustomComponent, setError, setOnline, clearMessages, openWebviewT, closeWebviewT, updateLastMessageDate, setCurrentAttachment,
121
+ // eslint-disable-next-line react-hooks/rules-of-hooks
122
+ } = props.webchatHooks || useWebchat();
123
+ const firstUpdate = useRef(true);
124
+ const isOnline = () => webchatState.online;
125
+ const currentDateString = () => new Date().toISOString();
126
+ const theme = merge(webchatState.theme, props.theme);
127
+ const { initialSession, initialDevSettings, onStateChange } = props;
128
+ const getThemeProperty = _getThemeProperty(theme);
129
+ const [customComponent, setCustomComponent] = useState(null);
130
+ const storage = props.storage;
131
+ const storageKey = typeof props.storageKey === 'function'
132
+ ? props.storageKey()
133
+ : props.storageKey;
134
+ const [botonicState, saveState] = useStorageState(storage, storageKey);
135
+ const host = props.host || document.body;
136
+ const deviceAdapter = new DeviceAdapter();
137
+ const saveWebchatState = webchatState => {
138
+ storage &&
139
+ saveState(JSON.parse(stringifyWithRegexs({
140
+ messages: webchatState.messagesJSON,
141
+ session: webchatState.session,
142
+ lastRoutePath: webchatState.lastRoutePath,
143
+ devSettings: webchatState.devSettings,
144
+ lastMessageUpdate: webchatState.lastMessageUpdate,
145
+ themeUpdates: webchatState.themeUpdates,
146
+ })));
147
+ };
148
+ const handleAttachment = event => {
149
+ if (!isAllowedSize(event.target.files[0].size)) {
150
+ throw new Error(`The file is too large. A maximum of ${MAX_ALLOWED_SIZE_MB}MB is allowed.`);
151
+ }
152
+ setCurrentAttachment({
153
+ fileName: event.target.files[0].name,
154
+ file: event.target.files[0],
155
+ attachmentType: getMediaType(event.target.files[0].type),
156
+ });
157
+ };
158
+ useEffect(() => {
159
+ if (webchatState.currentAttachment)
160
+ sendAttachment(webchatState.currentAttachment);
161
+ }, [webchatState.currentAttachment]);
162
+ const sendUserInput = async (input) => {
163
+ props.onUserInput &&
164
+ props.onUserInput({
165
+ user: webchatState.session.user,
166
+ input: input,
167
+ session: webchatState.session,
168
+ lastRoutePath: webchatState.lastRoutePath,
169
+ });
170
+ };
171
+ const sendChatEvent = async (chatEvent) => {
172
+ const chatEventInput = {
173
+ id: uuidv4(),
174
+ type: INPUT.CHAT_EVENT,
175
+ data: chatEvent,
176
+ };
177
+ props.onUserInput &&
178
+ props.onUserInput({
179
+ user: webchatState.session.user,
180
+ input: chatEventInput,
181
+ session: webchatState.session,
182
+ lastRoutePath: webchatState.lastRoutePath,
183
+ });
184
+ };
185
+ // Load styles stored in window._botonicInsertStyles by Webpack
186
+ useComponentWillMount(() => {
187
+ if (window._botonicInsertStyles && window._botonicInsertStyles.length) {
188
+ for (const botonicStyle of window._botonicInsertStyles) {
189
+ // Injecting styles at head is needed even if we use shadowDOM
190
+ // as some dependencies like simplebar rely on creating ephemeral elements
191
+ // on document.body and assume styles will be available globally
192
+ document.head.appendChild(botonicStyle);
193
+ // injecting styles in host node too so that shadowDOM works
194
+ if (props.shadowDOM)
195
+ host.appendChild(botonicStyle.cloneNode(true));
196
+ }
197
+ delete window._botonicInsertStyles;
198
+ }
199
+ if (props.shadowDOM) {
200
+ // emoji-picker-react injects styles in head, so we need to
201
+ // re-inject them in our host node to make it work with shadowDOM
202
+ for (const style of document.querySelectorAll('style')) {
203
+ if (style.textContent &&
204
+ style.textContent.includes('emoji-picker-react'))
205
+ host.appendChild(style.cloneNode(true));
206
+ }
207
+ }
208
+ });
209
+ // Load initial state from storage
210
+ useEffect(() => {
211
+ let { messages, session, lastRoutePath, devSettings, lastMessageUpdate, themeUpdates, } = botonicState || {};
212
+ session = initSession(session);
213
+ updateSession(session);
214
+ if (shouldKeepSessionOnReload({ initialDevSettings, devSettings })) {
215
+ if (messages) {
216
+ messages.forEach(m => {
217
+ addMessage(m);
218
+ const newComponent = msgToBotonic(Object.assign(Object.assign({}, m), { delay: 0, typing: 0 }), (props.theme.message && props.theme.message.customTypes) ||
219
+ props.theme.customMessageTypes);
220
+ if (newComponent)
221
+ addMessageComponent(newComponent);
222
+ });
223
+ }
224
+ if (initialSession)
225
+ updateSession(merge(initialSession, session));
226
+ if (lastRoutePath)
227
+ updateLastRoutePath(lastRoutePath);
228
+ }
229
+ else
230
+ updateSession(merge(initialSession, session));
231
+ if (devSettings)
232
+ updateDevSettings(devSettings);
233
+ else if (initialDevSettings)
234
+ updateDevSettings(initialDevSettings);
235
+ if (lastMessageUpdate)
236
+ updateLastMessageDate(lastMessageUpdate);
237
+ if (themeUpdates !== undefined)
238
+ updateTheme(merge(props.theme, themeUpdates), themeUpdates);
239
+ if (props.onInit)
240
+ setTimeout(() => props.onInit(), 100);
241
+ }, []);
242
+ useEffect(() => {
243
+ if (!webchatState.isWebchatOpen)
244
+ return;
245
+ deviceAdapter.init(host);
246
+ scrollToBottom({ behavior: 'auto', host });
247
+ }, [webchatState.isWebchatOpen]);
248
+ useEffect(() => {
249
+ if (onStateChange && typeof onStateChange === 'function')
250
+ onStateChange(webchatState);
251
+ saveWebchatState(webchatState);
252
+ }, [
253
+ webchatState.messagesJSON,
254
+ webchatState.session,
255
+ webchatState.lastRoutePath,
256
+ webchatState.devSettings,
257
+ webchatState.lastMessageUpdate,
258
+ ]);
259
+ useAsyncEffect(async () => {
260
+ if (!webchatState.online) {
261
+ setError({
262
+ message: getServerErrorMessage(props.server),
263
+ });
264
+ }
265
+ else {
266
+ if (!firstUpdate.current) {
267
+ setError(undefined);
268
+ }
269
+ }
270
+ }, [webchatState.online]);
271
+ useTyping({ webchatState, updateTyping, updateMessage, host });
272
+ useEffect(() => {
273
+ updateTheme(merge(props.theme, theme, webchatState.themeUpdates));
274
+ }, [props.theme, webchatState.themeUpdates]);
275
+ const openWebview = (webviewComponent, params) => updateWebview(webviewComponent, params);
276
+ const handleSelectedEmoji = (event, emojiObject) => {
277
+ textArea.current.value += emojiObject.emoji;
278
+ textArea.current.focus();
279
+ };
280
+ const closeWebview = options => {
281
+ updateWebview();
282
+ if (userInputEnabled) {
283
+ textArea.current.focus();
284
+ }
285
+ if (options && options.payload) {
286
+ sendPayload(options.payload);
287
+ }
288
+ else if (options && options.path) {
289
+ let params = '';
290
+ if (options.params)
291
+ params = params2queryString(options.params);
292
+ sendPayload(`__PATH_PAYLOAD__${options.path}?${params}`);
293
+ }
294
+ };
295
+ const handleMenu = () => {
296
+ togglePersistentMenu(!webchatState.isPersistentMenuOpen);
297
+ };
298
+ const handleEmojiClick = () => {
299
+ toggleEmojiPicker(!webchatState.isEmojiPickerOpen);
300
+ };
301
+ const persistentMenuOptions = getThemeProperty(WEBCHAT.CUSTOM_PROPERTIES.persistentMenu, props.persistentMenu);
302
+ const darkBackgroundMenu = getThemeProperty(WEBCHAT.CUSTOM_PROPERTIES.darkBackgroundMenu, false);
303
+ const getBlockInputs = (rule, inputData) => {
304
+ const processedInput = rule.preprocess
305
+ ? rule.preprocess(inputData)
306
+ : inputData;
307
+ return rule.match.some(regex => {
308
+ if (typeof regex === 'string')
309
+ regex = deserializeRegex(regex);
310
+ return regex.test(processedInput);
311
+ });
312
+ };
313
+ const checkBlockInput = input => {
314
+ // if is a text we check if it is a serialized RE
315
+ const blockInputs = getThemeProperty(WEBCHAT.CUSTOM_PROPERTIES.blockInputs, props.blockInputs);
316
+ if (!Array.isArray(blockInputs))
317
+ return false;
318
+ for (const rule of blockInputs) {
319
+ if (getBlockInputs(rule, input.data)) {
320
+ addMessageComponent(<Text id={input.id} from={SENDERS.user} blob={false} style={{
321
+ backgroundColor: COLORS.SCORPION_GRAY,
322
+ borderColor: COLORS.SCORPION_GRAY,
323
+ padding: '8px 12px',
324
+ }}>
325
+ {rule.message}
326
+ </Text>);
327
+ updateReplies(false);
328
+ return true;
329
+ }
330
+ }
331
+ return false;
332
+ };
333
+ const closeMenu = () => {
334
+ togglePersistentMenu(false);
335
+ };
336
+ const persistentMenu = () => {
337
+ return (<OpenedPersistentMenu onClick={closeMenu} options={persistentMenuOptions} borderRadius={webchatState.theme.style.borderRadius || '10px'}/>);
338
+ };
339
+ const getCoverComponent = () => {
340
+ return getThemeProperty(WEBCHAT.CUSTOM_PROPERTIES.coverComponent, props.coverComponent &&
341
+ (props.coverComponent.component || props.coverComponent));
342
+ };
343
+ const CoverComponent = getCoverComponent();
344
+ const closeCoverComponent = () => {
345
+ toggleCoverComponent(false);
346
+ };
347
+ useEffect(() => {
348
+ if (!CoverComponent)
349
+ return;
350
+ if (!botonicState ||
351
+ (botonicState.messages && botonicState.messages.length == 0))
352
+ toggleCoverComponent(true);
353
+ }, []);
354
+ const coverComponent = () => {
355
+ const coverComponentProps = getThemeProperty(WEBCHAT.CUSTOM_PROPERTIES.coverComponentProps, props.coverComponent && props.coverComponent.props);
356
+ if (CoverComponent && webchatState.isCoverComponentOpen)
357
+ return (<CoverComponent closeComponent={closeCoverComponent} {...coverComponentProps}/>);
358
+ return null;
359
+ };
360
+ const messageComponentFromInput = input => {
361
+ let messageComponent = null;
362
+ if (isText(input)) {
363
+ messageComponent = (<Text id={input.id} payload={input.payload} from={SENDERS.user}>
364
+ {input.data}
365
+ </Text>);
366
+ }
367
+ else if (isMedia(input)) {
368
+ const temporaryDisplayUrl = URL.createObjectURL(input.data);
369
+ const mediaProps = {
370
+ id: input.id,
371
+ from: SENDERS.user,
372
+ src: temporaryDisplayUrl,
373
+ };
374
+ if (isImage(input))
375
+ messageComponent = <Image {...mediaProps}/>;
376
+ else if (isAudio(input))
377
+ messageComponent = <Audio {...mediaProps}/>;
378
+ else if (isVideo(input))
379
+ messageComponent = <Video {...mediaProps}/>;
380
+ else if (isDocument(input))
381
+ messageComponent = <Document {...mediaProps}/>;
382
+ }
383
+ return messageComponent;
384
+ };
385
+ const sendInput = async (input) => {
386
+ if (!input || Object.keys(input).length == 0)
387
+ return;
388
+ if (isText(input) && (!input.data || !input.data.trim()))
389
+ return; // in case trim() doesn't work in a browser we can use !/\S/.test(input.data)
390
+ if (isText(input) && checkBlockInput(input))
391
+ return;
392
+ if (!input.id)
393
+ input.id = uuidv4();
394
+ const messageComponent = messageComponentFromInput(input);
395
+ if (messageComponent)
396
+ addMessageComponent(messageComponent);
397
+ if (isMedia(input))
398
+ input.data = await readDataURL(input.data);
399
+ sendUserInput(input);
400
+ updateLatestInput(input);
401
+ isOnline() && updateLastMessageDate(currentDateString());
402
+ updateReplies(false);
403
+ togglePersistentMenu(false);
404
+ toggleEmojiPicker(false);
405
+ };
406
+ /* This is the public API this component exposes to its parents
407
+ https://stackoverflow.com/questions/37949981/call-child-method-from-parent
408
+ */
409
+ const updateSessionWithUser = userToUpdate => updateSession(merge(webchatState.session, { user: userToUpdate }));
410
+ useImperativeHandle(ref, () => ({
411
+ addBotResponse: ({ response, session, lastRoutePath }) => {
412
+ updateTyping(false);
413
+ if (Array.isArray(response))
414
+ response.map(r => addMessageComponent(r));
415
+ else if (response)
416
+ addMessageComponent(response);
417
+ if (session) {
418
+ updateSession(merge(session, { user: webchatState.session.user }));
419
+ const action = session._botonic_action || '';
420
+ const handoff = action.startsWith('create_case');
421
+ if (handoff && isDev)
422
+ addMessageComponent(<Handoff />);
423
+ updateHandoff(handoff);
424
+ }
425
+ if (lastRoutePath)
426
+ updateLastRoutePath(lastRoutePath);
427
+ updateLastMessageDate(currentDateString());
428
+ },
429
+ setTyping: typing => updateTyping(typing),
430
+ addUserMessage: message => sendInput(message),
431
+ updateUser: updateSessionWithUser,
432
+ openWebchat: () => toggleWebchat(true),
433
+ closeWebchat: () => toggleWebchat(false),
434
+ toggleWebchat: () => toggleWebchat(!webchatState.isWebchatOpen),
435
+ openCoverComponent: () => toggleCoverComponent(true),
436
+ closeCoverComponent: () => toggleCoverComponent(false),
437
+ renderCustomComponent: _customComponent => {
438
+ setCustomComponent(_customComponent);
439
+ doRenderCustomComponent(true);
440
+ },
441
+ unmountCustomComponent: () => doRenderCustomComponent(false),
442
+ toggleCoverComponent: () => toggleCoverComponent(!webchatState.isCoverComponentOpen),
443
+ openWebviewApi: component => openWebviewT(component),
444
+ setError,
445
+ setOnline,
446
+ getMessages: () => webchatState.messagesJSON,
447
+ isOnline,
448
+ clearMessages: () => {
449
+ clearMessages();
450
+ updateReplies(false);
451
+ },
452
+ getLastMessageUpdate: () => webchatState.lastMessageUpdate,
453
+ updateMessageInfo: (msgId, messageInfo) => {
454
+ const messageToUpdate = webchatState.messagesJSON.filter(m => m.id == msgId)[0];
455
+ const updatedMsg = merge(messageToUpdate, messageInfo);
456
+ if (updatedMsg.ack === 1)
457
+ delete updatedMsg.unsentInput;
458
+ updateMessage(updatedMsg);
459
+ },
460
+ updateWebchatSettings: settings => {
461
+ const themeUpdates = normalizeWebchatSettings(settings);
462
+ updateTheme(merge(webchatState.theme, themeUpdates), themeUpdates);
463
+ },
464
+ }));
465
+ const resolveCase = () => {
466
+ updateHandoff(false);
467
+ updateSession(Object.assign(Object.assign({}, webchatState.session), { _botonic_action: null }));
468
+ };
469
+ const prevSession = usePrevious(webchatState.session);
470
+ useEffect(() => {
471
+ // Resume conversation after handoff
472
+ if (prevSession &&
473
+ prevSession._botonic_action &&
474
+ !webchatState.session._botonic_action) {
475
+ const action = getParsedAction(prevSession._botonic_action);
476
+ if (action && action.on_finish)
477
+ sendPayload(action.on_finish);
478
+ }
479
+ }, [webchatState.session._botonic_action]);
480
+ const sendText = async (text, payload) => {
481
+ if (!text)
482
+ return;
483
+ const input = { type: INPUT.TEXT, data: text, payload };
484
+ await sendInput(input);
485
+ };
486
+ const sendPayload = async (payload) => {
487
+ if (!payload)
488
+ return;
489
+ const input = { type: INPUT.POSTBACK, payload };
490
+ await sendInput(input);
491
+ };
492
+ const sendAttachment = async (attachment) => {
493
+ if (attachment.file) {
494
+ const attachmentType = getMediaType(attachment.file.type);
495
+ if (!attachmentType)
496
+ return;
497
+ const input = {
498
+ type: attachmentType,
499
+ data: attachment.file,
500
+ };
501
+ await sendInput(input);
502
+ setCurrentAttachment(undefined);
503
+ }
504
+ };
505
+ const sendTextAreaText = () => {
506
+ sendText(textArea.current.value);
507
+ textArea.current.value = '';
508
+ };
509
+ let isTyping = false;
510
+ let typingTimeout = null;
511
+ function clearTimeoutWithReset(reset) {
512
+ const waitTime = 20 * 1000;
513
+ if (typingTimeout)
514
+ clearTimeout(typingTimeout);
515
+ if (reset)
516
+ typingTimeout = setTimeout(stopTyping, waitTime);
517
+ }
518
+ function startTyping() {
519
+ isTyping = true;
520
+ sendChatEvent('typing_on');
521
+ }
522
+ function stopTyping() {
523
+ clearTimeoutWithReset(false);
524
+ isTyping = false;
525
+ sendChatEvent('typing_off');
526
+ }
527
+ const onKeyDown = event => {
528
+ if (event.keyCode === 13 && event.shiftKey === false) {
529
+ event.preventDefault();
530
+ sendTextAreaText();
531
+ stopTyping();
532
+ }
533
+ };
534
+ const onKeyUp = () => {
535
+ if (textArea.current.value === '') {
536
+ stopTyping();
537
+ return;
538
+ }
539
+ if (!isTyping) {
540
+ startTyping();
541
+ }
542
+ clearTimeoutWithReset(true);
543
+ };
544
+ const webviewRequestContext = {
545
+ getString: stringId => props.getString(stringId, webchatState.session),
546
+ setLocale: locale => props.getString(locale, webchatState.session),
547
+ session: webchatState.session || {},
548
+ params: webchatState.webviewParams || {},
549
+ closeWebview: closeWebview,
550
+ defaultDelay: props.defaultDelay || 0,
551
+ defaultTyping: props.defaultTyping || 0,
552
+ };
553
+ useEffect(() => {
554
+ if (firstUpdate.current) {
555
+ firstUpdate.current = false;
556
+ return;
557
+ }
558
+ if (webchatState.isWebchatOpen && props.onOpen)
559
+ props.onOpen();
560
+ if (!webchatState.isWebchatOpen && props.onClose && !firstUpdate.current) {
561
+ props.onClose();
562
+ toggleEmojiPicker(false);
563
+ togglePersistentMenu(false);
564
+ }
565
+ }, [webchatState.isWebchatOpen]);
566
+ const textArea = useRef();
567
+ const getTriggerImage = () => {
568
+ const triggerImage = getThemeProperty(WEBCHAT.CUSTOM_PROPERTIES.triggerButtonImage, null);
569
+ if (triggerImage === null) {
570
+ webchatState.theme.triggerButtonImage = WEBCHAT.DEFAULTS.LOGO;
571
+ return null;
572
+ }
573
+ return triggerImage;
574
+ };
575
+ const triggerButtonStyle = getThemeProperty(WEBCHAT.CUSTOM_PROPERTIES.triggerButtonStyle);
576
+ const CustomTriggerButton = getThemeProperty(WEBCHAT.CUSTOM_PROPERTIES.customTrigger, undefined);
577
+ const triggerButton = () => {
578
+ if (CustomTriggerButton) {
579
+ return <CustomTriggerButton />;
580
+ }
581
+ return (<StyledTriggerButton role={ROLES.TRIGGER_BUTTON} style={Object.assign({}, triggerButtonStyle)}>
582
+ {getTriggerImage() && (<TriggerImage src={resolveImage(getTriggerImage())}/>)}
583
+ </StyledTriggerButton>);
584
+ };
585
+ const webchatMessageList = () => (<WebchatMessageList style={{ flex: 1 }}>
586
+ {webchatState.typing && <TypingIndicator />}
587
+ </WebchatMessageList>);
588
+ const webchatReplies = () => <WebchatReplies replies={webchatState.replies}/>;
589
+ const isUserInputEnabled = () => {
590
+ const isUserInputEnabled = getThemeProperty(WEBCHAT.CUSTOM_PROPERTIES.enableUserInput, props.enableUserInput !== undefined ? props.enableUserInput : true);
591
+ return isUserInputEnabled && !webchatState.isCoverComponentOpen;
592
+ };
593
+ const userInputEnabled = isUserInputEnabled();
594
+ const userInputArea = () => {
595
+ return (userInputEnabled && (<UserInputContainer style={Object.assign({}, getThemeProperty(WEBCHAT.CUSTOM_PROPERTIES.userInputStyle))} className='user-input-container'>
596
+ {webchatState.isEmojiPickerOpen && (<OpenedEmojiPicker height={webchatState.theme.style.height} onEmojiClick={handleSelectedEmoji} onClick={handleEmojiClick}/>)}
597
+
598
+ <PersistentMenu onClick={handleMenu} persistentMenu={props.persistentMenu}/>
599
+
600
+ <TextAreaContainer>
601
+ <Textarea name='text' onFocus={() => deviceAdapter.onFocus(host)} onBlur={() => deviceAdapter.onBlur()} maxRows={4} wrap='soft' maxLength='1000' placeholder={getThemeProperty(WEBCHAT.CUSTOM_PROPERTIES.textPlaceholder, WEBCHAT.DEFAULTS.PLACEHOLDER)} autoFocus={true} inputRef={textArea} onKeyDown={e => onKeyDown(e)} onKeyUp={onKeyUp} style={Object.assign({ display: 'flex', fontSize: deviceAdapter.fontSize(14), width: '100%', border: 'none', resize: 'none', overflow: 'auto', outline: 'none', flex: '1 1 auto', padding: 10, paddingLeft: persistentMenuOptions ? 0 : 10, fontFamily: 'inherit' }, getThemeProperty(WEBCHAT.CUSTOM_PROPERTIES.userInputBoxStyle))}/>
602
+ </TextAreaContainer>
603
+
604
+ <EmojiPicker enableEmojiPicker={props.enableEmojiPicker} onClick={handleEmojiClick}/>
605
+
606
+ <Attachment enableAttachments={props.enableAttachments} onChange={handleAttachment} accept={getFullMimeWhitelist().join(',')}/>
607
+
608
+ <SendButton onClick={sendTextAreaText}/>
609
+ </UserInputContainer>));
610
+ };
611
+ const webchatWebview = () => (<RequestContext.Provider value={webviewRequestContext}>
612
+ <WebviewContainer style={Object.assign(Object.assign({}, getThemeProperty(WEBCHAT.CUSTOM_PROPERTIES.webviewStyle)), mobileStyle)} webview={webchatState.webview}/>
613
+ </RequestContext.Provider>);
614
+ let mobileStyle = {};
615
+ if (isMobile(getThemeProperty(WEBCHAT.CUSTOM_PROPERTIES.mobileBreakpoint))) {
616
+ mobileStyle = getThemeProperty(WEBCHAT.CUSTOM_PROPERTIES.mobileStyle) || {
617
+ width: '100%',
618
+ height: '100%',
619
+ right: 0,
620
+ bottom: 0,
621
+ borderRadius: 0,
622
+ };
623
+ }
624
+ useEffect(() => {
625
+ // Prod mode
626
+ saveWebchatState(webchatState);
627
+ scrollToBottom({ host });
628
+ }, [webchatState.themeUpdates]);
629
+ // Only needed for dev/serve mode
630
+ const updateWebchatDevSettings = settings => {
631
+ // eslint-disable-next-line react-hooks/rules-of-hooks
632
+ useEffect(() => {
633
+ const themeUpdates = normalizeWebchatSettings(settings);
634
+ updateTheme(merge(webchatState.theme, themeUpdates), themeUpdates);
635
+ }, [webchatState.messagesJSON]);
636
+ };
637
+ const DarkenBackground = ({ component }) => {
638
+ return (<div>
639
+ {darkBackgroundMenu && (<DarkBackgroundMenu style={{
640
+ borderRadius: webchatState.theme.style.borderRadius,
641
+ }}/>)}
642
+ {component}
643
+ </div>);
644
+ };
645
+ const _renderCustomComponent = () => {
646
+ if (!customComponent)
647
+ return <></>;
648
+ else
649
+ return customComponent;
650
+ };
651
+ const WebchatComponent = (<WebchatContext.Provider value={{
652
+ sendText,
653
+ sendAttachment,
654
+ sendPayload,
655
+ sendInput,
656
+ openWebview,
657
+ resolveCase,
658
+ webchatState,
659
+ getThemeProperty,
660
+ addMessage,
661
+ toggleWebchat,
662
+ updateMessage,
663
+ updateReplies,
664
+ updateLatestInput,
665
+ updateUser: updateSessionWithUser,
666
+ updateWebchatDevSettings: updateWebchatDevSettings,
667
+ }}>
668
+ {!webchatState.isWebchatOpen && (<div onClick={event => {
669
+ toggleWebchat(true);
670
+ event.preventDefault();
671
+ }}>
672
+ {triggerButton()}
673
+ </div>)}
674
+
675
+ {webchatState.isWebchatOpen && (<StyledWebchat
676
+ // TODO: Distinguis between multiple instances of webchat, e.g. `${uniqueId}-botonic-webchat`
677
+ role={ROLES.WEBCHAT} id={WEBCHAT.DEFAULTS.ID} width={webchatState.width} height={webchatState.height} style={Object.assign(Object.assign({}, webchatState.theme.style), mobileStyle)}>
678
+ <StyledWebchatHeader onCloseClick={() => {
679
+ toggleWebchat(false);
680
+ }}/>
681
+ {webchatState.error.message && (<ErrorMessageContainer>
682
+ <ErrorMessage>{webchatState.error.message}</ErrorMessage>
683
+ </ErrorMessageContainer>)}
684
+ {webchatMessageList()}
685
+ {webchatState.replies &&
686
+ Object.keys(webchatState.replies).length > 0 &&
687
+ webchatReplies()}
688
+ {webchatState.isPersistentMenuOpen && (<DarkenBackground component={persistentMenu()}/>)}
689
+ {!webchatState.handoff && userInputArea()}
690
+ {webchatState.webview && webchatWebview()}
691
+ {webchatState.isCoverComponentOpen && coverComponent()}
692
+ {webchatState.isCustomComponentRendered &&
693
+ customComponent &&
694
+ _renderCustomComponent()}
695
+ </StyledWebchat>)}
696
+ </WebchatContext.Provider>);
697
+ return props.shadowDOM ? (<StyleSheetManager target={host}>{WebchatComponent}</StyleSheetManager>) : (WebchatComponent);
698
+ });
699
+ //# sourceMappingURL=webchat.js.map