@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
@@ -2,7 +2,7 @@
2
2
  import { getString, params2queryString, PROVIDER } from '@botonic/core'
3
3
  import axios from 'axios'
4
4
  import React from 'react'
5
- import { render } from 'react-dom'
5
+ import { createRoot } from 'react-dom/client'
6
6
  import { BrowserRouter, Route } from 'react-router-dom'
7
7
 
8
8
  import { CloseWebviewOptions, WebviewRequestContext } from './contexts'
@@ -110,11 +110,13 @@ export class WebviewApp {
110
110
  }
111
111
 
112
112
  render(dest) {
113
- render(
113
+ const component = (
114
114
  <BrowserRouter>
115
115
  <App webviews={this.webviews} locales={this.locales} />
116
- </BrowserRouter>,
117
- dest
116
+ </BrowserRouter>
118
117
  )
118
+ const container = dest
119
+ const reactRoot = createRoot(container)
120
+ reactRoot.render(component)
119
121
  }
120
122
  }
@@ -1,389 +0,0 @@
1
- import { HubtypeService, INPUT } from '@botonic/core'
2
- import merge from 'lodash.merge'
3
- import React, { createRef } from 'react'
4
- import { render, unmountComponentAtNode } from 'react-dom'
5
-
6
- import { WEBCHAT } from './constants'
7
- import { SENDERS, Typing } from './index-types'
8
- import { msgToBotonic } from './msg-to-botonic'
9
- import { isShadowDOMSupported, onDOMLoaded } from './util/dom'
10
- import { Webchat } from './webchat/webchat'
11
-
12
- export class WebchatApp {
13
- constructor({
14
- theme = {},
15
- persistentMenu,
16
- coverComponent,
17
- blockInputs,
18
- enableEmojiPicker,
19
- enableAttachments,
20
- enableUserInput,
21
- enableAnimations,
22
- hostId,
23
- shadowDOM,
24
- defaultDelay,
25
- defaultTyping,
26
- storage,
27
- storageKey,
28
- onInit,
29
- onOpen,
30
- onClose,
31
- onMessage,
32
- onTrackEvent,
33
- onConnectionChange,
34
- appId,
35
- visibility,
36
- server,
37
- }) {
38
- this.theme = theme
39
- this.persistentMenu = persistentMenu
40
- this.coverComponent = coverComponent
41
- this.blockInputs = blockInputs
42
- this.enableEmojiPicker = enableEmojiPicker
43
- this.enableAttachments = enableAttachments
44
- this.enableUserInput = enableUserInput
45
- this.enableAnimations = enableAnimations
46
- this.shadowDOM = Boolean(
47
- typeof shadowDOM === 'function' ? shadowDOM() : shadowDOM
48
- )
49
- if (this.shadowDOM && !isShadowDOMSupported()) {
50
- console.warn('[botonic] ShadowDOM not supported on this browser')
51
- this.shadowDOM = false
52
- }
53
- this.hostId = hostId || WEBCHAT.DEFAULTS.HOST_ID
54
- this.defaultDelay = defaultDelay
55
- this.defaultTyping = defaultTyping
56
- this.storage = storage === undefined ? localStorage : storage
57
- this.storageKey = storageKey || WEBCHAT.DEFAULTS.STORAGE_KEY
58
- this.onInit = onInit
59
- this.onOpen = onOpen
60
- this.onClose = onClose
61
- this.onMessage = onMessage
62
- this.onTrackEvent = onTrackEvent
63
- this.onConnectionChange = onConnectionChange
64
- this.visibility = visibility
65
- this.server = server
66
- this.webchatRef = createRef()
67
- this.appId = appId
68
- }
69
-
70
- createRootElement(host) {
71
- // Create root element <div id='root'> if not exists
72
- // Create shadowDOM to root element if needed
73
- if (host) {
74
- if (host.id && this.hostId) {
75
- if (host.id != this.hostId) {
76
- console.warn(
77
- `[botonic] Host ID "${host.id}" don't match 'hostId' option: ${this.hostId}. Using value: ${host.id}.`
78
- )
79
- this.hostId = host.id
80
- }
81
- } else if (host.id) this.hostId = host.id
82
- else if (this.hostId) host.id = this.hostId
83
- } else {
84
- host = document.getElementById(this.hostId)
85
- }
86
- if (!host) {
87
- host = document.createElement('div')
88
- host.id = this.hostId
89
- if (document.body.firstChild)
90
- document.body.insertBefore(host, document.body.firstChild)
91
- else document.body.appendChild(host)
92
- }
93
- this.host = this.shadowDOM ? host.attachShadow({ mode: 'open' }) : host
94
- }
95
-
96
- getReactMountNode(node) {
97
- if (!node) node = this.host
98
- return node.shadowRoot ? node.shadowRoot : node
99
- }
100
-
101
- onInitWebchat(...args) {
102
- this.onInit && this.onInit(this, ...args)
103
- }
104
-
105
- onOpenWebchat(...args) {
106
- this.onOpen && this.onOpen(this, ...args)
107
- }
108
-
109
- onCloseWebchat(...args) {
110
- this.onClose && this.onClose(this, ...args)
111
- }
112
-
113
- async onUserInput({ user, input }) {
114
- this.onMessage &&
115
- this.onMessage(this, {
116
- sentBy: SENDERS.user,
117
- message: input,
118
- isUnread: false,
119
- })
120
- return this.hubtypeService.postMessage(user, input)
121
- }
122
-
123
- async onConnectionRegained() {
124
- return this.hubtypeService.onConnectionRegained()
125
- }
126
-
127
- onStateChange({ session: { user }, messagesJSON }) {
128
- const lastMessage = messagesJSON[messagesJSON.length - 1]
129
- const lastMessageId = lastMessage && lastMessage.id
130
- const lastMessageUpdateDate = this.getLastMessageUpdate()
131
- if (this.hubtypeService) {
132
- this.hubtypeService.lastMessageId = lastMessageId
133
- this.hubtypeService.lastMessageUpdateDate = lastMessageUpdateDate
134
- } else if (!this.hubtypeService && user) {
135
- this.hubtypeService = new HubtypeService({
136
- appId: this.appId,
137
- user,
138
- lastMessageId,
139
- lastMessageUpdateDate,
140
- onEvent: event => this.onServiceEvent(event),
141
- unsentInputs: () =>
142
- this.webchatRef.current
143
- .getMessages()
144
- .filter(msg => msg.ack === 0 && msg.unsentInput),
145
- server: this.server,
146
- })
147
- }
148
- }
149
-
150
- onServiceEvent(event) {
151
- if (event.action === 'connectionChange') {
152
- this.onConnectionChange && this.onConnectionChange(this, event.online)
153
- this.webchatRef.current.setOnline(event.online)
154
- } else if (event.action === 'update_message_info') {
155
- this.updateMessageInfo(event.message.id, event.message)
156
- } else if (event.message?.type === 'update_webchat_settings') {
157
- this.updateWebchatSettings(event.message.data)
158
- } else if (event.message?.type === 'sender_action') {
159
- this.setTyping(event.message.data === Typing.On)
160
- } else {
161
- this.onMessage &&
162
- this.onMessage(this, { sentBy: SENDERS.bot, message: event.message })
163
- this.addBotMessage(event.message)
164
- }
165
- }
166
-
167
- updateUser(user) {
168
- this.webchatRef.current.updateUser(user)
169
- }
170
-
171
- addBotMessage(message) {
172
- message.ack = 0
173
- message.isUnread = true
174
- message.sentBy = message.sent_by?.split('message_sent_by_')[1]
175
- delete message.sent_by
176
- const response = msgToBotonic(
177
- message,
178
- this.theme.message?.customTypes || this.theme.customMessageTypes
179
- )
180
-
181
- this.webchatRef.current.addBotResponse({
182
- response,
183
- })
184
- }
185
-
186
- addBotText(text) {
187
- this.addBotMessage({ type: INPUT.TEXT, data: text })
188
- }
189
-
190
- addUserMessage(message) {
191
- this.webchatRef.current.addUserMessage(message)
192
- }
193
-
194
- addUserText(text) {
195
- this.addUserMessage({ type: INPUT.TEXT, data: text })
196
- }
197
-
198
- addUserPayload(payload) {
199
- this.addUserMessage({ type: INPUT.POSTBACK, payload })
200
- }
201
-
202
- setTyping(typing) {
203
- this.webchatRef.current.setTyping(typing)
204
- }
205
-
206
- open() {
207
- this.webchatRef.current.openWebchat()
208
- }
209
-
210
- close() {
211
- this.webchatRef.current.closeWebchat()
212
- }
213
-
214
- async closeWebview() {
215
- await this.webchatRef.current.closeWebview()
216
- }
217
-
218
- toggle() {
219
- this.webchatRef.current.toggleWebchat()
220
- }
221
-
222
- openCoverComponent() {
223
- this.webchatRef.current.openCoverComponent()
224
- }
225
-
226
- closeCoverComponent() {
227
- this.webchatRef.current.closeCoverComponent()
228
- }
229
-
230
- renderCustomComponent(_customComponent) {
231
- this.webchatRef.current.renderCustomComponent(_customComponent)
232
- }
233
-
234
- unmountCustomComponent() {
235
- this.webchatRef.current.unmountCustomComponent()
236
- }
237
-
238
- toggleCoverComponent() {
239
- this.webchatRef.current.toggleCoverComponent()
240
- }
241
-
242
- getMessages() {
243
- return this.webchatRef.current.getMessages()
244
- }
245
-
246
- clearMessages() {
247
- this.webchatRef.current.clearMessages()
248
- }
249
-
250
- async getVisibility() {
251
- return this.resolveWebchatVisibility({
252
- appId: this.appId,
253
- visibility: this.visibility,
254
- })
255
- }
256
-
257
- getLastMessageUpdate() {
258
- return this.webchatRef.current.getLastMessageUpdate()
259
- }
260
-
261
- updateMessageInfo(msgId, messageInfo) {
262
- return this.webchatRef.current.updateMessageInfo(msgId, messageInfo)
263
- }
264
-
265
- updateWebchatSettings(settings) {
266
- return this.webchatRef.current.updateWebchatSettings(settings)
267
- }
268
-
269
- // eslint-disable-next-line complexity
270
- getComponent(host, optionsAtRuntime = {}) {
271
- let {
272
- theme = {},
273
- persistentMenu,
274
- coverComponent,
275
- blockInputs,
276
- enableAttachments,
277
- enableUserInput,
278
- enableAnimations,
279
- enableEmojiPicker,
280
- defaultDelay,
281
- defaultTyping,
282
- storage,
283
- storageKey,
284
- onInit,
285
- onOpen,
286
- onClose,
287
- onMessage,
288
- onConnectionChange,
289
- onTrackEvent,
290
- appId,
291
- visibility,
292
- server,
293
- hostId,
294
- ...webchatOptions
295
- } = optionsAtRuntime
296
- theme = merge(this.theme, theme)
297
- persistentMenu = persistentMenu || this.persistentMenu
298
- coverComponent = coverComponent || this.coverComponent
299
- blockInputs = blockInputs || this.blockInputs
300
- enableEmojiPicker = enableEmojiPicker || this.enableEmojiPicker
301
- enableAttachments = enableAttachments || this.enableAttachments
302
- enableUserInput = enableUserInput || this.enableUserInput
303
- enableAnimations = enableAnimations || this.enableAnimations
304
- defaultDelay = defaultDelay || this.defaultDelay
305
- defaultTyping = defaultTyping || this.defaultTyping
306
- server = server || this.server
307
- this.storage = storage || this.storage
308
- this.storageKey = storageKey || this.storageKey
309
- this.onInit = onInit || this.onInit
310
- this.onOpen = onOpen || this.onOpen
311
- this.onClose = onClose || this.onClose
312
- this.onMessage = onMessage || this.onMessage
313
- this.onTrackEvent = onTrackEvent || this.onTrackEvent
314
- this.onConnectionChange = onConnectionChange || this.onConnectionChange
315
- this.visibility = visibility || this.visibility
316
- this.appId = appId || this.appId
317
- this.hostId = hostId || this.hostId
318
- this.createRootElement(host)
319
- return (
320
- <Webchat
321
- {...webchatOptions}
322
- ref={this.webchatRef}
323
- host={this.host}
324
- shadowDOM={this.shadowDOM}
325
- theme={theme}
326
- persistentMenu={persistentMenu}
327
- coverComponent={coverComponent}
328
- blockInputs={blockInputs}
329
- enableEmojiPicker={enableEmojiPicker}
330
- enableAttachments={enableAttachments}
331
- enableUserInput={enableUserInput}
332
- enableAnimations={enableAnimations}
333
- storage={this.storage}
334
- storageKey={this.storageKey}
335
- defaultDelay={defaultDelay}
336
- defaultTyping={defaultTyping}
337
- onInit={(...args) => this.onInitWebchat(...args)}
338
- onOpen={(...args) => this.onOpenWebchat(...args)}
339
- onClose={(...args) => this.onCloseWebchat(...args)}
340
- onUserInput={(...args) => this.onUserInput(...args)}
341
- onStateChange={webchatState => this.onStateChange(webchatState)}
342
- onTrackEvent={(...args) => this.onTrackEvent(...args)}
343
- server={server}
344
- />
345
- )
346
- }
347
-
348
- async isWebchatVisible({ appId }) {
349
- try {
350
- const { status } = await HubtypeService.getWebchatVisibility({
351
- appId,
352
- })
353
- return status === 200
354
- } catch (e) {
355
- return false
356
- }
357
- }
358
-
359
- isOnline() {
360
- return this.webchatRef.current.isOnline()
361
- }
362
-
363
- async resolveWebchatVisibility(optionsAtRuntime) {
364
- let { appId, visibility } = optionsAtRuntime
365
- visibility = visibility || this.visibility
366
- if (visibility === undefined || visibility === true) return true
367
- if (typeof visibility === 'function' && visibility()) return true
368
- if (visibility === 'dynamic' && (await this.isWebchatVisible({ appId })))
369
- return true
370
- return false
371
- }
372
-
373
- destroy() {
374
- if (this.hubtypeService) this.hubtypeService.destroyPusher()
375
- unmountComponentAtNode(this.host)
376
- if (this.storage) this.storage.removeItem(this.storageKey)
377
- }
378
-
379
- async render(dest, optionsAtRuntime = {}) {
380
- onDOMLoaded(async () => {
381
- const isVisible = await this.resolveWebchatVisibility(optionsAtRuntime)
382
- if (isVisible)
383
- render(
384
- this.getComponent(dest, optionsAtRuntime),
385
- this.getReactMountNode(dest)
386
- )
387
- })
388
- }
389
- }