@microsoft/omnichannel-chat-widget 1.0.6-main.3aba33c → 1.0.6-main.ec7a5f0

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 (29) hide show
  1. package/lib/cjs/common/utils.js +17 -2
  2. package/lib/cjs/components/footerstateful/FooterStateful.js +2 -2
  3. package/lib/cjs/components/footerstateful/downloadtranscriptstateful/DownloadTranscriptStateful.js +21 -12
  4. package/lib/cjs/components/footerstateful/downloadtranscriptstateful/interfaces/IWebChatTranscriptConfig.js +1 -0
  5. package/lib/cjs/components/livechatwidget/common/createDownloadTranscriptProps.js +27 -0
  6. package/lib/cjs/components/livechatwidget/common/defaultProps/dummyDefaultProps.js +9 -1
  7. package/lib/cjs/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +13 -9
  8. package/lib/cjs/components/webchatcontainerstateful/WebChatContainerStateful.js +12 -10
  9. package/lib/cjs/components/webchatcontainerstateful/common/defaultStyles/defaultAdaptiveCardStyles.js +3 -1
  10. package/lib/cjs/plugins/createChatTranscript.js +548 -0
  11. package/lib/esm/common/utils.js +15 -1
  12. package/lib/esm/components/footerstateful/FooterStateful.js +2 -2
  13. package/lib/esm/components/footerstateful/downloadtranscriptstateful/DownloadTranscriptStateful.js +22 -13
  14. package/lib/esm/components/footerstateful/downloadtranscriptstateful/interfaces/IWebChatTranscriptConfig.js +1 -0
  15. package/lib/esm/components/livechatwidget/common/createDownloadTranscriptProps.js +20 -0
  16. package/lib/esm/components/livechatwidget/common/defaultProps/dummyDefaultProps.js +9 -1
  17. package/lib/esm/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +13 -9
  18. package/lib/esm/components/webchatcontainerstateful/WebChatContainerStateful.js +12 -10
  19. package/lib/esm/components/webchatcontainerstateful/common/defaultStyles/defaultAdaptiveCardStyles.js +3 -1
  20. package/lib/esm/plugins/createChatTranscript.js +543 -0
  21. package/lib/types/common/utils.d.ts +1 -0
  22. package/lib/types/components/footerstateful/downloadtranscriptstateful/DownloadTranscriptStateful.d.ts +2 -1
  23. package/lib/types/components/footerstateful/downloadtranscriptstateful/interfaces/IDownloadTranscriptProps.d.ts +5 -0
  24. package/lib/types/components/footerstateful/downloadtranscriptstateful/interfaces/IWebChatTranscriptConfig.d.ts +13 -0
  25. package/lib/types/components/livechatwidget/common/createDownloadTranscriptProps.d.ts +24 -0
  26. package/lib/types/components/webchatcontainerstateful/interfaces/IAdaptiveCardStyles.d.ts +2 -0
  27. package/lib/types/components/webchatcontainerstateful/interfaces/IWebChatProps.d.ts +1 -0
  28. package/lib/types/plugins/createChatTranscript.d.ts +2 -0
  29. package/package.json +1 -1
