@seamly/web-ui 20.8.1 → 21.0.1-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (225) hide show
  1. package/build/dist/lib/components.js +14855 -20
  2. package/build/dist/lib/components.min.js +2 -1
  3. package/build/dist/lib/components.min.js.LICENSE.txt +48 -0
  4. package/build/dist/lib/config.js +9 -3
  5. package/build/dist/lib/config.min.js +1 -1
  6. package/build/dist/lib/contexts.js +14 -5
  7. package/build/dist/lib/contexts.min.js +1 -1
  8. package/build/dist/lib/deprecated-view.js +1 -1
  9. package/build/dist/lib/hooks.js +8446 -20
  10. package/build/dist/lib/hooks.min.js +2 -1
  11. package/build/dist/lib/hooks.min.js.LICENSE.txt +38 -0
  12. package/build/dist/lib/index.debug.js +585 -584
  13. package/build/dist/lib/index.debug.min.js +1 -1
  14. package/build/dist/lib/index.debug.min.js.LICENSE.txt +110 -110
  15. package/build/dist/lib/index.js +20279 -26454
  16. package/build/dist/lib/index.min.js +1 -1
  17. package/build/dist/lib/index.min.js.LICENSE.txt +6 -1
  18. package/build/dist/lib/standalone.js +27823 -34681
  19. package/build/dist/lib/standalone.min.js +1 -1
  20. package/build/dist/lib/standalone.min.js.LICENSE.txt +1 -1
  21. package/build/dist/lib/storage.js +6 -15
  22. package/build/dist/lib/style-guide.js +23181 -7921
  23. package/build/dist/lib/style-guide.min.js +1 -1
  24. package/build/dist/lib/style-guide.min.js.LICENSE.txt +10 -0
  25. package/build/dist/lib/styles-default-implementation.js +1 -1
  26. package/build/dist/lib/styles.js +1 -1
  27. package/build/dist/lib/utils.js +22149 -17
  28. package/build/dist/lib/utils.min.js +2 -1
  29. package/build/dist/lib/utils.min.js.LICENSE.txt +48 -0
  30. package/package.json +54 -52
  31. package/src/icons/icon_check-16.svg +14 -0
  32. package/src/icons/icon_check-32.svg +14 -0
  33. package/src/javascripts/api/conversation-connector.ts +149 -0
  34. package/src/javascripts/api/errors/seamly-base-error.js +19 -0
  35. package/src/javascripts/api/errors/seamly-unavailable-error.js +5 -7
  36. package/src/javascripts/api/{index.js → index.ts} +163 -116
  37. package/src/javascripts/config.types.ts +5 -4
  38. package/src/javascripts/domains/app/actions.ts +47 -46
  39. package/src/javascripts/domains/app/hooks.js +1 -1
  40. package/src/javascripts/domains/config/actions.ts +2 -8
  41. package/src/javascripts/domains/config/hooks.ts +1 -1
  42. package/src/javascripts/domains/config/selectors.ts +6 -6
  43. package/src/javascripts/domains/config/slice.ts +3 -3
  44. package/src/javascripts/domains/errors/index.ts +66 -0
  45. package/src/javascripts/domains/forms/context.ts +1 -1
  46. package/src/javascripts/domains/forms/forms.types.ts +3 -3
  47. package/src/javascripts/domains/forms/hooks.ts +10 -10
  48. package/src/javascripts/domains/forms/provider.tsx +9 -9
  49. package/src/javascripts/domains/i18n/actions.ts +11 -5
  50. package/src/javascripts/domains/i18n/hooks.ts +11 -8
  51. package/src/javascripts/domains/i18n/selectors.ts +10 -4
  52. package/src/javascripts/domains/i18n/slice.ts +0 -1
  53. package/src/javascripts/domains/interrupt/hooks.ts +1 -1
  54. package/src/javascripts/domains/interrupt/middleware.ts +1 -1
  55. package/src/javascripts/domains/store/index.ts +1 -1
  56. package/src/javascripts/domains/store/selectors.ts +16 -0
  57. package/src/javascripts/domains/store/slice.ts +47 -41
  58. package/src/javascripts/domains/store/store.types.ts +38 -10
  59. package/src/javascripts/domains/translations/components/{options-button.js → options-button.tsx} +30 -20
  60. package/src/javascripts/domains/translations/components/options-dialog/index.tsx +33 -0
  61. package/src/javascripts/domains/translations/components/options-dialog/translation-option.tsx +42 -0
  62. package/src/javascripts/domains/translations/components/options-dialog/translation-options.tsx +81 -0
  63. package/src/javascripts/domains/translations/components/translation-status.tsx +15 -0
  64. package/src/javascripts/domains/translations/hooks.ts +77 -11
  65. package/src/javascripts/domains/translations/slice.ts +20 -9
  66. package/src/javascripts/domains/translations/translations.types.ts +4 -2
  67. package/src/javascripts/domains/visibility/actions.ts +6 -10
  68. package/src/javascripts/domains/visibility/hooks.ts +33 -14
  69. package/src/javascripts/domains/visibility/selectors.ts +3 -2
  70. package/src/javascripts/domains/visibility/slice.ts +2 -6
  71. package/src/javascripts/index.ts +18 -22
  72. package/src/javascripts/lib/engine/{index.js → index.tsx} +25 -7
  73. package/src/javascripts/lib/url-helpers.ts +112 -0
  74. package/src/javascripts/package/components.js +15 -1
  75. package/src/javascripts/package/config.js +1 -1
  76. package/src/javascripts/package/contexts.js +5 -3
  77. package/src/javascripts/package/hooks.js +19 -1
  78. package/src/javascripts/package/utils.js +13 -3
  79. package/src/javascripts/schema.ts +28 -0
  80. package/src/javascripts/style-guide/components/app.js +16 -12
  81. package/src/javascripts/style-guide/components/links.js +6 -6
  82. package/src/javascripts/style-guide/components/static-core.js +14 -9
  83. package/src/javascripts/style-guide/components/view.js +2 -2
  84. package/src/javascripts/style-guide/states.js +132 -36
  85. package/src/javascripts/style-guide/style-guide-engine.js +2 -1
  86. package/src/javascripts/style-guide/style-guide-external-api.js +1 -1
  87. package/src/javascripts/ui/components/app-options/index.js +25 -6
  88. package/src/javascripts/ui/components/chat-app.js +1 -1
  89. package/src/javascripts/ui/components/chat-status/chat-status-action.tsx +30 -0
  90. package/src/javascripts/ui/components/chat-status/index.tsx +61 -0
  91. package/src/javascripts/ui/components/conversation/component-filter.js +9 -9
  92. package/src/javascripts/ui/components/conversation/{conversation.js → conversation.tsx} +32 -41
  93. package/src/javascripts/ui/components/conversation/event/card-component.js +2 -2
  94. package/src/javascripts/ui/components/conversation/event/card-message.js +1 -1
  95. package/src/javascripts/ui/components/conversation/event/carousel-component/components/controls.js +2 -2
  96. package/src/javascripts/ui/components/conversation/event/carousel-component/index.js +4 -4
  97. package/src/javascripts/ui/components/conversation/event/carousel-message/components/slide.js +2 -2
  98. package/src/javascripts/ui/components/conversation/event/carousel-message/index.js +1 -1
  99. package/src/javascripts/ui/components/conversation/event/chat-scroll/chat-scroll-context.ts +12 -0
  100. package/src/javascripts/ui/components/conversation/event/chat-scroll/chat-scroll-provider.tsx +46 -0
  101. package/src/javascripts/ui/components/conversation/event/chat-scroll/unread-messages-button.tsx +30 -0
  102. package/src/javascripts/ui/components/conversation/event/choice-prompt.js +12 -8
  103. package/src/javascripts/ui/components/conversation/event/conversation-suggestions.js +6 -6
  104. package/src/javascripts/ui/components/conversation/event/cta.js +2 -2
  105. package/src/javascripts/ui/components/conversation/event/divider/index.js +0 -1
  106. package/src/javascripts/ui/components/conversation/event/divider/variants/default.js +1 -1
  107. package/src/javascripts/ui/components/conversation/event/divider/variants/new-translation.js +17 -22
  108. package/src/javascripts/ui/components/conversation/event/divider/variants/time-indicator.js +2 -2
  109. package/src/javascripts/ui/components/conversation/event/event-participant.js +1 -1
  110. package/src/javascripts/ui/components/conversation/event/event.tsx +66 -0
  111. package/src/javascripts/ui/components/conversation/event/hooks/use-event-link-click-handler.js +1 -1
  112. package/src/javascripts/ui/components/conversation/event/hooks/use-formatted-date.js +1 -1
  113. package/src/javascripts/ui/components/conversation/event/image-lightbox.js +1 -1
  114. package/src/javascripts/ui/components/conversation/event/image.js +2 -2
  115. package/src/javascripts/ui/components/conversation/event/splash.js +1 -1
  116. package/src/javascripts/ui/components/conversation/event/translation.js +1 -1
  117. package/src/javascripts/ui/components/conversation/event/upload.js +2 -2
  118. package/src/javascripts/ui/components/conversation/event/video.js +2 -2
  119. package/src/javascripts/ui/components/conversation/event-divider.js +1 -1
  120. package/src/javascripts/ui/components/conversation/message-container.js +1 -1
  121. package/src/javascripts/ui/components/conversation/use-chat-scroll.ts +108 -0
  122. package/src/javascripts/ui/components/core/{seamly-activity-monitor.js → seamly-activity-monitor.tsx} +12 -5
  123. package/src/javascripts/ui/components/core/seamly-api-context.ts +7 -0
  124. package/src/javascripts/ui/components/core/seamly-chat.tsx +8 -0
  125. package/src/javascripts/ui/components/core/{seamly-core.js → seamly-core.tsx} +27 -14
  126. package/src/javascripts/ui/components/core/seamly-event-subscriber.ts +340 -0
  127. package/src/javascripts/ui/components/core/seamly-file-upload.js +2 -2
  128. package/src/javascripts/ui/components/core/seamly-idle-detach-counter.js +1 -1
  129. package/src/javascripts/ui/components/core/seamly-instance-functions-loader.js +24 -11
  130. package/src/javascripts/ui/components/core/seamly-live-region.js +4 -4
  131. package/src/javascripts/ui/components/core/seamly-new-notifications.js +3 -3
  132. package/src/javascripts/ui/components/core/seamly-read-state.js +2 -33
  133. package/src/javascripts/ui/components/entry/deprecated-toggle-button.js +4 -4
  134. package/src/javascripts/ui/components/entry/entry-container.js +8 -8
  135. package/src/javascripts/ui/components/entry/text-entry/hooks.js +3 -3
  136. package/src/javascripts/ui/components/entry/text-entry/index.js +3 -3
  137. package/src/javascripts/ui/components/entry/text-entry/text-entry-form.js +4 -4
  138. package/src/javascripts/ui/components/entry/upload/file-upload-form.js +3 -3
  139. package/src/javascripts/ui/components/entry/upload/index.js +5 -5
  140. package/src/javascripts/ui/components/entry/upload-toggle.js +6 -6
  141. package/src/javascripts/ui/components/faq/faq.js +14 -14
  142. package/src/javascripts/ui/components/form-controls/error.js +2 -2
  143. package/src/javascripts/ui/components/form-controls/file-input.js +3 -3
  144. package/src/javascripts/ui/components/layout/agent-info.js +3 -3
  145. package/src/javascripts/ui/components/layout/chat-frame.js +20 -12
  146. package/src/javascripts/ui/components/layout/chat.js +5 -5
  147. package/src/javascripts/ui/components/layout/deprecated-app-frame.js +6 -6
  148. package/src/javascripts/ui/components/layout/deprecated-chat-frame.js +34 -0
  149. package/src/javascripts/ui/components/layout/header.js +2 -2
  150. package/src/javascripts/ui/components/layout/icon.js +11 -9
  151. package/src/javascripts/ui/components/layout/interrupt.js +7 -5
  152. package/src/javascripts/ui/components/layout/pre-chat-messages.js +1 -1
  153. package/src/javascripts/ui/components/layout/privacy-disclaimer.js +2 -2
  154. package/src/javascripts/ui/components/options/options-button.js +5 -5
  155. package/src/javascripts/ui/components/options/{options-frame.js → options-frame.tsx} +52 -18
  156. package/src/javascripts/ui/components/options/transcript/index.js +9 -10
  157. package/src/javascripts/ui/components/options/transcript/transcript-form.js +2 -2
  158. package/src/javascripts/ui/components/suggestions/index.js +8 -8
  159. package/src/javascripts/ui/components/suggestions/suggestions-item.js +1 -1
  160. package/src/javascripts/{domains/translations/components/chat-status.js → ui/components/translation-chat-status/index.tsx} +13 -14
  161. package/src/javascripts/ui/components/translation-proposal/index.tsx +36 -0
  162. package/src/javascripts/ui/components/view/app-view.js +2 -7
  163. package/src/javascripts/ui/components/view/deprecated-view.js +8 -10
  164. package/src/javascripts/ui/components/view/index.js +6 -6
  165. package/src/javascripts/ui/components/view/inline-view.js +4 -8
  166. package/src/javascripts/ui/components/view/window-view/collapse-button.js +2 -2
  167. package/src/javascripts/ui/components/view/window-view/index.js +11 -17
  168. package/src/javascripts/ui/components/view/window-view/window-open-button.js +6 -6
  169. package/src/javascripts/ui/components/warnings/idle-detach-warning.js +3 -3
  170. package/src/javascripts/ui/components/warnings/prompt.js +1 -1
  171. package/src/javascripts/ui/components/warnings/resume-conversation-prompt.js +4 -4
  172. package/src/javascripts/ui/components/widgets/in-out-transition.js +20 -18
  173. package/src/javascripts/ui/components/widgets/lightbox.js +3 -3
  174. package/src/javascripts/ui/components/widgets/modal.js +2 -2
  175. package/src/javascripts/ui/components/widgets/upload-progress.js +2 -2
  176. package/src/javascripts/ui/hooks/file-upload-hooks.js +1 -1
  177. package/src/javascripts/ui/hooks/focus-helper-hooks.js +1 -1
  178. package/src/javascripts/ui/hooks/seamly-entry-hooks.js +6 -6
  179. package/src/javascripts/ui/hooks/seamly-hooks.js +11 -10
  180. package/src/javascripts/ui/hooks/seamly-option-hooks.js +6 -6
  181. package/src/javascripts/ui/hooks/{seamly-state-hooks.js → seamly-state-hooks.ts} +9 -6
  182. package/src/javascripts/ui/hooks/use-click-outside.ts +29 -0
  183. package/src/javascripts/ui/hooks/use-event-component-mapping.js +11 -10
  184. package/src/javascripts/ui/hooks/use-interval.js +1 -1
  185. package/src/javascripts/ui/hooks/use-seamly-actions.ts +29 -29
  186. package/src/javascripts/ui/hooks/use-seamly-chat.js +14 -24
  187. package/src/javascripts/ui/hooks/use-seamly-commands.js +20 -15
  188. package/src/javascripts/ui/hooks/use-seamly-idle-detach-countdown.js +8 -8
  189. package/src/javascripts/ui/hooks/use-seamly-resume-conversation-prompt.js +2 -2
  190. package/src/javascripts/ui/hooks/use-single-file-upload.js +1 -1
  191. package/src/javascripts/ui/hooks/utility-hooks.js +1 -1
  192. package/src/javascripts/ui/utils/general-utils.js +0 -23
  193. package/src/javascripts/ui/utils/seamly-utils.ts +10 -1
  194. package/src/javascripts/ui/utils/seamly-utils.types.ts +9 -0
  195. package/src/stylesheets/1-settings/_config.scss +1 -1
  196. package/src/stylesheets/3-chat/_chat.scss +24 -9
  197. package/src/stylesheets/5-components/_chat-status.scss +72 -16
  198. package/src/stylesheets/5-components/_conversation.scss +35 -1
  199. package/src/stylesheets/5-components/_disclaimer.scss +0 -5
  200. package/src/stylesheets/5-components/_options.scss +16 -6
  201. package/src/stylesheets/5-components/_translation-options.scss +51 -0
  202. package/src/stylesheets/6-default-implementation/_scrollbar.scss +1 -1
  203. package/src/stylesheets/7-deprecated/3-app/_app.scss +19 -4
  204. package/src/stylesheets/7-deprecated/5-components/_chat-status.scss +5 -0
  205. package/src/stylesheets/7-deprecated/5-components/_options.scss +1 -4
  206. package/src/stylesheets/7-deprecated/5-components/_translation-options.scss +49 -0
  207. package/src/stylesheets/deprecated-view.scss +1 -0
  208. package/src/stylesheets/styles.scss +1 -0
  209. package/webpack/config.common.js +4 -4
  210. package/webpack/config.package.js +10 -16
  211. package/webpack/config.site.js +4 -1
  212. package/webpack/config.test.js +2 -1
  213. package/build/dist/lib/deprecated-view.css +0 -1
  214. package/build/dist/lib/styles-default-implementation.css +0 -1
  215. package/build/dist/lib/styles.css +0 -1
  216. package/src/.DS_Store +0 -0
  217. package/src/javascripts/api/event-producer.js +0 -20
  218. package/src/javascripts/api/producer.js +0 -136
  219. package/src/javascripts/domains/errors/index.js +0 -37
  220. package/src/javascripts/domains/translations/components/options-dialog/form.js +0 -70
  221. package/src/javascripts/domains/translations/components/options-dialog/index.js +0 -87
  222. package/src/javascripts/ui/components/chat-status/index.js +0 -38
  223. package/src/javascripts/ui/components/conversation/event/event.js +0 -36
  224. package/src/javascripts/ui/components/core/seamly-api-context.js +0 -5
  225. package/src/javascripts/ui/components/core/seamly-event-subscriber.js +0 -279
