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