@@ -0,0 +1,548 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _utils = require("../common/utils");
8
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
9
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
10
+ function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
11
+ class TranscriptHTMLBuilder {
12
+ // eslint-disable-line @typescript-eslint/no-explicit-any
13
+
14
+ constructor(options) {
15
+ var _this$options, _this$options2, _this$options3, _this$options4, _this$options5, _this$options6, _this$options7, _this$options8, _this$options9, _this$options10, _this$options11;
16
+ _defineProperty(this, "options", void 0);
17
+ _defineProperty(this, "pageTitle", "Customer Transcript");
18
+ _defineProperty(this, "attachmentMessage", "The following attachment was uploaded during the conversation: ");
19
+ _defineProperty(this, "networkOnlineMessage", "Connection restored. Please refresh the page");
20
+ _defineProperty(this, "networkOfflineMessage", "Network Error. Please make sure you are connected to the internet.");
21
+ _defineProperty(this, "transcriptBackgroundColor", "#FFF");
22
+ _defineProperty(this, "agentAvatarBackgroundColor", "#E8E8E8");
23
+ _defineProperty(this, "agentAvatarFontColor", "#000");
24
+ _defineProperty(this, "customerAvatarBackgroundColor", "#2266E3");
25
+ _defineProperty(this, "customerAvatarFontColor", "#FFF");
26
+ _defineProperty(this, "disableMarkdownMessageFormatting", false);
27
+ _defineProperty(this, "disableNewLineMarkdownSupport", false);
28
+ // eslint-disable-line @typescript-eslint/no-explicit-any
29
+ this.options = options;
30
+ if (!this.options || !this.options.messages) {
31
+ this.options.messages = [];
32
+ }
33
+ if ((_this$options = this.options) !== null && _this$options !== void 0 && _this$options.pageTitle) {
34
+ this.pageTitle = this.options.pageTitle;
35
+ }
36
+ if ((_this$options2 = this.options) !== null && _this$options2 !== void 0 && _this$options2.attachmentMessage) {
37
+ this.attachmentMessage = this.options.attachmentMessage;
38
+ }
39
+ if ((_this$options3 = this.options) !== null && _this$options3 !== void 0 && _this$options3.networkOnlineMessage) {
40
+ this.networkOnlineMessage = this.options.networkOnlineMessage;
41
+ }
42
+ if ((_this$options4 = this.options) !== null && _this$options4 !== void 0 && _this$options4.networkOfflineMessage) {
43
+ this.networkOfflineMessage = this.options.networkOfflineMessage;
44
+ }
45
+ if ((_this$options5 = this.options) !== null && _this$options5 !== void 0 && _this$options5.transcriptBackgroundColor) {
46
+ this.transcriptBackgroundColor = this.options.transcriptBackgroundColor;
47
+ }
48
+ if ((_this$options6 = this.options) !== null && _this$options6 !== void 0 && _this$options6.agentAvatarBackgroundColor) {
49
+ this.agentAvatarBackgroundColor = this.options.agentAvatarBackgroundColor;
50
+ }
51
+ if ((_this$options7 = this.options) !== null && _this$options7 !== void 0 && _this$options7.agentAvatarFontColor) {
52
+ this.agentAvatarFontColor = this.options.agentAvatarFontColor;
53
+ }
54
+ if ((_this$options8 = this.options) !== null && _this$options8 !== void 0 && _this$options8.customerAvatarBackgroundColor) {
55
+ this.customerAvatarBackgroundColor = this.options.customerAvatarBackgroundColor;
56
+ }
57
+ if ((_this$options9 = this.options) !== null && _this$options9 !== void 0 && _this$options9.customerAvatarFontColor) {
58
+ this.customerAvatarFontColor = this.options.customerAvatarFontColor;
59
+ }
60
+ if ((_this$options10 = this.options) !== null && _this$options10 !== void 0 && _this$options10.disableMarkdownMessageFormatting) {
61
+ this.disableMarkdownMessageFormatting = this.options.disableMarkdownMessageFormatting;
62
+ }
63
+ if ((_this$options11 = this.options) !== null && _this$options11 !== void 0 && _this$options11.disableNewLineMarkdownSupport) {
64
+ this.disableNewLineMarkdownSupport = this.options.disableNewLineMarkdownSupport;
65
+ }
66
+ }
67
+ createTitleElement() {
68
+ const htmlData = `<title> ${this.pageTitle} </title>`;
69
+ return htmlData;
70
+ }
71
+ createExternalScriptElements() {
72
+ const htmlData = `
73
+ <script src="https://cdn.botframework.com/botframework-webchat/4.15.7/webchat.js"><\/script>
74
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/rxjs/7.8.0/rxjs.umd.min.js" integrity="sha512-v0/YVjBcbjLN6scjmmJN+h86koeB7JhY4/2YeyA5l+rTdtKLv0VbDBNJ32rxJpsaW1QGMd1Z16lsLOSGI38Rbg==" crossorigin="anonymous" referrerpolicy="no-referrer"><\/script>
75
+ <script src="https://unpkg.com/react@18.2.0/umd/react.production.min.js"><\/script>
76
+ <script src="https://unpkg.com/react-dom@18.2.0/umd/react-dom.production.min.js"><\/script>
77
+ <script src="https://cdn.jsdelivr.net/npm/markdown-it@13.0.1/dist/markdown-it.min.js" integrity="sha256-hNyljag6giCsjv/yKmxK8/VeHzvMDvc5u8AzmRvm1BI=" crossorigin="anonymous"><\/script>
78
+ `;
79
+ return htmlData;
80
+ }
81
+ createHeadElement() {
82
+ const htmlData = `
83
+ <head>
84
+ ${this.createTitleElement()}
85
+ ${this.createExternalScriptElements()}
86
+ <script>
87
+ function shareObservable(observable) {
88
+ let observers = [];
89
+ let subscription;
90
+
91
+ return new Observable(observer => {
92
+ if (!subscription) {
93
+ subscription = observable.subscribe({
94
+ complete() {
95
+ observers.forEach(observer => observer.complete());
96
+ },
97
+ error(err) {
98
+ observers.forEach(observer => observer.error(err));
99
+ },
100
+ next(value) {
101
+ observers.forEach(observer => observer.next(value));
102
+ }
103
+ });
104
+ }
105
+
106
+ observers.push(observer);
107
+
108
+ return () => {
109
+ observers = observers.filter(o => o !== observer);
110
+
111
+ if (!observers.length) {
112
+ subscription.unsubscribe();
113
+ subscription = null;
114
+ }
115
+ };
116
+ });
117
+ }
118
+ <\/script>
119
+ <script>
120
+ const messages = ${JSON.stringify(this.options.messages)};
121
+ const disableMarkdownMessageFormatting = ${this.disableMarkdownMessageFormatting};
122
+ const disableNewLineMarkdownSupport = ${this.disableNewLineMarkdownSupport};
123
+ <\/script>
124
+ <script>
125
+ class Translator {
126
+ static convertTranscriptMessageToActivity(message) {
127
+ const {created, isControlMessage, content, tags, from, attachments, amsMetadata, amsReferences} = message;
128
+ const activity = {
129
+ from: {
130
+ role: 'bot'
131
+ },
132
+ type: 'message'
133
+ };
134
+
135
+ // Ignore control messages
136
+ if (isControlMessage) {
137
+ return false;
138
+ }
139
+
140
+ if (tags) {
141
+ const formattedTags = tags.split(',');
142
+
143
+ // Ignore system message
144
+ if (formattedTags.includes('system')) {
145
+ return false;
146
+ }
147
+
148
+ // Ignore hidden message
149
+ if (formattedTags.includes('Hidden')) {
150
+ return false;
151
+ }
152
+ }
153
+
154
+ // Add C1 user display name
155
+ if (from && from.user && from.user.displayName) {
156
+ activity.from.name = from.user.displayName;
157
+ }
158
+
159
+ // Add C2 user display name
160
+ if (from && from.application && from.application.displayName && from.application.displayName === 'Customer') {
161
+ activity.from = {
162
+ role: 'user',
163
+ name: from.application.displayName
164
+ };
165
+ }
166
+
167
+ // Attachments
168
+ if (amsReferences && amsMetadata) {
169
+ const metadata = JSON.parse(amsMetadata);
170
+ const { fileName } = metadata[0];
171
+ const text = \`${this.attachmentMessage}\${fileName}\`;
172
+
173
+ if (message.attachments && message.attachments.length > 0 && message.contentUrl) {
174
+ activity.attachments = message.attachments;
175
+ activity.attachments[0].contentUrl = message.contentUrl;
176
+ activity.attachments[0].thumbnailUrl = message.contentUrl;
177
+ };
178
+
179
+ return {
180
+ ...activity,
181
+ text,
182
+ timestamp: created
183
+ }
184
+ }
185
+
186
+ // Message
187
+ if (content) {
188
+ // Adaptive card formatting
189
+ if (content.includes('"text"') && content.includes('"attachments"') && content.includes('"suggestedActions"')) {
190
+ try {
191
+ const partialActivity = JSON.parse(content);
192
+ return {
193
+ ...activity,
194
+ ...partialActivity,
195
+ timestamp: created
196
+ };
197
+ } catch {
198
+
199
+ }
200
+ }
201
+ }
202
+
203
+ return {
204
+ ...activity,
205
+ text: content,
206
+ timestamp: created
207
+ };
208
+ }
209
+ }
210
+ <\/script>
211
+ <script>
212
+ class TranscriptAdapter {
213
+ constructor() {
214
+ this.connectionStatus$ = new window.rxjs.BehaviorSubject(0); // Uninitialized
215
+ this.activity$ = shareObservable(new Observable((observer) => {
216
+ this.activityObserver = observer;
217
+
218
+ this.connectionStatus$.next(1); // Connecting
219
+ this.connectionStatus$.next(2); // Online
220
+
221
+ // Retrieve messages
222
+ if (messages) {
223
+ setTimeout(() => { // setTimeout is needed due to some WebChat issues
224
+ messages.map((message) => {
225
+ this.activityObserver.next({
226
+ ...Translator.convertTranscriptMessageToActivity(message),
227
+ type: 'message'
228
+ });
229
+ });
230
+ }, 1);
231
+ }
232
+ }));
233
+ }
234
+ }
235
+ <\/script>
236
+ <style>
237
+ body {
238
+ margin: 0;
239
+ }
240
+
241
+ .message-name {
242
+ font-family: Segoe UI,SegoeUI,Helvetica Neue,Helvetica,Arial,sans-serif;
243
+ font-weight: 700;
244
+ font-size: 10px;
245
+ }
246
+
247
+ .message-timestamp {
248
+ font-family: Segoe UI,SegoeUI,Helvetica Neue,Helvetica,Arial,sans-serif;
249
+ font-weight: 500;
250
+ font-size: 10px;
251
+ }
252
+
253
+ .avatar {
254
+ width: 40px;
255
+ height: 40px;
256
+ border-radius: 50%;
257
+ text-align: center;
258
+ }
259
+
260
+ .avatar--bot {
261
+ background-color: ${this.agentAvatarBackgroundColor};
262
+ }
263
+
264
+ .avatar--user {
265
+ background-color: ${this.customerAvatarBackgroundColor};
266
+ }
267
+
268
+ .avatar > p {
269
+ font-weight: 600;
270
+ text-align: center;
271
+ line-height: 0.5;
272
+ font-family: "Segoe UI", Arial, sans-serif;
273
+ }
274
+
275
+ .avatar--bot > p {
276
+ color: ${this.agentAvatarFontColor};
277
+ }
278
+
279
+ .avatar--user > p {
280
+ color: ${this.customerAvatarFontColor};
281
+ }
282
+
283
+ .webchat__bubble__content>div.ms_lcw_webchat_adaptive_card {
284
+ background-color: #FFF;
285
+ }
286
+
287
+ div[class="ac-textBlock"] {
288
+ color: #000 !important;
289
+ }
290
+
291
+ .ms_lcw_webchat_received_message a:link, .ms_lcw_webchat_received_message a:visited, .ms_lcw_webchat_received_message a:hover, .ms_lcw_webchat_received_message a:active {
292
+ color: #FFF;
293
+ }
294
+ <\/style>
295
+ </head>
296
+ `;
297
+ return htmlData;
298
+ }
299
+ createBodyElement() {
300
+ const htmlData = `
301
+ <body>
302
+ <script>
303
+ if (!navigator.onLine) {
304
+ const offlineText = \`${this.networkOfflineMessage}\`;
305
+ document.body.innerHTML = offlineText;
306
+ }
307
+
308
+ window.addEventListener("online", () => {
309
+ document.body.innerHTML = \`${this.networkOnlineMessage} <button onclick="window.location.reload()"> Refresh </button>\`;
310
+ });
311
+ <\/script>
312
+ <div id="transcript"></div>
313
+ <script>
314
+ const getIconText = (text) => {
315
+ if (text) {
316
+ const initials = text.split(/\\s/).reduce((response, word) => response += word.slice(0, 1), '');
317
+ if (initials.length > 1) {
318
+ return initials.substring(0, 2).toUpperCase();
319
+ } else {
320
+ return text.substring(0, 2).toUpperCase();
321
+ }
322
+ }
323
+
324
+ return "";
325
+ }
326
+
327
+ const activityMiddleware = () => (next) => (...args) => {
328
+ const [card] = args;
329
+
330
+ if (card.activity) {
331
+ if (card.activity.from && card.activity.from.role === "channel") {
332
+ return () => false;
333
+ }
334
+
335
+ // Incoming text message
336
+ if (card.activity.text && card.activity.from && card.activity.from.role !== "user") {
337
+ return (...renderArgs) => (React.createElement(
338
+ 'div',
339
+ {className: 'ms_lcw_webchat_received_message'},
340
+ next(...args)(...renderArgs)
341
+ ))
342
+ }
343
+ }
344
+
345
+ return next(...args);
346
+ };
347
+
348
+ const activityStatusMiddleware = () => (next) => (...args) => {
349
+ const [card] = args;
350
+ const {activity} = card;
351
+
352
+ if (activity) {
353
+ const {from, timestamp} = activity;
354
+
355
+ const nameElement = React.createElement(
356
+ 'span',
357
+ {className: 'message-name'},
358
+ from.name
359
+ );
360
+
361
+ const formattedDate = new Date(timestamp);
362
+ const formattedTimeString = formattedDate.toLocaleTimeString("en-us", { year: "numeric", month:"numeric", day:"numeric", hour: "2-digit", minute: "2-digit"});
363
+
364
+ const timestampElement = React.createElement(
365
+ 'span',
366
+ {className: 'message-timestamp'},
367
+ formattedTimeString
368
+ );
369
+
370
+ return from.name && timestamp && React.createElement('span', null, nameElement, ' - ', timestampElement)
371
+ }
372
+
373
+ return next(...args);
374
+ };
375
+
376
+ const avatarMiddleware = () => (next) => (...args) => {
377
+ const [card] = args;
378
+ const {fromUser, activity} = card;
379
+ const initials = getIconText(activity.from.name);
380
+
381
+ const avatarElement = React.createElement(
382
+ "div",
383
+ {className: fromUser? "avatar avatar--user": "avatar avatar--bot"},
384
+ React.createElement(
385
+ "p",
386
+ null,
387
+ \`\${initials}\`
388
+ )
389
+ );
390
+
391
+ return avatarElement;
392
+ }
393
+
394
+ const attachmentMiddleware = () => (next) => (...args) => {
395
+ const [card] = args;
396
+ const {activity} = card;
397
+
398
+ if (activity) {
399
+ const { activity: { attachments }, attachment } = card;
400
+
401
+ // No attachment
402
+ if (!attachments || !attachments.length || !attachment) {
403
+ return next(...args);
404
+ }
405
+
406
+ let { content, contentType } = attachment || { content: "", contentType: "" };
407
+
408
+ // Adaptive card
409
+ if (contentType.startsWith("application/vnd.microsoft.card")) {
410
+ const adaptiveCardElement = React.createElement(
411
+ "div",
412
+ {className: 'ms_lcw_webchat_adaptive_card'},
413
+ next(...args)
414
+ );
415
+
416
+ return adaptiveCardElement;
417
+ }
418
+ }
419
+
420
+ return next(...args);
421
+ }
422
+
423
+ const createMarkdown = (disableMarkdownMessageFormatting, disableNewLineMarkdownSupport) => {
424
+ let markdown;
425
+ if (!disableMarkdownMessageFormatting) {
426
+ markdown = new window.markdownit(
427
+ "default",
428
+ {
429
+ html: true,
430
+ linkify: true,
431
+ breaks: (!disableNewLineMarkdownSupport)
432
+ }
433
+ );
434
+ } else {
435
+ markdown = new window.markdownit(
436
+ "zero",
437
+ {
438
+ html: true,
439
+ linkify: true,
440
+ breaks: (!disableNewLineMarkdownSupport)
441
+ }
442
+ );
443
+
444
+ markdown.enable([
445
+ "entity",
446
+ "linkify",
447
+ "html_block",
448
+ "html_inline",
449
+ "newline"
450
+ ]);
451
+ }
452
+
453
+ return markdown;
454
+ };
455
+
456
+ const markdown = createMarkdown(disableMarkdownMessageFormatting, disableNewLineMarkdownSupport);
457
+ const renderMarkdown = (text) => {
458
+ const render = disableNewLineMarkdownSupport? markdown.renderInline.bind(markdown): markdown.render.bind(markdown);
459
+ text = render(text);
460
+ return text;
461
+ };
462
+
463
+ const adapter = new TranscriptAdapter();
464
+ const styleOptions = {
465
+ hideSendBox: true,
466
+ backgroundColor: '${this.transcriptBackgroundColor}',
467
+ bubbleBackground: '${this.agentAvatarBackgroundColor}',
468
+ bubbleTextColor: '${this.agentAvatarFontColor}',
469
+ bubbleBorderRadius: 12,
470
+ bubbleNubSize: 1,
471
+ bubbleFromUserBackground: '${this.customerAvatarBackgroundColor}',
472
+ bubbleFromUserTextColor: '${this.customerAvatarFontColor}',
473
+ bubbleFromUserBorderRadius: 12,
474
+ bubbleFromUserNubSize: 1,
475
+ botAvatarInitials: 'C1',
476
+ userAvatarInitials: 'C2'
477
+ };
478
+
479
+ window.WebChat.renderWebChat({
480
+ directLine: adapter,
481
+ styleOptions,
482
+ activityMiddleware,
483
+ activityStatusMiddleware,
484
+ avatarMiddleware,
485
+ attachmentMiddleware,
486
+ renderMarkdown
487
+ },
488
+ document.getElementById('transcript'));
489
+ <\/script>
490
+ </body>
491
+ `;
492
+ return htmlData;
493
+ }
494
+ createHTML() {
495
+ const htmlData = `
496
+ <html>
497
+ ${this.createHeadElement()}
498
+ ${this.createBodyElement()}
499
+ </html>
500
+ `;
501
+ return htmlData;
502
+ }
503
+ }
504
+ const createChatTranscript = async function (transcript, chatSDK) {
505
+ let renderAttachments = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
506
+ let transcriptOptions = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
507
+ // eslint-disable-line @typescript-eslint/no-explicit-any
508
+ const transcriptMessages = JSON.parse(transcript);
509
+ const convertBlobToBase64 = async blob => {
510
+ return new Promise(resolve => {
511
+ const reader = new FileReader();
512
+ reader.onloadend = () => resolve(reader.result);
513
+ reader.readAsDataURL(blob);
514
+ });
515
+ };
516
+ let messages = transcriptMessages;
517
+ if (renderAttachments) {
518
+ messages = await Promise.all(transcriptMessages.map(async message => {
519
+ // eslint-disable-line @typescript-eslint/no-explicit-any
520
+ const {
521
+ amsReferences,
522
+ amsMetadata
523
+ } = message;
524
+ if (amsReferences && amsMetadata) {
525
+ const references = JSON.parse(amsReferences);
526
+ const metadata = JSON.parse(amsMetadata);
527
+ const fileMetadata = {
528
+ id: references[0],
529
+ type: metadata[0].contentType
530
+ };
531
+ const blob = await chatSDK.downloadFileAttachment(fileMetadata);
532
+ const base64 = await convertBlobToBase64(blob);
533
+ message.contentUrl = base64;
534
+ }
535
+ return message;
536
+ }));
537
+ }
538
+ const options = {
539
+ ...transcriptOptions,
540
+ messages
541
+ };
542
+ const htmlBuilder = new TranscriptHTMLBuilder(options);
543
+ const text = htmlBuilder.createHTML();
544
+ const fileName = `${transcriptOptions.fileName || "transcript"}.html`;
545
+ (0, _utils.createFileAndDownload)(fileName, text, "text/html");
546
+ };
547
+ var _default = createChatTranscript;
548
+ exports.default = _default;
@@ -1,5 +1,5 @@
1
1
  var _this = this;