@@ -0,0 +1,340 @@
1
+ import { useContext, useEffect, useRef } from 'preact/hooks'
2
+ import { useDispatch } from 'react-redux'
3
+ import SeamlyGeneralError from 'api/errors/seamly-general-error'
4
+ import SeamlyOfflineError from 'api/errors/seamly-offline-error'
5
+ import SeamlySessionExpiredError from 'api/errors/seamly-session-expired-error'
6
+ import { SeamlyEventBusContext } from 'ui/components/core/seamly-api-context'
7
+ import {
8
+ useEvents,
9
+ useSeamlyApiContext,
10
+ useSeamlyCommands,
11
+ useSeamlyIdleDetachCountdown,
12
+ } from 'ui/hooks/seamly-hooks'
13
+ import { featureKeys } from 'ui/utils/seamly-utils'
14
+ import { setHasResponded } from 'domains/app/slice'
15
+ import { clearInterrupt, setInterrupt } from 'domains/interrupt/slice'
16
+ import {
17
+ ackEvent,
18
+ addEvent,
19
+ clearEvents,
20
+ initResumeConversationPrompt,
21
+ setActiveService,
22
+ setFeatureEnabledState,
23
+ setHeaderSubTitle,
24
+ setHistory,
25
+ setIsLoading,
26
+ setParticipant,
27
+ setServiceDataItem,
28
+ setServiceEntryMetadata,
29
+ } from 'domains/store/slice'
30
+ import type { AckEvent, ChannelEvent } from 'domains/store/store.types'
31
+ import { setTranslationProposalPrompt } from 'domains/translations/slice'
32
+
33
+ const EMITTABLE_MESSAGE_TYPES = ['text', 'choice_prompt', 'image', 'video']
34
+
35
+ const SeamlyEventSubscriber = () => {
36
+ const api = useSeamlyApiContext()
37
+
38
+ const dispatch = useDispatch()
39
+ const events = useEvents()
40
+ const eventBus = useContext(SeamlyEventBusContext)
41
+ const prevEmittedEventId = useRef(null)
42
+ const { initCountdown, endCountdown } = useSeamlyIdleDetachCountdown()
43
+ const { emitEvent } = useSeamlyCommands()
44
+
45
+ useEffect(() => {
46
+ if (api.connectionInfo && api.conversation.socket) {
47
+ const { socket } = api.conversation
48
+ socket.onError((err) => {
49
+ const seamlyOfflineError = new SeamlyOfflineError(err)
50
+ dispatch(
51
+ setInterrupt({
52
+ name: seamlyOfflineError.name,
53
+ message: seamlyOfflineError.message,
54
+ langKey: seamlyOfflineError.langKey,
55
+ originalEvent: seamlyOfflineError.originalEvent,
56
+ originalError: seamlyOfflineError.originalError,
57
+ }),
58
+ )
59
+ dispatch(clearEvents())
60
+ })
61
+
62
+ socket.onOpen(() => {
63
+ dispatch(clearInterrupt())
64
+ })
65
+ }
66
+ }, [api, api.connectionInfo, api.conversation.socket, dispatch])
67
+
68
+ useEffect(() => {
69
+ if (api.connectionInfo && api.conversation.channel) {
70
+ const { channel } = api.conversation
71
+ return () => {
72
+ channel?.leave()
73
+ }
74
+ }
75
+ return () => {}
76
+ }, [api, api.connectionInfo, api.conversation])
77
+
78
+ useEffect(() => {
79
+ api.conversation.onConnection((connectionState) => {
80
+ if (connectionState === 'join_channel_erred') {
81
+ const seamlyGeneralError = new SeamlyGeneralError()
82
+ dispatch(
83
+ setInterrupt({
84
+ name: seamlyGeneralError.name,
85
+ message: seamlyGeneralError.message,
86
+ langKey: seamlyGeneralError.langKey,
87
+ originalEvent: seamlyGeneralError.originalEvent,
88
+ originalError: seamlyGeneralError.originalError,
89
+ action: seamlyGeneralError.action,
90
+ }),
91
+ )
92
+ }
93
+ })
94
+ }, [api.conversation, dispatch])
95
+
96
+ useEffect(() => {
97
+ if (api.connectionInfo && api.conversation.channel) {
98
+ const { channel } = api.conversation
99
+
100
+ const updateParticipant = (event) => {
101
+ const { payload } = event
102
+
103
+ if (!payload || !payload.participant) {
104
+ return
105
+ }
106
+
107
+ const { fromClient, participant } = payload
108
+
109
+ if (
110
+ !fromClient &&
111
+ typeof participant !== 'string' &&
112
+ participant?.name
113
+ ) {
114
+ dispatch(setHeaderSubTitle(participant.name))
115
+ }
116
+
117
+ dispatch(
118
+ setParticipant({
119
+ participant,
120
+ fromClient,
121
+ }),
122
+ )
123
+
124
+ if (typeof participant !== 'string' && participant.introduction) {
125
+ dispatch(
126
+ addEvent({
127
+ ...event,
128
+ payload: {
129
+ ...payload,
130
+ type: 'participant',
131
+ },
132
+ }),
133
+ )
134
+ }
135
+ }
136
+
137
+ channel.onMessage = (type, payload) => {
138
+ const event = { type, payload }
139
+
140
+ switch (type) {
141
+ case 'ui':
142
+ if (payload.state && payload.state.hasOwnProperty('loading')) {
143
+ dispatch(setIsLoading(payload.state.loading))
144
+ }
145
+ switch (payload.type) {
146
+ case 'idle_detach_countdown':
147
+ initCountdown(payload.body.duration)
148
+ break
149
+ case 'idle_detach_countdown_elapsed':
150
+ endCountdown(undefined, true)
151
+ break
152
+ case 'resume_conversation_prompt':
153
+ dispatch(initResumeConversationPrompt())
154
+ break
155
+ case 'translation_proposal':
156
+ dispatch(setTranslationProposalPrompt(payload.body))
157
+ break
158
+ case 'user_first_response':
159
+ dispatch(setHasResponded(true))
160
+ // @ts-ignore
161
+ eventBus.emit('system.userFirstResponse', payload.body)
162
+ break
163
+ }
164
+ break
165
+ case 'message':
166
+ updateParticipant(payload)
167
+ switch (payload.type) {
168
+ case 'text':
169
+ case 'choice_prompt':
170
+ case 'splash':
171
+ case 'image':
172
+ case 'upload':
173
+ case 'video':
174
+ case 'cta':
175
+ case 'custom':
176
+ case 'carousel':
177
+ case 'card':
178
+ if (payload.service && payload.service.serviceSessionId) {
179
+ dispatch(setActiveService(payload.service.serviceSessionId))
180
+ }
181
+
182
+ dispatch(addEvent(event as ChannelEvent))
183
+ break
184
+ }
185
+ break
186
+ case 'participant':
187
+ updateParticipant(event)
188
+ break
189
+ case 'service_data':
190
+ if (payload.persist) {
191
+ dispatch(setServiceDataItem(payload))
192
+ }
193
+ break
194
+ case 'ack':
195
+ dispatch(ackEvent(event as AckEvent))
196
+ break
197
+ case 'system':
198
+ if (payload.type === 'service_changed') {
199
+ const { serviceSettings, ...eventPayload } = payload
200
+ const { entry } = serviceSettings
201
+ const { upload } = entry.options
202
+
203
+ dispatch(
204
+ setFeatureEnabledState({
205
+ key: featureKeys.uploads,
206
+ enabled: !!(upload && upload.enabled),
207
+ }),
208
+ )
209
+
210
+ dispatch(setServiceEntryMetadata(entry))
211
+ if (payload.serviceSessionId) {
212
+ dispatch(setActiveService(payload.serviceSessionId))
213
+ }
214
+
215
+ emitEvent('system.serviceChanged', eventPayload)
216
+ }
217
+ break
218
+ case 'info':
219
+ if (
220
+ payload.type === 'divider' ||
221
+ payload.type === 'text' ||
222
+ payload.type === 'translation'
223
+ ) {
224
+ dispatch(addEvent(event as ChannelEvent))
225
+ }
226
+ break
227
+ case 'error':
228
+ switch (payload.type) {
229
+ case 'find_conversation_erred':
230
+ const seamlySessionExpiredError = new SeamlySessionExpiredError(
231
+ event,
232
+ )
233
+ dispatch(
234
+ setInterrupt({
235
+ name: seamlySessionExpiredError.name,
236
+ action: seamlySessionExpiredError.action,
237
+ message: seamlySessionExpiredError.message,
238
+ originalEvent: seamlySessionExpiredError.originalEvent,
239
+ originalError: seamlySessionExpiredError.originalError,
240
+ }),
241
+ )
242
+ break
243
+ case 'conversation_erred':
244
+ const seamlyGeneralError = new SeamlyGeneralError(event)
245
+ dispatch(
246
+ setInterrupt({
247
+ name: seamlyGeneralError.name,
248
+ message: seamlyGeneralError.message,
249
+ langKey: seamlyGeneralError.langKey,
250
+ originalEvent: seamlyGeneralError.originalEvent,
251
+ originalError: seamlyGeneralError.originalError,
252
+ action: seamlyGeneralError.action,
253
+ }),
254
+ )
255
+ break
256
+ }
257
+ }
258
+
259
+ return payload
260
+ }
261
+ }
262
+ }, [
263
+ api,
264
+ api.connectionInfo,
265
+ api.conversation.channel,
266
+ dispatch,
267
+ emitEvent,
268
+ endCountdown,
269
+ eventBus,
270
+ initCountdown,
271
+ ])
272
+
273
+ useEffect(() => {
274
+ if (api.connectionInfo && api.conversation.channel) {
275
+ const { channel } = api.conversation
276
+
277
+ channel.on('message', (payload) => {
278
+ if (!EMITTABLE_MESSAGE_TYPES.includes(payload.type)) {
279
+ return payload
280
+ }
281
+
282
+ // This check dedupes the sending of messages via
283
+ // the bus if a duplicate connection exists in an
284
+ // error situation.
285
+ if (payload.id !== prevEmittedEventId.current) {
286
+ // @ts-ignore
287
+ eventBus.emit('message', payload)
288
+ }
289
+ prevEmittedEventId.current = payload.id
290
+ return payload
291
+ })
292
+ }
293
+ }, [api, api.connectionInfo, api.conversation.channel, eventBus])
294
+
295
+ useEffect(() => {
296
+ if (api.connectionInfo && api.conversation.channel) {
297
+ const { channel } = api.conversation
298
+
299
+ const syncChannelRef = channel.on('sync', (payload) => {
300
+ const lastEvent = events[events.length - 1]
301
+ const payloadLastEventId = payload?.lastEvent?.id
302
+
303
+ if (lastEvent && payloadLastEventId === lastEvent.payload.id) {
304
+ return payload
305
+ }
306
+
307
+ return api
308
+ .getConversation()
309
+ .then((history) => {
310
+ if (!history) {
311
+ return
312
+ }
313
+ dispatch(setHistory(history))
314
+ })
315
+ .catch((error) => {
316
+ dispatch(
317
+ setInterrupt({
318
+ name: error?.name,
319
+ message: error?.message,
320
+ langKey: error?.langKey,
321
+ action: error?.action,
322
+ originalEvent: error?.originalEvent,
323
+ originalError: error?.originalError,
324
+ }),
325
+ )
326
+ })
327
+ })
328
+
329
+ return () => {
330
+ channel.off('sync', syncChannelRef)
331
+ }
332
+ }
333
+
334
+ return () => undefined
335
+ }, [api, api.connectionInfo, api.conversation.channel, events, dispatch])
336
+
337
+ return null
338
+ }
339
+
340
+ export default SeamlyEventSubscriber
@@ -1,3 +1,5 @@
1
+ import { useDispatch } from 'react-redux'
2
+ import { useSeamlyApiContext, useSeamlyCommands } from 'ui/hooks/seamly-hooks'
1
3
  import { useI18n } from 'domains/i18n/hooks'
