@botonic/react 0.31.0-alpha.4 → 0.31.0-alpha.5

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 (399) hide show
  1. package/lib/cjs/components/audio.d.ts +8 -7
  2. package/lib/cjs/components/audio.js +7 -4
  3. package/lib/cjs/components/audio.js.map +1 -1
  4. package/lib/cjs/components/button.js +3 -4
  5. package/lib/cjs/components/button.js.map +1 -1
  6. package/lib/cjs/components/carousel.js +2 -2
  7. package/lib/cjs/components/carousel.js.map +1 -1
  8. package/lib/cjs/components/custom-message.d.ts +16 -12
  9. package/lib/cjs/components/custom-message.js +3 -9
  10. package/lib/cjs/components/custom-message.js.map +1 -1
  11. package/lib/cjs/components/document.d.ts +8 -7
  12. package/lib/cjs/components/document.js +5 -5
  13. package/lib/cjs/components/document.js.map +1 -1
  14. package/lib/cjs/components/handoff.js +2 -2
  15. package/lib/cjs/components/handoff.js.map +1 -1
  16. package/lib/cjs/components/image.d.ts +8 -7
  17. package/lib/cjs/components/image.js +5 -5
  18. package/lib/cjs/components/image.js.map +1 -1
  19. package/lib/cjs/components/index-types.d.ts +33 -4
  20. package/lib/cjs/components/message/index.js +2 -1
  21. package/lib/cjs/components/message/index.js.map +1 -1
  22. package/lib/cjs/components/message/message-feedback.js +2 -2
  23. package/lib/cjs/components/message/message-feedback.js.map +1 -1
  24. package/lib/cjs/components/message/message-footer.js +2 -2
  25. package/lib/cjs/components/message/message-footer.js.map +1 -1
  26. package/lib/cjs/components/message/message-image.js +2 -2
  27. package/lib/cjs/components/message/message-image.js.map +1 -1
  28. package/lib/cjs/components/message/timestamps.js +2 -2
  29. package/lib/cjs/components/message/timestamps.js.map +1 -1
  30. package/lib/cjs/components/reply.d.ts +7 -6
  31. package/lib/cjs/components/reply.js +10 -6
  32. package/lib/cjs/components/reply.js.map +1 -1
  33. package/lib/cjs/components/video.d.ts +8 -7
  34. package/lib/cjs/components/video.js +2 -3
  35. package/lib/cjs/components/video.js.map +1 -1
  36. package/lib/cjs/components/webchat-settings.d.ts +1 -1
  37. package/lib/cjs/components/webchat-settings.js +2 -2
  38. package/lib/cjs/components/webchat-settings.js.map +1 -1
  39. package/lib/cjs/contexts.d.ts +3 -4
  40. package/lib/cjs/contexts.js +2 -79
  41. package/lib/cjs/contexts.js.map +1 -1
  42. package/lib/cjs/index-types.d.ts +87 -55
  43. package/lib/cjs/index-types.js.map +1 -1
  44. package/lib/cjs/index.d.ts +2 -2
  45. package/lib/cjs/index.js +1 -2
  46. package/lib/cjs/index.js.map +1 -1
  47. package/lib/cjs/msg-to-botonic.d.ts +1 -1
  48. package/lib/cjs/msg-to-botonic.js +5 -8
  49. package/lib/cjs/msg-to-botonic.js.map +1 -1
  50. package/lib/cjs/util/webchat.d.ts +17 -6
  51. package/lib/cjs/util/webchat.js +9 -7
  52. package/lib/cjs/util/webchat.js.map +1 -1
  53. package/lib/cjs/webchat/chat-area/index.js +3 -3
  54. package/lib/cjs/webchat/chat-area/index.js.map +1 -1
  55. package/lib/cjs/webchat/components/conditional-animation.js +2 -2
  56. package/lib/cjs/webchat/components/conditional-animation.js.map +1 -1
  57. package/lib/cjs/webchat/components/opened-persistent-menu.js +2 -2
  58. package/lib/cjs/webchat/components/opened-persistent-menu.js.map +1 -1
  59. package/lib/cjs/webchat/{actions.d.ts → context/actions.d.ts} +2 -0
  60. package/lib/cjs/webchat/{actions.js → context/actions.js} +3 -0
  61. package/lib/cjs/webchat/context/actions.js.map +1 -0
  62. package/lib/cjs/webchat/context/index.d.ts +5 -0
  63. package/lib/cjs/webchat/context/index.js +83 -0
  64. package/lib/cjs/webchat/context/index.js.map +1 -0
  65. package/lib/cjs/webchat/{messages-reducer.d.ts → context/messages-reducer.d.ts} +1 -1
  66. package/lib/cjs/webchat/{messages-reducer.js → context/messages-reducer.js} +3 -1
  67. package/lib/cjs/webchat/context/messages-reducer.js.map +1 -0
  68. package/lib/cjs/webchat/context/types.d.ts +74 -0
  69. package/lib/cjs/webchat/context/types.js +3 -0
  70. package/lib/cjs/webchat/context/types.js.map +1 -0
  71. package/lib/cjs/webchat/{hooks → context}/use-webchat.d.ts +18 -19
  72. package/lib/cjs/webchat/{hooks → context}/use-webchat.js +10 -5
  73. package/lib/cjs/webchat/context/use-webchat.js.map +1 -0
  74. package/lib/cjs/webchat/{webchat-reducer.d.ts → context/webchat-reducer.d.ts} +1 -1
  75. package/lib/cjs/webchat/{webchat-reducer.js → context/webchat-reducer.js} +2 -0
  76. package/lib/cjs/webchat/context/webchat-reducer.js.map +1 -0
  77. package/lib/cjs/webchat/cover-component/index.js +2 -2
  78. package/lib/cjs/webchat/cover-component/index.js.map +1 -1
  79. package/lib/cjs/webchat/header/default-header.d.ts +1 -0
  80. package/lib/cjs/webchat/header/default-header.js +25 -0
  81. package/lib/cjs/webchat/header/default-header.js.map +1 -0
  82. package/lib/cjs/webchat/header/index.d.ts +2 -0
  83. package/lib/cjs/webchat/header/index.js +23 -0
  84. package/lib/cjs/webchat/header/index.js.map +1 -0
  85. package/lib/cjs/webchat/header/styles.d.ts +7 -0
  86. package/lib/cjs/webchat/header/styles.js +59 -0
  87. package/lib/cjs/webchat/header/styles.js.map +1 -0
  88. package/lib/cjs/webchat/hooks/index.d.ts +0 -1
  89. package/lib/cjs/webchat/hooks/index.js +1 -4
  90. package/lib/cjs/webchat/hooks/index.js.map +1 -1
  91. package/lib/cjs/webchat/hooks/use-previous.d.ts +1 -1
  92. package/lib/cjs/webchat/hooks/use-previous.js.map +1 -1
  93. package/lib/cjs/webchat/hooks/use-scrollbar-controller.js +3 -3
  94. package/lib/cjs/webchat/hooks/use-scrollbar-controller.js.map +1 -1
  95. package/lib/cjs/webchat/hooks/use-typing.d.ts +1 -1
  96. package/lib/cjs/webchat/hooks/use-webchat-dimensions.js +2 -2
  97. package/lib/cjs/webchat/hooks/use-webchat-dimensions.js.map +1 -1
  98. package/lib/cjs/webchat/hooks/use-webchat-resizer.js +2 -2
  99. package/lib/cjs/webchat/hooks/use-webchat-resizer.js.map +1 -1
  100. package/lib/cjs/webchat/index-types.d.ts +3 -44
  101. package/lib/cjs/webchat/index.d.ts +1 -0
  102. package/lib/cjs/webchat/index.js +3 -1
  103. package/lib/cjs/webchat/index.js.map +1 -1
  104. package/lib/cjs/webchat/input-panel/attachment.d.ts +1 -1
  105. package/lib/cjs/webchat/input-panel/attachment.js +2 -2
  106. package/lib/cjs/webchat/input-panel/attachment.js.map +1 -1
  107. package/lib/cjs/webchat/input-panel/emoji-picker.d.ts +1 -1
  108. package/lib/cjs/webchat/input-panel/emoji-picker.js +2 -2
  109. package/lib/cjs/webchat/input-panel/emoji-picker.js.map +1 -1
  110. package/lib/cjs/webchat/input-panel/index.d.ts +3 -3
  111. package/lib/cjs/webchat/input-panel/index.js +8 -3
  112. package/lib/cjs/webchat/input-panel/index.js.map +1 -1
  113. package/lib/cjs/webchat/input-panel/persistent-menu.js +2 -2
  114. package/lib/cjs/webchat/input-panel/persistent-menu.js.map +1 -1
  115. package/lib/cjs/webchat/input-panel/send-button.js +2 -2
  116. package/lib/cjs/webchat/input-panel/send-button.js.map +1 -1
  117. package/lib/cjs/webchat/input-panel/textarea.d.ts +1 -1
  118. package/lib/cjs/webchat/input-panel/textarea.js +4 -2
  119. package/lib/cjs/webchat/input-panel/textarea.js.map +1 -1
  120. package/lib/cjs/webchat/message-list/index.js +5 -7
  121. package/lib/cjs/webchat/message-list/index.js.map +1 -1
  122. package/lib/cjs/webchat/message-list/intro-message.js +2 -2
  123. package/lib/cjs/webchat/message-list/intro-message.js.map +1 -1
  124. package/lib/cjs/webchat/message-list/styles.js +1 -0
  125. package/lib/cjs/webchat/message-list/styles.js.map +1 -1
  126. package/lib/cjs/webchat/message-list/unread-messages-banner.js +2 -2
  127. package/lib/cjs/webchat/message-list/unread-messages-banner.js.map +1 -1
  128. package/lib/cjs/webchat/message-list/use-notifications.js +2 -2
  129. package/lib/cjs/webchat/message-list/use-notifications.js.map +1 -1
  130. package/lib/cjs/webchat/replies/index.d.ts +1 -0
  131. package/lib/cjs/webchat/replies/index.js +32 -0
  132. package/lib/cjs/webchat/replies/index.js.map +1 -0
  133. package/lib/cjs/webchat/replies/styles.d.ts +8 -0
  134. package/lib/cjs/webchat/replies/styles.js +25 -0
  135. package/lib/cjs/webchat/replies/styles.js.map +1 -0
  136. package/lib/cjs/webchat/session-view.js +2 -2
  137. package/lib/cjs/webchat/session-view.js.map +1 -1
  138. package/lib/cjs/webchat/{webchat-typed/styles.d.ts → styles.d.ts} +6 -4
  139. package/lib/cjs/webchat/{webchat-typed/styles.js → styles.js} +1 -1
  140. package/lib/cjs/webchat/styles.js.map +1 -0
  141. package/lib/cjs/webchat/trigger-button/index.js +2 -2
  142. package/lib/cjs/webchat/trigger-button/index.js.map +1 -1
  143. package/lib/cjs/webchat/webchat-dev.js +2 -2
  144. package/lib/cjs/webchat/webchat-dev.js.map +1 -1
  145. package/lib/cjs/webchat/webchat.d.ts +4 -2
  146. package/lib/cjs/webchat/webchat.js +82 -103
  147. package/lib/cjs/webchat/webchat.js.map +1 -1
  148. package/lib/cjs/webchat/webview.js +3 -2
  149. package/lib/cjs/webchat/webview.js.map +1 -1
  150. package/lib/cjs/webchat-app.d.ts +11 -78
  151. package/lib/cjs/webchat-app.js +28 -14
  152. package/lib/cjs/webchat-app.js.map +1 -1
  153. package/lib/esm/components/audio.d.ts +8 -7
  154. package/lib/esm/components/audio.js +7 -4
  155. package/lib/esm/components/audio.js.map +1 -1
  156. package/lib/esm/components/button.js +2 -3
  157. package/lib/esm/components/button.js.map +1 -1
  158. package/lib/esm/components/carousel.js +1 -1
  159. package/lib/esm/components/carousel.js.map +1 -1
  160. package/lib/esm/components/custom-message.d.ts +16 -12
  161. package/lib/esm/components/custom-message.js +3 -9
  162. package/lib/esm/components/custom-message.js.map +1 -1
  163. package/lib/esm/components/document.d.ts +8 -7
  164. package/lib/esm/components/document.js +4 -4
  165. package/lib/esm/components/document.js.map +1 -1
  166. package/lib/esm/components/handoff.js +1 -1
  167. package/lib/esm/components/handoff.js.map +1 -1
  168. package/lib/esm/components/image.d.ts +8 -7
  169. package/lib/esm/components/image.js +4 -4
  170. package/lib/esm/components/image.js.map +1 -1
  171. package/lib/esm/components/index-types.d.ts +33 -4
  172. package/lib/esm/components/message/index.js +2 -1
  173. package/lib/esm/components/message/index.js.map +1 -1
  174. package/lib/esm/components/message/message-feedback.js +1 -1
  175. package/lib/esm/components/message/message-feedback.js.map +1 -1
  176. package/lib/esm/components/message/message-footer.js +1 -1
  177. package/lib/esm/components/message/message-footer.js.map +1 -1
  178. package/lib/esm/components/message/message-image.js +1 -1
  179. package/lib/esm/components/message/message-image.js.map +1 -1
  180. package/lib/esm/components/message/timestamps.js +1 -1
  181. package/lib/esm/components/message/timestamps.js.map +1 -1
  182. package/lib/esm/components/reply.d.ts +7 -6
  183. package/lib/esm/components/reply.js +9 -5
  184. package/lib/esm/components/reply.js.map +1 -1
  185. package/lib/esm/components/video.d.ts +8 -7
  186. package/lib/esm/components/video.js +2 -3
  187. package/lib/esm/components/video.js.map +1 -1
  188. package/lib/esm/components/webchat-settings.d.ts +1 -1
  189. package/lib/esm/components/webchat-settings.js +1 -1
  190. package/lib/esm/components/webchat-settings.js.map +1 -1
  191. package/lib/esm/contexts.d.ts +3 -4
  192. package/lib/esm/contexts.js +1 -78
  193. package/lib/esm/contexts.js.map +1 -1
  194. package/lib/esm/index-types.d.ts +87 -55
  195. package/lib/esm/index-types.js.map +1 -1
  196. package/lib/esm/index.d.ts +2 -2
  197. package/lib/esm/index.js +1 -1
  198. package/lib/esm/index.js.map +1 -1
  199. package/lib/esm/msg-to-botonic.d.ts +1 -1
  200. package/lib/esm/msg-to-botonic.js +5 -8
  201. package/lib/esm/msg-to-botonic.js.map +1 -1
  202. package/lib/esm/util/webchat.d.ts +17 -6
  203. package/lib/esm/util/webchat.js +9 -7
  204. package/lib/esm/util/webchat.js.map +1 -1
  205. package/lib/esm/webchat/chat-area/index.js +2 -2
  206. package/lib/esm/webchat/chat-area/index.js.map +1 -1
  207. package/lib/esm/webchat/components/conditional-animation.js +1 -1
  208. package/lib/esm/webchat/components/conditional-animation.js.map +1 -1
  209. package/lib/esm/webchat/components/opened-persistent-menu.js +1 -1
  210. package/lib/esm/webchat/components/opened-persistent-menu.js.map +1 -1
  211. package/lib/esm/webchat/{actions.d.ts → context/actions.d.ts} +2 -0
  212. package/lib/esm/webchat/{actions.js → context/actions.js} +3 -0
  213. package/lib/esm/webchat/context/actions.js.map +1 -0
  214. package/lib/esm/webchat/context/index.d.ts +5 -0
  215. package/lib/esm/webchat/context/index.js +78 -0
  216. package/lib/esm/webchat/context/index.js.map +1 -0
  217. package/lib/esm/webchat/{messages-reducer.d.ts → context/messages-reducer.d.ts} +1 -1
  218. package/lib/esm/webchat/{messages-reducer.js → context/messages-reducer.js} +3 -1
  219. package/lib/esm/webchat/context/messages-reducer.js.map +1 -0
  220. package/lib/esm/webchat/context/types.d.ts +74 -0
  221. package/lib/esm/webchat/context/types.js +2 -0
  222. package/lib/esm/webchat/context/types.js.map +1 -0
  223. package/lib/esm/webchat/{hooks → context}/use-webchat.d.ts +18 -19
  224. package/lib/esm/webchat/{hooks → context}/use-webchat.js +10 -5
  225. package/lib/esm/webchat/context/use-webchat.js.map +1 -0
  226. package/lib/esm/webchat/{webchat-reducer.d.ts → context/webchat-reducer.d.ts} +1 -1
  227. package/lib/esm/webchat/{webchat-reducer.js → context/webchat-reducer.js} +2 -0
  228. package/lib/esm/webchat/context/webchat-reducer.js.map +1 -0
  229. package/lib/esm/webchat/cover-component/index.js +1 -1
  230. package/lib/esm/webchat/cover-component/index.js.map +1 -1
  231. package/lib/esm/webchat/header/default-header.d.ts +1 -0
  232. package/lib/esm/webchat/header/default-header.js +21 -0
  233. package/lib/esm/webchat/header/default-header.js.map +1 -0
  234. package/lib/esm/webchat/header/index.d.ts +2 -0
  235. package/lib/esm/webchat/header/index.js +20 -0
  236. package/lib/esm/webchat/header/index.js.map +1 -0
  237. package/lib/esm/webchat/header/styles.d.ts +7 -0
  238. package/lib/esm/webchat/header/styles.js +55 -0
  239. package/lib/esm/webchat/header/styles.js.map +1 -0
  240. package/lib/esm/webchat/hooks/index.d.ts +0 -1
  241. package/lib/esm/webchat/hooks/index.js +0 -1
  242. package/lib/esm/webchat/hooks/index.js.map +1 -1
  243. package/lib/esm/webchat/hooks/use-previous.d.ts +1 -1
  244. package/lib/esm/webchat/hooks/use-previous.js.map +1 -1
  245. package/lib/esm/webchat/hooks/use-scrollbar-controller.js +2 -2
  246. package/lib/esm/webchat/hooks/use-scrollbar-controller.js.map +1 -1
  247. package/lib/esm/webchat/hooks/use-typing.d.ts +1 -1
  248. package/lib/esm/webchat/hooks/use-webchat-dimensions.js +1 -1
  249. package/lib/esm/webchat/hooks/use-webchat-dimensions.js.map +1 -1
  250. package/lib/esm/webchat/hooks/use-webchat-resizer.js +1 -1
  251. package/lib/esm/webchat/hooks/use-webchat-resizer.js.map +1 -1
  252. package/lib/esm/webchat/index-types.d.ts +3 -44
  253. package/lib/esm/webchat/index.d.ts +1 -0
  254. package/lib/esm/webchat/index.js +1 -0
  255. package/lib/esm/webchat/index.js.map +1 -1
  256. package/lib/esm/webchat/input-panel/attachment.d.ts +1 -1
  257. package/lib/esm/webchat/input-panel/attachment.js +1 -1
  258. package/lib/esm/webchat/input-panel/attachment.js.map +1 -1
  259. package/lib/esm/webchat/input-panel/emoji-picker.d.ts +1 -1
  260. package/lib/esm/webchat/input-panel/emoji-picker.js +1 -1
  261. package/lib/esm/webchat/input-panel/emoji-picker.js.map +1 -1
  262. package/lib/esm/webchat/input-panel/index.d.ts +3 -3
  263. package/lib/esm/webchat/input-panel/index.js +7 -2
  264. package/lib/esm/webchat/input-panel/index.js.map +1 -1
  265. package/lib/esm/webchat/input-panel/persistent-menu.js +1 -1
  266. package/lib/esm/webchat/input-panel/persistent-menu.js.map +1 -1
  267. package/lib/esm/webchat/input-panel/send-button.js +1 -1
  268. package/lib/esm/webchat/input-panel/send-button.js.map +1 -1
  269. package/lib/esm/webchat/input-panel/textarea.d.ts +1 -1
  270. package/lib/esm/webchat/input-panel/textarea.js +3 -1
  271. package/lib/esm/webchat/input-panel/textarea.js.map +1 -1
  272. package/lib/esm/webchat/message-list/index.js +4 -6
  273. package/lib/esm/webchat/message-list/index.js.map +1 -1
  274. package/lib/esm/webchat/message-list/intro-message.js +1 -1
  275. package/lib/esm/webchat/message-list/intro-message.js.map +1 -1
  276. package/lib/esm/webchat/message-list/styles.js +1 -0
  277. package/lib/esm/webchat/message-list/styles.js.map +1 -1
  278. package/lib/esm/webchat/message-list/unread-messages-banner.js +1 -1
  279. package/lib/esm/webchat/message-list/unread-messages-banner.js.map +1 -1
  280. package/lib/esm/webchat/message-list/use-notifications.js +1 -1
  281. package/lib/esm/webchat/message-list/use-notifications.js.map +1 -1
  282. package/lib/esm/webchat/replies/index.d.ts +1 -0
  283. package/lib/esm/webchat/replies/index.js +28 -0
  284. package/lib/esm/webchat/replies/index.js.map +1 -0
  285. package/lib/esm/webchat/replies/styles.d.ts +8 -0
  286. package/lib/esm/webchat/replies/styles.js +21 -0
  287. package/lib/esm/webchat/replies/styles.js.map +1 -0
  288. package/lib/esm/webchat/session-view.js +1 -1
  289. package/lib/esm/webchat/session-view.js.map +1 -1
  290. package/lib/esm/webchat/{webchat-typed/styles.d.ts → styles.d.ts} +6 -4
  291. package/lib/esm/webchat/{webchat-typed/styles.js → styles.js} +1 -1
  292. package/lib/esm/webchat/styles.js.map +1 -0
  293. package/lib/esm/webchat/trigger-button/index.js +1 -1
  294. package/lib/esm/webchat/trigger-button/index.js.map +1 -1
  295. package/lib/esm/webchat/webchat-dev.js +1 -1
  296. package/lib/esm/webchat/webchat-dev.js.map +1 -1
  297. package/lib/esm/webchat/webchat.d.ts +4 -2
  298. package/lib/esm/webchat/webchat.js +81 -102
  299. package/lib/esm/webchat/webchat.js.map +1 -1
  300. package/lib/esm/webchat/webview.js +2 -1
  301. package/lib/esm/webchat/webview.js.map +1 -1
  302. package/lib/esm/webchat-app.d.ts +11 -78
  303. package/lib/esm/webchat-app.js +28 -14
  304. package/lib/esm/webchat-app.js.map +1 -1
  305. package/package.json +2 -1
  306. package/src/components/{audio.jsx → audio.tsx} +10 -4
  307. package/src/components/button.tsx +1 -3
  308. package/src/components/carousel.jsx +1 -1
  309. package/src/components/{custom-message.jsx → custom-message.tsx} +19 -7
  310. package/src/components/{document.jsx → document.tsx} +5 -3
  311. package/src/components/handoff.jsx +1 -1
  312. package/src/components/{image.jsx → image.tsx} +10 -4
  313. package/src/components/index-types.ts +29 -4
  314. package/src/components/message/index.jsx +2 -1
  315. package/src/components/message/message-feedback.tsx +1 -1
  316. package/src/components/message/message-footer.tsx +1 -1
  317. package/src/components/message/message-image.tsx +1 -1
  318. package/src/components/message/timestamps.tsx +1 -1
  319. package/src/components/{reply.jsx → reply.tsx} +10 -4
  320. package/src/components/{video.jsx → video.tsx} +3 -2
  321. package/src/components/webchat-settings.tsx +2 -2
  322. package/src/contexts.tsx +5 -83
  323. package/src/index-types.ts +92 -59
  324. package/src/index.ts +2 -6
  325. package/src/msg-to-botonic.jsx +5 -9
  326. package/src/util/{webchat.js → webchat.ts} +15 -9
  327. package/src/webchat/chat-area/index.tsx +2 -4
  328. package/src/webchat/components/conditional-animation.jsx +1 -1
  329. package/src/webchat/components/opened-persistent-menu.jsx +1 -1
  330. package/src/webchat/{actions.ts → context/actions.ts} +3 -0
  331. package/src/webchat/context/index.tsx +81 -0
  332. package/src/webchat/{messages-reducer.ts → context/messages-reducer.ts} +4 -2
  333. package/src/webchat/context/types.ts +88 -0
  334. package/src/webchat/{hooks → context}/use-webchat.ts +59 -12
  335. package/src/webchat/{webchat-reducer.ts → context/webchat-reducer.ts} +3 -1
  336. package/src/webchat/cover-component/index.tsx +1 -1
  337. package/src/webchat/global.d.ts +3 -0
  338. package/src/webchat/header/default-header.tsx +75 -0
  339. package/src/webchat/header/index.tsx +37 -0
  340. package/src/webchat/header/styles.ts +62 -0
  341. package/src/webchat/hooks/index.ts +0 -1
  342. package/src/webchat/hooks/use-previous.ts +1 -1
  343. package/src/webchat/hooks/use-scrollbar-controller.ts +2 -2
  344. package/src/webchat/hooks/use-typing.ts +1 -1
  345. package/src/webchat/hooks/use-webchat-dimensions.ts +1 -1
  346. package/src/webchat/hooks/use-webchat-resizer.ts +1 -1
  347. package/src/webchat/index-types.ts +3 -49
  348. package/src/webchat/index.ts +1 -0
  349. package/src/webchat/input-panel/attachment.tsx +2 -2
  350. package/src/webchat/input-panel/emoji-picker.tsx +2 -2
  351. package/src/webchat/input-panel/index.tsx +9 -5
  352. package/src/webchat/input-panel/persistent-menu.tsx +1 -1
  353. package/src/webchat/input-panel/send-button.tsx +1 -1
  354. package/src/webchat/input-panel/textarea.tsx +4 -2
  355. package/src/webchat/message-list/index.tsx +4 -6
  356. package/src/webchat/message-list/intro-message.tsx +1 -1
  357. package/src/webchat/message-list/styles.ts +1 -0
  358. package/src/webchat/message-list/unread-messages-banner.tsx +1 -1
  359. package/src/webchat/message-list/use-notifications.ts +1 -1
  360. package/src/webchat/replies/index.tsx +47 -0
  361. package/src/webchat/replies/styles.ts +28 -0
  362. package/src/webchat/session-view.jsx +1 -1
  363. package/src/webchat/{webchat-typed/styles.ts → styles.ts} +7 -2
  364. package/src/webchat/trigger-button/index.tsx +1 -1
  365. package/src/webchat/webchat-dev.jsx +1 -1
  366. package/src/webchat/{webchat.jsx → webchat.tsx} +112 -122
  367. package/src/webchat/webview.jsx +2 -1
  368. package/src/webchat-app.tsx +48 -87
  369. package/lib/cjs/webchat/actions.js.map +0 -1
  370. package/lib/cjs/webchat/header.d.ts +0 -3
  371. package/lib/cjs/webchat/header.js +0 -86
  372. package/lib/cjs/webchat/header.js.map +0 -1
  373. package/lib/cjs/webchat/hooks/use-webchat.js.map +0 -1
  374. package/lib/cjs/webchat/messages-reducer.js.map +0 -1
  375. package/lib/cjs/webchat/replies.d.ts +0 -1
  376. package/lib/cjs/webchat/replies.js +0 -47
  377. package/lib/cjs/webchat/replies.js.map +0 -1
  378. package/lib/cjs/webchat/webchat-reducer.js.map +0 -1
  379. package/lib/cjs/webchat/webchat-typed/styles.js.map +0 -1
  380. package/lib/cjs/webchat/webchat-typed/webchat-typed.d.ts +0 -0
  381. package/lib/cjs/webchat/webchat-typed/webchat-typed.js +0 -663
  382. package/lib/cjs/webchat/webchat-typed/webchat-typed.js.map +0 -1
  383. package/lib/esm/webchat/actions.js.map +0 -1
  384. package/lib/esm/webchat/header.d.ts +0 -3
  385. package/lib/esm/webchat/header.js +0 -81
  386. package/lib/esm/webchat/header.js.map +0 -1
  387. package/lib/esm/webchat/hooks/use-webchat.js.map +0 -1
  388. package/lib/esm/webchat/messages-reducer.js.map +0 -1
  389. package/lib/esm/webchat/replies.d.ts +0 -1
  390. package/lib/esm/webchat/replies.js +0 -42
  391. package/lib/esm/webchat/replies.js.map +0 -1
  392. package/lib/esm/webchat/webchat-reducer.js.map +0 -1
  393. package/lib/esm/webchat/webchat-typed/styles.js.map +0 -1
  394. package/lib/esm/webchat/webchat-typed/webchat-typed.d.ts +0 -0
  395. package/lib/esm/webchat/webchat-typed/webchat-typed.js +0 -663
  396. package/lib/esm/webchat/webchat-typed/webchat-typed.js.map +0 -1
  397. package/src/webchat/header.jsx +0 -149
  398. package/src/webchat/replies.jsx +0 -64
  399. package/src/webchat/webchat-typed/webchat-typed.tsx +0 -728