2
- import { AriaTelemetryConstants, ChatSDKError, Constants, LocaleConstants } from "./Constants";
2
+ import { AriaTelemetryConstants, ChatSDKError, Constants, HtmlAttributeNames, LocaleConstants } from "./Constants";
3
3
  import { BroadcastEvent, LogLevel, TelemetryEvent } from "./telemetry/TelemetryConstants";
4
4
  import { BroadcastService } from "@microsoft/omnichannel-chat-components";
5
5
  import { DataStoreManager } from "./contextDataStore/DataStoreManager";
@@ -382,4 +382,18 @@ export const checkContactIdError = e => {
382
382
  };
383
383
  BroadcastService.postMessage(contactIdNotFoundErrorEvent);
384
384
  }
385
+ };
386
+ export const createFileAndDownload = (fileName, blobData, mimeType) => {
387
+ const aElement = document.createElement("a");
388
+ const blob = new Blob([blobData], {
389
+ type: mimeType
390
+ });
391
+ const objectUrl = URL.createObjectURL(blob);
392
+ aElement.setAttribute(HtmlAttributeNames.href, objectUrl);
393
+ aElement.setAttribute(HtmlAttributeNames.download, fileName);
394
+ aElement.setAttribute(HtmlAttributeNames.ariaHidden, "true");
395
+ aElement.style.display = "none";
396
+ document.body.appendChild(aElement);
397
+ aElement.click();
398
+ document.body.removeChild(aElement);
385
399
  };
