@microsoft/omnichannel-chat-sdk 1.0.1-main.2d305f2 → 1.0.1-main.474110f

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.
package/CHANGELOG.md CHANGED
@@ -11,12 +11,16 @@ All notable changes to this project will be documented in this file.
11
11
  - Add ability to automatically detect locale from chat config
12
12
  - Add `runtimeId` attribute in `OmnichannelChatSDK` & `ChatSDKRuntimeId` field in telemetry
13
13
  - Add ability to automatically pass locale from chat config on calling `ChatSDK.emailLiveChatTranscript()`
14
+ - Bubble up `WidgetUseOutsideOperatingHour` exception
15
+ - Add `acs_webchat-chat-adapter` middleware to add default `channelData.tags` & `channelData.metadata`
14
16
 
15
17
  ### Fix
16
18
  - Add `acs_webchat-chat-adapter` middlewares to format `channelData.tags`
17
19
  - Skip `session init` call on existing conversation
18
20
  - Fix `chat reconnect` not ending the conversation on calling `ChatSDK.endChat()`
19
21
  - Fix on messaging client not sending heartbeat on new conversations subsequent to the first conversation
22
+ - Fix `ChatSDK.getConversationDetails()` not passing `authenticatedUserToken`
23
+ - Fix `IC3Client.dispose()` called when `IC3Client` is `undefined`
20
24
 
21
25
  ### Changed
22
26
  - README: added examples on usages of the post chat APIs.
package/README.md CHANGED
@@ -131,7 +131,7 @@ The following steps will be required to run Omnichannel Chat SDK on React Native
131
131
  | OmnichannelChatSDK.getLiveChatTranscript() | Get transcript data (JSON) | |
132
132
  | OmnichannelChatSDK.uploadFileAttachment() | Send file attachment | |
133
133
  | OmnichannelChatSDK.downloadFileAttachment() | Download file attachment | |
134
- | OmnichannelChatSDK.createChatAdapter() | Get IC3Adapter | **Web only** |
134
+ | OmnichannelChatSDK.createChatAdapter() | Get Chat Adapter | **Web only** |
135
135
  | OmnichannelChatSDK.getVoiceVideoCalling() | Get VoiceVideoCall SDK for Escalation to Voice & Video | **Web only** |
136
136
  | OmnichannelChatSDK.getPostChatSurveyContext() | Get post chat survey link, survey locale, and whether an agent has joined the survey | |
137
137
 
@@ -1,5 +1,6 @@
1
1
  import ACSClient from "./core/messaging/ACSClient";
2
2
  import { ParticipantsRemovedEvent } from '@azure/communication-signaling';
3
+ import ChatAdapterOptionalParams from "./core/messaging/ChatAdapterOptionalParams";
3
4
  import ChatConfig from "./core/ChatConfig";
4
5
  import ChatReconnectContext from "./core/ChatReconnectContext";
5
6
  import ChatReconnectOptionalParams from "./core/ChatReconnectOptionalParams";
@@ -81,7 +82,7 @@ declare class OmnichannelChatSDK {
81
82
  downloadFileAttachment(fileMetadata: FileMetadata | IFileMetadata): Promise<Blob>;
82
83
  emailLiveChatTranscript(body: ChatTranscriptBody): Promise<any>;
83
84
  getLiveChatTranscript(): Promise<any>;
84
- createChatAdapter(protocol?: string | null): Promise<unknown>;
85
+ createChatAdapter(optionalParams?: ChatAdapterOptionalParams): Promise<unknown>;
85
86
  getVoiceVideoCalling(params?: any): Promise<any>;
86
87
  getPostChatSurveyContext(): Promise<any>;
87
88
  private getIC3Client;
@@ -89,5 +90,6 @@ declare class OmnichannelChatSDK {
89
90
  private resolveIC3ClientUrl;
90
91
  private resolveChatAdapterUrl;
91
92
  private updateChatToken;
93
+ private setAuthTokenProvider;
92
94
  }
93
95
  export default OmnichannelChatSDK;
@@ -65,6 +65,7 @@ var AMSFileManager_1 = require("./external/ACSAdapter/AMSFileManager");
65
65
  var CallingOptionsOptionSetNumber_1 = require("./core/CallingOptionsOptionSetNumber");
66
66
  var ChatAdapterProtocols_1 = require("./core/messaging/ChatAdapterProtocols");
67
67
  var ConversationMode_1 = require("./core/ConversationMode");
68
+ var createChannelDataEgressMiddleware_1 = require("./external/ACSAdapter/createChannelDataEgressMiddleware");
68
69
  var createFormatEgressTagsMiddleware_1 = require("./external/ACSAdapter/createFormatEgressTagsMiddleware");
69
70
  var createFormatIngressTagsMiddleware_1 = require("./external/ACSAdapter/createFormatIngressTagsMiddleware");
70
71
  var DeliveryMode_1 = require("@microsoft/omnichannel-ic3core/lib/model/DeliveryMode");
@@ -75,6 +76,7 @@ var LiveChatVersion_1 = require("./core/LiveChatVersion");
75
76
  var LiveWorkItemState_1 = require("./core/LiveWorkItemState");
76
77
  var MessageContentType_1 = require("@microsoft/omnichannel-ic3core/lib/model/MessageContentType");
77
78
  var MessageType_1 = require("@microsoft/omnichannel-ic3core/lib/model/MessageType");
79
+ var OmnichannelErrorCodes_1 = require("./core/OmnichannelErrorCodes");
78
80
  var PersonType_1 = require("@microsoft/omnichannel-ic3core/lib/model/PersonType");
79
81
  var ProtocoleType_1 = require("@microsoft/omnichannel-ic3core/lib/interfaces/ProtocoleType");
80
82
  var ScenarioMarker_1 = require("./telemetry/ScenarioMarker");
@@ -298,44 +300,44 @@ var OmnichannelChatSDK = /** @class */ (function () {
298
300
  });
299
301
  };
