@carbon/ai-chat 0.1.6 → 0.1.7-test-no-cjs

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 (144) hide show
  1. package/dist/es/{cds-aichat-internal.js → AppContainer.js} +50756 -18310
  2. package/dist/es/Carousel.js +14 -8
  3. package/dist/es/GenesysMessengerServiceDesk.js +17 -11
  4. package/dist/es/HumanAgentServiceImpl.js +17 -12
  5. package/dist/es/NiceDFOServiceDesk.js +17 -12
  6. package/dist/es/PDFViewerContainer.js +15 -108
  7. package/dist/es/ReactPlayer.js +2 -2
  8. package/dist/es/SFServiceDesk.js +18 -11
  9. package/dist/es/ServiceDeskImpl.js +2 -2
  10. package/dist/es/Table.js +429 -315
  11. package/dist/es/ZendeskServiceDesk.js +17 -11
  12. package/dist/es/_node-resolve_empty.js +2 -2
  13. package/dist/es/aiChatEntry.js +137 -120
  14. package/dist/es/ar-dz.js +3 -4
  15. package/dist/es/ar-kw.js +3 -4
  16. package/dist/es/ar-ly.js +3 -4
  17. package/dist/es/ar-ma.js +3 -4
  18. package/dist/es/ar-sa.js +3 -4
  19. package/dist/es/ar-tn.js +3 -4
  20. package/dist/es/ar.js +3 -4
  21. package/dist/es/ar2.js +2 -2
  22. package/dist/es/cds-aichat-container.js +104 -18
  23. package/dist/es/cds-aichat-custom-element.js +31 -21
  24. package/dist/es/cs.js +3 -4
  25. package/dist/es/cs2.js +2 -2
  26. package/dist/es/de-at.js +3 -4
  27. package/dist/es/de-ch.js +3 -4
  28. package/dist/es/de.js +3 -4
  29. package/dist/es/de2.js +2 -2
  30. package/dist/es/en-au.js +3 -4
  31. package/dist/es/en-ca.js +3 -4
  32. package/dist/es/en-gb.js +3 -4
  33. package/dist/es/en-ie.js +3 -4
  34. package/dist/es/en-il.js +3 -4
  35. package/dist/es/en-nz.js +3 -4
  36. package/dist/es/es-do.js +3 -4
  37. package/dist/es/es-us.js +3 -4
  38. package/dist/es/es.js +3 -4
  39. package/dist/es/es2.js +2 -2
  40. package/dist/es/export.js +3 -3
  41. package/dist/es/export.legacy.js +3 -3
  42. package/dist/es/fontUtils.js +2 -2
  43. package/dist/es/fr-ca.js +3 -4
  44. package/dist/es/fr-ch.js +3 -4
  45. package/dist/es/fr.js +3 -4
  46. package/dist/es/fr2.js +2 -2
  47. package/dist/es/it-ch.js +3 -4
  48. package/dist/es/it.js +3 -4
  49. package/dist/es/it2.js +2 -2
  50. package/dist/es/ja.js +3 -4
  51. package/dist/es/ja2.js +2 -2
  52. package/dist/es/ko.js +3 -4
  53. package/dist/es/ko2.js +2 -2
  54. package/dist/es/mockServiceDesk.js +17 -11
  55. package/dist/es/nl.js +3 -4
  56. package/dist/es/nl2.js +2 -2
  57. package/dist/es/pt-br.js +3 -4
  58. package/dist/es/pt-br2.js +2 -2
  59. package/dist/es/pt.js +3 -4
  60. package/dist/es/render.js +25 -12
  61. package/dist/es/zh-cn.js +3 -4
  62. package/dist/es/zh-tw.js +3 -4
  63. package/dist/es/zh-tw2.js +2 -2
  64. package/dist/es/zh.js +2 -2
  65. package/dist/types/aiChatEntry.d.ts +599 -11
  66. package/package.json +29 -21
  67. package/dist/cjs/Carousel.js +0 -5711
  68. package/dist/cjs/Chat.js +0 -8838
  69. package/dist/cjs/GenesysMessengerServiceDesk.js +0 -598
  70. package/dist/cjs/HumanAgentServiceImpl.js +0 -1145
  71. package/dist/cjs/NiceDFOServiceDesk.js +0 -2116
  72. package/dist/cjs/PDFViewerContainer.js +0 -83227
  73. package/dist/cjs/ReactPlayer.js +0 -57
  74. package/dist/cjs/SFServiceDesk.js +0 -1031
  75. package/dist/cjs/ServiceDeskImpl.js +0 -74
  76. package/dist/cjs/Table.js +0 -3146
  77. package/dist/cjs/ZendeskServiceDesk.js +0 -670
  78. package/dist/cjs/_node-resolve_empty.js +0 -27
  79. package/dist/cjs/agentActions.js +0 -214
  80. package/dist/cjs/aiChatEntry.js +0 -354
  81. package/dist/cjs/anonymousUserIDStorage.js +0 -254
  82. package/dist/cjs/ar-dz.js +0 -57
  83. package/dist/cjs/ar-kw.js +0 -57
  84. package/dist/cjs/ar-ly.js +0 -57
  85. package/dist/cjs/ar-ma.js +0 -57
  86. package/dist/cjs/ar-sa.js +0 -57
  87. package/dist/cjs/ar-tn.js +0 -57
  88. package/dist/cjs/ar.js +0 -57
  89. package/dist/cjs/ar2.js +0 -763
  90. package/dist/cjs/cds-aichat-container.js +0 -143
  91. package/dist/cjs/cds-aichat-custom-element.js +0 -200
  92. package/dist/cjs/cds-aichat-internal.js +0 -39150
  93. package/dist/cjs/cs.js +0 -57
  94. package/dist/cjs/cs2.js +0 -763
  95. package/dist/cjs/de-at.js +0 -57
  96. package/dist/cjs/de-ch.js +0 -57
  97. package/dist/cjs/de.js +0 -57
  98. package/dist/cjs/de2.js +0 -763
  99. package/dist/cjs/en-au.js +0 -57
  100. package/dist/cjs/en-ca.js +0 -57
  101. package/dist/cjs/en-gb.js +0 -57
  102. package/dist/cjs/en-ie.js +0 -57
  103. package/dist/cjs/en-il.js +0 -57
  104. package/dist/cjs/en-nz.js +0 -57
  105. package/dist/cjs/es-do.js +0 -57
  106. package/dist/cjs/es-us.js +0 -57
  107. package/dist/cjs/es.js +0 -57
  108. package/dist/cjs/es2.js +0 -763
  109. package/dist/cjs/export.js +0 -27
  110. package/dist/cjs/export.legacy.js +0 -27
  111. package/dist/cjs/fontUtils.js +0 -1038
  112. package/dist/cjs/fr-ca.js +0 -57
  113. package/dist/cjs/fr-ch.js +0 -57
  114. package/dist/cjs/fr.js +0 -57
  115. package/dist/cjs/fr2.js +0 -763
  116. package/dist/cjs/highlight_js.js +0 -15325
  117. package/dist/cjs/it-ch.js +0 -57
  118. package/dist/cjs/it.js +0 -57
  119. package/dist/cjs/it2.js +0 -763
  120. package/dist/cjs/ja.js +0 -57
  121. package/dist/cjs/ja2.js +0 -763
  122. package/dist/cjs/jstz.min.js +0 -43
  123. package/dist/cjs/ko.js +0 -57
  124. package/dist/cjs/ko2.js +0 -763
  125. package/dist/cjs/markdown.js +0 -8505
  126. package/dist/cjs/markdown_attrs.js +0 -805
  127. package/dist/cjs/mockServiceDesk.js +0 -887
  128. package/dist/cjs/nl.js +0 -57
  129. package/dist/cjs/nl2.js +0 -763
  130. package/dist/cjs/pt-br.js +0 -57
  131. package/dist/cjs/pt-br2.js +0 -763
  132. package/dist/cjs/pt.js +0 -57
  133. package/dist/cjs/render.js +0 -94
  134. package/dist/cjs/zh-cn.js +0 -57
  135. package/dist/cjs/zh-tw.js +0 -57
  136. package/dist/cjs/zh-tw2.js +0 -763
  137. package/dist/cjs/zh.js +0 -763
  138. package/dist/es/Chat.js +0 -8836
  139. package/dist/es/agentActions.js +0 -186
  140. package/dist/es/anonymousUserIDStorage.js +0 -249
  141. package/dist/es/highlight_js.js +0 -15320
  142. package/dist/es/jstz.min.js +0 -41
  143. package/dist/es/markdown.js +0 -8501
  144. package/dist/es/markdown_attrs.js +0 -803
