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

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 (327) hide show
  1. package/lib/cjs/botonic-tester.js +8 -10
  2. package/lib/cjs/botonic-tester.js.map +1 -1
  3. package/lib/cjs/components/audio.js +3 -7
  4. package/lib/cjs/components/audio.js.map +1 -1
  5. package/lib/cjs/components/button.js +7 -18
  6. package/lib/cjs/components/button.js.map +1 -1
  7. package/lib/cjs/components/carousel.d.ts +1 -1
  8. package/lib/cjs/components/carousel.js +6 -19
  9. package/lib/cjs/components/carousel.js.map +1 -1
  10. package/lib/cjs/components/custom-message.d.ts +3 -34
  11. package/lib/cjs/components/custom-message.js +4 -10
  12. package/lib/cjs/components/custom-message.js.map +1 -1
  13. package/lib/cjs/components/document.js +3 -6
  14. package/lib/cjs/components/document.js.map +1 -1
  15. package/lib/cjs/components/element.js +3 -2
  16. package/lib/cjs/components/element.js.map +1 -1
  17. package/lib/cjs/components/handoff.js +3 -7
  18. package/lib/cjs/components/handoff.js.map +1 -1
  19. package/lib/cjs/components/image.js +3 -7
  20. package/lib/cjs/components/image.js.map +1 -1
  21. package/lib/cjs/components/index-types.d.ts +174 -0
  22. package/lib/cjs/components/index-types.js +17 -0
  23. package/lib/cjs/components/index-types.js.map +1 -0
  24. package/lib/cjs/components/index.d.ts +23 -20
  25. package/lib/cjs/components/index.js +6 -1
  26. package/lib/cjs/components/index.js.map +1 -1
  27. package/lib/cjs/components/location.js +3 -9
  28. package/lib/cjs/components/location.js.map +1 -1
  29. package/lib/cjs/components/message-template.js +2 -3
  30. package/lib/cjs/components/message-template.js.map +1 -1
  31. package/lib/cjs/components/message.js +7 -25
  32. package/lib/cjs/components/message.js.map +1 -1
  33. package/lib/cjs/components/multichannel/index-types.d.ts +45 -0
  34. package/lib/cjs/components/multichannel/index-types.js +3 -0
  35. package/lib/cjs/components/multichannel/index-types.js.map +1 -0
  36. package/lib/cjs/components/multichannel/index.d.ts +11 -6
  37. package/lib/cjs/components/multichannel/index.js +2 -0
  38. package/lib/cjs/components/multichannel/index.js.map +1 -1
  39. package/lib/cjs/components/multichannel/multichannel-button.js +4 -5
  40. package/lib/cjs/components/multichannel/multichannel-button.js.map +1 -1
  41. package/lib/cjs/components/multichannel/multichannel-carousel.js +3 -20
  42. package/lib/cjs/components/multichannel/multichannel-carousel.js.map +1 -1
  43. package/lib/cjs/components/multichannel/multichannel-context.d.ts +1 -1
  44. package/lib/cjs/components/multichannel/multichannel-reply.js +2 -1
  45. package/lib/cjs/components/multichannel/multichannel-reply.js.map +1 -1
  46. package/lib/cjs/components/multichannel/multichannel-text.d.ts +1 -1
  47. package/lib/cjs/components/multichannel/multichannel-text.js +9 -24
  48. package/lib/cjs/components/multichannel/multichannel-text.js.map +1 -1
  49. package/lib/cjs/components/multichannel/multichannel.js +16 -28
  50. package/lib/cjs/components/multichannel/multichannel.js.map +1 -1
  51. package/lib/cjs/components/pic.js +3 -2
  52. package/lib/cjs/components/pic.js.map +1 -1
  53. package/lib/cjs/components/raw.js +3 -12
  54. package/lib/cjs/components/raw.js.map +1 -1
  55. package/lib/cjs/components/reply.js +5 -8
  56. package/lib/cjs/components/reply.js.map +1 -1
  57. package/lib/cjs/components/share-button.js +2 -3
  58. package/lib/cjs/components/share-button.js.map +1 -1
  59. package/lib/cjs/components/subtitle.js +3 -4
  60. package/lib/cjs/components/subtitle.js.map +1 -1
  61. package/lib/cjs/components/text.js +3 -6
  62. package/lib/cjs/components/text.js.map +1 -1
  63. package/lib/cjs/components/timestamps.js +2 -5
  64. package/lib/cjs/components/timestamps.js.map +1 -1
  65. package/lib/cjs/components/title.js +3 -2
  66. package/lib/cjs/components/title.js.map +1 -1
  67. package/lib/cjs/components/video.js +3 -6
  68. package/lib/cjs/components/video.js.map +1 -1
  69. package/lib/cjs/components/webchat-settings.js +2 -1
  70. package/lib/cjs/components/webchat-settings.js.map +1 -1
  71. package/lib/cjs/components/whatsapp-button-list.d.ts +24 -0
  72. package/lib/cjs/components/whatsapp-button-list.js +26 -0
  73. package/lib/cjs/components/whatsapp-button-list.js.map +1 -0
  74. package/lib/cjs/components/whatsapp-template.js +3 -4
  75. package/lib/cjs/components/whatsapp-template.js.map +1 -1
  76. package/lib/cjs/contexts.d.ts +2 -3
  77. package/lib/cjs/contexts.js +3 -4
  78. package/lib/cjs/contexts.js.map +1 -1
  79. package/lib/cjs/dev-app.d.ts +2 -2
  80. package/lib/cjs/dev-app.js +2 -1
  81. package/lib/cjs/dev-app.js.map +1 -1
  82. package/lib/cjs/index-types.d.ts +94 -0
  83. package/lib/cjs/index-types.js +12 -0
  84. package/lib/cjs/index-types.js.map +1 -0
  85. package/lib/cjs/index.d.ts +9 -10
  86. package/lib/cjs/index.js +5 -7
  87. package/lib/cjs/index.js.map +1 -1
  88. package/lib/cjs/message-utils.d.ts +1 -1
  89. package/lib/cjs/message-utils.js +16 -16
  90. package/lib/cjs/message-utils.js.map +1 -1
  91. package/lib/cjs/msg-to-botonic.d.ts +1 -1
  92. package/lib/cjs/msg-to-botonic.js +24 -46
  93. package/lib/cjs/msg-to-botonic.js.map +1 -1
  94. package/lib/cjs/node-app.d.ts +2 -2
  95. package/lib/cjs/react-bot.d.ts +1 -1
  96. package/lib/cjs/react-bot.js +5 -6
  97. package/lib/cjs/react-bot.js.map +1 -1
  98. package/lib/cjs/util/error-boundary.d.ts +6 -39
  99. package/lib/cjs/util/error-boundary.js +17 -30
  100. package/lib/cjs/util/error-boundary.js.map +1 -1
  101. package/lib/cjs/util/index.d.ts +8 -0
  102. package/lib/cjs/util/index.js +10 -0
  103. package/lib/cjs/util/index.js.map +1 -1
  104. package/lib/cjs/util/webchat.d.ts +1 -1
  105. package/lib/cjs/webchat/components/attachment.js +7 -10
  106. package/lib/cjs/webchat/components/attachment.js.map +1 -1
  107. package/lib/cjs/webchat/components/common.js +2 -1
  108. package/lib/cjs/webchat/components/common.js.map +1 -1
  109. package/lib/cjs/webchat/components/conditional-animation.js +2 -3
  110. package/lib/cjs/webchat/components/conditional-animation.js.map +1 -1
  111. package/lib/cjs/webchat/components/emoji-picker.js +3 -12
  112. package/lib/cjs/webchat/components/emoji-picker.js.map +1 -1
  113. package/lib/cjs/webchat/components/persistent-menu.js +5 -19
  114. package/lib/cjs/webchat/components/persistent-menu.js.map +1 -1
  115. package/lib/cjs/webchat/components/send-button.js +2 -7
  116. package/lib/cjs/webchat/components/send-button.js.map +1 -1
  117. package/lib/cjs/webchat/components/typing-indicator.js +2 -5
  118. package/lib/cjs/webchat/components/typing-indicator.js.map +1 -1
  119. package/lib/cjs/webchat/devices/device-adapter.d.ts +2 -2
  120. package/lib/cjs/webchat/header.js +4 -14
  121. package/lib/cjs/webchat/header.js.map +1 -1
  122. package/lib/cjs/webchat/hooks.js +2 -1
  123. package/lib/cjs/webchat/hooks.js.map +1 -1
  124. package/lib/cjs/webchat/index-types.d.ts +55 -0
  125. package/lib/cjs/webchat/index-types.js +3 -0
  126. package/lib/cjs/webchat/index-types.js.map +1 -0
  127. package/lib/cjs/webchat/index.d.ts +4 -6
  128. package/lib/cjs/webchat/index.js +3 -3
  129. package/lib/cjs/webchat/index.js.map +1 -1
  130. package/lib/cjs/webchat/message-list.js +5 -12
  131. package/lib/cjs/webchat/message-list.js.map +1 -1
  132. package/lib/cjs/webchat/replies.js +2 -5
  133. package/lib/cjs/webchat/replies.js.map +1 -1
  134. package/lib/cjs/webchat/session-view.js +7 -30
  135. package/lib/cjs/webchat/session-view.js.map +1 -1
  136. package/lib/cjs/webchat/use-storage-state-hook.js +12 -2
  137. package/lib/cjs/webchat/use-storage-state-hook.js.map +1 -1
  138. package/lib/cjs/webchat/webchat-dev.d.ts +1 -1
  139. package/lib/cjs/webchat/webchat-dev.js +6 -10
  140. package/lib/cjs/webchat/webchat-dev.js.map +1 -1
  141. package/lib/cjs/webchat/webchat.d.ts +1 -1
  142. package/lib/cjs/webchat/webchat.js +43 -86
  143. package/lib/cjs/webchat/webchat.js.map +1 -1
  144. package/lib/cjs/webchat/webview.js +5 -13
  145. package/lib/cjs/webchat/webview.js.map +1 -1
  146. package/lib/cjs/webchat-app.d.ts +2 -2
  147. package/lib/cjs/webchat-app.js +6 -4
  148. package/lib/cjs/webchat-app.js.map +1 -1
  149. package/lib/cjs/webview-app.js +12 -13
  150. package/lib/cjs/webview-app.js.map +1 -1
  151. package/lib/esm/botonic-tester.js +5 -7
  152. package/lib/esm/botonic-tester.js.map +1 -1
  153. package/lib/esm/components/audio.js +3 -7
  154. package/lib/esm/components/audio.js.map +1 -1
  155. package/lib/esm/components/button.js +7 -18
  156. package/lib/esm/components/button.js.map +1 -1
  157. package/lib/esm/components/carousel.d.ts +2 -1
  158. package/lib/esm/components/carousel.js +6 -19
  159. package/lib/esm/components/carousel.js.map +1 -1
  160. package/lib/esm/components/custom-message.d.ts +3 -34
  161. package/lib/esm/components/custom-message.js +4 -10
  162. package/lib/esm/components/custom-message.js.map +1 -1
  163. package/lib/esm/components/document.js +3 -6
  164. package/lib/esm/components/document.js.map +1 -1
  165. package/lib/esm/components/element.js +3 -2
  166. package/lib/esm/components/element.js.map +1 -1
  167. package/lib/esm/components/handoff.js +3 -7
  168. package/lib/esm/components/handoff.js.map +1 -1
  169. package/lib/esm/components/image.js +3 -7
  170. package/lib/esm/components/image.js.map +1 -1
  171. package/lib/esm/components/index-types.d.ts +174 -0
  172. package/lib/esm/components/index-types.js +16 -0
  173. package/lib/esm/components/index-types.js.map +1 -0
  174. package/lib/esm/components/index.d.ts +23 -19
  175. package/lib/esm/components/index.js +3 -0
  176. package/lib/esm/components/index.js.map +1 -1
  177. package/lib/esm/components/location.js +3 -9
  178. package/lib/esm/components/location.js.map +1 -1
  179. package/lib/esm/components/message-template.js +2 -3
  180. package/lib/esm/components/message-template.js.map +1 -1
  181. package/lib/esm/components/message.js +7 -25
  182. package/lib/esm/components/message.js.map +1 -1
  183. package/lib/esm/components/multichannel/index-types.d.ts +45 -0
  184. package/lib/esm/components/multichannel/index-types.js +2 -0
  185. package/lib/esm/components/multichannel/index-types.js.map +1 -0
  186. package/lib/esm/components/multichannel/index.d.ts +11 -6
  187. package/lib/esm/components/multichannel/index.js +1 -0
  188. package/lib/esm/components/multichannel/index.js.map +1 -1
  189. package/lib/esm/components/multichannel/multichannel-button.js +4 -5
  190. package/lib/esm/components/multichannel/multichannel-button.js.map +1 -1
  191. package/lib/esm/components/multichannel/multichannel-carousel.js +3 -20
  192. package/lib/esm/components/multichannel/multichannel-carousel.js.map +1 -1
  193. package/lib/esm/components/multichannel/multichannel-context.d.ts +1 -1
  194. package/lib/esm/components/multichannel/multichannel-reply.js +2 -1
  195. package/lib/esm/components/multichannel/multichannel-reply.js.map +1 -1
  196. package/lib/esm/components/multichannel/multichannel-text.d.ts +1 -1
  197. package/lib/esm/components/multichannel/multichannel-text.js +9 -24
  198. package/lib/esm/components/multichannel/multichannel-text.js.map +1 -1
  199. package/lib/esm/components/multichannel/multichannel.js +11 -23
  200. package/lib/esm/components/multichannel/multichannel.js.map +1 -1
  201. package/lib/esm/components/pic.js +3 -2
  202. package/lib/esm/components/pic.js.map +1 -1
  203. package/lib/esm/components/raw.js +3 -12
  204. package/lib/esm/components/raw.js.map +1 -1
  205. package/lib/esm/components/reply.js +5 -8
  206. package/lib/esm/components/reply.js.map +1 -1
  207. package/lib/esm/components/share-button.js +2 -3
  208. package/lib/esm/components/share-button.js.map +1 -1
  209. package/lib/esm/components/subtitle.js +3 -4
  210. package/lib/esm/components/subtitle.js.map +1 -1
  211. package/lib/esm/components/text.js +3 -6
  212. package/lib/esm/components/text.js.map +1 -1
  213. package/lib/esm/components/timestamps.js +2 -5
  214. package/lib/esm/components/timestamps.js.map +1 -1
  215. package/lib/esm/components/title.js +3 -2
  216. package/lib/esm/components/title.js.map +1 -1
  217. package/lib/esm/components/video.js +3 -6
  218. package/lib/esm/components/video.js.map +1 -1
  219. package/lib/esm/components/webchat-settings.js +2 -1
  220. package/lib/esm/components/webchat-settings.js.map +1 -1
  221. package/lib/esm/components/whatsapp-button-list.d.ts +24 -0
  222. package/lib/esm/components/whatsapp-button-list.js +22 -0
  223. package/lib/esm/components/whatsapp-button-list.js.map +1 -0
  224. package/lib/esm/components/whatsapp-template.js +3 -4
  225. package/lib/esm/components/whatsapp-template.js.map +1 -1
  226. package/lib/esm/contexts.d.ts +2 -3
  227. package/lib/esm/contexts.js +3 -3
  228. package/lib/esm/contexts.js.map +1 -1
  229. package/lib/esm/dev-app.d.ts +2 -2
  230. package/lib/esm/dev-app.js +2 -1
  231. package/lib/esm/dev-app.js.map +1 -1
  232. package/lib/esm/index-types.d.ts +94 -0
  233. package/lib/esm/index-types.js +9 -0
  234. package/lib/esm/index-types.js.map +1 -0
  235. package/lib/esm/index.d.ts +9 -9
  236. package/lib/esm/index.js +4 -3
  237. package/lib/esm/index.js.map +1 -1
  238. package/lib/esm/message-utils.d.ts +2 -1
  239. package/lib/esm/message-utils.js +1 -1
  240. package/lib/esm/message-utils.js.map +1 -1
  241. package/lib/esm/msg-to-botonic.d.ts +1 -1
  242. package/lib/esm/msg-to-botonic.js +23 -45
  243. package/lib/esm/msg-to-botonic.js.map +1 -1
  244. package/lib/esm/node-app.d.ts +4 -4
  245. package/lib/esm/react-bot.d.ts +2 -1
  246. package/lib/esm/react-bot.js +4 -5
  247. package/lib/esm/react-bot.js.map +1 -1
  248. package/lib/esm/util/error-boundary.d.ts +6 -39
  249. package/lib/esm/util/error-boundary.js +17 -30
  250. package/lib/esm/util/error-boundary.js.map +1 -1
  251. package/lib/esm/util/index.d.ts +8 -0
  252. package/lib/esm/util/index.js +8 -1
  253. package/lib/esm/util/index.js.map +1 -1
  254. package/lib/esm/util/webchat.d.ts +1 -1
  255. package/lib/esm/webchat/components/attachment.js +8 -11
  256. package/lib/esm/webchat/components/attachment.js.map +1 -1
  257. package/lib/esm/webchat/components/common.js +2 -1
  258. package/lib/esm/webchat/components/common.js.map +1 -1
  259. package/lib/esm/webchat/components/conditional-animation.js +2 -3
  260. package/lib/esm/webchat/components/conditional-animation.js.map +1 -1
  261. package/lib/esm/webchat/components/emoji-picker.js +3 -12
  262. package/lib/esm/webchat/components/emoji-picker.js.map +1 -1
  263. package/lib/esm/webchat/components/persistent-menu.js +5 -19
  264. package/lib/esm/webchat/components/persistent-menu.js.map +1 -1
  265. package/lib/esm/webchat/components/send-button.js +2 -7
  266. package/lib/esm/webchat/components/send-button.js.map +1 -1
  267. package/lib/esm/webchat/components/typing-indicator.js +2 -5
  268. package/lib/esm/webchat/components/typing-indicator.js.map +1 -1
  269. package/lib/esm/webchat/devices/device-adapter.d.ts +2 -2
  270. package/lib/esm/webchat/header.js +4 -14
  271. package/lib/esm/webchat/header.js.map +1 -1
  272. package/lib/esm/webchat/hooks.js +2 -1
  273. package/lib/esm/webchat/hooks.js.map +1 -1
  274. package/lib/esm/webchat/index-types.d.ts +55 -0
  275. package/lib/esm/webchat/index-types.js +2 -0
  276. package/lib/esm/webchat/index-types.js.map +1 -0
  277. package/lib/esm/webchat/index.d.ts +4 -6
  278. package/lib/esm/webchat/index.js +2 -3
  279. package/lib/esm/webchat/index.js.map +1 -1
  280. package/lib/esm/webchat/message-list.js +5 -12
  281. package/lib/esm/webchat/message-list.js.map +1 -1
  282. package/lib/esm/webchat/replies.js +2 -5
  283. package/lib/esm/webchat/replies.js.map +1 -1
  284. package/lib/esm/webchat/session-view.js +7 -30
  285. package/lib/esm/webchat/session-view.js.map +1 -1
  286. package/lib/esm/webchat/use-storage-state-hook.js +12 -2
  287. package/lib/esm/webchat/use-storage-state-hook.js.map +1 -1
  288. package/lib/esm/webchat/webchat-dev.d.ts +1 -1
  289. package/lib/esm/webchat/webchat-dev.js +6 -10
  290. package/lib/esm/webchat/webchat-dev.js.map +1 -1
  291. package/lib/esm/webchat/webchat.d.ts +1 -1
  292. package/lib/esm/webchat/webchat.js +43 -86
  293. package/lib/esm/webchat/webchat.js.map +1 -1
  294. package/lib/esm/webchat/webview.js +5 -13
  295. package/lib/esm/webchat/webview.js.map +1 -1
  296. package/lib/esm/webchat-app.d.ts +5 -4
  297. package/lib/esm/webchat-app.js +4 -2
  298. package/lib/esm/webchat-app.js.map +1 -1
  299. package/lib/esm/webview-app.js +5 -6
  300. package/lib/esm/webview-app.js.map +1 -1
  301. package/package.json +22 -16
  302. package/src/botonic-tester.jsx +1 -1
  303. package/src/components/{index.d.ts → index-types.ts} +22 -43
  304. package/src/components/{index.js → index.ts} +6 -0
  305. package/src/components/multichannel/{index.d.ts → index-types.ts} +1 -10
  306. package/src/components/multichannel/{index.js → index.ts} +2 -0
  307. package/src/components/whatsapp-button-list.tsx +64 -0
  308. package/src/contexts.jsx +3 -3
  309. package/src/index-types.ts +195 -0
  310. package/src/{index.js → index.ts} +4 -3
  311. package/src/message-utils.js +1 -1
  312. package/src/msg-to-botonic.jsx +11 -11
  313. package/src/react-bot.jsx +1 -1
  314. package/src/util/error-boundary.jsx +15 -30
  315. package/src/util/index.ts +8 -0
  316. package/src/webchat/components/attachment.jsx +10 -2
  317. package/src/webchat/components/emoji-picker.jsx +7 -1
  318. package/src/webchat/hooks.js +2 -1
  319. package/src/webchat/{index.d.ts → index-types.ts} +11 -13
  320. package/src/webchat/{index.js → index.ts} +3 -3
  321. package/src/webchat/use-storage-state-hook.js +13 -2
  322. package/src/webchat/webchat.jsx +5 -7
  323. package/src/webchat-app.jsx +2 -1
  324. package/src/webview-app.tsx +1 -1
  325. package/src/index.d.ts +0 -238
  326. package/src/util/index.d.ts +0 -9
  327. package/src/util/index.js +0 -0