300
302
  OmnichannelChatSDK.prototype.startChat = function (optionalParams) {
301
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
303
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
302
304
  if (optionalParams === void 0) { optionalParams = {}; }
303
305
  return __awaiter(this, void 0, void 0, function () {
304
- var shouldReinitIC3Client, _p, reconnectableChatsParams, reconnectableChatsResponse, _q, exceptionDetails, conversationDetails, exceptionDetails, exceptionDetails, sessionInitOptionalParams, error_3, exceptionDetails, chatAdapterConfig, error_4, exceptionDetails, _r, error_5, exceptionDetails, error_6, exceptionDetails, error_7, exceptionDetails, _s, error_8, exceptionDetails;
306
+ var shouldReinitIC3Client, _s, reconnectableChatsParams, reconnectableChatsResponse, _t, exceptionDetails, conversationDetails, exceptionDetails, exceptionDetails, sessionInitOptionalParams, error_3, exceptionDetails, chatAdapterConfig, error_4, exceptionDetails, _u, error_5, exceptionDetails, error_6, exceptionDetails, error_7, exceptionDetails, _v, error_8, exceptionDetails;
305
307
  var _this = this;
306
- return __generator(this, function (_t) {
307
- switch (_t.label) {
308
+ return __generator(this, function (_w) {
309
+ switch (_w.label) {
308
310
  case 0:
309
311
  this.scenarioMarker.startScenario(TelemetryEvent_1.default.StartChat, {
310
312
  RequestId: this.requestId
311
313
  });
312
314
  shouldReinitIC3Client = !platform_1.default.isNode() && !platform_1.default.isReactNative() && !this.IC3Client && this.liveChatVersion === LiveChatVersion_1.default.V1;
313
315
  if (!shouldReinitIC3Client) return [3 /*break*/, 2];
314
- _p = this;
316
+ _s = this;
315
317
  return [4 /*yield*/, this.getIC3Client()];
316
318
  case 1:
317
- _p.IC3Client = _t.sent();
318
- _t.label = 2;
319
+ _s.IC3Client = _w.sent();
320
+ _w.label = 2;
319
321
  case 2:
320
322
  if (this.isChatReconnect && !((_a = this.chatSDKConfig.chatReconnect) === null || _a === void 0 ? void 0 : _a.disable) && !this.isPersistentChat && optionalParams.reconnectId) {
321
323
  this.reconnectId = optionalParams.reconnectId;
322
324
  }
323
325
  if (!(this.isPersistentChat && !((_b = this.chatSDKConfig.persistentChat) === null || _b === void 0 ? void 0 : _b.disable))) return [3 /*break*/, 6];
324
- _t.label = 3;
326
+ _w.label = 3;
325
327
  case 3:
326
- _t.trys.push([3, 5, , 6]);
328
+ _w.trys.push([3, 5, , 6]);
327
329
  reconnectableChatsParams = {
328
330
  authenticatedUserToken: this.authenticatedUserToken
329
331
  };
330
332
  return [4 /*yield*/, this.OCClient.getReconnectableChats(reconnectableChatsParams)];
331
333
  case 4:
332
- reconnectableChatsResponse = _t.sent();
334
+ reconnectableChatsResponse = _w.sent();
333
335
  if (reconnectableChatsResponse && reconnectableChatsResponse.reconnectid) {
334
336
  this.reconnectId = reconnectableChatsResponse.reconnectid;
335
337
  }
336
338
  return [3 /*break*/, 6];
337
339
  case 5:
338
- _q = _t.sent();
340
+ _t = _w.sent();
339
341
  exceptionDetails = {
340
342
  response: "OCClientGetReconnectableChatsFailed"
341
343
  };
@@ -346,7 +348,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
346
348
  this.requestId = optionalParams.liveChatContext.requestId || ocsdk_1.uuidv4();
347
349
  return [4 /*yield*/, this.getConversationDetails()];
348
350
  case 7:
349
- conversationDetails = _t.sent();
351
+ conversationDetails = _w.sent();
350
352
  if (Object.keys(conversationDetails).length === 0) {
351
353
  exceptionDetails = {
352
354
  response: "InvalidConversation"
@@ -371,13 +373,13 @@ var OmnichannelChatSDK = /** @class */ (function () {
371
373
  console.error("Unable to join conversation that's in '" + conversationDetails.state + "' state");
372
374
  throw Error(exceptionDetails.response);
373
375
  }
374
- _t.label = 8;
376
+ _w.label = 8;
375
377
  case 8:
376
378
  if (!(this.chatToken && Object.keys(this.chatToken).length === 0)) return [3 /*break*/, 10];
377
379
  return [4 /*yield*/, this.getChatToken(false)];
378
380
  case 9:
379
- _t.sent();
380
- _t.label = 10;
381
+ _w.sent();
382
+ _w.label = 10;
381
383
  case 10:
382
384
  (_c = this.ic3ClientLogger) === null || _c === void 0 ? void 0 : _c.setChatId(this.chatToken.chatId || '');
383
385
  (_d = this.ocSdkLogger) === null || _d === void 0 ? void 0 : _d.setChatId(this.chatToken.chatId || '');
@@ -419,25 +421,30 @@ var OmnichannelChatSDK = /** @class */ (function () {
419
421
  sessionInitOptionalParams.authenticatedUserToken = this.authenticatedUserToken;
420
422
  }
421
423
  if (!!optionalParams.liveChatContext) return [3 /*break*/, 14];
422
- _t.label = 11;
424
+ _w.label = 11;
423
425
  case 11:
424
- _t.trys.push([11, 13, , 14]);
426
+ _w.trys.push([11, 13, , 14]);
425
427
  return [4 /*yield*/, this.OCClient.sessionInit(this.requestId, sessionInitOptionalParams)];
426
428
  case 12:
427
- _t.sent();
429
+ _w.sent();
428
430
  return [3 /*break*/, 14];
429
431
  case 13:
430
- error_3 = _t.sent();
432
+ error_3 = _w.sent();
431
433
  exceptionDetails = {
432
434
  response: "OCClientSessionInitFailed"
433
435
  };
436
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
437
+ if (((_j = error_3) === null || _j === void 0 ? void 0 : _j.isAxiosError) && ((_l = (_k = error_3.response) === null || _k === void 0 ? void 0 : _k.headers) === null || _l === void 0 ? void 0 : _l.errorcode.toString()) === OmnichannelErrorCodes_1.default.WidgetUseOutsideOperatingHour.toString()) {
438
+ exceptionDetails.response = OmnichannelErrorCodes_1.default[OmnichannelErrorCodes_1.default.WidgetUseOutsideOperatingHour].toString();
439
+ exceptionDetails.message = 'Widget used outside of operating hours';
440
+ console.error(exceptionDetails.message);
441
+ }
434
442
  this.scenarioMarker.failScenario(TelemetryEvent_1.default.StartChat, {
435
443
  RequestId: this.requestId,
436
444
  ChatId: this.chatToken.chatId,
437
445
  ExceptionDetails: JSON.stringify(exceptionDetails)
438
446
  });
439
- console.error("OmnichannelChatSDK/startChat/sessionInit/error " + error_3);
440
- return [2 /*return*/, error_3];
447
+ throw new Error(exceptionDetails.response);
441
448
  case 14:
442
449
  if (!(this.liveChatVersion === LiveChatVersion_1.default.V2)) return [3 /*break*/, 25];
443
450
  chatAdapterConfig = {
@@ -447,18 +454,18 @@ var OmnichannelChatSDK = /** @class */ (function () {
447
454
  environmentUrl: this.chatToken.acsEndpoint,
448
455
  pollingInterval: 1000
449
456
  };
450
- _t.label = 15;
457
+ _w.label = 15;
451
458
  case 15:
452
- _t.trys.push([15, 17, , 18]);
453
- return [4 /*yield*/, ((_j = this.ACSClient) === null || _j === void 0 ? void 0 : _j.initialize({
459
+ _w.trys.push([15, 17, , 18]);
460
+ return [4 /*yield*/, ((_m = this.ACSClient) === null || _m === void 0 ? void 0 : _m.initialize({
454
461
  token: chatAdapterConfig.token,
455
462
  environmentUrl: chatAdapterConfig.environmentUrl
456
463
  }))];
457
464
  case 16:
458
- _t.sent();
465
+ _w.sent();
459
466
  return [3 /*break*/, 18];
460
467
  case 17:
461
- error_4 = _t.sent();
468
+ error_4 = _w.sent();
462
469
  exceptionDetails = {
463
470
  response: "ACSClientInitializeFailed"
464
471
  };
@@ -470,22 +477,22 @@ var OmnichannelChatSDK = /** @class */ (function () {
470
477
  console.error("OmnichannelChatSDK/startChat/initialize/error " + error_4);
471
478
  return [2 /*return*/, error_4];
472
479
  case 18:
473
- _t.trys.push([18, 20, , 21]);
474
- _r = this;
475
- return [4 /*yield*/, ((_k = this.ACSClient) === null || _k === void 0 ? void 0 : _k.joinConversation({
480
+ _w.trys.push([18, 20, , 21]);
481
+ _u = this;
482
+ return [4 /*yield*/, ((_o = this.ACSClient) === null || _o === void 0 ? void 0 : _o.joinConversation({
476
483
  id: chatAdapterConfig.id,
477
484
  threadId: chatAdapterConfig.threadId,
478
485
  pollingInterval: chatAdapterConfig.pollingInterval
479
486
  }))];
480
487
  case 19:
481
- _r.conversation = (_t.sent());
488
+ _u.conversation = (_w.sent());
482
489
  this.scenarioMarker.completeScenario(TelemetryEvent_1.default.StartChat, {
483
490
  RequestId: this.requestId,
484
491
  ChatId: this.chatToken.chatId
485
492
  });
486
493
  return [3 /*break*/, 21];
487
494
  case 20:
488
- error_5 = _t.sent();
495
+ error_5 = _w.sent();
489
496
  exceptionDetails = {
490
497
  response: "ACSClientJoinConversationFailed"
491
498
  };
@@ -497,15 +504,15 @@ var OmnichannelChatSDK = /** @class */ (function () {
497
504
  console.error("OmnichannelChatSDK/startChat/joinConversation/error " + error_5);
498
505
  throw Error(exceptionDetails.response);
499
506
  case 21:
500
- _t.trys.push([21, 23, , 24]);
501
- return [4 /*yield*/, ((_l = this.AMSClient) === null || _l === void 0 ? void 0 : _l.initialize({
507
+ _w.trys.push([21, 23, , 24]);
508
+ return [4 /*yield*/, ((_p = this.AMSClient) === null || _p === void 0 ? void 0 : _p.initialize({
502
509
  chatToken: this.chatToken
503
510
  }))];
504
511
  case 22:
505
- _t.sent();
512
+ _w.sent();
506
513
  return [3 /*break*/, 24];
507
514
  case 23:
508
- error_6 = _t.sent();
515
+ error_6 = _w.sent();
509
516
  exceptionDetails = {
510
517
  response: "AMSClientInitializeFailed"
511
518
  };
@@ -517,17 +524,17 @@ var OmnichannelChatSDK = /** @class */ (function () {
517
524
  throw Error(exceptionDetails.response);
518
525
  case 24: return [3 /*break*/, 31];
519
526
  case 25:
520
- _t.trys.push([25, 27, , 28]);
527
+ _w.trys.push([25, 27, , 28]);
521
528
  return [4 /*yield*/, this.IC3Client.initialize({
522
529
  token: this.chatToken.token,
523
530
  regionGtms: this.chatToken.regionGTMS,
524
531
  visitor: true
525
532
  })];
526
533
  case 26:
527
- _t.sent();
534
+ _w.sent();
528
535
  return [3 /*break*/, 28];
529
536
  case 27:
530
- error_7 = _t.sent();
537
+ error_7 = _w.sent();
531
538
  exceptionDetails = {
532
539
  response: "IC3ClientInitializeFailed"
533
540
  };
@@ -539,18 +546,18 @@ var OmnichannelChatSDK = /** @class */ (function () {
539
546
  console.error("OmnichannelChatSDK/startChat/initialize/error " + error_7);
540
547
  return [2 /*return*/, error_7];
541
548
  case 28:
542
- _t.trys.push([28, 30, , 31]);
543
- _s = this;
549
+ _w.trys.push([28, 30, , 31]);
550
+ _v = this;
544
551
  return [4 /*yield*/, this.IC3Client.joinConversation(this.chatToken.chatId)];
545
552
  case 29:
546
- _s.conversation = _t.sent();
553
+ _v.conversation = _w.sent();
547
554
  this.scenarioMarker.completeScenario(TelemetryEvent_1.default.StartChat, {
548
555
  RequestId: this.requestId,
549
556
  ChatId: this.chatToken.chatId
550
557
  });
551
558
  return [3 /*break*/, 31];
552
559
  case 30:
553
- error_8 = _t.sent();
560
+ error_8 = _w.sent();
554
561
  exceptionDetails = {
555
562
  response: "IC3ClientJoinConversationFailed"
556
563
  };
@@ -562,7 +569,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
562
569
  console.error("OmnichannelChatSDK/startChat/joinConversation/error " + error_8);
563
570
  return [2 /*return*/, error_8];
564
571
  case 31:
565
- if (this.isPersistentChat && !((_m = this.chatSDKConfig.persistentChat) === null || _m === void 0 ? void 0 : _m.disable)) {
572
+ if (this.isPersistentChat && !((_q = this.chatSDKConfig.persistentChat) === null || _q === void 0 ? void 0 : _q.disable)) {
566
573
  this.refreshTokenTimer = setInterval(function () { return __awaiter(_this, void 0, void 0, function () {
567
574
  return __generator(this, function (_a) {
568
575
  switch (_a.label) {
@@ -573,7 +580,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
573
580
  return [2 /*return*/];
574
581
  }
575
582
  });
576
- }); }, (_o = this.chatSDKConfig.persistentChat) === null || _o === void 0 ? void 0 : _o.tokenUpdateTime);
583
+ }); }, (_r = this.chatSDKConfig.persistentChat) === null || _r === void 0 ? void 0 : _r.tokenUpdateTime);
577
584
  }
578
585
  return [2 /*return*/];
579
586
  }
@@ -620,9 +627,11 @@ var OmnichannelChatSDK = /** @class */ (function () {
620
627
  this.requestId = ocsdk_1.uuidv4();
621
628
  this.chatToken = {};
622
629
  this.reconnectId = null;
623
- this.IC3Client.dispose();
624
- !platform_1.default.isNode() && !platform_1.default.isReactNative() && WebUtils_1.removeElementById(this.IC3Client.id);
625
- this.IC3Client = null;
630
+ if (this.IC3Client) {
631
+ this.IC3Client.dispose();
632
+ !platform_1.default.isNode() && !platform_1.default.isReactNative() && WebUtils_1.removeElementById(this.IC3Client.id);
633
+ this.IC3Client = null;
634
+ }
626
635
  (_d = this.ic3ClientLogger) === null || _d === void 0 ? void 0 : _d.setRequestId(this.requestId);
627
636
  (_e = this.ic3ClientLogger) === null || _e === void 0 ? void 0 : _e.setChatId('');
628
637
  (_f = this.ocSdkLogger) === null || _f === void 0 ? void 0 : _f.setRequestId(this.requestId);
@@ -684,22 +693,32 @@ var OmnichannelChatSDK = /** @class */ (function () {
684
693
  });
685
694
  };
686
695
  OmnichannelChatSDK.prototype.getConversationDetails = function () {
687
- var _a, _b;
696
+ var _a, _b, _c, _d;
688
697
  return __awaiter(this, void 0, void 0, function () {
689
- var lwiDetails, state, conversationId, agentAcceptedOn, liveWorkItemDetails, error_10;
690
- return __generator(this, function (_c) {
691
- switch (_c.label) {
698
+ var getLWIDetailsOptionalParams, lwiDetails, state, conversationId, agentAcceptedOn, liveWorkItemDetails, error_10;
699
+ return __generator(this, function (_e) {
700
+ switch (_e.label) {
692
701
  case 0:
693
702
  this.scenarioMarker.startScenario(TelemetryEvent_1.default.GetConversationDetails, {
694
703
  RequestId: this.requestId,
695
704
  ChatId: ((_a = this.chatToken) === null || _a === void 0 ? void 0 : _a.chatId) || '',
696
705
  });
697
- _c.label = 1;
706
+ getLWIDetailsOptionalParams = {};
707
+ if (this.isPersistentChat && !((_b = this.chatSDKConfig.persistentChat) === null || _b === void 0 ? void 0 : _b.disable) && this.reconnectId) {
708
+ getLWIDetailsOptionalParams.reconnectId = this.reconnectId;
709
+ }
710
+ if (this.isChatReconnect && !((_c = this.chatSDKConfig.chatReconnect) === null || _c === void 0 ? void 0 : _c.disable) && !this.isPersistentChat && this.reconnectId) {
711
+ getLWIDetailsOptionalParams.reconnectId = this.reconnectId;
712
+ }
713
+ if (this.authenticatedUserToken) {
714
+ getLWIDetailsOptionalParams.authenticatedUserToken = this.authenticatedUserToken;
715
+ }
716
+ _e.label = 1;
698
717
  case 1:
699
- _c.trys.push([1, 3, , 4]);
700
- return [4 /*yield*/, this.OCClient.getLWIDetails(this.requestId)];
718
+ _e.trys.push([1, 3, , 4]);
719
+ return [4 /*yield*/, this.OCClient.getLWIDetails(this.requestId, getLWIDetailsOptionalParams)];
701
720
  case 2:
702
- lwiDetails = _c.sent();
721
+ lwiDetails = _e.sent();
703
722
  state = lwiDetails.State, conversationId = lwiDetails.ConversationId, agentAcceptedOn = lwiDetails.AgentAcceptedOn;
704
723
  liveWorkItemDetails = {
705
724
  state: state,
@@ -710,11 +729,11 @@ var OmnichannelChatSDK = /** @class */ (function () {
710
729
  }
711
730
  this.scenarioMarker.completeScenario(TelemetryEvent_1.default.GetConversationDetails, {
712
731
  RequestId: this.requestId,
713
- ChatId: ((_b = this.chatToken) === null || _b === void 0 ? void 0 : _b.chatId) || '',
732
+ ChatId: ((_d = this.chatToken) === null || _d === void 0 ? void 0 : _d.chatId) || '',
714
733
  });
715
734
  return [2 /*return*/, liveWorkItemDetails];
716
735
  case 3:
717
- error_10 = _c.sent();
736
+ error_10 = _e.sent();
718
737
  this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetConversationDetails, {
719
738
  RequestId: this.requestId,
720
739
  ChatId: this.chatToken.chatId || '',
@@ -1520,36 +1539,36 @@ var OmnichannelChatSDK = /** @class */ (function () {
1520
1539
  });
1521
1540
  });
1522
1541
  };
1523
- OmnichannelChatSDK.prototype.createChatAdapter = function (protocol) {
1524
- if (protocol === void 0) { protocol = null; }
1542
+ OmnichannelChatSDK.prototype.createChatAdapter = function (optionalParams) {
1543
+ if (optionalParams === void 0) { optionalParams = {}; }
1525
1544
  return __awaiter(this, void 0, void 0, function () {
1526
- var supportedChatAdapterProtocols;
1545
+ var protocol, supportedChatAdapterProtocols;
1527
1546
  var _this = this;
1528
1547
  return __generator(this, function (_a) {
1529
1548
  if (platform_1.default.isNode() || platform_1.default.isReactNative()) {
1530
1549
  return [2 /*return*/, Promise.reject('ChatAdapter is only supported on browser')];
1531
1550
  }
1551
+ protocol = optionalParams.protocol;
1532
1552
  supportedChatAdapterProtocols = [ChatAdapterProtocols_1.default.ACS, ChatAdapterProtocols_1.default.IC3];
1533
1553
  if (protocol && !supportedChatAdapterProtocols.includes(protocol)) {
1534
1554
  return [2 /*return*/, Promise.reject("ChatAdapter for protocol " + protocol + " currently not supported")];
1535
1555
  }
1536
1556
  if (protocol === ChatAdapterProtocols_1.default.ACS || this.liveChatVersion === LiveChatVersion_1.default.V2) {
1537
1557
  return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
1538
- var egressMiddlewares, ingressMiddlewares, featuresOption, acsAdapterCDNUrl;
1558
+ var options, defaultEgressMiddlewares, defaultIngressMiddlewares, egressMiddleware, ingressMiddleware, featuresOption, acsAdapterCDNUrl;
1539
1559
  var _this = this;
1540
1560
  var _a;
1541
1561
  return __generator(this, function (_b) {
1542
1562
  switch (_b.label) {
1543
1563
  case 0:
1544
- egressMiddlewares = [createFormatEgressTagsMiddleware_1.default()];
1545
- ingressMiddlewares = [createFormatIngressTagsMiddleware_1.default()];
1546
- featuresOption = {
1547
- enableAdaptiveCards: true,
1548
- enableThreadMemberUpdateNotification: true,
1549
- enableLeaveThreadOnWindowClosed: false,
1550
- egressMiddleware: egressMiddlewares,
1551
- ingressMiddleware: ingressMiddlewares
1552
- };
1564
+ options = optionalParams.ACSAdapter ? optionalParams.ACSAdapter.options : {};
1565
+ defaultEgressMiddlewares = [createChannelDataEgressMiddleware_1.default({ widgetId: this.omnichannelConfig.widgetId }), createFormatEgressTagsMiddleware_1.default()];
1566
+ defaultIngressMiddlewares = [createFormatIngressTagsMiddleware_1.default()];
1567
+ egressMiddleware = (options === null || options === void 0 ? void 0 : options.egressMiddleware) ? __spreadArrays(options.egressMiddleware, defaultEgressMiddlewares) : __spreadArrays(defaultEgressMiddlewares);
1568
+ ingressMiddleware = (options === null || options === void 0 ? void 0 : options.ingressMiddleware) ? __spreadArrays(options.egressMiddleware, defaultIngressMiddlewares) : __spreadArrays(defaultIngressMiddlewares);
1569
+ featuresOption = __assign(__assign({ enableAdaptiveCards: true, enableThreadMemberUpdateNotification: true, enableLeaveThreadOnWindowClosed: false }, options), { // overrides
1570
+ ingressMiddleware: ingressMiddleware,
1571
+ egressMiddleware: egressMiddleware });
1553
1572
  acsAdapterCDNUrl = this.resolveChatAdapterUrl(protocol || ChatAdapterProtocols_1.default.ACS);
1554
1573
  (_a = this.telemetry) === null || _a === void 0 ? void 0 : _a.setCDNPackages({
1555
1574
  ACSAdapter: acsAdapterCDNUrl
@@ -1560,7 +1579,8 @@ var OmnichannelChatSDK = /** @class */ (function () {
1560
1579
  try {
1561
1580
  var ChatAdapter = window.ChatAdapter; // eslint-disable-line @typescript-eslint/no-explicit-any
1562
1581
  var fileManager = new AMSFileManager_1.default(_this.AMSClient, _this.acsAdapterLogger);
1563
- var adapter = ChatAdapter.createACSAdapter(_this.chatToken.token, _this.chatToken.visitorId || 'teamsvisitor', _this.chatToken.chatId, _this.chatToken.acsEndpoint, fileManager, 1000, ACSParticipantDisplayName_1.default.Customer, undefined, undefined, // logger
1582
+ var adapter = ChatAdapter.createACSAdapter(_this.chatToken.token, _this.chatToken.visitorId || 'teamsvisitor', _this.chatToken.chatId, _this.chatToken.acsEndpoint, fileManager, 1000, ACSParticipantDisplayName_1.default.Customer, undefined, // chatClient
1583
+ undefined, // logger
1564
1584
  featuresOption);
1565
1585
  resolve(adapter);
1566
1586
  }
@@ -1579,12 +1599,13 @@ var OmnichannelChatSDK = /** @class */ (function () {
1579
1599
  }
1580
1600
  else if (protocol === ChatAdapterProtocols_1.default.IC3 || this.liveChatVersion === LiveChatVersion_1.default.V1) {
1581
1601
  return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
1582
- var ic3AdapterCDNUrl;
1602
+ var options, ic3AdapterCDNUrl;
1583
1603
  var _this = this;
1584
1604
  var _a;
1585
1605
  return __generator(this, function (_b) {
1586
1606
  switch (_b.label) {
1587
1607
  case 0:
1608
+ options = optionalParams.IC3Adapter ? optionalParams.IC3Adapter.options : {};
1588
1609
  ic3AdapterCDNUrl = this.resolveChatAdapterUrl(protocol || ChatAdapterProtocols_1.default.IC3);
1589
1610
  (_a = this.telemetry) === null || _a === void 0 ? void 0 : _a.setCDNPackages({
1590
1611
  IC3Adapter: ic3AdapterCDNUrl
@@ -1593,13 +1614,8 @@ var OmnichannelChatSDK = /** @class */ (function () {
1593
1614
  return [4 /*yield*/, WebUtils_1.loadScript(ic3AdapterCDNUrl, function () {
1594
1615
  /* istanbul ignore next */
1595
1616
  _this.debug && console.debug('IC3Adapter loaded!');
1596
- var adapterConfig = {
1597
- chatToken: _this.chatToken,
1598
- userDisplayName: 'Customer',
1599
- userId: 'teamsvisitor',
1600
- sdkURL: _this.resolveIC3ClientUrl(),
1601
- sdk: _this.IC3Client
1602
- };
1617
+ var adapterConfig = __assign({ chatToken: _this.chatToken, userDisplayName: 'Customer', userId: _this.chatToken.visitorId || 'teamsvisitor', sdkURL: _this.resolveIC3ClientUrl(), sdk: _this.IC3Client }, options // overrides
1618
+ );
1603
1619
  var adapter = new window.Microsoft.BotFramework.WebChat.IC3Adapter(adapterConfig);
1604
1620
  adapter.logger = _this.ic3ClientLogger;
1605
1621
  _this.scenarioMarker.completeScenario(TelemetryEvent_1.default.CreateIC3Adapter);
@@ -1874,14 +1890,14 @@ var OmnichannelChatSDK = /** @class */ (function () {
1874
1890
  };
1875
1891
  OmnichannelChatSDK.prototype.getChatConfig = function () {
1876
1892
  return __awaiter(this, void 0, void 0, function () {
1877
- var liveChatConfig, dataMaskingConfig, authSettings, liveWSAndLiveChatEngJoin, liveChatVersion, chatWidgetLanguage, msdyn_localeid, setting, preChatSurvey, msdyn_prechatenabled, msdyn_callingoptions, msdyn_conversationmode, msdyn_enablechatreconnect, isPreChatEnabled, isChatReconnectEnabled, token, exceptionDetails, _a, exceptionDetails, exceptionDetails, error_18;
1878
- return __generator(this, function (_b) {
1879
- switch (_b.label) {
1893
+ var liveChatConfig, dataMaskingConfig, authSettings, liveWSAndLiveChatEngJoin, liveChatVersion, chatWidgetLanguage, msdyn_localeid, setting, preChatSurvey, msdyn_prechatenabled, msdyn_callingoptions, msdyn_conversationmode, msdyn_enablechatreconnect, isPreChatEnabled, isChatReconnectEnabled, error_18;
1894
+ return __generator(this, function (_a) {
1895
+ switch (_a.label) {
1880
1896
  case 0:
1881
- _b.trys.push([0, 8, , 9]);
1897
+ _a.trys.push([0, 4, , 5]);
1882
1898
  return [4 /*yield*/, this.OCClient.getChatConfig()];
1883
1899
  case 1:
1884
- liveChatConfig = _b.sent();
1900
+ liveChatConfig = _a.sent();
1885
1901
  dataMaskingConfig = liveChatConfig.DataMaskingInfo, authSettings = liveChatConfig.LiveChatConfigAuthSettings, liveWSAndLiveChatEngJoin = liveChatConfig.LiveWSAndLiveChatEngJoin, liveChatVersion = liveChatConfig.LiveChatVersion, chatWidgetLanguage = liveChatConfig.ChatWidgetLanguage;
1886
1902
  msdyn_localeid = chatWidgetLanguage.msdyn_localeid;
1887
1903
  this.localeId = msdyn_localeid || locale_1.defaultLocaleId;
@@ -1907,47 +1923,12 @@ var OmnichannelChatSDK = /** @class */ (function () {
1907
1923
  if (isPreChatEnabled && preChatSurvey && preChatSurvey.trim().length > 0) {
1908
1924
  this.preChatSurvey = preChatSurvey;
1909
1925
  }
1910
- if (!this.authSettings) return [3 /*break*/, 7];
1911
- this.scenarioMarker.startScenario(TelemetryEvent_1.default.GetAuthToken);
1912
- if (!this.chatSDKConfig.getAuthToken) return [3 /*break*/, 6];
1913
- _b.label = 2;
1926
+ if (!this.authSettings) return [3 /*break*/, 3];
1927
+ return [4 /*yield*/, this.setAuthTokenProvider(this.chatSDKConfig.getAuthToken)];
1914
1928
  case 2:
1915
- _b.trys.push([2, 4, , 5]);
1916
- return [4 /*yield*/, this.chatSDKConfig.getAuthToken()];
1929
+ _a.sent();
1930
+ _a.label = 3;
1917
1931
  case 3:
1918
- token = _b.sent();
1919
- if (token) {
1920
- this.authenticatedUserToken = token;
1921
- this.scenarioMarker.completeScenario(TelemetryEvent_1.default.GetAuthToken);
1922
- }
1923
- else {
1924
- exceptionDetails = {
1925
- response: "UndefinedAuthToken"
1926
- };
1927
- this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetAuthToken, {
1928
- ExceptionDetails: JSON.stringify(exceptionDetails)
1929
- });
1930
- }
1931
- return [3 /*break*/, 5];
1932
- case 4:
1933
- _a = _b.sent();
1934
- exceptionDetails = {
1935
- response: "GetAuthTokenFailed"
1936
- };
1937
- this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetAuthToken, {
1938
- ExceptionDetails: JSON.stringify(exceptionDetails)
1939
- });
1940
- return [3 /*break*/, 5];
1941
- case 5: return [3 /*break*/, 7];
1942
- case 6:
1943
- exceptionDetails = {
1944
- response: "GetAuthTokenNotFound"
1945
- };
1946
- this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetAuthToken, {
1947
- ExceptionDetails: JSON.stringify(exceptionDetails)
1948
- });
1949
- _b.label = 7;
1950
- case 7:
1951
1932
  if (this.preChatSurvey) {
1952
1933
  /* istanbul ignore next */
1953
1934
  this.debug && console.log('Prechat Survey!');
@@ -1955,11 +1936,11 @@ var OmnichannelChatSDK = /** @class */ (function () {
1955
1936
  this.callingOption = msdyn_callingoptions;
1956
1937
  this.liveChatConfig = liveChatConfig;
1957
1938
  return [2 /*return*/, this.liveChatConfig];
1958
- case 8:
1959
- error_18 = _b.sent();
1939
+ case 4:
1940
+ error_18 = _a.sent();
1960
1941
  console.error("OmnichannelChatSDK/getChatConfig/error " + error_18);
1961
1942
  return [2 /*return*/, error_18];
1962
- case 9: return [2 /*return*/];
1943
+ case 5: return [2 /*return*/];
1963
1944
  }
1964
1945
  });
1965
1946
  });
@@ -2041,6 +2022,57 @@ var OmnichannelChatSDK = /** @class */ (function () {
2041
2022
  });
2042
2023
  });
2043
2024
  };
2025
+ OmnichannelChatSDK.prototype.setAuthTokenProvider = function (provider) {
2026
+ return __awaiter(this, void 0, void 0, function () {
2027
+ var token, exceptionDetails, _a, exceptionDetails, exceptionDetails;
2028
+ return __generator(this, function (_b) {
2029
+ switch (_b.label) {
2030
+ case 0:
2031
+ this.scenarioMarker.startScenario(TelemetryEvent_1.default.GetAuthToken);
2032
+ this.chatSDKConfig.getAuthToken = provider;
2033
+ if (!this.chatSDKConfig.getAuthToken) return [3 /*break*/, 5];
2034
+ _b.label = 1;
2035
+ case 1:
2036
+ _b.trys.push([1, 3, , 4]);
2037
+ return [4 /*yield*/, this.chatSDKConfig.getAuthToken()];
2038
+ case 2:
2039
+ token = _b.sent();
2040
+ if (token) {
2041
+ this.authenticatedUserToken = token;
2042
+ this.scenarioMarker.completeScenario(TelemetryEvent_1.default.GetAuthToken);
2043
+ }
2044
+ else {
2045
+ exceptionDetails = {
2046
+ response: "UndefinedAuthToken"
2047
+ };
2048
+ this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetAuthToken, {
2049
+ ExceptionDetails: JSON.stringify(exceptionDetails)
2050
+ });
2051
+ }
2052
+ return [3 /*break*/, 4];
2053
+ case 3:
2054
+ _a = _b.sent();
2055
+ exceptionDetails = {
2056
+ response: "GetAuthTokenFailed"
2057
+ };
2058
+ this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetAuthToken, {
2059
+ ExceptionDetails: JSON.stringify(exceptionDetails)
2060
+ });
2061
+ return [3 /*break*/, 4];
2062
+ case 4: return [3 /*break*/, 6];
2063
+ case 5:
2064
+ exceptionDetails = {
2065
+ response: "GetAuthTokenNotFound"
2066
+ };
2067
+ this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetAuthToken, {
2068
+ ExceptionDetails: JSON.stringify(exceptionDetails)
2069
+ });
2070
+ _b.label = 6;
2071
+ case 6: return [2 /*return*/];
2072
+ }
2073
+ });
2074
+ });
2075
+ };
2044
2076
  return OmnichannelChatSDK;
2045
2077
  }());
2046
2078
  exports.default = OmnichannelChatSDK;