@@ -16,7 +16,7 @@ import useChatSDKStore from "../../hooks/useChatSDKStore";
16
16
  export const FooterStateful = props => {
17
17
  var _footerProps$controlP3, _footerProps$controlP4;
18
18
  const [state, dispatch] = useChatContextStore();
19
- // hideFooterDisplay - the purpose of this is to keep the footer always "active",
19
+ // hideFooterDisplay - the purpose of this is to keep the footer always "active",
20
20
  // but hide it visually in certain states (e.g., loading state) and show in some other states (e.g. active state).
21
21
  // The reason for this approach is to make sure that state variables for audio notification work correctly after minimizing
22
22
  const {
@@ -36,7 +36,7 @@ export const FooterStateful = props => {
36
36
  Event: TelemetryEvent.DownloadTranscriptButtonClicked,
37
37
  Description: "Download Transcript button clicked."
38
38
  });
39
- await downloadTranscript(chatSDK, downloadTranscriptProps === null || downloadTranscriptProps === void 0 ? void 0 : downloadTranscriptProps.renderMarkDown, downloadTranscriptProps === null || downloadTranscriptProps === void 0 ? void 0 : downloadTranscriptProps.bannerMessageOnError, downloadTranscriptProps === null || downloadTranscriptProps === void 0 ? void 0 : downloadTranscriptProps.attachmentMessage, state);
39
+ await downloadTranscript(chatSDK, downloadTranscriptProps, state);
40
40
  } catch (ex) {
41
41
  TelemetryHelper.logActionEvent(LogLevel.ERROR, {
42
42
  Event: TelemetryEvent.DownloadTranscriptFailed,
@@ -1,9 +1,11 @@
1
- import { Constants, HtmlAttributeNames, TranscriptConstants } from "../../../common/Constants";
1
+ import { Constants, TranscriptConstants } from "../../../common/Constants";
2
2
  import { NotificationScenarios } from "../../webchatcontainerstateful/webchatcontroller/enums/NotificationScenarios";
3
3
  import { NotificationHandler } from "../../webchatcontainerstateful/webchatcontroller/notification/NotificationHandler";
4
4
  import { TelemetryHelper } from "../../../common/telemetry/TelemetryHelper";
5
5
  import { LogLevel, TelemetryEvent } from "../../../common/telemetry/TelemetryConstants";
6
+ import createChatTranscript from "../../../plugins/createChatTranscript";
6
7
  import DOMPurify from "dompurify";
8
+ import { createFileAndDownload, isNullOrUndefined } from "../../../common/utils";
7
9
  const processDisplayName = displayName => {
8
10
  // if displayname matches "teamsvisitor:<some alphanumeric string>", we replace it with "Customer"
9
11
  const displayNameRegex = ".+:.+";
@@ -154,7 +156,7 @@ const beautifyChatTranscripts = (chatTranscripts, renderMarkDown, attachmentMess
154
156
  };
155
157
 
156
158
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
157
- export const downloadTranscript = async (chatSDK, renderMarkDown, bannerMessageOnError, attachmentMessage, state) => {
159
+ export const downloadTranscript = async (chatSDK, downloadTranscriptProps, state) => {
158
160
  var _state$domainStates, _state$domainStates2, _state$domainStates2$;
159
161
  // Need to keep existing request id for scenarios when trnascript is downloaded after endchat
160
162
  const liveChatContext = {
@@ -167,18 +169,25 @@ export const downloadTranscript = async (chatSDK, renderMarkDown, bannerMessageO
167
169
  if (typeof data === Constants.String) {
168
170
  data = JSON.parse(data);
169
171
  }
172
+ const {
173
+ bannerMessageOnError,
174
+ renderMarkDown,
175
+ attachmentMessage,
176
+ webChatTranscript
177
+ } = downloadTranscriptProps;
170
178
  if (data[Constants.ChatMessagesJson] !== null && data[Constants.ChatMessagesJson] !== undefined) {
171
- const chatTranscripts = window.btoa(encodeURIComponent(beautifyChatTranscripts(data[Constants.ChatMessagesJson], renderMarkDown, attachmentMessage)));
172
- const byteCharacters = decodeURIComponent(window.atob(chatTranscripts));
173
- const blob = new Blob([byteCharacters], {
174
- "type": "text/html;charset=utf-8"
175
- });
176
- const link = document.createElement("a");
177
- document.body.appendChild(link);
178
- link.setAttribute(HtmlAttributeNames.download, TranscriptConstants.ChatTranscriptDownloadFile);
179
- link.setAttribute(HtmlAttributeNames.href, URL.createObjectURL(blob));
180
- link.setAttribute(HtmlAttributeNames.ariaHidden, "true");
181
- link.click();
179
+ const useWebChatTranscript = isNullOrUndefined(webChatTranscript === null || webChatTranscript === void 0 ? void 0 : webChatTranscript.disabled) || (webChatTranscript === null || webChatTranscript === void 0 ? void 0 : webChatTranscript.disabled) === false;
180
+ if (useWebChatTranscript) {
181
+ const transcriptOptions = {
182
+ ...webChatTranscript
183
+ };
184
+ await createChatTranscript(data[Constants.ChatMessagesJson], chatSDK, false, transcriptOptions);
185
+ } else {
186
+ // Legacy Transcript
187
+ const chatTranscripts = window.btoa(encodeURIComponent(beautifyChatTranscripts(data[Constants.ChatMessagesJson], renderMarkDown, attachmentMessage)));
188
+ const byteCharacters = decodeURIComponent(window.atob(chatTranscripts));
189
+ createFileAndDownload(TranscriptConstants.ChatTranscriptDownloadFile, byteCharacters, "text/html;charset=utf-8");
190
+ }
182
191
  } else {
183
192
  TelemetryHelper.logActionEvent(LogLevel.ERROR, {
184
193
  Event: TelemetryEvent.DownloadTranscriptResponseNullOrUndefined,