@@ -0,0 +1,195 @@
1
+ import type {
2
+ BotRequest as CoreBotRequest,
3
+ Input as CoreInput,
4
+ InputType as CoreInputType,
5
+ Plugin as CorePlugin,
6
+ Route as CoreRoute,
7
+ Routes as CoreRoutes,
8
+ Session as CoreSession,
9
+ SessionUser as CoreSessionUser,
10
+ } from '@botonic/core/lib/esm/models/legacy-types'
11
+ import React from 'react'
12
+
13
+ import {
14
+ ButtonProps,
15
+ ReplyProps,
16
+ ThemeProps,
17
+ WebchatSettingsProps,
18
+ Webview,
19
+ } from './components/index-types'
20
+ import { WebchatState } from './webchat'
21
+
22
+ /**
23
+ * See @botonic/core's Response for the description of the Response's semantics*/
24
+ export interface BotResponse extends CoreBotRequest {
25
+ response: [React.ReactNode]
26
+ }
27
+
28
+ export interface Route extends CoreRoute {
29
+ action?: React.ComponentType<any>
30
+ retryAction?: React.ComponentType<any>
31
+ }
32
+ export type Routes = CoreRoutes<Route>
33
+
34
+ // Parameters of the actions' botonicInit method
35
+ export interface ActionRequest {
36
+ defaultDelay: number
37
+ defaultTyping: number
38
+ input: CoreInput
39
+ lastRoutePath: string
40
+ params: { [key: string]: string }
41
+ plugins: { [id: string]: CorePlugin }
42
+ session: CoreSession
43
+ }
44
+
45
+ export interface RequestContextInterface extends ActionRequest {
46
+ getString: (stringId: string) => string
47
+ setLocale: (locale: string) => string
48
+ }
49
+
50
+ export interface CustomMessageType {
51
+ customTypeName: string
52
+ }
53
+
54
+ // TODO: Reuse types to be reused in respective components
55
+ // export class WebchatApp {
56
+ // constructor(options: WebchatAppArgs)
57
+ // addBotMessage(message: WebchatMessage): void
58
+ // addBotText(text: string): void
59
+ // addUserMessage(message: WebchatMessage): void
60
+ // addUserPayload(payload: string): void
61
+ // addUserText(text: string): void
62
+ // clearMessages(): void
63
+ // close(): void
64
+ // closeCoverComponent(): void
65
+ // destroy(): void
66
+ // getComponent(
67
+ // host: HTMLElement,
68
+ // optionsAtRuntime?: WebchatAppArgs
69
+ // ): React.ForwardRefExoticComponent<any>
70
+ // getLastMessageUpdate(): string
71
+ // getMessages(): WebchatMessage[]
72
+ // getVisibility(): Promise<boolean>
73
+ // isWebchatVisible({ appId: string }): Promise<boolean>
74
+ // onCloseWebchat(args: any): void
75
+ // onInitWebchat(args: any): void
76
+ // onOpenWebchat(args: any): void
77
+ // onServiceEvent(event: Event): void
78
+ // onStateChange(args: OnStateChangeArgs): void
79
+ // onUserInput(args: OnUserInputArgs): Promise<void>
80
+ // open(): void
81
+ // openCoverComponent(): void
82
+ // render(dest?: HTMLElement, optionsAtRuntime?: WebchatAppArgs): void
83
+ // resendUnsentInputs(): Promise<void>
84
+ // resolveWebchatVisibility(optionsAtRuntime: {
85
+ // appId: string
86
+ // visibility: () => boolean
87
+ // }): Promise<boolean>
88
+ // setTyping(enable: boolean): void
89
+ // toggle(): void
90
+ // toggleCoverComponent(): void
91
+ // updateMessageInfo(msgId: string, messageInfo: MessageInfo): void
92
+ // updateLastMessageDate(date: string): void
93
+ // updateUser(user: Partial<CoreSessionUser>): void
94
+ // updateWebchatSettings(settings: WebchatSettingsProps): void
95
+ // renderCustomComponent(customComponent: React.ReactNode): void
96
+ // unmountCustomComponent(): void
97
+ // }
98
+
99
+ // export interface WebchatArgs {
100
+ // blockInputs?: BlockInputOption[]
101
+ // coverComponent?: CoverComponentOptions
102
+ // defaultDelay?: number
103
+ // defaultTyping?: number
104
+ // enableAnimations?: boolean
105
+ // enableAttachments?: boolean
106
+ // enableEmojiPicker?: boolean
107
+ // enableUserInput?: boolean
108
+ // shadowDOM?: boolean | (() => boolean)
109
+ // hostId?: string
110
+ // getString?: (stringId: string, session: CoreSession) => string
111
+ // onClose?: (app: WebchatApp, args: any) => void
112
+ // onInit?: (app: WebchatApp, args: any) => void
113
+ // onMessage?: (app: WebchatApp, message: WebchatMessage) => void
114
+ // onOpen?: (app: WebchatApp, args: any) => void
115
+ // onConnectionChange?: (app: WebchatApp, isOnline: boolean) => void
116
+ // persistentMenu?: PersistentMenuTheme
117
+ // storage?: Storage | null
118
+ // storageKey?: any
119
+ // theme?: ThemeProps
120
+ // }
121
+
122
+ // export interface WebchatAppArgs extends WebchatArgs {
123
+ export interface WebchatAppArgs {
124
+ appId?: string
125
+ visibility?: () => boolean
126
+ }
127
+
128
+ export interface WebchatMessage {
129
+ ack: 0 | 1
130
+ buttons: ButtonProps[]
131
+ data: any
132
+ delay: number
133
+ display: boolean
134
+ from: 'user' | 'bot'
135
+ id: string
136
+ markdown: boolean
137
+ replies: ReplyProps[]
138
+ timestamp: string
139
+ type: CoreInputType
140
+ typing: number
141
+ }
142
+
143
+ export interface OnUserInputArgs {
144
+ input: CoreInput
145
+ lastRoutePath?: string
146
+ session?: CoreSession
147
+ user: CoreSessionUser
148
+ }
149
+
150
+ export interface OnStateChangeArgs {
151
+ messagesJSON: WebchatMessage[]
152
+ user: CoreSessionUser
153
+ }
154
+
155
+ export interface MessageInfo {
156
+ data: any | 'typing_on'
157
+ id: string
158
+ type: 'update_webchat_settings' | 'sender_action'
159
+ }
160
+
161
+ export interface Event {
162
+ action?: 'update_message_info'
163
+ isError?: boolean
164
+ message?: MessageInfo
165
+ }
166
+
167
+ export interface WebchatContextProps {
168
+ sendText: (text: string, payload?: string) => void
169
+ sendAttachment: (attachment: File) => void
170
+ sendPayload: (payload: string) => void
171
+ sendInput: (input: CoreInput) => void
172
+ openWebview: (webviewComponent: Webview) => void
173
+ addMessage: (message: WebchatMessage) => void
174
+ updateMessage: (message: WebchatMessage) => void
175
+ updateReplies: (replies: boolean) => void
176
+ updateLatestInput: (input: CoreInput) => void
177
+ closeWebview: () => void
178
+ toggleWebchat: () => void
179
+ getThemeProperty: (property: string, defaultValue?: string) => any
180
+ resolveCase: () => void
181
+ theme: ThemeProps
182
+ webchatState: WebchatState
183
+ updateWebchatDevSettings: (settings: WebchatSettingsProps) => void
184
+ updateUser: (user: Partial<CoreSessionUser>) => void
185
+ }
186
+
187
+ // export class DevApp extends WebchatApp {
188
+ // constructor(args: WebchatAppArgs)
189
+ // onUserInput(args: OnUserInputArgs): Promise<void>
190
+ // render(dest: HTMLElement, optionsAtRuntime: WebchatAppArgs): void
191
+ // }
192
+
193
+ export * from './components'
194
+ export * from './util'
195
+ export * from './webchat'
@@ -1,10 +1,11 @@
1
1
  export { BotonicInputTester, BotonicOutputTester } from './botonic-tester'