package/src/contexts.tsx CHANGED
@@ -1,8 +1,7 @@
1
1
  import { Input as CoreInput, Session as CoreSession } from '@botonic/core'
2
2
  import { createContext } from 'react'
3
3
 
4
- import { ActionRequest, WebchatContextProps } from './index-types'
5
- import { webchatInitialState } from './webchat/hooks'
4
+ import { ActionRequest } from './index-types'
6
5
 
7
6
  export const RequestContext = createContext<
8
7
  Partial<ActionRequest> & {
@@ -27,89 +26,12 @@ export interface CloseWebviewOptions {
27
26
 
28
27
  export const WebviewRequestContext = createContext<{
29
28
  closeWebview: (options?: CloseWebviewOptions) => Promise<void>
30
- getString: (stringId: string) => string
29
+ getString?: (stringId: string) => string
31
30
  params: Record<string, any>
32
- session: CoreSession
31
+ session: Partial<CoreSession>
33
32
  }>({
34
33
  closeWebview: async () => undefined,
35
- getString: () => '',
34
+ getString: undefined,
36
35
  params: {} as Record<string, any>,
37
- session: {} as CoreSession,
38
- })
39
-
40
- export const WebchatContext = createContext<WebchatContextProps>({
41
- addMessage: () => {
42
- return
43
- },
44
- closeWebview: async () => {
45
- return
46
- },
47
- getThemeProperty: () => {
48
- return
49
- }, // used to retrieve a specific property of the theme defined by the developer in his 'webchat/index.js'
50
- openWebview: () => {
51
- return
52
- },
53
- resolveCase: () => {
54
- return
55
- },
56
- resetUnreadMessages: () => {
57
- return
58
- },
59
- setIsInputFocused: () => {
60
- return
61
- },
62
- setLastMessageVisible: () => {
63
- return
64
- },
65
- sendAttachment: async () => {
66
- return
67
- },
68
- sendInput: async () => {
69
- return
70
- },
71
- sendPayload: async () => {
72
- return
73
- },
74
- sendText: async () => {
75
- return
76
- },
77
- theme: {},
78
- toggleCoverComponent: () => {
79
- return
80
- },
81
- toggleWebchat: () => {
82
- return
83
- },
84
- toggleEmojiPicker: () => {
85
- return
86
- },
87
- togglePersistentMenu: () => {
88
- return
89
- },
90
- updateLatestInput: () => {
91
- return
92
- },
93
- updateMessage: () => {
94
- return
95
- },
96
- updateReplies: () => {
97
- return
98
- },
99
- updateUser: () => {
100
- return
101
- },
102
- updateWebchatDevSettings: () => {
103
- return
104
- },
105
- webchatState: webchatInitialState,
106
- trackEvent: async () => {
107
- return
108
- },
109
- webchatRef: { current: null },
110
- chatAreaRef: { current: null },
111
- inputPanelRef: { current: null },
112
- headerRef: { current: null },
113
- scrollableMessagesListRef: { current: null },
114
- repliesRef: { current: null },
36
+ session: {} as Partial<CoreSession>,
115
37
  })
@@ -5,6 +5,7 @@ import {
5
5
  Plugin as CorePlugin,
6
6
  Route as CoreRoute,
7
7
  Routes as CoreRoutes,
8
+ ServerConfig,
8
9
  Session as CoreSession,
9
10
  SessionUser as CoreSessionUser,
10
11
  } from '@botonic/core'
@@ -18,9 +19,9 @@ import {
18
19
  ReplyProps,
19
20
  ThemeProps,
20
21
  WebchatSettingsProps,
21
- Webview,
22
22
  } from './components/index-types'
23
- import { WebchatState } from './webchat/index-types'
23
+ import { CloseWebviewOptions } from './contexts'
24
+ import { UseWebchat } from './webchat/context/use-webchat'
24
25
  import { WebchatApp } from './webchat-app'
25
26
 
26
27
  /**
@@ -51,32 +52,91 @@ export interface RequestContextInterface extends ActionRequest {
51
52
  setLocale: (locale: string) => string
52
53
  }
53
54
 
54
- export interface CustomMessageType {
55
- customTypeName: string
55
+ export interface WebchatRef {
56
+ addBotResponse: ({
57
+ response,
58
+ session,
59
+ lastRoutePath,
60
+ }: AddBotResponseArgs) => void
61
+ setTyping: (typing: boolean) => void
62
+ addUserMessage: (message: any) => Promise<void>
63
+ updateUser: (userToUpdate: any) => void
64
+ openWebchat: () => void
65
+ closeWebchat: () => void
66
+ toggleWebchat: () => void
67
+ openCoverComponent: () => void
68
+ closeCoverComponent: () => void
69
+ toggleCoverComponent: () => void
70
+ renderCustomComponent: (customComponent: any) => void
71
+ unmountCustomComponent: () => void
72
+ isOnline: () => boolean
73
+ setOnline: (online: boolean) => void
74
+ getMessages: () => { id: string; ack: number; unsentInput: CoreInput }[] // TODO: define MessagesJSON
75
+ clearMessages: () => void
76
+ getLastMessageUpdate: () => string | undefined
77
+ updateMessageInfo: (msgId: string, messageInfo: any) => void
78
+ updateWebchatSettings: (settings: WebchatSettingsProps) => void
79
+ closeWebview: (options?: CloseWebviewOptions) => Promise<void>
80
+ }
81
+
82
+ interface AddBotResponseArgs {
83
+ response: any
84
+ session?: any
85
+ lastRoutePath?: any
56
86
  }
57
87
 
58
88
  export interface WebchatArgs {
59
- blockInputs?: BlockInputOption[]
89
+ theme?: ThemeProps
90
+ persistentMenu?: PersistentMenuTheme
60
91
  coverComponent?: CoverComponentOptions
61
- defaultDelay?: number
62
- defaultTyping?: number
63
- enableAnimations?: boolean
64
- enableAttachments?: boolean
92
+ blockInputs?: BlockInputOption[]
65
93
  enableEmojiPicker?: boolean
94
+ enableAttachments?: boolean
66
95
  enableUserInput?: boolean
67
- shadowDOM?: boolean | (() => boolean)
96
+ enableAnimations?: boolean
68
97
  hostId?: string
69
- getString?: (stringId: string, session: CoreSession) => string
70
- onClose?: (app: WebchatApp, args: any) => void
98
+ shadowDOM?: boolean | (() => boolean)
99
+ defaultDelay?: number
100
+ defaultTyping?: number
101
+ storage?: Storage | null
102
+ storageKey?: string
71
103
  onInit?: (app: WebchatApp, args: any) => void
72
- onMessage?: (app: WebchatApp, message: WebchatMessage) => void
73
104
  onOpen?: (app: WebchatApp, args: any) => void
74
- onConnectionChange?: (app: WebchatApp, isOnline: boolean) => void
105
+ onClose?: (app: WebchatApp, args: any) => void
106
+ onMessage?: (app: WebchatApp, message: WebchatMessage) => void
75
107
  onTrackEvent?: TrackEventFunction
108
+ onConnectionChange?: (app: WebchatApp, isOnline: boolean) => void
109
+ appId?: string
110
+ visibility?: boolean | (() => boolean) | 'dynamic'
111
+ server?: ServerConfig
112
+ }
113
+
114
+ export interface WebchatProps {
115
+ webchatHooks?: UseWebchat
116
+ initialSession?: any
117
+ initialDevSettings?: any
118
+ onStateChange: (args: OnStateChangeArgs) => void
119
+
120
+ shadowDOM?: any
121
+ theme?: ThemeProps
76
122
  persistentMenu?: PersistentMenuTheme
123
+ coverComponent?: CoverComponentOptions
124
+ blockInputs?: BlockInputOption[]
125
+ enableEmojiPicker?: boolean
126
+ enableAttachments?: boolean
127
+ enableUserInput?: boolean
128
+ enableAnimations?: boolean
77
129
  storage?: Storage | null
78
- storageKey?: any
79
- theme?: ThemeProps
130
+ storageKey?: string | (() => string)
131
+ defaultDelay?: number
132
+ defaultTyping?: number
133
+ onInit?: (args?: any) => void
134
+ onOpen?: (args?: any) => void
135
+ onClose?: (args?: any) => void
136
+ onUserInput(args: OnUserInputArgs): Promise<void>
137
+ onTrackEvent?: TrackEventFunction
138
+ host?: any
139
+ server?: ServerConfig
80
140
  }
81
141
 
82
142
  export type EventArgs = { [key: string]: any }
@@ -101,19 +161,19 @@ export interface WebchatMessage {
101
161
  ack: 0 | 1
102
162
  blob: boolean
103
163
  buttons: ButtonProps[]
104
- children: any
105
- data: any
164
+ children: any // messageJSON don't have children prop
165
+ data: any // if message.type === 'text' => message.data = {text: string}
106
166
  delay: number
107
167
  display: boolean
108
- enabletimestamps: boolean
168
+ enabletimestamps?: boolean
109
169
  id: string
110
- imagestyle: any
170
+ imagestyle?: any
111
171
  isUnread: boolean
112
172
  json: any
113
- markdown: boolean
173
+ markdown: boolean // 0 | 1
114
174
  replies: ReplyProps[]
115
175
  sentBy: SENDERS
116
- style: any
176
+ style?: any
117
177
  timestamp: string
118
178
  type: CoreInputType
119
179
  typing: number
@@ -123,7 +183,7 @@ export interface OnUserInputArgs {
123
183
  input: CoreInput
124
184
  lastRoutePath?: string
125
185
  session?: CoreSession
126
- user: CoreSessionUser
186
+ user?: CoreSessionUser
127
187
  }
128
188
 
129
189
  export interface OnStateChangeArgs {
@@ -137,44 +197,17 @@ export interface MessageInfo {
137
197
  type: 'update_webchat_settings' | 'sender_action'
138
198
  }
139
199
 
140
- export interface Event {
141
- action?: 'update_message_info'
200
+ export type Event = ConnectionChangeEvent | UpdateMessageInfoEvent
201
+
202
+ interface ConnectionChangeEvent {
203
+ action: 'connectionChange'
204
+ online: boolean
142
205
  isError?: boolean
143
206
  message?: MessageInfo
144
207
  }
145
208
 
146
- // ClientInput: type for sendInput and updateLatestInput function without message_id and bot_interaction_id because backend set this values
147
- export type ClientInput = Omit<CoreInput, 'message_id' | 'bot_interaction_id'>
148
-
149
- export interface WebchatContextProps {
150
- addMessage: (message: WebchatMessage) => void
151
- closeWebview: () => Promise<void>
152
- getThemeProperty: (property: string, defaultValue?: any) => any
153
- openWebview: (webviewComponent: Webview, params?: any) => void
154
- resetUnreadMessages: () => void
155
- resolveCase: () => void
156
- sendAttachment: (attachment: File) => Promise<void>
157
- sendInput: (input: ClientInput) => Promise<void>
158
- sendPayload: (payload: string) => Promise<void>
159
- sendText: (text: string, payload?: string) => Promise<void>
160
- setIsInputFocused: (isInputFocused: boolean) => void
161
- setLastMessageVisible: (isLastMessageVisible: boolean) => void
162
- theme: ThemeProps
163
- toggleWebchat: (toggle: boolean) => void
164
- toggleEmojiPicker: (toggle: boolean) => void
165
- togglePersistentMenu: (toggle: boolean) => void
166
- toggleCoverComponent: (toggle: boolean) => void
167
- updateLatestInput: (input: ClientInput) => void
168
- updateMessage: (message: WebchatMessage) => void
169
- updateReplies: (replies: boolean) => void
170
- updateUser: (user: Partial<CoreSessionUser>) => void
171
- updateWebchatDevSettings: (settings: WebchatSettingsProps) => void
172
- webchatState: WebchatState
173
- trackEvent: TrackEventFunction
174
- webchatRef: React.MutableRefObject<HTMLDivElement | null>
175
- chatAreaRef: React.MutableRefObject<HTMLDivElement | null>
176
- inputPanelRef: React.MutableRefObject<HTMLDivElement | null>
177
- headerRef: React.MutableRefObject<HTMLDivElement | null>
178
- scrollableMessagesListRef: React.MutableRefObject<HTMLDivElement | null>
179
- repliesRef: React.MutableRefObject<HTMLDivElement | null>
209
+ interface UpdateMessageInfoEvent {
210
+ action: 'update_message_info'
211
+ message: MessageInfo
212
+ isError?: boolean
180
213
  }
package/src/index.ts CHANGED
@@ -1,15 +1,11 @@
1
1
  export { BotonicInputTester, BotonicOutputTester } from './botonic-tester'
2
2
  export * from './components'
3
- export {
4
- RequestContext,
5
- WebchatContext,
6
- WebviewRequestContext,
7
- } from './contexts'
3
+ export { RequestContext, WebviewRequestContext } from './contexts'
8
4
  export { DevApp } from './dev-app'
9
5
  export * from './index-types'
10
6
  export { msgsToBotonic, msgToBotonic } from './msg-to-botonic'
11
7
  export { NodeApp } from './node-app'
12
8
  export * from './util'
13
9
  export * from './webchat'
14
- export { WebchatApp, WebchatAppProps } from './webchat-app'
10
+ export { WebchatApp } from './webchat-app'
15
11
  export { WebviewApp } from './webview-app'
@@ -32,7 +32,7 @@ import {
32
32
  * @param customMessageTypes {{customTypeName}[]?}
33
33
  * @return {React.ReactNode}
34
34
  */
35
- export function msgToBotonic(msg, customMessageTypes) {
35
+ export function msgToBotonic(msg, customMessageTypes = []) {
36
36
  delete msg.display
37
37
  if (isCustom(msg)) {
38
38
  try {
@@ -56,28 +56,28 @@ export function msgToBotonic(msg, customMessageTypes) {
56
56
  <Image
57
57
  key={msg.key}
58
58
  {...msg}
59
- src={msg.data.image != undefined ? msg.data.image : msg.data}
59
+ src={msg.data.image !== undefined ? msg.data.image : msg.data}
60
60
  />
61
61
  )
62
62
  } else if (isVideo(msg)) {
63
63
  return (
64
64
  <Video
65
65
  {...msg}
66
- src={msg.data.video != undefined ? msg.data.video : msg.data}
66
+ src={msg.data.video !== undefined ? msg.data.video : msg.data}
67
67
  />
68
68
  )
69
69
  } else if (isAudio(msg)) {
70
70
  return (
71
71
  <Audio
72
72
  {...msg}
73
- src={msg.data.audio != undefined ? msg.data.audio : msg.data}
73
+ src={msg.data.audio !== undefined ? msg.data.audio : msg.data}
74
74
  />
75
75
  )
76
76
  } else if (isDocument(msg)) {
77
77
  return (
78
78
  <Document
79
79
  {...msg}
80
- src={msg.data.document != undefined ? msg.data.document : msg.data}
80
+ src={msg.data.document !== undefined ? msg.data.document : msg.data}
81
81
  />
82
82
  )
83
83
  } else if (isLocation(msg)) {
@@ -99,10 +99,6 @@ export function msgToBotonic(msg, customMessageTypes) {
99
99
  return null
100
100
  }
101
101
 
102
- function rndStr() {
103
- return Math.random().toString()
104
- }
105
-
106
102
  /**
107
103
  * @param msgs {object|object[]}
108
104
  * @param customMessageTypes {{customTypeName}[]?}
@@ -2,6 +2,7 @@ import merge from 'lodash.merge'
2
2
  import UAParser from 'ua-parser-js'
3
3
  import { v7 as uuidv7 } from 'uuid'
4
4
 
5
+ import { ThemeProps } from '../components'
5
6
  import { WEBCHAT } from '../constants'
6
7
  import { getProperty } from './objects'
7
8
 
@@ -11,13 +12,12 @@ import { getProperty } from './objects'
11
12
  * If property doesn't exist, returns the defaultValue.
12
13
  */
13
14
  export const _getThemeProperty =
14
- theme =>
15
- (property, defaultValue = undefined) => {
16
- for (const [k, v] of Object.entries(WEBCHAT.CUSTOM_PROPERTIES)) {
17
- if (v == property) {
18
- const nestedProperty = getProperty(theme, v)
15
+ (theme: ThemeProps) => (property: string, defaultValue?: any) => {
16
+ for (const [key, value] of Object.entries(WEBCHAT.CUSTOM_PROPERTIES)) {
17
+ if (value === property) {
18
+ const nestedProperty = getProperty(theme, value)
19
19
  if (nestedProperty !== undefined) return nestedProperty
20
- const plainProperty = getProperty(theme, k)
20
+ const plainProperty = getProperty(theme, key)
21
21
  if (plainProperty !== undefined) return plainProperty
22
22
  return defaultValue
23
23
  }
@@ -25,7 +25,10 @@ export const _getThemeProperty =
25
25
  return undefined
26
26
  }
27
27
 
28
- export const createUser = () => {
28
+ export const createUser = (): {
29
+ id: string
30
+ name: string
31
+ } => {
29
32
  const parser = new UAParser()
30
33
  const ua = parser.getResult()
31
34
  let name = `${ua.os.name} ${ua.browser.name}`
@@ -35,9 +38,11 @@ export const createUser = () => {
35
38
  name,
36
39
  }
37
40
  }
38
- export const initSession = session => {
41
+ export const initSession = (
42
+ session: any
43
+ ): { user: { id: string; name: string } } => {
39
44
  if (!session) session = {}
40
- const hasUserId = session.user && session.user.id !== undefined
45
+ const hasUserId = session?.user?.id !== undefined
41
46
  if (!session.user || Object.keys(session.user).length === 0 || !hasUserId)
42
47
  session.user = !hasUserId ? merge(session.user, createUser()) : createUser()
43
48
  return session
@@ -48,6 +53,7 @@ export const shouldKeepSessionOnReload = ({
48
53
  devSettings,
49
54
  }) => !initialDevSettings || (devSettings && devSettings.keepSessionOnReload)
50
55
 
56
+ //TODO: Review param serverConfig if is of type ServerConfig this never have errorMessage
51
57
  export const getServerErrorMessage = serverConfig => {
52
58
  if (!serverConfig || !serverConfig.errorMessage) return 'Connection issues'
53
59
  if (typeof serverConfig.errorMessage === 'function') {
@@ -1,7 +1,7 @@
1
1
  import React, { useContext, useEffect, useState } from 'react'
2
2
 
3
- import { WebchatContext } from '../../contexts'
4
3
  import { BotonicContainerId } from '../constants'
4
+ import { WebchatContext } from '../context'
5
5
  import { useWebchatDimensions } from '../hooks'
6
6
  import { WebchatMessageList } from '../message-list'
7
7
  import { WebchatReplies } from '../replies'
@@ -27,9 +27,7 @@ export const ChatArea = () => {
27
27
  height={chatAreaHeight}
28
28
  >
29
29
  <WebchatMessageList />
30
- {replies && Object.keys(replies).length > 0 && (
31
- <WebchatReplies replies={replies} />
32
- )}
30
+ {replies && replies.length > 0 && <WebchatReplies />}
33
31
  </StyledChatArea>
34
32
  )
35
33
  }
@@ -1,9 +1,9 @@
1
1
  import React, { useContext } from 'react'
2
2
 
3
3
  import { WEBCHAT } from '../../constants'
4
- import { WebchatContext } from '../../contexts'
5
4
  import { Scale } from '../../shared/styles'
6
5
  import { ConditionalWrapper } from '../../util/react'
6
+ import { WebchatContext } from '../context'
7
7
 
8
8
  export const ConditionalAnimation = props => {
9
9
  const { getThemeProperty } = useContext(WebchatContext)
@@ -3,7 +3,7 @@ import styled from 'styled-components'
3
3
 
4
4
  import { Button } from '../../components/button'
5
5
  import { ROLES, WEBCHAT } from '../../constants'
6
- import { WebchatContext } from '../../contexts'
6
+ import { WebchatContext } from '../context'
7
7
  import { useComponentVisible } from '../hooks'
8
8
 
9
9
  const ButtonsContainer = styled.div`
@@ -1,3 +1,4 @@
1
+ /* eslint-disable @typescript-eslint/naming-convention */
1
2
  export enum WebchatAction {
2
3
  ADD_MESSAGE = 'addMessage',
3
4
  ADD_MESSAGE_COMPONENT = 'addMessageComponent',
@@ -23,5 +24,7 @@ export enum WebchatAction {
23
24
  UPDATE_THEME = 'updateTheme',
24
25
  UPDATE_TYPING = 'updateTyping',
25
26
  UPDATE_WEBVIEW = 'updateWebview',
27
+ REMOVE_REPLIES = 'removeReplies',
28
+ REMOVE_WEBVIEW = 'removeWebview',
26
29
  SET_IS_INPUT_FOCUSED = 'setIsInputFocused',
27
30
  }
@@ -0,0 +1,81 @@
1
+ import { createContext } from 'react'
2
+
3
+ import { WebchatContextProps } from './types'
4
+ import { webchatInitialState } from './use-webchat'
5
+
6
+ export { WebchatState } from './types'
7
+ export { useWebchat, webchatInitialState } from './use-webchat'
8
+
9
+ export const WebchatContext = createContext<WebchatContextProps>({
10
+ addMessage: () => {
11
+ return
12
+ },
13
+ getThemeProperty: () => {
14
+ return
15
+ }, // used to retrieve a specific property of the theme defined by the developer in his 'webchat/index.js'
16
+ openWebview: () => {
17
+ return
18
+ },
19
+ resolveCase: () => {
20
+ return
21
+ },
22
+ resetUnreadMessages: () => {
23
+ return
24
+ },
25
+ setIsInputFocused: () => {
26
+ return
27
+ },
28
+ setLastMessageVisible: () => {
29
+ return
30
+ },
31
+ sendAttachment: async () => {
32
+ return
33
+ },
34
+ sendInput: async () => {
35
+ return
36
+ },
37
+ sendPayload: async () => {
38
+ return
39
+ },
40
+ sendText: async () => {
41
+ return
42
+ },
43
+ theme: {},
44
+ toggleCoverComponent: () => {
45
+ return
46
+ },
47
+ toggleWebchat: () => {
48
+ return
49
+ },
50
+ toggleEmojiPicker: () => {
51
+ return
52
+ },
53
+ togglePersistentMenu: () => {
54
+ return
55
+ },
56
+ updateLatestInput: () => {
57
+ return
58
+ },
59
+ updateMessage: () => {
60
+ return
61
+ },
62
+ updateReplies: () => {
63
+ return
64
+ },
65
+ updateUser: () => {
66
+ return
67
+ },
68
+ updateWebchatDevSettings: () => {
69
+ return
70
+ },
71
+ webchatState: webchatInitialState,
72
+ trackEvent: async () => {
73
+ return
74
+ },
75
+ webchatRef: { current: null },
76
+ chatAreaRef: { current: null },
77
+ inputPanelRef: { current: null },
78
+ headerRef: { current: null },
79
+ scrollableMessagesListRef: { current: null },
80
+ repliesRef: { current: null },
81
+ })
@@ -1,6 +1,6 @@
1
- import { SENDERS } from '../index-types'
1
+ import { SENDERS } from '../../index-types'
2
2
  import { WebchatAction } from './actions'
3
- import { WebchatState } from './index-types'
3
+ import { WebchatState } from './types'
4
4
 
5
5
  export const messagesReducer = (
6
6
  state: WebchatState,
@@ -15,6 +15,8 @@ export const messagesReducer = (
15
15
  return updateMessageReducer(state, action)
16
16
  case WebchatAction.UPDATE_REPLIES:
17
17
  return { ...state, replies: action.payload }
18
+ case WebchatAction.REMOVE_REPLIES:
19
+ return { ...state, replies: undefined }
18
20
  case WebchatAction.CLEAR_MESSAGES:
19
21
  return {
20
22
  ...state,
@@ -0,0 +1,88 @@
1
+ import {
2
+ Input as CoreInput,
3
+ Session as CoreSession,
4
+ SessionUser as CoreSessionUser,
5
+ } from '@botonic/core'
6
+
7
+ import { Reply } from '../../components'
8
+ import {
9
+ ThemeProps,
10
+ WebchatSettingsProps,
11
+ Webview,
12
+ } from '../../components/index-types'
13
+ import { TrackEventFunction, WebchatMessage } from '../../index-types'
14
+ import { WebchatStateTheme } from '../index-types'
15
+
16
+ export interface ErrorMessage {
17
+ message?: string
18
+ }
19
+
20
+ export interface DevSettings {
21
+ keepSessionOnReload?: boolean
22
+ showSessionView?: boolean
23
+ }
24
+
25
+ export interface WebchatState {
26
+ width: number
27
+ height: number
28
+ messagesJSON: any[]
29
+ messagesComponents: any[]
30
+ replies?: (typeof Reply)[]
31
+ latestInput: Partial<CoreInput>
32
+ typing: boolean
33
+ webview: Webview | null
34
+ webviewParams: null
35
+ session: Partial<CoreSession>
36
+ lastRoutePath?: string
37
+ handoff: boolean
38
+ theme: WebchatStateTheme
39
+ themeUpdates: Partial<WebchatStateTheme>
40
+ error: ErrorMessage
41
+ online: boolean
42
+ devSettings: DevSettings
43
+ isWebchatOpen: boolean
44
+ isEmojiPickerOpen: boolean
45
+ isPersistentMenuOpen: boolean
46
+ isCoverComponentOpen: boolean
47
+ isCustomComponentRendered: boolean
48
+ lastMessageUpdate?: string
49
+ currentAttachment?: File
50
+ numUnreadMessages: number
51
+ isLastMessageVisible: boolean
52
+ isInputFocused: boolean
53
+ }
54
+
55
+ // ClientInput: type for sendInput and updateLatestInput function without message_id and bot_interaction_id because backend set this values
56
+ export type ClientInput = Omit<CoreInput, 'message_id' | 'bot_interaction_id'>
57
+
58
+ export interface WebchatContextProps {
59
+ addMessage: (message: WebchatMessage) => void
60
+ getThemeProperty: (property: string, defaultValue?: any) => any
61
+ openWebview: (webviewComponent: Webview, params?: any) => void
62
+ resetUnreadMessages: () => void
63
+ resolveCase: () => void
64
+ sendAttachment: (attachment: File) => Promise<void>
65
+ sendInput: (input: ClientInput) => Promise<void>
66
+ sendPayload: (payload: string) => Promise<void>
67
+ sendText: (text: string, payload?: string) => Promise<void>
68
+ setIsInputFocused: (isInputFocused: boolean) => void
69
+ setLastMessageVisible: (isLastMessageVisible: boolean) => void
70
+ theme: ThemeProps // TODO: Review if theme is needed and used from WebchatContext
71
+ toggleWebchat: (toggle: boolean) => void
72
+ toggleEmojiPicker: (toggle: boolean) => void
73
+ togglePersistentMenu: (toggle: boolean) => void
74
+ toggleCoverComponent: (toggle: boolean) => void
75
+ updateLatestInput: (input: ClientInput) => void
76
+ updateMessage: (message: WebchatMessage) => void
77
+ updateReplies: (replies: (typeof Reply)[]) => void
78
+ updateUser: (user: Partial<CoreSessionUser>) => void
79
+ updateWebchatDevSettings: (settings: WebchatSettingsProps) => void
80
+ trackEvent?: TrackEventFunction
81
+ webchatState: WebchatState
82
+ webchatRef: React.MutableRefObject<HTMLDivElement | null> // Rename this to webchatContainerRef
83
+ chatAreaRef: React.MutableRefObject<HTMLDivElement | null>
84
+ inputPanelRef: React.MutableRefObject<HTMLDivElement | null>
85
+ headerRef: React.MutableRefObject<HTMLDivElement | null>
86
+ scrollableMessagesListRef: React.MutableRefObject<HTMLDivElement | null>
87
+ repliesRef: React.MutableRefObject<HTMLDivElement | null>
88
+ }