@@ -1,598 +0,0 @@
1
- /*
2
-
3
-
4
- (C) Copyright IBM Corp. 2017, 2025. All Rights Reserved.
5
-
6
- Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
7
- in compliance with the License. You may obtain a copy of the License at
8
-
9
- http://www.apache.org/licenses/LICENSE-2.0
10
-
11
- Unless required by applicable law or agreed to in writing, software distributed under the License
12
- is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
13
- or implied. See the License for the specific language governing permissions and limitations under
14
- the License.
15
-
16
- @carbon/ai-chat 0.1.6
17
-
18
- Built: Feb 3 2025 9:58 am -05:00
19
-
20
-
21
-
22
- */
23
- 'use strict';
24
-
25
- var cdsAichatInternal = require('./cds-aichat-internal.js');
26
- var ServiceDeskImpl = require('./ServiceDeskImpl.js');
27
- require('lit');
28
- require('lit/decorators.js');
29
- require('react');
30
- require('react-dom');
31
- require('./highlight_js.js');
32
- require('@carbon/react');
33
- require('react-intl');
34
- require('react-redux');
35
- require('./markdown.js');
36
- require('./markdown_attrs.js');
37
- require('@carbon/web-components/es/components/button/index.js');
38
- require('@carbon/web-components/es/components/overflow-menu/index.js');
39
- require('lit/directives/unsafe-html.js');
40
- require('@carbon/web-components/es/components/slug/index.js');
41
- require('@carbon/web-components/es/components/popover/defs.js');
42
- require('@carbon/web-components/es/components/slug/defs.js');
43
- require('@carbon/web-components/es/components/slug/slug-action-button.js');
44
- require('@carbon/web-components/es/components/slug/slug.js');
45
- require('@carbon/web-components/es/components/textarea/index.js');
46
- require('@carbon/web-components/es/components/icon-button/index.js');
47
- require('lit/directives/unsafe-svg.js');
48
- require('@carbon/web-components/es/components/tag/index.js');
49
- require('@carbon/web-components/es/components/chat-button/index.js');
50
- require('@carbon/web-components/es/components/button/button.js');
51
- require('@carbon/web-components/es/components/layer/index.js');
52
-
53
- /**
54
- *
55
- * IBM Confidential
56
- *
57
- * (C) Copyright IBM Corp. 2023
58
- *
59
- * The source code for this program is not published or otherwise
60
- * divested of its trade secrets, irrespective of what has been
61
- * deposited with the U. S. Copyright Office
62
- *
63
- * US Government Users Restricted Rights - Use, duplication or
64
- * disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
65
- *
66
- */
67
- /**
68
- * This service desk integration is an integration to the Genesys contact center using their Web Messenger
69
- * functionality.
70
- *
71
- * @see https://developer.genesys.cloud/commdigital/digital/webmessaging/messengersdk for their SDK documentation.
72
- * @see https://developer.genesys.cloud/forum for their developer forum.
73
- * @see https://help.mypurecloud.com/articles/get-started-with-web-messaging for getting started with web messaging.
74
- */
75
- const PREFIX = '[GenesysMessengerServiceDesk]';
76
- // The amount of time to wait for steps in the initialization process to complete before timing out.
77
- const INIT_TIMEOUT_SECS = 10;
78
- // The Promise that is used to load the SDK. The resolve value indicates if we are reconnecting to an existing session.
79
- let scriptPromise;
80
- // This is the global Genesys object that is created by their SDK.
81
- let Genesys;
82
- class GenesysMessengerServiceDesk extends ServiceDeskImpl.ServiceDeskImpl {
83
- constructor() {
84
- super(...arguments);
85
- /**
86
- * The maximum size of files that are allowed (if file uploads are allowed). A value of 0 indicates that file
87
- * uploads are not allowed.
88
- */
89
- this.maxFileSizeKB = 0;
90
- /**
91
- * Uploads the given file.
92
- */
93
- this.doFileUpload = async (upload) => {
94
- const transfer = new DataTransfer();
95
- transfer.items.add(upload.file);
96
- const failed = () => {
97
- this.callback.setFileUploadStatus(upload.id, true, this.getIntlText('fileSharing_uploadFailed'));
98
- };
99
- // Request an upload. This process will conclude when the fileUploaded event is fired. We'll resolve the upload
100
- // Promise when that happens.
101
- this.currentFileUploadID = upload.id;
102
- cdsAichatInternal.debugLog(`${PREFIX} MessagingService.requestUpload`, upload);
103
- Genesys('command', 'MessagingService.requestUpload', { file: transfer.files }, null, failed);
104
- };
105
- }
106
- /**
107
- * Instructs the service desk to start a new chat. This should be called immediately after the service desk
108
- * instance has been created. It will make the appropriate calls to the service desk and begin communicating back
109
- * to the calling code using the callback produce to the instance. This may only be called once per instance.
110
- */
111
- async startChat(connectMessage, startChatOptions) {
112
- this.updatePersistedState({ agentsJoined: {}, lastAgentMessageID: null }, false);
113
- await this.ensureGenesys(false);
114
- const connectItem = connectMessage.output.generic.find(cdsAichatInternal.isConnectToAgent);
115
- const { preStartChatPayload } = startChatOptions;
116
- // Create an attribute with the session history key so the agent app can be loaded. Also add in any custom
117
- // attributes that may be in the pre-chat payload.
118
- const { sessionHistoryKey } = startChatOptions.agentAppInfo;
119
- const customAttributes = {
120
- ...preStartChatPayload?.customAttributes,
121
- wacSessionHistoryKey: sessionHistoryKey,
122
- };
123
- Genesys('command', 'Database.set', { messaging: { customAttributes } });
124
- // Send each of the default summary message texts to the agent.
125
- const messagesToAgent = cdsAichatInternal.getSummaryMessages(connectItem, 'Begin conversation');
126
- messagesToAgent.forEach(message => {
127
- Genesys('command', 'MessagingService.sendMessage', { message });
128
- });
129
- }
130
- /**
131
- * Handles an incoming MessagingService.messagesReceived event.
132
- */
133
- async handleMessagesReceived(event) {
134
- cdsAichatInternal.debugLog(`${PREFIX} MessagingService.messagesReceived`, event);
135
- const outbound = event.data.messages.filter((message) => message?.direction === 'Outbound');
136
- if (outbound.length) {
137
- this.callback.agentTyping(false);
138
- await cdsAichatInternal.asyncForEach(outbound, async (message) => this.handleOutboundMessage(message, true));
139
- }
140
- }
141
- /**
142
- * Handles a message.
143
- */
144
- async handleOutboundMessage(message, includeEvents) {
145
- // The agent info is on different properties depending on if the message came from the restored event or a live
146
- // message event.
147
- const agentInfo = message.channel?.from || message.from;
148
- const nickname = agentInfo?.nickname || agentInfo?.name || null;
149
- const profile_picture_url = agentInfo?.avatar || agentInfo?.image || null;
150
- const agentID = nickname || 'default-agent';
151
- const { isConnected } = this.serviceManager.store.getState().persistedToBrowserStorage.chatState.agentState;
152
- const persistedState = this.persistedState();
153
- if (!persistedState.agentsJoined[nickname] || !isConnected) {
154
- this.updatePersistedState({ agentsJoined: { [nickname]: true } });
155
- await this.callback.agentJoined({ id: agentID, nickname, profile_picture_url });
156
- }
157
- this.updatePersistedState({ lastAgentMessageID: message.id });
158
- if (message.type?.toLowerCase() === 'event') {
159
- if (includeEvents) {
160
- this.handleMessagesReceivedEvent(message);
161
- }
162
- }
163
- else if (message.text) {
164
- this.handleMessagesReceivedText(message, agentID);
165
- }
166
- else if (message.content?.length || message.files?.length) {
167
- this.handleFileAttachments(message, agentID);
168
- }
169
- }
170
- /**
171
- * Handles an event message. These include the co-browse requests.
172
- */
173
- async handleMessagesReceivedEvent(message) {
174
- cdsAichatInternal.asyncForEach(message.events, async (event) => {
175
- if (event.eventType === 'CoBrowse' && event.coBrowse?.type === 'OfferingExpired') {
176
- cdsAichatInternal.debugLog(`${PREFIX} The agent cancelled the co-browse request.`);
177
- await this.callback.screenShareEnded();
178
- }
179
- else if (event.eventType === 'CoBrowse' && event.coBrowse?.type === 'Offering') {
180
- cdsAichatInternal.debugLog(`${PREFIX} Requesting co-browse sharing from the user...`);
181
- const result = await this.callback.screenShareRequest();
182
- cdsAichatInternal.debugLog(`${PREFIX} Got result for the co-browse request: ${result}`);
183
- const { sessionId, sessionJoinToken } = event.coBrowse;
184
- const params = { joinCode: sessionJoinToken, sessionId };
185
- if (result === cdsAichatInternal.ScreenShareState.ACCEPTED) {
186
- const onSuccess = () => cdsAichatInternal.debugLog(`${PREFIX} Co-browse session successfully started`);
187
- const onError = (error) => cdsAichatInternal.consoleError(`${PREFIX} Error starting a co-browse session`, error);
188
- Genesys('command', 'CobrowseService.acceptSession', params, onSuccess, onError);
189
- }
190
- else {
191
- Genesys('command', 'CobrowseService.declineSession', params);
192
- }
193
- }
194
- });
195
- }
196
- /**
197
- * Handles a message with text in it.
198
- */
199
- async handleMessagesReceivedText(message, agentID) {
200
- await this.callback.sendMessageToUser(message.text, agentID);
201
- }
202
- /**
203
- * Handles a message with content in it. These would include file links.
204
- */
205
- async handleFileAttachments(message, agentID) {
206
- const files = this.getFileAttachments(message);
207
- const items = files.map(({ filename, url }) => cdsAichatInternal.assertType({
208
- response_type: cdsAichatInternal.MessageResponseTypes.BUTTON,
209
- kind: cdsAichatInternal.ButtonItemKind.LINK,
210
- button_type: cdsAichatInternal.ButtonItemType.URL,
211
- url,
212
- label: filename,
213
- }));
214
- if (items.length) {
215
- const messageToUser = { id: null, output: { generic: items } };
216
- await this.callback.sendMessageToUser(messageToUser, agentID);
217
- }
218
- }
219
- /**
220
- * Extracts file download links from the given message.
221
- */
222
- getFileAttachments(message) {
223
- const files = [];
224
- // Files that come in on live messages.
225
- message.content
226
- ?.filter((content) => content?.attachment)
227
- .forEach(({ attachment }) => files.push({ filename: attachment.filename, url: attachment.url }));
228
- // Files that come in from a restored event.
229
- message.files?.forEach((file) => files.push({ filename: file.name, url: file.downloadUrl }));
230
- return files;
231
- }
232
- /**
233
- * Handles an incoming MessagingService.typingReceived event. This indicates that an agent is typing.
234
- */
235
- handleTypingReceived(event) {
236
- cdsAichatInternal.debugLog(`${PREFIX} MessagingService.typingReceived`, event);
237
- if (!cdsAichatInternal.isEmptyObject(this.persistedState().agentsJoined)) {
238
- if (this.agentTypingTimeout) {
239
- clearTimeout(this.agentTypingTimeout);
240
- }
241
- const isTyping = event.data?.typing?.type === 'On';
242
- this.callback.agentTyping(isTyping);
243
- // We're supposed to get a "timeout" event to tell us when the agent has stopped typing but that event seems
244
- // to be inconsistent and we don't always get it. So we're just going to use our own timeout so we don't get
245
- // stuck with an agent permanently typing.
246
- if (isTyping) {
247
- this.agentTypingTimeout = setTimeout(() => {
248
- this.callback.agentTyping(false);
249
- this.agentTypingTimeout = null;
250
- }, event.data?.typing?.duration || 5000);
251
- }
252
- }
253
- }
254
- /**
255
- * Handles an incoming MessagingService.handleTypingTimeout event. This is the timout for an agent typing.
256
- */
257
- handleTypingTimeout(event) {
258
- cdsAichatInternal.debugLog(`${PREFIX} MessagingService.handleTypingTimeout`, event);
259
- this.callback.agentTyping(false);
260
- }
261
- /**
262
- * Handles an incoming MessagingService.fileUploaded event.
263
- */
264
- async handleFileUploaded(event) {
265
- cdsAichatInternal.debugLog(`${PREFIX} MessagingService.fileUploaded`, event);
266
- // We have to send an actual message to Genesys in order to deliver the files.
267
- Genesys('command', 'MessagingService.sendMessage', {
268
- message: this.getIntlText('fileSharing_agentMessageText'),
269
- });
270
- this.callback.setFileUploadStatus(this.currentFileUploadID);
271
- }
272
- /**
273
- * Handles an incoming MessagingService.fileUploadError event.
274
- */
275
- handleFileUploadError(event) {
276
- cdsAichatInternal.consoleError(`${PREFIX} MessagingService.fileUploadError`, event);
277
- if (this.currentFileUploadID) {
278
- this.callback.setFileUploadStatus(this.currentFileUploadID, true, this.getIntlText('fileSharing_uploadFailed'));
279
- }
280
- }
281
- /**
282
- * Handles an incoming MessagingService.error event.
283
- */
284
- handleError(event) {
285
- cdsAichatInternal.consoleError(`${PREFIX} MessagingService.error`, event);
286
- if (this.currentFileUploadID) {
287
- const errorCode = event.data?.error?.body?.errorCode;
288
- const errorMessage = event.data?.error?.body?.errorMessage || this.getIntlText('fileSharing_uploadFailed');
289
- // See https://developer.genesys.cloud/commdigital/digital/webmessaging/websocketapi#error-codes
290
- switch (errorCode) {
291
- case 4001: // File type is not supported.
292
- case 4002: // File size is greater than 102400.
293
- case 4003: // Invalid file content.
294
- case 4004: // File name invalid.
295
- case 4005: // File name is too long.
296
- case 4008: // Attachment has expired.
297
- case 4010: // Attachment not successfully uploaded.
298
- this.callback.setFileUploadStatus(this.currentFileUploadID, true, errorMessage);
299
- break;
300
- }
301
- }
302
- }
303
- /**
304
- * Handles an incoming MessagingService.restored event. This occurs when the user has reconnected to an existing
305
- * session after reloading the page.
306
- */
307
- async handleRestored(event) {
308
- cdsAichatInternal.debugLog(`${PREFIX} MessagingService.restored`, event);
309
- const { lastAgentMessageID } = this.persistedState();
310
- cdsAichatInternal.debugLog(`${PREFIX} Last agent message: ${lastAgentMessageID}`);
311
- // First we need to see if the agent's last message is in the list. If not, we're just going to give up and
312
- // assume something is not right about the history instead of just potentially repeating the whole thing.
313
- if (lastAgentMessageID && event.data?.messages?.length) {
314
- const { messages } = event.data;
315
- const lastIndex = messages.findIndex((message) => message.id === lastAgentMessageID);
316
- if (lastIndex > 0) {
317
- // Go backwards from the last index and handle each message.
318
- for (let index = lastIndex - 1; index >= 0; index--) {
319
- const message = messages[index];
320
- if (message.messageType === 'outbound') {
321
- // eslint-disable-next-line no-await-in-loop
322
- await this.handleOutboundMessage(message, false);
323
- }
324
- }
325
- }
326
- }
327
- }
328
- /**
329
- * Handles an incoming MessagingService.offline event.
330
- */
331
- handleOffline(event) {
332
- cdsAichatInternal.debugLog(`${PREFIX} MessagingService.offline`, event);
333
- this.callback.setErrorStatus({ type: cdsAichatInternal.ErrorType.DISCONNECTED, isDisconnected: true });
334
- }
335
- /**
336
- * Handles an incoming MessagingService.reconnected event.
337
- */
338
- handleReconnected(event) {
339
- cdsAichatInternal.debugLog(`${PREFIX} MessagingService.reconnected`, event);
340
- this.callback.setErrorStatus({ type: cdsAichatInternal.ErrorType.DISCONNECTED, isDisconnected: false });
341
- }
342
- /**
343
- * Handles an incoming CobrowseService.sessionEnded event.
344
- */
345
- async handleCoBrowseEnded(event) {
346
- cdsAichatInternal.debugLog(`${PREFIX} CobrowseService.sessionEnded`, event);
347
- await this.callback.screenShareEnded();
348
- }
349
- /**
350
- * Tells the service desk to terminate the chat.
351
- */
352
- async endChat() {
353
- this.stopUserTypingInterval();
354
- this.updatePersistedState({ agentsJoined: {}, lastAgentMessageID: null }, false);
355
- }
356
- /**
357
- * Sends a message to the agent in the service desk.
358
- */
359
- async sendMessageToAgent(message, messageID, additionalData) {
360
- if (message.input.text) {
361
- Genesys('command', 'MessagingService.sendMessage', {
362
- message: message.input.text,
363
- });
364
- }
365
- if (additionalData.filesToUpload.length) {
366
- // If a file was provided, then upload it. The web chat service should guarantee we never get more than one.
367
- this.doFileUpload(additionalData.filesToUpload[0]);
368
- }
369
- }
370
- /**
371
- * Informs the service desk that the user has read all the messages that have been sent by the service desk.
372
- *
373
- * @returns Returns a Promise that resolves when the service desk has successfully handled the call.
374
- */
375
- async userReadMessages() {
376
- // Not supported in this integration.
377
- }
378
- /**
379
- * Tells the service desk if a user has started or stopped typing.
380
- */
381
- async userTyping(isTyping) {
382
- this.stopUserTypingInterval();
383
- if (isTyping) {
384
- Genesys('command', 'MessagingService.sendTyping');
385
- // Genesys seems to expect us to keep sending a typing indicator while a user is typing or the indicator
386
- // automatically stops after 5 seconds.
387
- this.userTypingInterval = window.setInterval(() => {
388
- Genesys('command', 'MessagingService.sendTyping');
389
- }, 2500);
390
- }
391
- }
392
- /**
393
- * Stops and clear the interval that is used to tell Genesys that the user is typing.
394
- */
395
- stopUserTypingInterval() {
396
- if (this.userTypingInterval) {
397
- clearInterval(this.userTypingInterval);
398
- this.userTypingInterval = null;
399
- }
400
- }
401
- /**
402
- * Checks if any agents are online and ready to communicate with the user.
403
- */
404
- async areAnyAgentsOnline(connectMessage) {
405
- // Genesys doesn't provide this information.
406
- return true;
407
- }
408
- /**
409
- * Indicates that the user has selected some files to be uploaded but that the user has not yet chosen to send
410
- * them to the agent. This method can use this as an opportunity to perform any early validation of the files in
411
- * order to display an error to the user. It should not actually upload the files at this point. If the user
412
- * chooses to send the files to the agent, they will be included later when {@link #sendMessageToAgent} is called.
413
- */
414
- filesSelectedForUpload(uploads) {
415
- uploads.forEach(upload => {
416
- if (upload.file.size > this.maxFileSizeKB * 1024) {
417
- const maxSize = `${this.maxFileSizeKB}KB`;
418
- const errorMessage = this.instance.getIntl().formatMessage({ id: 'fileSharing_fileTooLarge' }, { maxSize });
419
- this.callback.setFileUploadStatus(upload.id, true, errorMessage);
420
- }
421
- });
422
- }
423
- /**
424
- * Tells the service desk that the user has requested to stop sharing their screen.
425
- */
426
- async screenShareStop() {
427
- Genesys('command', 'CobrowseService.stopSession');
428
- }
429
- /**
430
- * Ensures that the Genesys script is loaded.
431
- */
432
- async ensureGenesys(isReconnecting) {
433
- if (!scriptPromise) {
434
- scriptPromise = this.installGenesys(isReconnecting);
435
- }
436
- return scriptPromise;
437
- }
438
- /**
439
- * This installs Genesys using their embed code.
440
- */
441
- async installGenesys(isReconnecting) {
442
- const { environment, deploymentID, scriptURL } = this.config;
443
- cdsAichatInternal.debugLog(`${PREFIX} Creating integration using config`, this.config);
444
- if (!this.persistedState()) {
445
- this.updatePersistedState({ agentsJoined: {}, lastAgentMessageID: null }, false);
446
- }
447
- else {
448
- cdsAichatInternal.debugLog(`${PREFIX} Retrieved previous state`, this.persistedState());
449
- }
450
- const config = { environment, deploymentId: deploymentID, debug: this.instance.getState().isDebugEnabled };
451
- // This code is a simplified version of the Genesys embed script and is required by their SDK.
452
- const windowObject = window;
453
- const propertyName = 'Genesys';
454
- windowObject._genesysJs = propertyName;
455
- windowObject[propertyName] = {
456
- t: new Date(),
457
- c: config,
458
- q: [],
459
- };
460
- await cdsAichatInternal.loadScript(scriptURL);
461
- Genesys = windowObject[propertyName];
462
- // Uncomment for debugging/development purposes.
463
- // this.addAllEvents();
464
- const serviceStartedPromise = new Promise((resolve, reject) => {
465
- function serviceStartedHandler(event) {
466
- cdsAichatInternal.debugLog(`${PREFIX} MessagingService.started`, event);
467
- resolve(!event?.data?.newSession);
468
- }
469
- Genesys('subscribe', 'MessagingService.started', serviceStartedHandler, reject);
470
- });
471
- // Subscribe to all the events that we will need to listen to.
472
- Genesys('subscribe', 'MessagingService.messagesReceived', (event) => this.handleMessagesReceived(event));
473
- Genesys('subscribe', 'MessagingService.typingReceived', (event) => this.handleTypingReceived(event));
474
- Genesys('subscribe', 'MessagingService.typingTimeout', (event) => this.handleTypingTimeout(event));
475
- Genesys('subscribe', 'MessagingService.fileUploaded', (event) => this.handleFileUploaded(event));
476
- Genesys('subscribe', 'MessagingService.fileUploadError', (event) => this.handleFileUploadError(event));
477
- Genesys('subscribe', 'MessagingService.error', (event) => this.handleError(event));
478
- Genesys('subscribe', 'MessagingService.reconnected', (event) => this.handleReconnected(event));
479
- Genesys('subscribe', 'MessagingService.offline', (event) => this.handleOffline(event));
480
- Genesys('subscribe', 'MessagingService.restored', (event) => this.handleRestored(event));
481
- Genesys('subscribe', 'CobrowseService.sessionEnded', (event) => this.handleCoBrowseEnded(event));
482
- // Load the configuration data for the deployment.
483
- await cdsAichatInternal.resolveOrTimeout(new Promise((resolve, reject) => {
484
- Genesys('registerPlugin', 'ConfigPlugin', (plugin) => {
485
- plugin
486
- .command('GenesysJS.configuration')
487
- .then((data) => {
488
- this.genesysConfig = data;
489
- cdsAichatInternal.debugLog(`${PREFIX} Received GenesysJS.configuration`, this.genesysConfig);
490
- resolve();
491
- })
492
- .catch(reject);
493
- });
494
- }), INIT_TIMEOUT_SECS * 1000, `The GenesysJS.configuration command failed to return a configuration after ${INIT_TIMEOUT_SECS} seconds.`);
495
- // Create the plugin that would be used when using user authentication.
496
- if (this.genesysConfig?.auth.enabled) {
497
- cdsAichatInternal.debugLog(`${PREFIX} Authentication is enabled`);
498
- Genesys('registerPlugin', 'AuthProvider', (authProvider) => {
499
- authProvider.registerCommand('getAuthCode', (event) => {
500
- cdsAichatInternal.debugLog(`${PREFIX} AuthProvider.getAuthCode`, event);
501
- this.eventBus.fire({ type: "agent:genesysMessenger:getAuthCode" /* BusEventType.GENESYS_MESSENGER_GET_AUTH_CODE */, genesysEvent: event }, this.instance);
502
- });
503
- authProvider.registerCommand('reAuthenticate', (event) => {
504
- cdsAichatInternal.debugLog(`${PREFIX} AuthProvider.reAuthenticate`, event);
505
- this.eventBus.fire({ type: "agent:genesysMessenger:reAuthenticate" /* BusEventType.GENESYS_MESSENGER_REAUTHENTICATE */, genesysEvent: event }, this.instance);
506
- });
507
- authProvider.subscribe('Auth.loggedOut', (event) => {
508
- cdsAichatInternal.debugLog(`${PREFIX} AuthProvider.loggedOut`, event);
509
- this.eventBus.fire({ type: "agent:genesysMessenger:loggedOut" /* BusEventType.GENESYS_MESSENGER_LOGGED_OUT */, genesysEvent: event }, this.instance);
510
- });
511
- authProvider.subscribe('Auth.authError', (error) => {
512
- cdsAichatInternal.debugLog(`${PREFIX} AuthProvider.authError`, error);
513
- this.eventBus.fire({ type: "agent:genesysMessenger:authError" /* BusEventType.GENESYS_MESSENGER_AUTH_ERROR */, genesysError: error }, this.instance);
514
- });
515
- // Tell Messenger that your plugin is ready (mandatory).
516
- authProvider.ready();
517
- // Make the AuthProvider instance available to the client.
518
- this.eventBus.fire({ type: "agent:genesysMessenger:AuthProvider" /* BusEventType.GENESYS_MESSENGER_AUTH_PROVIDER */, authProvider }, this.instance);
519
- });
520
- }
521
- // Wait for the messaging service to become ready before completing the initialization.
522
- await cdsAichatInternal.resolveOrTimeout(new Promise(resolve => {
523
- Genesys('subscribe', 'MessagingService.ready', (event) => {
524
- cdsAichatInternal.debugLog(`${PREFIX} MessagingService.ready`, event);
525
- resolve();
526
- });
527
- }), INIT_TIMEOUT_SECS * 1000, `The Genesys MessagingService failed to report ready after ${INIT_TIMEOUT_SECS} seconds.`);
528
- let isNewSession = false;
529
- if (isReconnecting) {
530
- // This event only fires if reconnecting to an existing session.
531
- isNewSession = await cdsAichatInternal.resolveOrTimeout(serviceStartedPromise, INIT_TIMEOUT_SECS * 1000, `The MessagingService.started event failed to fire after ${INIT_TIMEOUT_SECS} seconds.`);
532
- }
533
- // We have to look through the file upload modes to see if there are any files allowed. The docs suggest there
534
- // should only be one object here but the schema does use an array so let's just go through all the objects to
535
- // be safe. We'll collect up the unique set of mime types allowed and figure out the largest file size allowed.
536
- // The servers will still do their own validation.
537
- const mimeTypesSet = new Set();
538
- if (this.genesysConfig?.messenger?.fileUpload?.modes) {
539
- Object.values(this.genesysConfig.messenger.fileUpload.modes).forEach((mode) => {
540
- if (mode.maxFileSizeKB > 0) {
541
- this.maxFileSizeKB = Math.max(this.maxFileSizeKB, mode.maxFileSizeKB);
542
- }
543
- mode.fileTypes?.forEach((type) => mimeTypesSet.add(type));
544
- });
545
- }
546
- const allowedFileUploadTypes = Array.from(mimeTypesSet).join(',') || undefined;
547
- this.callback.updateCapabilities({ allowFileUploads: this.maxFileSizeKB > 0, allowedFileUploadTypes });
548
- return isNewSession;
549
- }
550
- /**
551
- * This will be called when the service desk is first initialized and it is determined that the user was previously
552
- * connected to an agent. This function should perform whatever steps are necessary to reconnect the user. Web chat
553
- * will assume the user is permitted to send messages and is connected to the same agent when this function returns.
554
- *
555
- * @returns true to indicate that the reconnect was successful.
556
- */
557
- async reconnect() {
558
- cdsAichatInternal.debugLog(`${PREFIX} Reconnecting to agent...`);
559
- return this.ensureGenesys(true);
560
- }
561
- // Old code to support debugging.
562
- addAllEvents() {
563
- this.addEvent('MessagingService.ready');
564
- this.addEvent('MessagingService.started');
565
- this.addEvent('MessagingService.messagesReceived');
566
- this.addEvent('MessagingService.uploading');
567
- this.addEvent('MessagingService.uploadApproved');
568
- this.addEvent('MessagingService.fileUploaded');
569
- this.addEvent('MessagingService.fileUploadError');
570
- this.addEvent('MessagingService.fileUploadCancelled');
571
- this.addEvent('MessagingService.fileReceived');
572
- this.addEvent('MessagingService.messagesUpdated');
573
- this.addEvent('MessagingService.fileDownloaded');
574
- this.addEvent('MessagingService.fileDownloadError');
575
- this.addEvent('MessagingService.fileDeleted');
576
- this.addEvent('MessagingService.oldMessages');
577
- this.addEvent('MessagingService.historyComplete');
578
- this.addEvent('MessagingService.typingReceived');
579
- this.addEvent('MessagingService.typingTimeout');
580
- this.addEvent('MessagingService.typingStarted');
581
- this.addEvent('MessagingService.restored');
582
- this.addEvent('MessagingService.sessionCleared');
583
- this.addEvent('MessagingService.offline');
584
- this.addEvent('MessagingService.reconnecting');
585
- this.addEvent('MessagingService.reconnected');
586
- this.addEvent('MessagingService.conversationDisconnected');
587
- this.addEvent('MessagingService.readOnlyConversation');
588
- this.addEvent('MessagingService.conversationReset');
589
- this.addEvent('MessagingService.error');
590
- }
591
- addEvent(eventName) {
592
- Genesys('subscribe', eventName, (...args) => {
593
- console.log(`${PREFIX} (All) ${eventName}`, args);
594
- });
595
- }
596
- }
597
-
598
- exports.GenesysMessengerServiceDesk = GenesysMessengerServiceDesk;