2
- export * from './components'
2
+ // export * from './components'
3
3
  export { RequestContext, WebchatContext } from './contexts'
4
4
  export { DevApp } from './dev-app'
5
+ export * from './index-types'
5
6
  export { msgsToBotonic, msgToBotonic } from './msg-to-botonic'
6
7
  export { NodeApp } from './node-app'
7
- export { staticAsset } from './util/environment'
8
- export { getBotonicApp, Webchat } from './webchat/index.js'
8
+ export * from './util'
9
+ // export { getBotonicApp, Webchat } from './webchat/index'
9
10
  export { WebchatApp } from './webchat-app'
10
11
  export { WebviewApp } from './webview-app'
@@ -1,4 +1,4 @@
1
- import { INPUT } from '@botonic/core'
1
+ import { INPUT } from '@botonic/core/lib/esm/models/legacy-types'
2
2
 
3
3
  import { MAX_ALLOWED_SIZE_MB, MIME_WHITELIST } from './constants'
4
4
 
@@ -1,16 +1,5 @@
1
1
  import React from 'react'
2
2
 
3
- import {
4
- isAudio,
5
- isButtonMessage,
6
- isCarousel,
7
- isCustom,
8
- isDocument,
9
- isImage,
10
- isLocation,
11
- isText,
12
- isVideo,
13
- } from './message-utils'
14
3
  import { Audio } from './components/audio'