2
4
  import {
3
5
  registerUpload,
@@ -6,8 +8,6 @@ import {
6
8
  setUploadProgress,
7
9
  } from 'domains/store/slice'
8
10
  import { randomId } from 'lib/id'
9
- import { useDispatch } from 'react-redux'
10
- import { useSeamlyApiContext, useSeamlyCommands } from 'ui/hooks/seamly-hooks'
11
11
  import SeamlyFileUploadContext from './seamly-file-upload-context'
12
12
 
13
13
  const SeamlyFileUpload = ({ children }) => {
@@ -1,5 +1,5 @@
1
- import useSeamlyIdleDetachCountdown from 'ui/hooks/use-seamly-idle-detach-countdown'
2
1
  import useInterval from 'ui/hooks/use-interval'
2
+ import useSeamlyIdleDetachCountdown from 'ui/hooks/use-seamly-idle-detach-countdown'
3
3
 
4
4
  const SeamlyIdleDetachCounter = () => {
5
5
  const { hasCountdown, isActive, remaining, decrementCountdown } =
@@ -1,18 +1,21 @@
1
1
  import { useContext, useEffect, useRef } from 'preact/hooks'
2
+ import { useDispatch } from 'react-redux'
3
+ import { userParticipantId } from 'config'
2
4
  import {
3
- useSeamlyCommands,
4
- useSeamlyUnreadCount,
5
- useSeamlyLayoutMode,
6
- useSeamlyConversationUrl,
7
5
  useSeamlyActivityEventHandler,
8
6
  useSeamlyApiContext,
7
+ useSeamlyCommands,
8
+ useSeamlyConversationUrl,
9
+ useSeamlyLayoutMode,
10
+ useSeamlyUnreadCount,
9
11
  } from 'ui/hooks/seamly-hooks'
10
- import { actionTypes } from 'ui/utils/seamly-utils'
11
- import { useTranslations } from 'domains/translations/hooks'
12
- import { useInterrupt } from 'domains/interrupt/hooks'
12
+ import { actionTypes, sourceTypes } from 'ui/utils/seamly-utils'
13
13
  import { useConfig } from 'domains/config/hooks'
14
- import { useVisibility } from 'domains/visibility/hooks'
14
+ import { updateConfig } from 'domains/config/slice'
15
+ import { useInterrupt } from 'domains/interrupt/hooks'
16
+ import { useTranslations } from 'domains/translations/hooks'
15
17
  import { visibilityStates } from 'domains/visibility/constants'
18
+ import { useVisibility } from 'domains/visibility/hooks'
16
19
  import { SeamlyEventBusContext } from './seamly-api-context'
17
20
 
18
21
  function useSeamlyInstanceFunction(functionName, fn, deps = []) {
@@ -35,6 +38,7 @@ function useSeamlyInstanceFunction(functionName, fn, deps = []) {
35
38
  const SeamlyInstanceFunctionsLoader = () => {
36
39
  const config = useConfig()
37
40
  const { sendMessage, sendContext, sendAction } = useSeamlyCommands()
41
+ const dispatch = useDispatch()
38
42
  const { setVisibility, visible } = useVisibility()
39
43
  const currentVisibility = useRef(visible)
40
44
  const eventBus = useContext(SeamlyEventBusContext)
@@ -101,11 +105,20 @@ const SeamlyInstanceFunctionsLoader = () => {
101
105
  )
102
106
  useSeamlyInstanceFunction(
103
107
  'setTopic',
104
- ({ name, fallbackMessage }) => {
108
+ ({ name, fallbackMessage, userTriggered }) => {
109
+ if (userTriggered) {
110
+ dispatch(updateConfig({ showSuggestions: false }))
111
+ }
112
+
105
113
  if (name && fallbackMessage) {
114
+ const participant = userTriggered ? userParticipantId : undefined
106
115
  sendAction({
107
116
  type: actionTypes.setTopic,
108
- body: { name, fallbackMessage },
117
+ body: {
118
+ name,
119
+ fallbackMessage,
120
+ participant,
121
+ },
109
122
  })
110
123
  } else {
111
124
  console.warn(
@@ -120,7 +133,7 @@ const SeamlyInstanceFunctionsLoader = () => {
120
133
  'setTranslation',
121
134
  ({ enabled, locale }) => {
122
135
  if (enabled) {
123
- enableTranslations(locale)
136
+ enableTranslations(locale, sourceTypes.windowApi)
124
137
  } else {
125
138
  disableTranslations()
126
139
  }
@@ -1,14 +1,14 @@
1
1
  import {
2
- useState,
3
- useEffect,
4
- useRef,
5
2
  useCallback,
6
3
  useContext,
4
+ useEffect,
5
+ useRef,
6
+ useState,
7
7
  } from 'preact/hooks'
8
8
  import { ariaLiveLevels } from 'ui/utils/seamly-utils'
9
9
  import { className } from 'lib/css'
10
- import { SeamlyLiveRegionContext } from './seamly-live-region-context'
11
10
  import { SeamlyEventBusContext } from './seamly-api-context'
11
+ import { SeamlyLiveRegionContext } from './seamly-live-region-context'
12
12
 
13
13
  const SeamlyLiveRegion = ({ children }) => {
14
14
  const eventBus = useContext(SeamlyEventBusContext)
@@ -1,12 +1,12 @@
1
- import { useEffect, useRef, useMemo } from 'preact/hooks'
2
- import { useI18n } from 'domains/i18n/hooks'
1
+ import { useEffect, useMemo, useRef } from 'preact/hooks'
2
+ import { newMessageScreenReaderWait } from 'config'
3
3
  import {
4
4
  useEvents,
5
5
  useLiveRegion,
6
6
  useSeamlyIsHistoryLoaded,
7
7
  } from 'ui/hooks/seamly-hooks'
8
- import { newMessageScreenReaderWait } from 'config'
9
8
  import { debounce } from 'ui/utils/general-utils'
9
+ import { useI18n } from 'domains/i18n/hooks'
10
10
  import { useVisibility } from 'domains/visibility/hooks'
11
11
 
12
12
  const SeamlyNewNotifications = () => {
@@ -1,24 +1,13 @@
1
1
  import { useEffect, useMemo, useRef } from 'preact/hooks'
2
2
  import { unreadScreenReaderWait } from 'config'
3
+ import { useLiveRegion, useSeamlyUnreadCount } from 'ui/hooks/seamly-hooks'
4
+ import { debounce } from 'ui/utils/general-utils'
3
5
  import { useI18n } from 'domains/i18n/hooks'
4
- import { isUnreadMessage, setEventsRead } from 'domains/store/slice'
5
6
  import { useVisibility } from 'domains/visibility/hooks'
6
- import {
7
- useEvents,
8
- useLiveRegion,
9
- useSeamlyCommands,
10
- useSeamlyUnreadCount,
11
- } from 'ui/hooks/seamly-hooks'
12
- import { debounce } from 'ui/utils/general-utils'
13
- import { actionTypes, readStates } from 'ui/utils/seamly-utils'
14
- import { useDispatch } from 'react-redux'
15
7
 
16
8
  const SeamlyReadState = () => {
17
9
  const { t } = useI18n()
18
- const events = useEvents()
19
- const dispatch = useDispatch()
20
10
  const { isOpen, isVisible } = useVisibility()
21
- const { sendAction } = useSeamlyCommands()
22
11
  const unreadCount = useSeamlyUnreadCount()
23
12
  const { sendPolite } = useLiveRegion()
24
13
  const sendLive = useMemo(
@@ -29,26 +18,6 @@ const SeamlyReadState = () => {
29
18
  const prevIsVisible = useRef(null)
30
19
  const cancelSend = useRef(null)
31
20
 
32
- useEffect(() => {
33
- if (!isOpen) {
34
- return
35
- }
36
-
37
- const unread = events
38
- .filter((event) => {
39
- return (
40
- isUnreadMessage(event) &&
41
- event.payload.messageStatus === readStates.received
42
- )
43
- })
44
- .map((event) => event.payload.id)
45
-
46
- if (unread.length > 0) {
47
- dispatch(setEventsRead(unread))
48
- sendAction({ type: actionTypes.read, events: unread })
49
- }
50
- }, [events, dispatch, isOpen, sendAction])
51
-
52
21
  useEffect(() => {
53
22
  if (
54
23
  prevIsVisible.current !== isVisible &&
@@ -1,16 +1,16 @@
1
1
  import { useLayoutEffect, useRef } from 'preact/hooks'
2
- import { useI18n } from 'domains/i18n/hooks'
3
- import { className } from 'lib/css'
4
2
  import {
5
- useSkiplinkTargetFocusing,
6
3
  useFocusIfSeamlyContainedFocus,
4
+ useGeneratedId,
7
5
  useSeamlyCurrentAgent,
8
6
  useSeamlyHeaderData,
9
- useGeneratedId,
10
7
  useSeamlyStateContext,
8
+ useSkiplinkTargetFocusing,
11
9
  } from 'ui/hooks/seamly-hooks'
10
+ import { useI18n } from 'domains/i18n/hooks'
12
11
  import { useInterrupt } from 'domains/interrupt/hooks'
13
12
  import { useVisibility } from 'domains/visibility/hooks'
13
+ import { className } from 'lib/css'
14
14
 
15
15
  // Deprecated Toggle Button, should be removed once it is removed from clients
16
16
  const DeprecatedToggleButton = ({ onOpenChat }) => {
@@ -1,21 +1,21 @@
1
- import { useEffect, useRef, useState, useCallback } from 'preact/hooks'
2
- import { className } from 'lib/css'
1
+ import { useCallback, useEffect, useRef, useState } from 'preact/hooks'
2
+ import IdleDetachWarning from 'ui/components/warnings/idle-detach-warning'
3
+ import ResumeConversationPrompt from 'ui/components/warnings/resume-conversation-prompt'
4
+ import { useSeamlyEntry } from 'ui/hooks/seamly-entry-hooks'
3
5
  import {
6
+ useFileUploadMeta,
4
7
  useSeamlyIdleDetachCountdown,
5
8
  useSeamlyResumeConversationPrompt,
6
9
  useSkiplinkTargetFocusing,
7
- useFileUploadMeta,
8
10
  } from 'ui/hooks/seamly-hooks'
9
- import { entryTypes } from 'ui/utils/seamly-utils'
10
11
  import { runIfElementContainsOrHasFocus } from 'ui/utils/general-utils'
11
- import IdleDetachWarning from 'ui/components/warnings/idle-detach-warning'
12
- import ResumeConversationPrompt from 'ui/components/warnings/resume-conversation-prompt'
12
+ import { entryTypes } from 'ui/utils/seamly-utils'
13
13
  import { useConfig } from 'domains/config/hooks'
14
14
  import { useVisibility } from 'domains/visibility/hooks'
15
- import { useSeamlyEntry } from 'ui/hooks/seamly-entry-hooks'
15
+ import { className } from 'lib/css'
16
16
  import TextEntry from './text-entry'
17
- import UploadToggle from './upload-toggle'
18
17
  import Upload from './upload'
18
+ import UploadToggle from './upload-toggle'
19
19
 
20
20
  const EntryContainer = () => {
21
21
  const { isOpen } = useVisibility()
@@ -1,10 +1,10 @@
1
- import { maxCharacterSrDebounceDelay, maxCharacterWarningLimit } from 'config'
2
- import { useFormControl } from 'domains/forms/hooks'
3
- import { useI18n } from 'domains/i18n/hooks'
4
1
  import { useEffect, useMemo } from 'preact/hooks'
2
+ import { maxCharacterSrDebounceDelay, maxCharacterWarningLimit } from 'config'
5
3
  import { useLiveRegion } from 'ui/hooks/live-region-hooks'
6
4
  import { useEntryTextLimit } from 'ui/hooks/seamly-state-hooks'
7
5
  import { debounce } from 'ui/utils/general-utils'
6
+ import { useFormControl } from 'domains/forms/hooks'
7
+ import { useI18n } from 'domains/i18n/hooks'
8
8
 
9
9
  export function useCharacterLimit(controlName) {
10
10
  const { t } = useI18n()
@@ -1,12 +1,12 @@
1
- import FormProvider from 'domains/forms/provider'
2
- import { visibilityStates } from 'domains/visibility/constants'
3
- import { useVisibility } from 'domains/visibility/hooks'
4
1
  import { useCallback } from 'preact/hooks'
5
2
  import {
6
3
  useSeamlyCommands,
7
4
  useSkiplink,
8
5
  useSkiplinkTargetFocusing,
9
6
  } from 'ui/hooks/seamly-hooks'
7
+ import FormProvider from 'domains/forms/provider'
8
+ import { visibilityStates } from 'domains/visibility/constants'
9
+ import { useVisibility } from 'domains/visibility/hooks'
10
10
  import TextEntryForm from './text-entry-form'
11
11
 
12
12
  const controlName = 'textMessageEntry'
@@ -1,12 +1,12 @@
1
- import { useFormControl } from 'domains/forms/hooks'
2
- import { useI18n } from 'domains/i18n/hooks'
3
- import { className } from 'lib/css'
4
1
  import { useCallback, useLayoutEffect, useMemo } from 'preact/hooks'
5
2
  import Form from 'ui/components/form-controls/form'
6
3
  import Input from 'ui/components/form-controls/input'
7
4
  import Icon from 'ui/components/layout/icon'
8
- import { useLiveRegion, useSeamlyCommands } from 'ui/hooks/seamly-hooks'
9
5
  import { useSeamlyEntry, useSeamlyTyping } from 'ui/hooks/seamly-entry-hooks'
6
+ import { useLiveRegion, useSeamlyCommands } from 'ui/hooks/seamly-hooks'
7
+ import { useFormControl } from 'domains/forms/hooks'
8
+ import { useI18n } from 'domains/i18n/hooks'
9
+ import { className } from 'lib/css'
10
10
  import { useCharacterLimit } from './hooks'
11
11
 
12
12
  export default function TextEntryForm({ controlName, skipLinkId }) {
@@ -1,8 +1,8 @@
1
- import { className } from 'lib/css'
2
- import Form from 'ui/components/form-controls/form'
3
1
  import FileInput from 'ui/components/form-controls/file-input'
4
- import { useI18n } from 'domains/i18n/hooks'
2
+ import Form from 'ui/components/form-controls/form'
5
3
  import { useFormControl } from 'domains/forms/hooks'
4
+ import { useI18n } from 'domains/i18n/hooks'
5
+ import { className } from 'lib/css'
6
6
 
7
7
  export default function FileInputForm({
8
8
  skiplinkId,
@@ -1,8 +1,6 @@
1
- import FormProvider from 'domains/forms/provider'
2
- import { useI18n } from 'domains/i18n/hooks'
3
- import { className } from 'lib/css'
4
1
  import { useCallback, useEffect, useMemo, useRef } from 'preact/hooks'
5
2
  import UploadProgress from 'ui/components/widgets/upload-progress'
3
+ import { useSeamlyEntry } from 'ui/hooks/seamly-entry-hooks'
6
4
  import {
7
5
  useFileUploadMeta,
8
6
  useFileUploads,
@@ -11,7 +9,6 @@ import {
11
9
  useSkiplink,
12
10
  useSkiplinkTargetFocusing,
13
11
  } from 'ui/hooks/seamly-hooks'
14
- import { useSeamlyEntry } from 'ui/hooks/seamly-entry-hooks'
15
12
  import useSingleFileUpload from 'ui/hooks/use-single-file-upload'
16
13
  import { getValidator } from 'ui/utils/form-utils'
17
14
  import { formatBytes } from 'ui/utils/general-utils'
@@ -19,6 +16,9 @@ import {
19
16
  fileListObjectIsNotEmpty,
20
17
  validateFileSize,
21
18
  } from 'ui/utils/validations'
19
+ import FormProvider from 'domains/forms/provider'
20
+ import { useI18n } from 'domains/i18n/hooks'
21
+ import { className } from 'lib/css'
22
22
  import FileInputForm from './file-upload-form'
23
23
 
24
24
  const formName = 'fileListForm'
@@ -54,7 +54,7 @@ const Upload = () => {
54
54
  useEffect(() => {
55
55
  if (
56
56
  prevContentHintText.current &&
57
- containerRef.current.contains(document.activeElement) &&
57
+ containerRef.current?.contains(document.activeElement) &&
58
58
  document.activeElement.tagName === 'INPUT'
59
59
  ) {
60
60
  sendAssertive(contentHintText)