@microsoft/omnichannel-chat-sdk 1.0.1-main.4ed9317 → 1.0.1-main.6219e16

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.
@@ -75,6 +75,7 @@ var LiveChatVersion_1 = require("./core/LiveChatVersion");
75
75
  var LiveWorkItemState_1 = require("./core/LiveWorkItemState");
76
76
  var MessageContentType_1 = require("@microsoft/omnichannel-ic3core/lib/model/MessageContentType");
77
77
  var MessageType_1 = require("@microsoft/omnichannel-ic3core/lib/model/MessageType");
78
+ var OmnichannelErrorCodes_1 = require("./core/OmnichannelErrorCodes");
78
79
  var PersonType_1 = require("@microsoft/omnichannel-ic3core/lib/model/PersonType");
79
80
  var ProtocoleType_1 = require("@microsoft/omnichannel-ic3core/lib/interfaces/ProtocoleType");
80
81
  var ScenarioMarker_1 = require("./telemetry/ScenarioMarker");
@@ -109,11 +110,13 @@ var OmnichannelChatSDK = /** @class */ (function () {
109
110
  this.reconnectId = null;
110
111
  this.refreshTokenTimer = null;
111
112
  this.debug = false;
113
+ this.runtimeId = ocsdk_1.uuidv4();
112
114
  this.omnichannelConfig = omnichannelConfig;
113
115
  this.chatSDKConfig = __assign(__assign({}, SDKConfigValidators_1.defaultChatSDKConfig), chatSDKConfig // overrides
114
116
  );
115
117
  this.isInitialized = false;
116
118
  this.liveChatVersion = LiveChatVersion_1.default.V1;
119
+ this.localeId = locale_1.defaultLocaleId;
117
120
  this.requestId = ocsdk_1.uuidv4();
118
121
  this.chatToken = {};
119
122
  this.liveChatConfig = {};
@@ -131,6 +134,11 @@ var OmnichannelChatSDK = /** @class */ (function () {
131
134
  this.ocSdkLogger.useTelemetry(this.telemetry);
132
135
  this.acsClientLogger.useTelemetry(this.telemetry);
133
136
  this.acsAdapterLogger.useTelemetry(this.telemetry);
137
+ this.scenarioMarker.setRuntimeId(this.runtimeId);
138
+ this.ic3ClientLogger.setRuntimeId(this.runtimeId);
139
+ this.ocSdkLogger.setRuntimeId(this.runtimeId);
140
+ this.acsClientLogger.setRuntimeId(this.runtimeId);
141
+ this.acsAdapterLogger.setRuntimeId(this.runtimeId);
134
142
  OmnichannelConfigValidator_1.default(omnichannelConfig);
135
143
  SDKConfigValidators_1.default(chatSDKConfig);
136
144
  ((_a = this.chatSDKConfig.telemetry) === null || _a === void 0 ? void 0 : _a.disable) && ((_b = this.telemetry) === null || _b === void 0 ? void 0 : _b.disable());
@@ -291,47 +299,55 @@ var OmnichannelChatSDK = /** @class */ (function () {
291
299
  });
292
300
  };
293
301
  OmnichannelChatSDK.prototype.startChat = function (optionalParams) {
294
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
302
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
295
303
  if (optionalParams === void 0) { optionalParams = {}; }
296
304
  return __awaiter(this, void 0, void 0, function () {
297
- var reconnectableChatsParams, reconnectableChatsResponse, _p, exceptionDetails, conversationDetails, exceptionDetails, exceptionDetails, sessionInitOptionalParams, error_3, exceptionDetails, chatAdapterConfig, error_4, exceptionDetails, _q, error_5, exceptionDetails, error_6, exceptionDetails, error_7, exceptionDetails, _r, error_8, exceptionDetails;
305
+ 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;
298
306
  var _this = this;
299
- return __generator(this, function (_s) {
300
- switch (_s.label) {
307
+ return __generator(this, function (_w) {
308
+ switch (_w.label) {
301
309
  case 0:
302
310
  this.scenarioMarker.startScenario(TelemetryEvent_1.default.StartChat, {
303
311
  RequestId: this.requestId
304
312
  });
313
+ shouldReinitIC3Client = !platform_1.default.isNode() && !platform_1.default.isReactNative() && !this.IC3Client && this.liveChatVersion === LiveChatVersion_1.default.V1;
314
+ if (!shouldReinitIC3Client) return [3 /*break*/, 2];
315
+ _s = this;
316
+ return [4 /*yield*/, this.getIC3Client()];
317
+ case 1:
318
+ _s.IC3Client = _w.sent();
319
+ _w.label = 2;
320
+ case 2:
305
321
  if (this.isChatReconnect && !((_a = this.chatSDKConfig.chatReconnect) === null || _a === void 0 ? void 0 : _a.disable) && !this.isPersistentChat && optionalParams.reconnectId) {
306
322
  this.reconnectId = optionalParams.reconnectId;
307
323
  }
308
- if (!(this.isPersistentChat && !((_b = this.chatSDKConfig.persistentChat) === null || _b === void 0 ? void 0 : _b.disable))) return [3 /*break*/, 4];
309
- _s.label = 1;
310
- case 1:
311
- _s.trys.push([1, 3, , 4]);
324
+ if (!(this.isPersistentChat && !((_b = this.chatSDKConfig.persistentChat) === null || _b === void 0 ? void 0 : _b.disable))) return [3 /*break*/, 6];
325
+ _w.label = 3;
326
+ case 3:
327
+ _w.trys.push([3, 5, , 6]);
312
328
  reconnectableChatsParams = {
313
329
  authenticatedUserToken: this.authenticatedUserToken
314
330
  };
315
331
  return [4 /*yield*/, this.OCClient.getReconnectableChats(reconnectableChatsParams)];
316
- case 2:
317
- reconnectableChatsResponse = _s.sent();
332
+ case 4:
333
+ reconnectableChatsResponse = _w.sent();
318
334
  if (reconnectableChatsResponse && reconnectableChatsResponse.reconnectid) {
319
335
  this.reconnectId = reconnectableChatsResponse.reconnectid;
320
336
  }
321
- return [3 /*break*/, 4];
322
- case 3:
323
- _p = _s.sent();
337
+ return [3 /*break*/, 6];
338
+ case 5:
339
+ _t = _w.sent();
324
340
  exceptionDetails = {
325
341
  response: "OCClientGetReconnectableChatsFailed"
326
342
  };
327
343
  throw Error(exceptionDetails.response);
328
- case 4:
329
- if (!(optionalParams.liveChatContext && !this.reconnectId)) return [3 /*break*/, 6];
344
+ case 6:
345
+ if (!(optionalParams.liveChatContext && !this.reconnectId)) return [3 /*break*/, 8];
330
346
  this.chatToken = optionalParams.liveChatContext.chatToken || {};
331
347
  this.requestId = optionalParams.liveChatContext.requestId || ocsdk_1.uuidv4();
332
348
  return [4 /*yield*/, this.getConversationDetails()];
333
- case 5:
334
- conversationDetails = _s.sent();
349
+ case 7:
350
+ conversationDetails = _w.sent();
335
351
  if (Object.keys(conversationDetails).length === 0) {
336
352
  exceptionDetails = {
337
353
  response: "InvalidConversation"
@@ -356,14 +372,14 @@ var OmnichannelChatSDK = /** @class */ (function () {
356
372
  console.error("Unable to join conversation that's in '" + conversationDetails.state + "' state");
357
373
  throw Error(exceptionDetails.response);
358
374
  }
359
- _s.label = 6;
360
- case 6:
361
- if (!(this.chatToken && Object.keys(this.chatToken).length === 0)) return [3 /*break*/, 8];
362
- return [4 /*yield*/, this.getChatToken(false)];
363
- case 7:
364
- _s.sent();
365
- _s.label = 8;
375
+ _w.label = 8;
366
376
  case 8:
377
+ if (!(this.chatToken && Object.keys(this.chatToken).length === 0)) return [3 /*break*/, 10];
378
+ return [4 /*yield*/, this.getChatToken(false)];
379
+ case 9:
380
+ _w.sent();
381
+ _w.label = 10;
382
+ case 10:
367
383
  (_c = this.ic3ClientLogger) === null || _c === void 0 ? void 0 : _c.setChatId(this.chatToken.chatId || '');
368
384
  (_d = this.ocSdkLogger) === null || _d === void 0 ? void 0 : _d.setChatId(this.chatToken.chatId || '');
369
385
  (_e = this.acsClientLogger) === null || _e === void 0 ? void 0 : _e.setChatId(this.chatToken.chatId || '');
@@ -371,6 +387,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
371
387
  sessionInitOptionalParams = {
372
388
  initContext: {}
373
389
  };
390
+ sessionInitOptionalParams.initContext.locale = locale_1.getLocaleStringFromId(this.localeId);
374
391
  if (this.isPersistentChat && !((_g = this.chatSDKConfig.persistentChat) === null || _g === void 0 ? void 0 : _g.disable)) {
375
392
  sessionInitOptionalParams.reconnectId = this.reconnectId;
376
393
  }
@@ -402,28 +419,33 @@ var OmnichannelChatSDK = /** @class */ (function () {
402
419
  if (this.authenticatedUserToken) {
403
420
  sessionInitOptionalParams.authenticatedUserToken = this.authenticatedUserToken;
404
421
  }
405
- if (!!optionalParams.liveChatContext) return [3 /*break*/, 12];
406
- _s.label = 9;
407
- case 9:
408
- _s.trys.push([9, 11, , 12]);
409
- return [4 /*yield*/, this.OCClient.sessionInit(this.requestId, sessionInitOptionalParams)];
410
- case 10:
411
- _s.sent();
412
- return [3 /*break*/, 12];
422
+ if (!!optionalParams.liveChatContext) return [3 /*break*/, 14];
423
+ _w.label = 11;
413
424
  case 11:
414
- error_3 = _s.sent();
425
+ _w.trys.push([11, 13, , 14]);
426
+ return [4 /*yield*/, this.OCClient.sessionInit(this.requestId, sessionInitOptionalParams)];
427
+ case 12:
428
+ _w.sent();
429
+ return [3 /*break*/, 14];
430
+ case 13:
431
+ error_3 = _w.sent();
415
432
  exceptionDetails = {
416
433
  response: "OCClientSessionInitFailed"
417
434
  };
435
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
436
+ 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()) {
437
+ exceptionDetails.response = OmnichannelErrorCodes_1.default[OmnichannelErrorCodes_1.default.WidgetUseOutsideOperatingHour].toString();
438
+ exceptionDetails.message = 'Widget used outside of operating hours';
439
+ console.error(exceptionDetails.message);
440
+ }
418
441
  this.scenarioMarker.failScenario(TelemetryEvent_1.default.StartChat, {
419
442
  RequestId: this.requestId,
420
443
  ChatId: this.chatToken.chatId,
421
444
  ExceptionDetails: JSON.stringify(exceptionDetails)
422
445
  });
423
- console.error("OmnichannelChatSDK/startChat/sessionInit/error " + error_3);
424
- return [2 /*return*/, error_3];
425
- case 12:
426
- if (!(this.liveChatVersion === LiveChatVersion_1.default.V2)) return [3 /*break*/, 23];
446
+ throw new Error(exceptionDetails.response);
447
+ case 14:
448
+ if (!(this.liveChatVersion === LiveChatVersion_1.default.V2)) return [3 /*break*/, 25];
427
449
  chatAdapterConfig = {
428
450
  token: this.chatToken.token,
429
451
  id: this.chatToken.visitorId || 'teamsvisitor',
@@ -431,18 +453,18 @@ var OmnichannelChatSDK = /** @class */ (function () {
431
453
  environmentUrl: this.chatToken.acsEndpoint,
432
454
  pollingInterval: 1000
433
455
  };
434
- _s.label = 13;
435
- case 13:
436
- _s.trys.push([13, 15, , 16]);
437
- return [4 /*yield*/, ((_j = this.ACSClient) === null || _j === void 0 ? void 0 : _j.initialize({
456
+ _w.label = 15;
457
+ case 15:
458
+ _w.trys.push([15, 17, , 18]);
459
+ return [4 /*yield*/, ((_m = this.ACSClient) === null || _m === void 0 ? void 0 : _m.initialize({
438
460
  token: chatAdapterConfig.token,
439
461
  environmentUrl: chatAdapterConfig.environmentUrl
440
462
  }))];
441
- case 14:
442
- _s.sent();
443
- return [3 /*break*/, 16];
444
- case 15:
445
- error_4 = _s.sent();
463
+ case 16:
464
+ _w.sent();
465
+ return [3 /*break*/, 18];
466
+ case 17:
467
+ error_4 = _w.sent();
446
468
  exceptionDetails = {
447
469
  response: "ACSClientInitializeFailed"
448
470
  };
@@ -453,23 +475,23 @@ var OmnichannelChatSDK = /** @class */ (function () {
453
475
  });
454
476
  console.error("OmnichannelChatSDK/startChat/initialize/error " + error_4);
455
477
  return [2 /*return*/, error_4];
456
- case 16:
457
- _s.trys.push([16, 18, , 19]);
458
- _q = this;
459
- return [4 /*yield*/, ((_k = this.ACSClient) === null || _k === void 0 ? void 0 : _k.joinConversation({
478
+ case 18:
479
+ _w.trys.push([18, 20, , 21]);
480
+ _u = this;
481
+ return [4 /*yield*/, ((_o = this.ACSClient) === null || _o === void 0 ? void 0 : _o.joinConversation({
460
482
  id: chatAdapterConfig.id,
461
483
  threadId: chatAdapterConfig.threadId,
462
484
  pollingInterval: chatAdapterConfig.pollingInterval
463
485
  }))];
464
- case 17:
465
- _q.conversation = (_s.sent());
486
+ case 19:
487
+ _u.conversation = (_w.sent());
466
488
  this.scenarioMarker.completeScenario(TelemetryEvent_1.default.StartChat, {
467
489
  RequestId: this.requestId,
468
490
  ChatId: this.chatToken.chatId
469
491
  });
470
- return [3 /*break*/, 19];
471
- case 18:
472
- error_5 = _s.sent();
492
+ return [3 /*break*/, 21];
493
+ case 20:
494
+ error_5 = _w.sent();
473
495
  exceptionDetails = {
474
496
  response: "ACSClientJoinConversationFailed"
475
497
  };
@@ -480,16 +502,16 @@ var OmnichannelChatSDK = /** @class */ (function () {
480
502
  });
481
503
  console.error("OmnichannelChatSDK/startChat/joinConversation/error " + error_5);
482
504
  throw Error(exceptionDetails.response);
483
- case 19:
484
- _s.trys.push([19, 21, , 22]);
485
- return [4 /*yield*/, ((_l = this.AMSClient) === null || _l === void 0 ? void 0 : _l.initialize({
505
+ case 21:
506
+ _w.trys.push([21, 23, , 24]);
507
+ return [4 /*yield*/, ((_p = this.AMSClient) === null || _p === void 0 ? void 0 : _p.initialize({
486
508
  chatToken: this.chatToken
487
509
  }))];
488
- case 20:
489
- _s.sent();
490
- return [3 /*break*/, 22];
491
- case 21:
492
- error_6 = _s.sent();
510
+ case 22:
511
+ _w.sent();
512
+ return [3 /*break*/, 24];
513
+ case 23:
514
+ error_6 = _w.sent();
493
515
  exceptionDetails = {
494
516
  response: "AMSClientInitializeFailed"
495
517
  };
@@ -499,19 +521,19 @@ var OmnichannelChatSDK = /** @class */ (function () {
499
521
  ExceptionDetails: JSON.stringify(exceptionDetails)
500
522
  });
501
523
  throw Error(exceptionDetails.response);
502
- case 22: return [3 /*break*/, 29];
503
- case 23:
504
- _s.trys.push([23, 25, , 26]);
524
+ case 24: return [3 /*break*/, 31];
525
+ case 25:
526
+ _w.trys.push([25, 27, , 28]);
505
527
  return [4 /*yield*/, this.IC3Client.initialize({
506
528
  token: this.chatToken.token,
507
529
  regionGtms: this.chatToken.regionGTMS,
508
530
  visitor: true
509
531
  })];
510
- case 24:
511
- _s.sent();
512
- return [3 /*break*/, 26];
513
- case 25:
514
- error_7 = _s.sent();
532
+ case 26:
533
+ _w.sent();
534
+ return [3 /*break*/, 28];
535
+ case 27:
536
+ error_7 = _w.sent();
515
537
  exceptionDetails = {
516
538
  response: "IC3ClientInitializeFailed"
517
539
  };
@@ -522,19 +544,19 @@ var OmnichannelChatSDK = /** @class */ (function () {
522
544
  });
523
545
  console.error("OmnichannelChatSDK/startChat/initialize/error " + error_7);
524
546
  return [2 /*return*/, error_7];
525
- case 26:
526
- _s.trys.push([26, 28, , 29]);
527
- _r = this;
547
+ case 28:
548
+ _w.trys.push([28, 30, , 31]);
549
+ _v = this;
528
550
  return [4 /*yield*/, this.IC3Client.joinConversation(this.chatToken.chatId)];
529
- case 27:
530
- _r.conversation = _s.sent();
551
+ case 29:
552
+ _v.conversation = _w.sent();
531
553
  this.scenarioMarker.completeScenario(TelemetryEvent_1.default.StartChat, {
532
554
  RequestId: this.requestId,
533
555
  ChatId: this.chatToken.chatId
534
556
  });
535
- return [3 /*break*/, 29];
536
- case 28:
537
- error_8 = _s.sent();
557
+ return [3 /*break*/, 31];
558
+ case 30:
559
+ error_8 = _w.sent();
538
560
  exceptionDetails = {
539
561
  response: "IC3ClientJoinConversationFailed"
540
562
  };
@@ -545,8 +567,8 @@ var OmnichannelChatSDK = /** @class */ (function () {
545
567
  });
546
568
  console.error("OmnichannelChatSDK/startChat/joinConversation/error " + error_8);
547
569
  return [2 /*return*/, error_8];
548
- case 29:
549
- if (this.isPersistentChat && !((_m = this.chatSDKConfig.persistentChat) === null || _m === void 0 ? void 0 : _m.disable)) {
570
+ case 31:
571
+ if (this.isPersistentChat && !((_q = this.chatSDKConfig.persistentChat) === null || _q === void 0 ? void 0 : _q.disable)) {
550
572
  this.refreshTokenTimer = setInterval(function () { return __awaiter(_this, void 0, void 0, function () {
551
573
  return __generator(this, function (_a) {
552
574
  switch (_a.label) {
@@ -557,7 +579,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
557
579
  return [2 /*return*/];
558
580
  }
559
581
  });
560
- }); }, (_o = this.chatSDKConfig.persistentChat) === null || _o === void 0 ? void 0 : _o.tokenUpdateTime);
582
+ }); }, (_r = this.chatSDKConfig.persistentChat) === null || _r === void 0 ? void 0 : _r.tokenUpdateTime);
561
583
  }
562
584
  return [2 /*return*/];
563
585
  }
@@ -583,6 +605,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
583
605
  }
584
606
  if (this.isChatReconnect && !((_b = this.chatSDKConfig.chatReconnect) === null || _b === void 0 ? void 0 : _b.disable) && !this.isPersistentChat) {
585
607
  isChatReconnect = this.reconnectId !== null ? true : false;
608
+ this.requestId = isChatReconnect ? this.reconnectId : this.requestId; // Chat Reconnect session to close
586
609
  sessionCloseOptionalParams.isReconnectChat = isChatReconnect;
587
610
  }
588
611
  if (this.authenticatedUserToken) {
@@ -603,6 +626,11 @@ var OmnichannelChatSDK = /** @class */ (function () {
603
626
  this.requestId = ocsdk_1.uuidv4();
604
627
  this.chatToken = {};
605
628
  this.reconnectId = null;
629
+ if (this.IC3Client) {
630
+ this.IC3Client.dispose();
631
+ !platform_1.default.isNode() && !platform_1.default.isReactNative() && WebUtils_1.removeElementById(this.IC3Client.id);
632
+ this.IC3Client = null;
633
+ }
606
634
  (_d = this.ic3ClientLogger) === null || _d === void 0 ? void 0 : _d.setRequestId(this.requestId);
607
635
  (_e = this.ic3ClientLogger) === null || _e === void 0 ? void 0 : _e.setChatId('');
608
636
  (_f = this.ocSdkLogger) === null || _f === void 0 ? void 0 : _f.setRequestId(this.requestId);
@@ -664,22 +692,32 @@ var OmnichannelChatSDK = /** @class */ (function () {
664
692
  });
665
693
  };
666
694
  OmnichannelChatSDK.prototype.getConversationDetails = function () {
667
- var _a, _b;
695
+ var _a, _b, _c, _d;
668
696
  return __awaiter(this, void 0, void 0, function () {
669
- var lwiDetails, state, conversationId, agentAcceptedOn, liveWorkItemDetails, error_10;
670
- return __generator(this, function (_c) {
671
- switch (_c.label) {
697
+ var getLWIDetailsOptionalParams, lwiDetails, state, conversationId, agentAcceptedOn, liveWorkItemDetails, error_10;
698
+ return __generator(this, function (_e) {
699
+ switch (_e.label) {
672
700
  case 0:
673
701
  this.scenarioMarker.startScenario(TelemetryEvent_1.default.GetConversationDetails, {
674
702
  RequestId: this.requestId,
675
703
  ChatId: ((_a = this.chatToken) === null || _a === void 0 ? void 0 : _a.chatId) || '',
676
704
  });
677
- _c.label = 1;
705
+ getLWIDetailsOptionalParams = {};
706
+ if (this.isPersistentChat && !((_b = this.chatSDKConfig.persistentChat) === null || _b === void 0 ? void 0 : _b.disable) && this.reconnectId) {
707
+ getLWIDetailsOptionalParams.reconnectId = this.reconnectId;
708
+ }
709
+ if (this.isChatReconnect && !((_c = this.chatSDKConfig.chatReconnect) === null || _c === void 0 ? void 0 : _c.disable) && !this.isPersistentChat && this.reconnectId) {
710
+ getLWIDetailsOptionalParams.reconnectId = this.reconnectId;
711
+ }
712
+ if (this.authenticatedUserToken) {
713
+ getLWIDetailsOptionalParams.authenticatedUserToken = this.authenticatedUserToken;
714
+ }
715
+ _e.label = 1;
678
716
  case 1:
679
- _c.trys.push([1, 3, , 4]);
680
- return [4 /*yield*/, this.OCClient.getLWIDetails(this.requestId)];
717
+ _e.trys.push([1, 3, , 4]);
718
+ return [4 /*yield*/, this.OCClient.getLWIDetails(this.requestId, getLWIDetailsOptionalParams)];
681
719
  case 2:
682
- lwiDetails = _c.sent();
720
+ lwiDetails = _e.sent();
683
721
  state = lwiDetails.State, conversationId = lwiDetails.ConversationId, agentAcceptedOn = lwiDetails.AgentAcceptedOn;
684
722
  liveWorkItemDetails = {
685
723
  state: state,
@@ -690,11 +728,11 @@ var OmnichannelChatSDK = /** @class */ (function () {
690
728
  }
691
729
  this.scenarioMarker.completeScenario(TelemetryEvent_1.default.GetConversationDetails, {
692
730
  RequestId: this.requestId,
693
- ChatId: ((_b = this.chatToken) === null || _b === void 0 ? void 0 : _b.chatId) || '',
731
+ ChatId: ((_d = this.chatToken) === null || _d === void 0 ? void 0 : _d.chatId) || '',
694
732
  });
695
733
  return [2 /*return*/, liveWorkItemDetails];
696
734
  case 3:
697
- error_10 = _c.sent();
735
+ error_10 = _e.sent();
698
736
  this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetConversationDetails, {
699
737
  RequestId: this.requestId,
700
738
  ChatId: this.chatToken.chatId || '',
@@ -1450,7 +1488,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
1450
1488
  ChatId: this.chatToken.chatId,
1451
1489
  EmailAddress: body.emailAddress,
1452
1490
  DefaultAttachmentMessage: body.attachmentMessage,
1453
- CustomerLocale: body.locale
1491
+ CustomerLocale: body.locale || locale_1.getLocaleStringFromId(this.localeId)
1454
1492
  };
1455
1493
  emailResponse = this.OCClient.emailTranscript(this.requestId, this.chatToken.token, emailRequestBody, emailTranscriptOptionalParams);
1456
1494
  this.scenarioMarker.completeScenario(TelemetryEvent_1.default.EmailLiveChatTranscript, {
@@ -1500,36 +1538,33 @@ var OmnichannelChatSDK = /** @class */ (function () {
1500
1538
  });
1501
1539
  });
1502
1540
  };
1503
- OmnichannelChatSDK.prototype.createChatAdapter = function (protocol) {
1504
- if (protocol === void 0) { protocol = null; }
1541
+ OmnichannelChatSDK.prototype.createChatAdapter = function (optionalParams) {
1542
+ if (optionalParams === void 0) { optionalParams = {}; }
1505
1543
  return __awaiter(this, void 0, void 0, function () {
1506
- var supportedChatAdapterProtocols;
1544
+ var protocol, supportedChatAdapterProtocols;
1507
1545
  var _this = this;
1508
1546
  return __generator(this, function (_a) {
1509
1547
  if (platform_1.default.isNode() || platform_1.default.isReactNative()) {
1510
1548
  return [2 /*return*/, Promise.reject('ChatAdapter is only supported on browser')];
1511
1549
  }
1550
+ protocol = optionalParams.protocol;
1512
1551
  supportedChatAdapterProtocols = [ChatAdapterProtocols_1.default.ACS, ChatAdapterProtocols_1.default.IC3];
1513
1552
  if (protocol && !supportedChatAdapterProtocols.includes(protocol)) {
1514
1553
  return [2 /*return*/, Promise.reject("ChatAdapter for protocol " + protocol + " currently not supported")];
1515
1554
  }
1516
1555
  if (protocol === ChatAdapterProtocols_1.default.ACS || this.liveChatVersion === LiveChatVersion_1.default.V2) {
1517
1556
  return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
1518
- var egressMiddlewares, ingressMiddlewares, featuresOption, acsAdapterCDNUrl;
1557
+ var options, egressMiddlewares, ingressMiddlewares, featuresOption, acsAdapterCDNUrl;
1519
1558
  var _this = this;
1520
1559
  var _a;
1521
1560
  return __generator(this, function (_b) {
1522
1561
  switch (_b.label) {
1523
1562
  case 0:
1563
+ options = optionalParams.ACSAdapter ? optionalParams.ACSAdapter.options : {};
1524
1564
  egressMiddlewares = [createFormatEgressTagsMiddleware_1.default()];
1525
1565
  ingressMiddlewares = [createFormatIngressTagsMiddleware_1.default()];
1526
- featuresOption = {
1527
- enableAdaptiveCards: true,
1528
- enableThreadMemberUpdateNotification: true,
1529
- enableLeaveThreadOnWindowClosed: false,
1530
- egressMiddleware: egressMiddlewares,
1531
- ingressMiddleware: ingressMiddlewares
1532
- };
1566
+ featuresOption = __assign({ enableAdaptiveCards: true, enableThreadMemberUpdateNotification: true, enableLeaveThreadOnWindowClosed: false, egressMiddleware: egressMiddlewares, ingressMiddleware: ingressMiddlewares }, options // overrides
1567
+ );
1533
1568
  acsAdapterCDNUrl = this.resolveChatAdapterUrl(protocol || ChatAdapterProtocols_1.default.ACS);
1534
1569
  (_a = this.telemetry) === null || _a === void 0 ? void 0 : _a.setCDNPackages({
1535
1570
  ACSAdapter: acsAdapterCDNUrl
@@ -1540,7 +1575,8 @@ var OmnichannelChatSDK = /** @class */ (function () {
1540
1575
  try {
1541
1576
  var ChatAdapter = window.ChatAdapter; // eslint-disable-line @typescript-eslint/no-explicit-any
1542
1577
  var fileManager = new AMSFileManager_1.default(_this.AMSClient, _this.acsAdapterLogger);
1543
- 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
1578
+ 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
1579
+ undefined, // logger
1544
1580
  featuresOption);
1545
1581
  resolve(adapter);
1546
1582
  }
@@ -1559,12 +1595,13 @@ var OmnichannelChatSDK = /** @class */ (function () {
1559
1595
  }
1560
1596
  else if (protocol === ChatAdapterProtocols_1.default.IC3 || this.liveChatVersion === LiveChatVersion_1.default.V1) {
1561
1597
  return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
1562
- var ic3AdapterCDNUrl;
1598
+ var options, ic3AdapterCDNUrl;
1563
1599
  var _this = this;
1564
1600
  var _a;
1565
1601
  return __generator(this, function (_b) {
1566
1602
  switch (_b.label) {
1567
1603
  case 0:
1604
+ options = optionalParams.IC3Adapter ? optionalParams.IC3Adapter.options : {};
1568
1605
  ic3AdapterCDNUrl = this.resolveChatAdapterUrl(protocol || ChatAdapterProtocols_1.default.IC3);
1569
1606
  (_a = this.telemetry) === null || _a === void 0 ? void 0 : _a.setCDNPackages({
1570
1607
  IC3Adapter: ic3AdapterCDNUrl
@@ -1573,17 +1610,10 @@ var OmnichannelChatSDK = /** @class */ (function () {
1573
1610
  return [4 /*yield*/, WebUtils_1.loadScript(ic3AdapterCDNUrl, function () {
1574
1611
  /* istanbul ignore next */
1575
1612
  _this.debug && console.debug('IC3Adapter loaded!');
1576
- var adapterConfig = {
1577
- chatToken: _this.chatToken,
1578
- userDisplayName: 'Customer',
1579
- userId: 'teamsvisitor',
1580
- sdkURL: _this.resolveIC3ClientUrl(),
1581
- sdk: _this.IC3Client
1582
- };
1613
+ var adapterConfig = __assign({ chatToken: _this.chatToken, userDisplayName: 'Customer', userId: _this.chatToken.visitorId || 'teamsvisitor', sdkURL: _this.resolveIC3ClientUrl(), sdk: _this.IC3Client }, options // overrides
1614
+ );
1583
1615
  var adapter = new window.Microsoft.BotFramework.WebChat.IC3Adapter(adapterConfig);
1584
1616
  adapter.logger = _this.ic3ClientLogger;
1585
- // Keep iframe communication alive to reuse the same IC3Client instance
1586
- window.Microsoft.BotFramework.WebChat.IC3SDKProvider.disposeSdk = function () { }; // eslint-disable-line @typescript-eslint/no-empty-function
1587
1617
  _this.scenarioMarker.completeScenario(TelemetryEvent_1.default.CreateIC3Adapter);
1588
1618
  resolve(adapter);
1589
1619
  }, function () {
@@ -1677,7 +1707,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
1677
1707
  };
1678
1708
  OmnichannelChatSDK.prototype.getPostChatSurveyContext = function () {
1679
1709
  return __awaiter(this, void 0, void 0, function () {
1680
- var conversationId, chatConfig, liveWSAndLiveChatEngJoin, chatWidgetLanguage, msdyn_postconversationsurveyenable, msfp_sourcesurveyidentifier, postConversationSurveyOwnerId, msdyn_localeid, localeId, liveWorkItemDetails, participantJoined, surveyInviteLinkRequest, optionalParams, surveyInviteLinkResponse, surveyInviteLink, formsProLocale, postChatContext, ex_1;
1710
+ var conversationId, liveWSAndLiveChatEngJoin, msdyn_postconversationsurveyenable, msfp_sourcesurveyidentifier, postConversationSurveyOwnerId, liveWorkItemDetails, participantJoined, surveyInviteLinkRequest, optionalParams, surveyInviteLinkResponse, surveyInviteLink, formsProLocale, postChatContext, ex_1;
1681
1711
  return __generator(this, function (_a) {
1682
1712
  switch (_a.label) {
1683
1713
  case 0:
@@ -1687,11 +1717,8 @@ var OmnichannelChatSDK = /** @class */ (function () {
1687
1717
  _a.label = 1;
1688
1718
  case 1:
1689
1719
  _a.trys.push([1, 6, , 7]);
1690
- chatConfig = this.liveChatConfig;
1691
- liveWSAndLiveChatEngJoin = chatConfig.LiveWSAndLiveChatEngJoin, chatWidgetLanguage = chatConfig.ChatWidgetLanguage;
1720
+ liveWSAndLiveChatEngJoin = this.liveChatConfig.LiveWSAndLiveChatEngJoin;
1692
1721
  msdyn_postconversationsurveyenable = liveWSAndLiveChatEngJoin.msdyn_postconversationsurveyenable, msfp_sourcesurveyidentifier = liveWSAndLiveChatEngJoin.msfp_sourcesurveyidentifier, postConversationSurveyOwnerId = liveWSAndLiveChatEngJoin.postConversationSurveyOwnerId;
1693
- msdyn_localeid = chatWidgetLanguage.msdyn_localeid;
1694
- localeId = msdyn_localeid !== null && msdyn_localeid !== void 0 ? msdyn_localeid : "1033";
1695
1722
  if (!msdyn_postconversationsurveyenable) return [3 /*break*/, 4];
1696
1723
  return [4 /*yield*/, this.OCClient.getLWIDetails(this.requestId)];
1697
1724
  case 2:
@@ -1701,7 +1728,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
1701
1728
  surveyInviteLinkRequest = {
1702
1729
  "FormId": msfp_sourcesurveyidentifier,
1703
1730
  "ConversationId": conversationId,
1704
- "OCLocaleCode": locale_1.getLocaleStringFromId(localeId)
1731
+ "OCLocaleCode": locale_1.getLocaleStringFromId(this.localeId) || locale_1.getLocaleStringFromId(locale_1.defaultLocaleId)
1705
1732
  };
1706
1733
  optionalParams = {
1707
1734
  "requestId": this.requestId
@@ -1790,7 +1817,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
1790
1817
  this.debug && console.debug('IC3Client');
1791
1818
  // Use IC3Client if browser is detected
1792
1819
  return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
1793
- var ic3ClientCDNUrl;
1820
+ var ic3ClientCDNUrl, IC3Client;
1794
1821
  var _this = this;
1795
1822
  var _a;
1796
1823
  return __generator(this, function (_b) {
@@ -1801,6 +1828,16 @@ var OmnichannelChatSDK = /** @class */ (function () {
1801
1828
  IC3Client: ic3ClientCDNUrl
1802
1829
  });
1803
1830
  this.scenarioMarker.startScenario(TelemetryEvent_1.default.GetIC3Client);
1831
+ if (!this.IC3SDKProvider) return [3 /*break*/, 2];
1832
+ return [4 /*yield*/, this.IC3SDKProvider.getSDK({
1833
+ hostType: HostType_1.default.IFrame,
1834
+ protocolType: ProtocoleType_1.default.IC3V1SDK,
1835
+ logger: this.ic3ClientLogger // eslint-disable-line @typescript-eslint/no-explicit-any
1836
+ })];
1837
+ case 1:
1838
+ IC3Client = _b.sent();
1839
+ return [2 /*return*/, resolve(IC3Client)];
1840
+ case 2:
1804
1841
  window.addEventListener("ic3:sdk:load", function () { return __awaiter(_this, void 0, void 0, function () {
1805
1842
  var ic3sdk, IC3SDKProvider, IC3Client;
1806
1843
  return __generator(this, function (_a) {
@@ -1837,7 +1874,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
1837
1874
  });
1838
1875
  reject('Failed to load IC3Client');
1839
1876
  })];
1840
- case 1:
1877
+ case 3:
1841
1878
  _b.sent();
1842
1879
  return [2 /*return*/];
1843
1880
  }
@@ -1849,15 +1886,17 @@ var OmnichannelChatSDK = /** @class */ (function () {
1849
1886
  };
1850
1887
  OmnichannelChatSDK.prototype.getChatConfig = function () {
1851
1888
  return __awaiter(this, void 0, void 0, function () {
1852
- var liveChatConfig, dataMaskingConfig, authSettings, liveWSAndLiveChatEngJoin, liveChatVersion, setting, preChatSurvey, msdyn_prechatenabled, msdyn_callingoptions, msdyn_conversationmode, msdyn_enablechatreconnect, isPreChatEnabled, isChatReconnectEnabled, token, exceptionDetails, _a, exceptionDetails, exceptionDetails, error_18;
1853
- return __generator(this, function (_b) {
1854
- switch (_b.label) {
1889
+ var liveChatConfig, dataMaskingConfig, authSettings, liveWSAndLiveChatEngJoin, liveChatVersion, chatWidgetLanguage, msdyn_localeid, setting, preChatSurvey, msdyn_prechatenabled, msdyn_callingoptions, msdyn_conversationmode, msdyn_enablechatreconnect, isPreChatEnabled, isChatReconnectEnabled, error_18;
1890
+ return __generator(this, function (_a) {
1891
+ switch (_a.label) {
1855
1892
  case 0:
1856
- _b.trys.push([0, 8, , 9]);
1893
+ _a.trys.push([0, 4, , 5]);
1857
1894
  return [4 /*yield*/, this.OCClient.getChatConfig()];
1858
1895
  case 1:
1859
- liveChatConfig = _b.sent();
1860
- dataMaskingConfig = liveChatConfig.DataMaskingInfo, authSettings = liveChatConfig.LiveChatConfigAuthSettings, liveWSAndLiveChatEngJoin = liveChatConfig.LiveWSAndLiveChatEngJoin, liveChatVersion = liveChatConfig.LiveChatVersion;
1896
+ liveChatConfig = _a.sent();
1897
+ dataMaskingConfig = liveChatConfig.DataMaskingInfo, authSettings = liveChatConfig.LiveChatConfigAuthSettings, liveWSAndLiveChatEngJoin = liveChatConfig.LiveWSAndLiveChatEngJoin, liveChatVersion = liveChatConfig.LiveChatVersion, chatWidgetLanguage = liveChatConfig.ChatWidgetLanguage;
1898
+ msdyn_localeid = chatWidgetLanguage.msdyn_localeid;
1899
+ this.localeId = msdyn_localeid || locale_1.defaultLocaleId;
1861
1900
  this.liveChatVersion = liveChatVersion || LiveChatVersion_1.default.V1;
1862
1901
  /* istanbul ignore next */
1863
1902
  this.debug && console.log("[OmnichannelChatSDK][getChatConfig][liveChatVersion] " + this.liveChatVersion);
@@ -1880,47 +1919,12 @@ var OmnichannelChatSDK = /** @class */ (function () {
1880
1919
  if (isPreChatEnabled && preChatSurvey && preChatSurvey.trim().length > 0) {
1881
1920
  this.preChatSurvey = preChatSurvey;
1882
1921
  }
1883
- if (!this.authSettings) return [3 /*break*/, 7];
1884
- this.scenarioMarker.startScenario(TelemetryEvent_1.default.GetAuthToken);
1885
- if (!this.chatSDKConfig.getAuthToken) return [3 /*break*/, 6];
1886
- _b.label = 2;
1922
+ if (!this.authSettings) return [3 /*break*/, 3];
1923
+ return [4 /*yield*/, this.setAuthTokenProvider(this.chatSDKConfig.getAuthToken)];
1887
1924
  case 2:
1888
- _b.trys.push([2, 4, , 5]);
1889
- return [4 /*yield*/, this.chatSDKConfig.getAuthToken()];
1925
+ _a.sent();
1926
+ _a.label = 3;
1890
1927
  case 3:
1891
- token = _b.sent();
1892
- if (token) {
1893
- this.authenticatedUserToken = token;
1894
- this.scenarioMarker.completeScenario(TelemetryEvent_1.default.GetAuthToken);
1895
- }
1896
- else {
1897
- exceptionDetails = {
1898
- response: "UndefinedAuthToken"
1899
- };
1900
- this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetAuthToken, {
1901
- ExceptionDetails: JSON.stringify(exceptionDetails)
1902
- });
1903
- }
1904
- return [3 /*break*/, 5];
1905
- case 4:
1906
- _a = _b.sent();
1907
- exceptionDetails = {
1908
- response: "GetAuthTokenFailed"
1909
- };
1910
- this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetAuthToken, {
1911
- ExceptionDetails: JSON.stringify(exceptionDetails)
1912
- });
1913
- return [3 /*break*/, 5];
1914
- case 5: return [3 /*break*/, 7];
1915
- case 6:
1916
- exceptionDetails = {
1917
- response: "GetAuthTokenNotFound"
1918
- };
1919
- this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetAuthToken, {
1920
- ExceptionDetails: JSON.stringify(exceptionDetails)
1921
- });
1922
- _b.label = 7;
1923
- case 7:
1924
1928
  if (this.preChatSurvey) {
1925
1929
  /* istanbul ignore next */
1926
1930
  this.debug && console.log('Prechat Survey!');
@@ -1928,11 +1932,11 @@ var OmnichannelChatSDK = /** @class */ (function () {
1928
1932
  this.callingOption = msdyn_callingoptions;
1929
1933
  this.liveChatConfig = liveChatConfig;
1930
1934
  return [2 /*return*/, this.liveChatConfig];
1931
- case 8:
1932
- error_18 = _b.sent();
1935
+ case 4:
1936
+ error_18 = _a.sent();
1933
1937
  console.error("OmnichannelChatSDK/getChatConfig/error " + error_18);
1934
1938
  return [2 /*return*/, error_18];
1935
- case 9: return [2 /*return*/];
1939
+ case 5: return [2 /*return*/];
1936
1940
  }
1937
1941
  });
1938
1942
  });
@@ -2014,6 +2018,57 @@ var OmnichannelChatSDK = /** @class */ (function () {
2014
2018
  });
2015
2019
  });
2016
2020
  };
2021
+ OmnichannelChatSDK.prototype.setAuthTokenProvider = function (provider) {
2022
+ return __awaiter(this, void 0, void 0, function () {
2023
+ var token, exceptionDetails, _a, exceptionDetails, exceptionDetails;
2024
+ return __generator(this, function (_b) {
2025
+ switch (_b.label) {
2026
+ case 0:
2027
+ this.scenarioMarker.startScenario(TelemetryEvent_1.default.GetAuthToken);
2028
+ this.chatSDKConfig.getAuthToken = provider;
2029
+ if (!this.chatSDKConfig.getAuthToken) return [3 /*break*/, 5];
2030
+ _b.label = 1;
2031
+ case 1:
2032
+ _b.trys.push([1, 3, , 4]);
2033
+ return [4 /*yield*/, this.chatSDKConfig.getAuthToken()];
2034
+ case 2:
2035
+ token = _b.sent();
2036
+ if (token) {
2037
+ this.authenticatedUserToken = token;
2038
+ this.scenarioMarker.completeScenario(TelemetryEvent_1.default.GetAuthToken);
2039
+ }
2040
+ else {
2041
+ exceptionDetails = {
2042
+ response: "UndefinedAuthToken"
2043
+ };
2044
+ this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetAuthToken, {
2045
+ ExceptionDetails: JSON.stringify(exceptionDetails)
2046
+ });
2047
+ }
2048
+ return [3 /*break*/, 4];
2049
+ case 3:
2050
+ _a = _b.sent();
2051
+ exceptionDetails = {
2052
+ response: "GetAuthTokenFailed"
2053
+ };
2054
+ this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetAuthToken, {
2055
+ ExceptionDetails: JSON.stringify(exceptionDetails)
2056
+ });
2057
+ return [3 /*break*/, 4];
2058
+ case 4: return [3 /*break*/, 6];
2059
+ case 5:
2060
+ exceptionDetails = {
2061
+ response: "GetAuthTokenNotFound"
2062
+ };
2063
+ this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetAuthToken, {
2064
+ ExceptionDetails: JSON.stringify(exceptionDetails)
2065
+ });
2066
+ _b.label = 6;
2067
+ case 6: return [2 /*return*/];
2068
+ }
2069
+ });
2070
+ });
2071
+ };
2017
2072
  return OmnichannelChatSDK;
2018
2073
  }());
2019
2074
  exports.default = OmnichannelChatSDK;