15
4
  import { Button } from './components/button'
16
5
  import { ButtonsDisabler } from './components/buttons-disabler'
@@ -25,6 +14,17 @@ import { Subtitle } from './components/subtitle'
25
14
  import { Text } from './components/text'
26
15
  import { Title } from './components/title'
27
16
  import { Video } from './components/video'
17
+ import {
18
+ isAudio,
19
+ isButtonMessage,
20
+ isCarousel,
21
+ isCustom,
22
+ isDocument,
23
+ isImage,
24
+ isLocation,
25
+ isText,
26
+ isVideo,
27
+ } from './message-utils'
28
28
 
29
29
  /**
30
30
  *
package/src/react-bot.jsx CHANGED
@@ -1,4 +1,4 @@
1
- import { CoreBot } from '@botonic/core'
1
+ import { CoreBot } from '@botonic/core/lib/esm'
2
2
  import React from 'react'
3
3
 
4
4
  import { Text } from './components/text'
@@ -1,48 +1,33 @@
1
+ // @ts-nocheck
1
2
  import { isNode } from '@botonic/core'
2
- import React from 'react'
3
+ import React, { useState } from 'react'
3
4
 
4
5
  import { Text } from '../components/text'
5
6
 
6
- /**
7
- * Replaces crashed children with the provided fallback component.
8
- * https://reactjs.org/blog/2017/07/26/error-handling-in-react-16.html
9
- * See alternative at https://stackoverflow.com/a/60255291/145289
10
- */
11
7
  export const createErrorBoundary = ({
12
- errorComponent = props => <Text>The message cannot be displayed</Text>,
8
+ errorComponent = ({ errorMessage }) => (
9
+ <Text>The message cannot be displayed</Text>
10
+ ),
13
11
  } = {}) => {
14
- class ErrorBoundary extends React.Component {
15
- constructor(props) {
16
- super(props)
17
- this.state = { error: null }
18
- }
12
+ const ErrorBoundary = ({ children }) => {
13
+ const [error, setError] = useState(null)
19
14
 
20
- /**
21
- * @param error the exception which was trown
22
- * @param errorInfo the stack of component names at the error
23
- */
24
- componentDidCatch(error, errorInfo) {
25
- // No need to log the error because at least chrome & firefox already show
26
- // both component and call stacks
15
+ const componentDidCatch = (error, errorInfo) => {
27
16
  if (isNode()) {
28
- // In node, only the component stack is displayed
29
17
  console.error(`Failure at:`, error)
30
18
  }
31
19
  }
32
20
 
33
- static getDerivedStateFromError(error) {
21
+ const getDerivedStateFromError = error => {
34
22
  return { error }
35
23
  }
36
24
 
37
- render() {
38
- if (this.state.error) {
39
- return errorComponent({
40
- ...this.props,
41
- errorMessage: this.state.error.message,
42
- })
43
- } else {
44
- return this.props.children
45
- }
25
+ if (error) {
26
+ return errorComponent({
27
+ errorMessage: error.message,
28
+ })
29
+ } else {
30
+ return children
46
31
  }
47
32
  }
48
33
 
@@ -0,0 +1,8 @@
1
+ export * from './dom'
2
+ export * from './environment'
3
+ export * from './error-boundary'
4
+ export * from './logs'
5
+ export * from './objects'
6
+ export * from './react'
7
+ export * from './regexs'
8
+ export * from './webchat'
@@ -1,4 +1,4 @@
1
- import React, { useContext } from 'react'
1
+ import React, { useContext, useRef } from 'react'
2
2
 
3
3
  import AttachmentIcon from '../../assets/attachment-icon.svg'
4
4
  import { ROLES, WEBCHAT } from '../../constants'
@@ -9,6 +9,8 @@ import { Icon } from './common'
9
9
  export const Attachment = ({ onChange, accept, enableAttachments }) => {
10
10
  const { getThemeProperty } = useContext(WebchatContext)
11
11
 
12
+ const fileInputRef = useRef(null)
13
+
12
14
  const CustomAttachments = getThemeProperty(
13
15
  WEBCHAT.CUSTOM_PROPERTIES.customAttachments,
14
16
  undefined
@@ -25,6 +27,11 @@ export const Attachment = ({ onChange, accept, enableAttachments }) => {
25
27
  }
26
28
  const attachmentsEnabled = isAttachmentsEnabled()
27
29
 
30
+ const handleOnChange = event => {
31
+ onChange(event)
32
+ fileInputRef.current.value = null
33
+ }
34
+
28
35
  return (
29
36
  <>
30
37
  {attachmentsEnabled ? (
@@ -38,11 +45,12 @@ export const Attachment = ({ onChange, accept, enableAttachments }) => {
38
45
  )}
39
46
  </label>
40
47
  <input
48
+ ref={fileInputRef}
41
49
  type='file'
42
50
  name='file'
43
51
  id='attachment'
44
52
  style={{ display: 'none' }}
45
- onChange={onChange}
53
+ onChange={handleOnChange}
46
54
  accept={accept}
47
55
  />
48
56
  </div>
@@ -64,7 +64,13 @@ export const OpenedEmojiPicker = props => {
64
64
  <div ref={ref}>
65
65
  {isComponentVisible && (
66
66
  <Container role={ROLES.EMOJI_PICKER}>
67
- <Picker onEmojiClick={props.onEmojiClick} disableAutoFocus={true} />
67
+ <Picker
68
+ width='100%'
69
+ height='19rem'
70
+ previewConfig={{ showPreview: false }}
71
+ onEmojiClick={props.onEmojiClick}
72
+ disableAutoFocus={true}
73
+ />
68
74
  </Container>
69
75
  )}
70
76
  </div>
@@ -247,7 +247,8 @@ export function useComponentVisible(initialIsVisible, onClickOutside) {
247
247
  const [isComponentVisible, setIsComponentVisible] = useState(initialIsVisible)
248
248
  const ref = useRef(null)
249
249
  const handleClickOutside = event => {
250
- if (ref.current && !ref.current.contains(event.path[0])) {
250
+ const target = event.path ? event.path[0] : event.target
251
+ if (ref.current && !ref.current.contains(target)) {
251
252
  setIsComponentVisible(false)
252
253
  onClickOutside()
253
254
  }
@@ -1,9 +1,10 @@
1
- import * as core from '@botonic/core'
2
- import * as React from 'react'
1
+ import type {
2
+ Input as CoreInput,
3
+ Session as CoreSession,
4
+ } from '@botonic/core/lib/esm/models/legacy-types'
3
5
  import { RefObject } from 'react'
4
6
 
5
- import { Reply, Webview } from '../components/index'
6
- import { Message, WebchatApp, WebchatArgs } from '../index'
7
+ import { Webview } from '../components/index-types'
7
8
 
8
9
  export interface WebchatStateTheme {
9
10
  headerTitle: string
@@ -20,13 +21,13 @@ export interface WebchatState {
20
21
  width: number
21
22
  height: number
22
23
  messagesJSON: any[]
23
- messagesComponents: Message[]
24
- replies: Reply[]
25
- latestInput: Partial<core.Input>
24
+ messagesComponents: any[]
25
+ replies: any[]
26
+ latestInput: Partial<CoreInput>
26
27
  typing: boolean
27
28
  webview: Webview | null
28
29
  webviewParams: null
29
- session: Partial<core.Session>
30
+ session: Partial<CoreSession>
30
31
  lastRoutePath: string | null
31
32
  handoff: boolean
32
33
  theme: WebchatStateTheme
@@ -41,11 +42,11 @@ export interface WebchatState {
41
42
  currentAttachment: File | undefined
42
43
  }
43
44
 
44
- export interface WebchatProps extends WebchatArgs {
45
+ // export interface WebchatProps extends WebchatArgs {
46
+ export interface WebchatProps {
45
47
  ref: RefObject<any>
46
48
  onConnectionRegained?: () => Promise<void>
47
49
  }
48
- export const WebChat: React.ForwardRefExoticComponent<WebchatProps>
49
50
 
50
51
  export interface WebchatDevProps extends WebchatProps {
51
52
  initialDevSettings?: {
@@ -53,9 +54,6 @@ export interface WebchatDevProps extends WebchatProps {
53
54
  showSessionView?: boolean
54
55
  }
55
56
  }
56
- export const WebChatDev: React.ForwardRefExoticComponent<WebchatDevProps>
57
-
58
- export function getBotonicApp(): WebchatApp
59
57
 
60
58
  export interface CoverComponentProps {
61
59
  closeComponent: () => void
@@ -1,11 +1,11 @@
1
+ // @ts-nocheck
1
2
  export { Webchat } from './webchat'
2
3
  export { WebchatDev } from './webchat-dev'
3
4
 
4
- /**
5
- * @returns {WebChatApp}
6
- */
7
5
  export function getBotonicApp() {
8
6
  // Botonic is exported from your bot
9
7
  // eslint-disable-next-line no-undef
10
8
  return Botonic
11
9
  }
10
+
11
+ export * from './index-types'
@@ -1,9 +1,20 @@
1
1
  import { useCallback, useEffect, useState } from 'react'
2
2
 
3
- //Code taken from https://github.com/leny/react-use-storage
4
- const evtTarget = new EventTarget()
3
+ // Code taken from https://github.com/leny/react-use-storage/blob/master/src/index.js
4
+ const IS_BROWSER =
5
+ typeof window !== 'undefined' &&
6
+ typeof navigator !== 'undefined' &&
7
+ typeof document !== 'undefined'
5
8
 
6
9
  export function useStorageState(storage, key, defaultValue) {
10
+ let evtTarget
11
+
12
+ try {
13
+ evtTarget = new EventTarget()
14
+ } catch {
15
+ evtTarget = (IS_BROWSER ? document : {})?.createElement?.('phony')
16
+ }
17
+
7
18
  const raw = storage?.getItem(key)
8
19
 
9
20
  const [value, setValue] = useState(raw ? JSON.parse(raw) : defaultValue)
@@ -1,5 +1,4 @@
1
1
  import { INPUT, isMobile, params2queryString } from '@botonic/core'
2
- import { motion } from 'framer-motion'
3
2
  import merge from 'lodash.merge'
4
3
  import React, {
5
4
  forwardRef,
@@ -161,7 +160,7 @@ const DarkBackgroundMenu = styled.div`
161
160
  height: 100%;
162
161
  `
163
162
 
164
- // eslint-disable-next-line complexity
163
+ // eslint-disable-next-line complexity, react/display-name
165
164
  export const Webchat = forwardRef((props, ref) => {
166
165
  const {
167
166
  webchatState,
@@ -372,8 +371,8 @@ export const Webchat = forwardRef((props, ref) => {
372
371
  const openWebview = (webviewComponent, params) =>
373
372
  updateWebview(webviewComponent, params)
374
373
 
375
- const handleSelectedEmoji = (event, emojiObject) => {
376
- textArea.current.value += emojiObject.emoji
374
+ const handleSelectedEmoji = event => {
375
+ textArea.current.value += event.emoji
377
376
  textArea.current.focus()
378
377
  }
379
378
 
@@ -712,8 +711,6 @@ export const Webchat = forwardRef((props, ref) => {
712
711
  }
713
712
  }, [webchatState.isWebchatOpen])
714
713
 
715
- const textArea = useRef()
716
-
717
714
  const getTriggerImage = () => {
718
715
  const triggerImage = getThemeProperty(
719
716
  WEBCHAT.CUSTOM_PROPERTIES.triggerButtonImage,
@@ -768,6 +765,7 @@ export const Webchat = forwardRef((props, ref) => {
768
765
 
769
766
  const userInputEnabled = isUserInputEnabled()
770
767
 
768
+ const textArea = useRef(null)
771
769
  const userInputArea = () => {
772
770
  return (
773
771
  userInputEnabled && (
@@ -792,6 +790,7 @@ export const Webchat = forwardRef((props, ref) => {
792
790
 
793
791
  <TextAreaContainer>
794
792
  <Textarea
793
+ inputRef={textArea}
795
794
  name='text'
796
795
  onFocus={() => deviceAdapter.onFocus(host)}
797
796
  onBlur={() => deviceAdapter.onBlur()}
@@ -803,7 +802,6 @@ export const Webchat = forwardRef((props, ref) => {
803
802
  WEBCHAT.DEFAULTS.PLACEHOLDER
804
803
  )}
805
804
  autoFocus={true}
806
- inputRef={textArea}
807
805
  onKeyDown={e => onKeyDown(e)}
808
806
  onKeyUp={onKeyUp}
809
807
  style={{
@@ -1,4 +1,5 @@
1
- import { HubtypeService, INPUT } from '@botonic/core'
1
+ import { HubtypeService } from '@botonic/core'
2
+ import { INPUT } from '@botonic/core/lib/esm/models/legacy-types'
2
3
  import merge from 'lodash.merge'
3
4
  import React, { createRef } from 'react'
4
5
  import { render, unmountComponentAtNode } from 'react-dom'
@@ -1,6 +1,6 @@
1
1
  // @ts-nocheck
2
- import type { PROVIDER } from '@botonic/core'
3
2
  import { getString } from '@botonic/core/lib/esm/i18n'
3
+ import { PROVIDER } from '@botonic/core/lib/esm/models/legacy-types'
4
4
  import { params2queryString } from '@botonic/core/lib/esm/utils'
5
5
  import axios from 'axios'
6
6
  import React from 'react'