@microsoft/omnichannel-chat-sdk 1.2.1-main.d718a78 → 1.3.0

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.
@@ -87,6 +87,7 @@ var createOmnichannelMessage_1 = require("./utils/createOmnichannelMessage");
87
87
  var createTelemetry_1 = require("./utils/createTelemetry");
88
88
  var createVoiceVideoCalling_1 = require("./api/createVoiceVideoCalling");
89
89
  var MessageTags_1 = require("./core/messaging/MessageTags");
90
+ var location_1 = require("./utils/location");
90
91
  var utilities_1 = require("./utils/utilities");
91
92
  var urlResolvers_1 = require("./utils/urlResolvers");
92
93
  var OmnichannelConfigValidator_1 = require("./validators/OmnichannelConfigValidator");
@@ -94,7 +95,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
94
95
  function OmnichannelChatSDK(omnichannelConfig, chatSDKConfig) {
95
96
  var _this = this;
96
97
  if (chatSDKConfig === void 0) { chatSDKConfig = SDKConfigValidators_1.defaultChatSDKConfig; }
97
- var _a, _b, _c, _d, _e, _f, _g, _h;
98
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
98
99
  this.ACSClient = null;
99
100
  this.AMSClient = null;
100
101
  this.authSettings = null;
@@ -107,6 +108,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
107
108
  this.acsClientLogger = null;
108
109
  this.acsAdapterLogger = null;
109
110
  this.callingSdkLogger = null;
111
+ this.amsClientLogger = null;
110
112
  this.isPersistentChat = false;
111
113
  this.isChatReconnect = false;
112
114
  this.reconnectId = null;
@@ -131,6 +133,9 @@ var OmnichannelChatSDK = /** @class */ (function () {
131
133
  if (optionalParams.preChatResponse) {
132
134
  requestOptionalParams.initContext.preChatResponse = optionalParams.preChatResponse;
133
135
  }
136
+ if (optionalParams.portalContactId) {
137
+ requestOptionalParams.initContext.portalcontactid = optionalParams.portalContactId;
138
+ }
134
139
  if (optionalParams.sendDefaultInitContext) {
135
140
  if (platform_1.default.isNode() || platform_1.default.isReactNative()) {
136
141
  var exceptionDetails = {
@@ -166,7 +171,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
166
171
  this.chatSDKConfig = __assign(__assign({}, SDKConfigValidators_1.defaultChatSDKConfig), chatSDKConfig // overrides
167
172
  );
168
173
  this.isInitialized = false;
169
- this.liveChatVersion = LiveChatVersion_1.default.V1;
174
+ this.liveChatVersion = LiveChatVersion_1.default.V2;
170
175
  this.localeId = locale_1.defaultLocaleId;
171
176
  this.requestId = ocsdk_1.uuidv4();
172
177
  this.chatToken = {};
@@ -181,18 +186,21 @@ var OmnichannelChatSDK = /** @class */ (function () {
181
186
  this.acsClientLogger = loggers_1.createACSClientLogger(this.omnichannelConfig);
182
187
  this.acsAdapterLogger = loggers_1.createACSAdapterLogger(this.omnichannelConfig);
183
188
  this.callingSdkLogger = loggers_1.createCallingSDKLogger(this.omnichannelConfig);
189
+ this.amsClientLogger = loggers_1.createAMSClientLogger(this.omnichannelConfig);
184
190
  this.scenarioMarker.useTelemetry(this.telemetry);
185
191
  this.ic3ClientLogger.useTelemetry(this.telemetry);
186
192
  this.ocSdkLogger.useTelemetry(this.telemetry);
187
193
  this.acsClientLogger.useTelemetry(this.telemetry);
188
194
  this.acsAdapterLogger.useTelemetry(this.telemetry);
189
195
  this.callingSdkLogger.useTelemetry(this.telemetry);
196
+ this.amsClientLogger.useTelemetry(this.telemetry);
190
197
  this.scenarioMarker.setRuntimeId(this.runtimeId);
191
198
  this.ic3ClientLogger.setRuntimeId(this.runtimeId);
192
199
  this.ocSdkLogger.setRuntimeId(this.runtimeId);
193
200
  this.acsClientLogger.setRuntimeId(this.runtimeId);
194
201
  this.acsAdapterLogger.setRuntimeId(this.runtimeId);
195
202
  this.callingSdkLogger.setRuntimeId(this.runtimeId);
203
+ this.amsClientLogger.setRuntimeId(this.runtimeId);
196
204
  OmnichannelConfigValidator_1.default(omnichannelConfig);
197
205
  SDKConfigValidators_1.default(chatSDKConfig);
198
206
  ((_a = this.chatSDKConfig.telemetry) === null || _a === void 0 ? void 0 : _a.disable) && ((_b = this.telemetry) === null || _b === void 0 ? void 0 : _b.disable());
@@ -204,10 +212,11 @@ var OmnichannelChatSDK = /** @class */ (function () {
204
212
  (_f = this.acsClientLogger) === null || _f === void 0 ? void 0 : _f.setRequestId(this.requestId);
205
213
  (_g = this.acsAdapterLogger) === null || _g === void 0 ? void 0 : _g.setRequestId(this.requestId);
206
214
  (_h = this.callingSdkLogger) === null || _h === void 0 ? void 0 : _h.setRequestId(this.requestId);
215
+ (_j = this.amsClientLogger) === null || _j === void 0 ? void 0 : _j.setRequestId(this.requestId);
207
216
  }
208
217
  /* istanbul ignore next */
209
218
  OmnichannelChatSDK.prototype.setDebug = function (flag) {
210
- var _a, _b, _c, _d, _e, _f, _g;
219
+ var _a, _b, _c, _d, _e, _f, _g, _h;
211
220
  this.debug = flag;
212
221
  (_a = this.AMSClient) === null || _a === void 0 ? void 0 : _a.setDebug(flag);
213
222
  (_b = this.telemetry) === null || _b === void 0 ? void 0 : _b.setDebug(flag);
@@ -217,31 +226,32 @@ var OmnichannelChatSDK = /** @class */ (function () {
217
226
  (_e = this.acsClientLogger) === null || _e === void 0 ? void 0 : _e.setDebug(flag);
218
227
  (_f = this.acsAdapterLogger) === null || _f === void 0 ? void 0 : _f.setDebug(flag);
219
228
  (_g = this.callingSdkLogger) === null || _g === void 0 ? void 0 : _g.setDebug(flag);
229
+ (_h = this.amsClientLogger) === null || _h === void 0 ? void 0 : _h.setDebug(flag);
220
230
  };
221
231
  OmnichannelChatSDK.prototype.initialize = function (optionalParams) {
222
232
  if (optionalParams === void 0) { optionalParams = {}; }
223
233
  return __awaiter(this, void 0, void 0, function () {
224
- var _a, getLiveChatConfigOptionalParams, _b, _c, _d;
225
- return __generator(this, function (_e) {
226
- switch (_e.label) {
234
+ var _a, getLiveChatConfigOptionalParams, _b, _c, e_1;
235
+ return __generator(this, function (_d) {
236
+ switch (_d.label) {
227
237
  case 0:
228
238
  this.scenarioMarker.startScenario(TelemetryEvent_1.default.InitializeChatSDK);
229
239
  if (this.isInitialized) {
230
240
  this.scenarioMarker.completeScenario(TelemetryEvent_1.default.InitializeChatSDK);
231
241
  return [2 /*return*/, this.liveChatConfig];
232
242
  }
233
- _e.label = 1;
243
+ _d.label = 1;
234
244
  case 1:
235
- _e.trys.push([1, 8, , 9]);
245
+ _d.trys.push([1, 9, , 10]);
236
246
  this.OCSDKProvider = ocsdk_1.SDKProvider;
237
247
  _a = this;
238
248
  return [4 /*yield*/, ocsdk_1.SDKProvider.getSDK(this.omnichannelConfig, {}, this.ocSdkLogger)];
239
249
  case 2:
240
- _a.OCClient = _e.sent();
250
+ _a.OCClient = _d.sent();
241
251
  getLiveChatConfigOptionalParams = optionalParams.getLiveChatConfigOptionalParams;
242
252
  return [4 /*yield*/, this.getChatConfig(getLiveChatConfigOptionalParams || {})];
243
253
  case 3:
244
- _e.sent();
254
+ _d.sent();
245
255
  if (!(this.liveChatVersion === LiveChatVersion_1.default.V2)) return [3 /*break*/, 5];
246
256
  this.ACSClient = new ACSClient_1.default(this.acsClientLogger);
247
257
  _b = this;
@@ -249,26 +259,30 @@ var OmnichannelChatSDK = /** @class */ (function () {
249
259
  framedMode: platform_1.isBrowser(),
250
260
  multiClient: true,
251
261
  debug: false,
252
- logger: undefined
262
+ logger: this.amsClientLogger
253
263
  })];
254
264
  case 4:
255
- _b.AMSClient = _e.sent();
256
- return [3 /*break*/, 7];
265
+ _b.AMSClient = _d.sent();
266
+ return [3 /*break*/, 8];
257
267
  case 5:
268
+ if (!(this.liveChatVersion === LiveChatVersion_1.default.V1)) return [3 /*break*/, 7];
258
269
  _c = this;
259
270
  return [4 /*yield*/, this.getIC3Client()];
260
271
  case 6:
261
- _c.IC3Client = _e.sent();
262
- _e.label = 7;
263
- case 7:
272
+ _c.IC3Client = _d.sent();
273
+ return [3 /*break*/, 8];
274
+ case 7: throw new Error("Unsupported LiveChatVersion");
275
+ case 8:
264
276
  this.isInitialized = true;
265
277
  this.scenarioMarker.completeScenario(TelemetryEvent_1.default.InitializeChatSDK);
266
- return [3 /*break*/, 9];
267
- case 8:
268
- _d = _e.sent();
269
- this.scenarioMarker.failScenario(TelemetryEvent_1.default.InitializeChatSDK);
270
- return [3 /*break*/, 9];
271
- case 9: return [2 /*return*/, this.liveChatConfig];
278
+ return [3 /*break*/, 10];
279
+ case 9:
280
+ e_1 = _d.sent();
281
+ this.scenarioMarker.failScenario(TelemetryEvent_1.default.InitializeChatSDK, {
282
+ ExceptionDetails: JSON.stringify(e_1)
283
+ });
284
+ return [3 /*break*/, 10];
285
+ case 10: return [2 /*return*/, this.liveChatConfig];
272
286
  }
273
287
  });
274
288
  });
@@ -358,44 +372,44 @@ var OmnichannelChatSDK = /** @class */ (function () {
358
372
  });
359
373
  };
360
374
  OmnichannelChatSDK.prototype.startChat = function (optionalParams) {
361
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
375
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v;
362
376
  if (optionalParams === void 0) { optionalParams = {}; }
363
377
  return __awaiter(this, void 0, void 0, function () {
364
- var shouldReinitIC3Client, _t, reconnectableChatsParams, reconnectableChatsResponse, _u, exceptionDetails, conversationDetails, exceptionDetails, exceptionDetails, _v, exceptionDetails, sessionInitOptionalParams, error_3, exceptionDetails, chatAdapterConfig, error_4, exceptionDetails, _w, error_5, exceptionDetails, error_6, exceptionDetails, error_7, exceptionDetails, _x, error_8, exceptionDetails;
378
+ var shouldReinitIC3Client, _w, reconnectableChatsParams, reconnectableChatsResponse, _x, exceptionDetails, conversationDetails, exceptionDetails, exceptionDetails, _y, exceptionDetails, sessionInitOptionalParams, location_2, error_3, exceptionDetails, chatAdapterConfig, error_4, exceptionDetails, _z, error_5, exceptionDetails, error_6, exceptionDetails, error_7, exceptionDetails, _0, error_8, exceptionDetails;
365
379
  var _this = this;
366
- return __generator(this, function (_y) {
367
- switch (_y.label) {
380
+ return __generator(this, function (_1) {
381
+ switch (_1.label) {
368
382
  case 0:
369
383
  this.scenarioMarker.startScenario(TelemetryEvent_1.default.StartChat, {
370
384
  RequestId: this.requestId
371
385
  });
372
386
  shouldReinitIC3Client = !platform_1.default.isNode() && !platform_1.default.isReactNative() && !this.IC3Client && this.liveChatVersion === LiveChatVersion_1.default.V1;
373
387
  if (!shouldReinitIC3Client) return [3 /*break*/, 2];
374
- _t = this;
388
+ _w = this;
375
389
  return [4 /*yield*/, this.getIC3Client()];
376
390
  case 1:
377
- _t.IC3Client = _y.sent();
378
- _y.label = 2;
391
+ _w.IC3Client = _1.sent();
392
+ _1.label = 2;
379
393
  case 2:
380
394
  if (this.isChatReconnect && !((_a = this.chatSDKConfig.chatReconnect) === null || _a === void 0 ? void 0 : _a.disable) && !this.isPersistentChat && optionalParams.reconnectId) {
381
395
  this.reconnectId = optionalParams.reconnectId;
382
396
  }
383
397
  if (!(this.isPersistentChat && !((_b = this.chatSDKConfig.persistentChat) === null || _b === void 0 ? void 0 : _b.disable))) return [3 /*break*/, 6];
384
- _y.label = 3;
398
+ _1.label = 3;
385
399
  case 3:
386
- _y.trys.push([3, 5, , 6]);
400
+ _1.trys.push([3, 5, , 6]);
387
401
  reconnectableChatsParams = {
388
402
  authenticatedUserToken: this.authenticatedUserToken
389
403
  };
390
404
  return [4 /*yield*/, this.OCClient.getReconnectableChats(reconnectableChatsParams)];
391
405
  case 4:
392
- reconnectableChatsResponse = _y.sent();
406
+ reconnectableChatsResponse = _1.sent();
393
407
  if (reconnectableChatsResponse && reconnectableChatsResponse.reconnectid) {
394
408
  this.reconnectId = reconnectableChatsResponse.reconnectid;
395
409
  }
396
410
  return [3 /*break*/, 6];
397
411
  case 5:
398
- _u = _y.sent();
412
+ _x = _1.sent();
399
413
  exceptionDetails = {
400
414
  response: "OCClientGetReconnectableChatsFailed"
401
415
  };
@@ -406,7 +420,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
406
420
  this.requestId = optionalParams.liveChatContext.requestId || ocsdk_1.uuidv4();
407
421
  return [4 /*yield*/, this.getConversationDetails()];
408
422
  case 7:
409
- conversationDetails = _y.sent();
423
+ conversationDetails = _1.sent();
410
424
  if (Object.keys(conversationDetails).length === 0) {
411
425
  exceptionDetails = {
412
426
  response: "InvalidConversation"
@@ -431,30 +445,30 @@ var OmnichannelChatSDK = /** @class */ (function () {
431
445
  console.error("Unable to join conversation that's in '" + conversationDetails.state + "' state");
432
446
  throw Error(exceptionDetails.response);
433
447
  }
434
- _y.label = 8;
448
+ _1.label = 8;
435
449
  case 8:
436
450
  if (!this.authSettings) return [3 /*break*/, 14];
437
451
  if (!!this.authenticatedUserToken) return [3 /*break*/, 10];
438
452
  return [4 /*yield*/, this.setAuthTokenProvider(this.chatSDKConfig.getAuthToken)];
439
453
  case 9:
440
- _y.sent();
441
- _y.label = 10;
454
+ _1.sent();
455
+ _1.label = 10;
442
456
  case 10:
443
457
  if (!(optionalParams.liveChatContext && Object.keys(optionalParams.liveChatContext).length > 0)) return [3 /*break*/, 14];
444
458
  this.chatToken = optionalParams.liveChatContext.chatToken || {};
445
459
  this.requestId = optionalParams.liveChatContext.requestId || ocsdk_1.uuidv4();
446
- _y.label = 11;
460
+ _1.label = 11;
447
461
  case 11:
448
- _y.trys.push([11, 13, , 14]);
462
+ _1.trys.push([11, 13, , 14]);
449
463
  return [4 /*yield*/, this.OCClient.validateAuthChatRecord(this.requestId, {
450
464
  authenticatedUserToken: this.authenticatedUserToken,
451
465
  chatId: this.chatToken.chatId
452
466
  })];
453
467
  case 12:
454
- _y.sent();
468
+ _1.sent();
455
469
  return [3 /*break*/, 14];
456
470
  case 13:
457
- _v = _y.sent();
471
+ _y = _1.sent();
458
472
  exceptionDetails = {
459
473
  response: "OCClientValidateAuthChatRecordFailed",
460
474
  message: "InvalidAuthChatRecord"
@@ -469,39 +483,49 @@ var OmnichannelChatSDK = /** @class */ (function () {
469
483
  if (!(this.chatToken && Object.keys(this.chatToken).length === 0)) return [3 /*break*/, 16];
470
484
  return [4 /*yield*/, this.getChatToken(false)];
471
485
  case 15:
472
- _y.sent();
473
- _y.label = 16;
486
+ _1.sent();
487
+ _1.label = 16;
474
488
  case 16:
475
489
  (_c = this.ic3ClientLogger) === null || _c === void 0 ? void 0 : _c.setChatId(this.chatToken.chatId || '');
476
490
  (_d = this.ocSdkLogger) === null || _d === void 0 ? void 0 : _d.setChatId(this.chatToken.chatId || '');
477
491
  (_e = this.acsClientLogger) === null || _e === void 0 ? void 0 : _e.setChatId(this.chatToken.chatId || '');
478
492
  (_f = this.acsAdapterLogger) === null || _f === void 0 ? void 0 : _f.setChatId(this.chatToken.chatId || '');
479
493
  (_g = this.callingSdkLogger) === null || _g === void 0 ? void 0 : _g.setChatId(this.chatToken.chatId || '');
494
+ (_h = this.amsClientLogger) === null || _h === void 0 ? void 0 : _h.setChatId(this.chatToken.chatId || '');
480
495
  sessionInitOptionalParams = {
481
496
  initContext: {}
482
497
  };
483
498
  sessionInitOptionalParams = this.populateInitChatOptionalParam(sessionInitOptionalParams, optionalParams);
484
- if (this.isPersistentChat && !((_h = this.chatSDKConfig.persistentChat) === null || _h === void 0 ? void 0 : _h.disable)) {
499
+ sessionInitOptionalParams.initContext.isProactiveChat = !!optionalParams.isProactiveChat;
500
+ if (this.isPersistentChat && !((_j = this.chatSDKConfig.persistentChat) === null || _j === void 0 ? void 0 : _j.disable)) {
485
501
  sessionInitOptionalParams.reconnectId = this.reconnectId;
486
502
  }
487
- else if (this.isChatReconnect && !((_j = this.chatSDKConfig.chatReconnect) === null || _j === void 0 ? void 0 : _j.disable) && !this.isPersistentChat) {
503
+ else if (this.isChatReconnect && !((_k = this.chatSDKConfig.chatReconnect) === null || _k === void 0 ? void 0 : _k.disable) && !this.isPersistentChat) {
488
504
  sessionInitOptionalParams.reconnectId = this.reconnectId;
489
505
  }
490
- if (!!optionalParams.liveChatContext) return [3 /*break*/, 20];
491
- _y.label = 17;
506
+ if (!(((_m = (_l = this.liveChatConfig) === null || _l === void 0 ? void 0 : _l.LiveWSAndLiveChatEngJoin) === null || _m === void 0 ? void 0 : _m.msdyn_requestvisitorlocation) === "true")) return [3 /*break*/, 18];
507
+ return [4 /*yield*/, location_1.getLocationInfo(this.scenarioMarker, this.chatToken.chatId, this.requestId)];
492
508
  case 17:
493
- _y.trys.push([17, 19, , 20]);
494
- return [4 /*yield*/, this.OCClient.sessionInit(this.requestId, sessionInitOptionalParams)];
509
+ location_2 = _1.sent();
510
+ sessionInitOptionalParams.initContext.latitude = location_2.latitude;
511
+ sessionInitOptionalParams.initContext.longitude = location_2.longitude;
512
+ _1.label = 18;
495
513
  case 18:
496
- _y.sent();
497
- return [3 /*break*/, 20];
514
+ if (!!optionalParams.liveChatContext) return [3 /*break*/, 22];
515
+ _1.label = 19;
498
516
  case 19:
499
- error_3 = _y.sent();
517
+ _1.trys.push([19, 21, , 22]);
518
+ return [4 /*yield*/, this.OCClient.sessionInit(this.requestId, sessionInitOptionalParams)];
519
+ case 20:
520
+ _1.sent();
521
+ return [3 /*break*/, 22];
522
+ case 21:
523
+ error_3 = _1.sent();
500
524
  exceptionDetails = {
501
525
  response: "OCClientSessionInitFailed"
502
526
  };
503
527
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
504
- if (((_k = error_3) === null || _k === void 0 ? void 0 : _k.isAxiosError) && ((_m = (_l = error_3.response) === null || _l === void 0 ? void 0 : _l.headers) === null || _m === void 0 ? void 0 : _m.errorcode.toString()) === OmnichannelErrorCodes_1.default.WidgetUseOutsideOperatingHour.toString()) {
528
+ if (((_o = error_3) === null || _o === void 0 ? void 0 : _o.isAxiosError) && ((_q = (_p = error_3.response) === null || _p === void 0 ? void 0 : _p.headers) === null || _q === void 0 ? void 0 : _q.errorcode.toString()) === OmnichannelErrorCodes_1.default.WidgetUseOutsideOperatingHour.toString()) {
505
529
  exceptionDetails.response = OmnichannelErrorCodes_1.default[OmnichannelErrorCodes_1.default.WidgetUseOutsideOperatingHour].toString();
506
530
  exceptionDetails.message = 'Widget used outside of operating hours';
507
531
  console.error(exceptionDetails.message);
@@ -512,8 +536,8 @@ var OmnichannelChatSDK = /** @class */ (function () {
512
536
  ExceptionDetails: JSON.stringify(exceptionDetails)
513
537
  });
514
538
  throw new Error(exceptionDetails.response);
515
- case 20:
516
- if (!(this.liveChatVersion === LiveChatVersion_1.default.V2)) return [3 /*break*/, 31];
539
+ case 22:
540
+ if (!(this.liveChatVersion === LiveChatVersion_1.default.V2)) return [3 /*break*/, 33];
517
541
  chatAdapterConfig = {
518
542
  token: this.chatToken.token,
519
543
  id: this.chatToken.visitorId || 'teamsvisitor',
@@ -521,18 +545,18 @@ var OmnichannelChatSDK = /** @class */ (function () {
521
545
  environmentUrl: this.chatToken.acsEndpoint,
522
546
  pollingInterval: 30000
523
547
  };
524
- _y.label = 21;
525
- case 21:
526
- _y.trys.push([21, 23, , 24]);
527
- return [4 /*yield*/, ((_o = this.ACSClient) === null || _o === void 0 ? void 0 : _o.initialize({
548
+ _1.label = 23;
549
+ case 23:
550
+ _1.trys.push([23, 25, , 26]);
551
+ return [4 /*yield*/, ((_r = this.ACSClient) === null || _r === void 0 ? void 0 : _r.initialize({
528
552
  token: chatAdapterConfig.token,
529
553
  environmentUrl: chatAdapterConfig.environmentUrl
530
554
  }))];
531
- case 22:
532
- _y.sent();
533
- return [3 /*break*/, 24];
534
- case 23:
535
- error_4 = _y.sent();
555
+ case 24:
556
+ _1.sent();
557
+ return [3 /*break*/, 26];
558
+ case 25:
559
+ error_4 = _1.sent();
536
560
  exceptionDetails = {
537
561
  response: "ACSClientInitializeFailed"
538
562
  };
@@ -543,23 +567,23 @@ var OmnichannelChatSDK = /** @class */ (function () {
543
567
  });
544
568
  console.error("OmnichannelChatSDK/startChat/initialize/error " + error_4);
545
569
  return [2 /*return*/, error_4];
546
- case 24:
547
- _y.trys.push([24, 26, , 27]);
548
- _w = this;
549
- return [4 /*yield*/, ((_p = this.ACSClient) === null || _p === void 0 ? void 0 : _p.joinConversation({
570
+ case 26:
571
+ _1.trys.push([26, 28, , 29]);
572
+ _z = this;
573
+ return [4 /*yield*/, ((_s = this.ACSClient) === null || _s === void 0 ? void 0 : _s.joinConversation({
550
574
  id: chatAdapterConfig.id,
551
575
  threadId: chatAdapterConfig.threadId,
552
576
  pollingInterval: chatAdapterConfig.pollingInterval
553
577
  }))];
554
- case 25:
555
- _w.conversation = (_y.sent());
578
+ case 27:
579
+ _z.conversation = (_1.sent());
556
580
  this.scenarioMarker.completeScenario(TelemetryEvent_1.default.StartChat, {
557
581
  RequestId: this.requestId,
558
582
  ChatId: this.chatToken.chatId
559
583
  });
560
- return [3 /*break*/, 27];
561
- case 26:
562
- error_5 = _y.sent();
584
+ return [3 /*break*/, 29];
585
+ case 28:
586
+ error_5 = _1.sent();
563
587
  exceptionDetails = {
564
588
  response: "ACSClientJoinConversationFailed"
565
589
  };
@@ -570,16 +594,16 @@ var OmnichannelChatSDK = /** @class */ (function () {
570
594
  });
571
595
  console.error("OmnichannelChatSDK/startChat/joinConversation/error " + error_5);
572
596
  throw Error(exceptionDetails.response);
573
- case 27:
574
- _y.trys.push([27, 29, , 30]);
575
- return [4 /*yield*/, ((_q = this.AMSClient) === null || _q === void 0 ? void 0 : _q.initialize({
597
+ case 29:
598
+ _1.trys.push([29, 31, , 32]);
599
+ return [4 /*yield*/, ((_t = this.AMSClient) === null || _t === void 0 ? void 0 : _t.initialize({
576
600
  chatToken: this.chatToken
577
601
  }))];
578
- case 28:
579
- _y.sent();
580
- return [3 /*break*/, 30];
581
- case 29:
582
- error_6 = _y.sent();
602
+ case 30:
603
+ _1.sent();
604
+ return [3 /*break*/, 32];
605
+ case 31:
606
+ error_6 = _1.sent();
583
607
  exceptionDetails = {
584
608
  response: "AMSClientInitializeFailed"
585
609
  };
@@ -589,19 +613,19 @@ var OmnichannelChatSDK = /** @class */ (function () {
589
613
  ExceptionDetails: JSON.stringify(exceptionDetails)
590
614
  });
591
615
  throw Error(exceptionDetails.response);
592
- case 30: return [3 /*break*/, 37];
593
- case 31:
594
- _y.trys.push([31, 33, , 34]);
616
+ case 32: return [3 /*break*/, 39];
617
+ case 33:
618
+ _1.trys.push([33, 35, , 36]);
595
619
  return [4 /*yield*/, this.IC3Client.initialize({
596
620
  token: this.chatToken.token,
597
621
  regionGtms: this.chatToken.regionGTMS,
598
622
  visitor: true
599
623
  })];
600
- case 32:
601
- _y.sent();
602
- return [3 /*break*/, 34];
603
- case 33:
604
- error_7 = _y.sent();
624
+ case 34:
625
+ _1.sent();
626
+ return [3 /*break*/, 36];
627
+ case 35:
628
+ error_7 = _1.sent();
605
629
  exceptionDetails = {
606
630
  response: "IC3ClientInitializeFailed"
607
631
  };
@@ -612,19 +636,19 @@ var OmnichannelChatSDK = /** @class */ (function () {
612
636
  });
613
637
  console.error("OmnichannelChatSDK/startChat/initialize/error " + error_7);
614
638
  return [2 /*return*/, error_7];
615
- case 34:
616
- _y.trys.push([34, 36, , 37]);
617
- _x = this;
639
+ case 36:
640
+ _1.trys.push([36, 38, , 39]);
641
+ _0 = this;
618
642
  return [4 /*yield*/, this.IC3Client.joinConversation(this.chatToken.chatId)];
619
- case 35:
620
- _x.conversation = _y.sent();
643
+ case 37:
644
+ _0.conversation = _1.sent();
621
645
  this.scenarioMarker.completeScenario(TelemetryEvent_1.default.StartChat, {
622
646
  RequestId: this.requestId,
623
647
  ChatId: this.chatToken.chatId
624
648
  });
625
- return [3 /*break*/, 37];
626
- case 36:
627
- error_8 = _y.sent();
649
+ return [3 /*break*/, 39];
650
+ case 38:
651
+ error_8 = _1.sent();
628
652
  exceptionDetails = {
629
653
  response: "IC3ClientJoinConversationFailed"
630
654
  };
@@ -635,8 +659,8 @@ var OmnichannelChatSDK = /** @class */ (function () {
635
659
  });
636
660
  console.error("OmnichannelChatSDK/startChat/joinConversation/error " + error_8);
637
661
  return [2 /*return*/, error_8];
638
- case 37:
639
- if (this.isPersistentChat && !((_r = this.chatSDKConfig.persistentChat) === null || _r === void 0 ? void 0 : _r.disable)) {
662
+ case 39:
663
+ if (this.isPersistentChat && !((_u = this.chatSDKConfig.persistentChat) === null || _u === void 0 ? void 0 : _u.disable)) {
640
664
  this.refreshTokenTimer = setInterval(function () { return __awaiter(_this, void 0, void 0, function () {
641
665
  return __generator(this, function (_a) {
642
666
  switch (_a.label) {
@@ -647,7 +671,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
647
671
  return [2 /*return*/];
648
672
  }
649
673
  });
650
- }); }, (_s = this.chatSDKConfig.persistentChat) === null || _s === void 0 ? void 0 : _s.tokenUpdateTime);
674
+ }); }, (_v = this.chatSDKConfig.persistentChat) === null || _v === void 0 ? void 0 : _v.tokenUpdateTime);
651
675
  }
652
676
  return [2 /*return*/];
653
677
  }
@@ -655,11 +679,11 @@ var OmnichannelChatSDK = /** @class */ (function () {
655
679
  });
656
680
  };
657
681
  OmnichannelChatSDK.prototype.endChat = function () {
658
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
682
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
659
683
  return __awaiter(this, void 0, void 0, function () {
660
684
  var sessionCloseOptionalParams, isReconnectChat, isChatReconnect, error_9, exceptionDetails;
661
- return __generator(this, function (_p) {
662
- switch (_p.label) {
685
+ return __generator(this, function (_r) {
686
+ switch (_r.label) {
663
687
  case 0:
664
688
  this.scenarioMarker.startScenario(TelemetryEvent_1.default.EndChat, {
665
689
  RequestId: this.requestId,
@@ -679,12 +703,12 @@ var OmnichannelChatSDK = /** @class */ (function () {
679
703
  if (this.authenticatedUserToken) {
680
704
  sessionCloseOptionalParams.authenticatedUserToken = this.authenticatedUserToken;
681
705
  }
682
- _p.label = 1;
706
+ _r.label = 1;
683
707
  case 1:
684
- _p.trys.push([1, 3, , 4]);
708
+ _r.trys.push([1, 3, , 4]);
685
709
  return [4 /*yield*/, this.OCClient.sessionClose(this.requestId, sessionCloseOptionalParams)];
686
710
  case 2:
687
- _p.sent();
711
+ _r.sent();
688
712
  this.scenarioMarker.completeScenario(TelemetryEvent_1.default.EndChat, {
689
713
  RequestId: this.requestId,
690
714
  ChatId: this.chatToken.chatId
@@ -709,9 +733,11 @@ var OmnichannelChatSDK = /** @class */ (function () {
709
733
  (_l = this.acsAdapterLogger) === null || _l === void 0 ? void 0 : _l.setChatId('');
710
734
  (_m = this.callingSdkLogger) === null || _m === void 0 ? void 0 : _m.setRequestId(this.requestId);
711
735
  (_o = this.callingSdkLogger) === null || _o === void 0 ? void 0 : _o.setChatId('');
736
+ (_p = this.amsClientLogger) === null || _p === void 0 ? void 0 : _p.setRequestId(this.requestId);
737
+ (_q = this.amsClientLogger) === null || _q === void 0 ? void 0 : _q.setChatId('');
712
738
  return [3 /*break*/, 4];
713
739
  case 3:
714
- error_9 = _p.sent();
740
+ error_9 = _r.sent();
715
741
  exceptionDetails = {
716
742
  response: "OCClientSessionCloseFailed"
717
743
  };
@@ -1735,28 +1761,33 @@ var OmnichannelChatSDK = /** @class */ (function () {
1735
1761
  };
1736
1762
  OmnichannelChatSDK.prototype.getPostChatSurveyContext = function () {
1737
1763
  return __awaiter(this, void 0, void 0, function () {
1738
- var conversationId, chatConfig, liveWSAndLiveChatEngJoin, msdyn_postconversationsurveyenable, msfp_sourcesurveyidentifier, msfp_botsourcesurveyidentifier, postConversationSurveyOwnerId, postConversationBotSurveyOwnerId, liveWorkItemDetails, participantJoined, participantType, surveyInviteLinkRequest, optionalParams, ownerId, surveyInviteLinkResponse, surveyInviteLink, formsProLocale, postChatContext, ex_1;
1739
- return __generator(this, function (_a) {
1740
- switch (_a.label) {
1764
+ var conversationId, chatConfig, liveWSAndLiveChatEngJoin, msdyn_postconversationsurveyenable, msfp_sourcesurveyidentifier, msfp_botsourcesurveyidentifier, postConversationSurveyOwnerId, postConversationBotSurveyOwnerId, liveWorkItemDetails, participantJoined, participantType, agentSurveyInviteLinkRequest, botSurveyInviteLinkRequest, optionalParams, agentSurveyInviteLinkResponse, botSurveyInviteLinkResponse, _a, agentSurveyInviteLink, agentFormsProLocale, botSurveyInviteLink, botFormsProLocale, postChatContext, ex_1;
1765
+ return __generator(this, function (_b) {
1766
+ switch (_b.label) {
1741
1767
  case 0:
1742
1768
  this.scenarioMarker.startScenario(TelemetryEvent_1.default.GetPostChatSurveyContext, {
1743
1769
  RequestId: this.requestId
1744
1770
  });
1745
- _a.label = 1;
1771
+ _b.label = 1;
1746
1772
  case 1:
1747
- _a.trys.push([1, 6, , 7]);
1773
+ _b.trys.push([1, 8, , 9]);
1748
1774
  chatConfig = this.liveChatConfig;
1749
1775
  liveWSAndLiveChatEngJoin = chatConfig.LiveWSAndLiveChatEngJoin;
1750
1776
  msdyn_postconversationsurveyenable = liveWSAndLiveChatEngJoin.msdyn_postconversationsurveyenable, msfp_sourcesurveyidentifier = liveWSAndLiveChatEngJoin.msfp_sourcesurveyidentifier, msfp_botsourcesurveyidentifier = liveWSAndLiveChatEngJoin.msfp_botsourcesurveyidentifier, postConversationSurveyOwnerId = liveWSAndLiveChatEngJoin.postConversationSurveyOwnerId, postConversationBotSurveyOwnerId = liveWSAndLiveChatEngJoin.postConversationBotSurveyOwnerId;
1751
- if (!(msdyn_postconversationsurveyenable === "true")) return [3 /*break*/, 4];
1777
+ if (!(msdyn_postconversationsurveyenable === "true")) return [3 /*break*/, 6];
1752
1778
  return [4 /*yield*/, this.getConversationDetails()];
1753
1779
  case 2:
1754
- liveWorkItemDetails = _a.sent();
1780
+ liveWorkItemDetails = _b.sent();
1755
1781
  participantJoined = (liveWorkItemDetails === null || liveWorkItemDetails === void 0 ? void 0 : liveWorkItemDetails.canRenderPostChat) === "True";
1756
1782
  participantType = liveWorkItemDetails === null || liveWorkItemDetails === void 0 ? void 0 : liveWorkItemDetails.participantType;
1757
1783
  conversationId = liveWorkItemDetails === null || liveWorkItemDetails === void 0 ? void 0 : liveWorkItemDetails.conversationId;
1758
- surveyInviteLinkRequest = {
1759
- "FormId": participantType === "Bot" ? msfp_botsourcesurveyidentifier : msfp_sourcesurveyidentifier,
1784
+ agentSurveyInviteLinkRequest = {
1785
+ "FormId": msfp_sourcesurveyidentifier,
1786
+ "ConversationId": conversationId,
1787
+ "OCLocaleCode": locale_1.getLocaleStringFromId(this.localeId)
1788
+ };
1789
+ botSurveyInviteLinkRequest = {
1790
+ "FormId": msfp_botsourcesurveyidentifier,
1760
1791
  "ConversationId": conversationId,
1761
1792
  "OCLocaleCode": locale_1.getLocaleStringFromId(this.localeId)
1762
1793
  };
@@ -1766,14 +1797,21 @@ var OmnichannelChatSDK = /** @class */ (function () {
1766
1797
  if (this.authenticatedUserToken) {
1767
1798
  optionalParams.authenticatedUserToken = this.authenticatedUserToken;
1768
1799
  }
1769
- ownerId = participantType === "Bot" ? postConversationBotSurveyOwnerId : postConversationSurveyOwnerId;
1770
- return [4 /*yield*/, this.OCClient.getSurveyInviteLink(ownerId, surveyInviteLinkRequest, optionalParams)];
1800
+ return [4 /*yield*/, this.OCClient.getSurveyInviteLink(postConversationSurveyOwnerId, agentSurveyInviteLinkRequest, optionalParams)];
1771
1801
  case 3:
1772
- surveyInviteLinkResponse = _a.sent();
1773
- surveyInviteLink = void 0, formsProLocale = void 0;
1774
- if (surveyInviteLinkResponse != null) {
1775
- if (surveyInviteLinkResponse.inviteList != null && surveyInviteLinkResponse.inviteList.length == 1) {
1776
- surveyInviteLink = surveyInviteLinkResponse.inviteList[0].invitationLink;
1802
+ agentSurveyInviteLinkResponse = _b.sent();
1803
+ _a = postConversationBotSurveyOwnerId && msfp_botsourcesurveyidentifier;
1804
+ if (!_a) return [3 /*break*/, 5];
1805
+ return [4 /*yield*/, this.OCClient.getSurveyInviteLink(postConversationBotSurveyOwnerId, botSurveyInviteLinkRequest, optionalParams)];
1806
+ case 4:
1807
+ _a = (_b.sent());
1808
+ _b.label = 5;
1809
+ case 5:
1810
+ botSurveyInviteLinkResponse = _a;
1811
+ agentSurveyInviteLink = void 0, agentFormsProLocale = void 0, botSurveyInviteLink = void 0, botFormsProLocale = void 0;
1812
+ if (agentSurveyInviteLinkResponse != null) {
1813
+ if (agentSurveyInviteLinkResponse.inviteList != null && agentSurveyInviteLinkResponse.inviteList.length == 1) {
1814
+ agentSurveyInviteLink = agentSurveyInviteLinkResponse.inviteList[0].invitationLink;
1777
1815
  }
1778
1816
  else {
1779
1817
  this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetPostChatSurveyContext, {
@@ -1783,14 +1821,24 @@ var OmnichannelChatSDK = /** @class */ (function () {
1783
1821
  });
1784
1822
  return [2 /*return*/, Promise.reject("Survey Invite link failed to send response.")];
1785
1823
  }
1786
- if (surveyInviteLinkResponse.formsProLocaleCode != null) {
1787
- formsProLocale = surveyInviteLinkResponse.formsProLocaleCode;
1824
+ if (agentSurveyInviteLinkResponse.formsProLocaleCode != null) {
1825
+ agentFormsProLocale = agentSurveyInviteLinkResponse.formsProLocaleCode;
1826
+ }
1827
+ if (botSurveyInviteLinkResponse != null) {
1828
+ if (botSurveyInviteLinkResponse.inviteList != null && botSurveyInviteLinkResponse.inviteList.length == 1) {
1829
+ botSurveyInviteLink = botSurveyInviteLinkResponse.inviteList[0].invitationLink;
1830
+ }
1831
+ if (botSurveyInviteLinkResponse.formsProLocaleCode != null) {
1832
+ botFormsProLocale = botSurveyInviteLinkResponse.formsProLocaleCode;
1833
+ }
1788
1834
  }
1789
1835
  postChatContext = {
1790
1836
  participantJoined: participantJoined,
1791
1837
  participantType: participantType,
1792
- surveyInviteLink: surveyInviteLink,
1793
- formsProLocale: formsProLocale
1838
+ surveyInviteLink: agentSurveyInviteLink,
1839
+ botSurveyInviteLink: botSurveyInviteLink,
1840
+ formsProLocale: agentFormsProLocale,
1841
+ botFormsProLocale: botFormsProLocale
1794
1842
  };
1795
1843
  return [2 /*return*/, Promise.resolve(postChatContext)];
1796
1844
  }
@@ -1802,23 +1850,23 @@ var OmnichannelChatSDK = /** @class */ (function () {
1802
1850
  });
1803
1851
  return [2 /*return*/, Promise.reject("surveyInviteLinkResponse is null.")];
1804
1852
  }
1805
- return [3 /*break*/, 5];
1806
- case 4:
1853
+ return [3 /*break*/, 7];
1854
+ case 6:
1807
1855
  this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetPostChatSurveyContext, {
1808
1856
  RequestId: this.requestId,
1809
1857
  ExceptionDetails: "Post Chat Survey is disabled. Please check the Omnichannel Administration Portal."
1810
1858
  });
1811
1859
  return [2 /*return*/, Promise.reject("Post Chat is disabled from admin side.")];
1812
- case 5: return [3 /*break*/, 7];
1813
- case 6:
1814
- ex_1 = _a.sent();
1860
+ case 7: return [3 /*break*/, 9];
1861
+ case 8:
1862
+ ex_1 = _b.sent();
1815
1863
  this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetPostChatSurveyContext, {
1816
1864
  ConversationId: conversationId !== null && conversationId !== void 0 ? conversationId : "",
1817
1865
  RequestId: this.requestId,
1818
1866
  ExceptionDetails: JSON.stringify(ex_1)
1819
1867
  });
1820
1868
  return [2 /*return*/, Promise.reject("Retrieving post chat context failed " + JSON.stringify(ex_1))];
1821
- case 7: return [2 /*return*/];
1869
+ case 9: return [2 /*return*/];
1822
1870
  }
1823
1871
  });
1824
1872
  });
@@ -1826,7 +1874,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
1826
1874
  OmnichannelChatSDK.prototype.getAgentAvailability = function (optionalParams) {
1827
1875
  if (optionalParams === void 0) { optionalParams = {}; }
1828
1876
  return __awaiter(this, void 0, void 0, function () {
1829
- var reportError, getAgentAvailabilityOptionalParams, response, e_1;
1877
+ var reportError, getAgentAvailabilityOptionalParams, response, e_2;
1830
1878
  var _this = this;
1831
1879
  return __generator(this, function (_a) {
1832
1880
  switch (_a.label) {
@@ -1868,9 +1916,9 @@ var OmnichannelChatSDK = /** @class */ (function () {
1868
1916
  response = _a.sent();
1869
1917
  return [2 /*return*/, response];
1870
1918
  case 3:
1871
- e_1 = _a.sent();
1919
+ e_2 = _a.sent();
1872
1920
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
1873
- reportError("GetAgentAvailabilityFailed", e_1.message);
1921
+ reportError("GetAgentAvailabilityFailed", e_2.message);
1874
1922
  return [3 /*break*/, 4];
1875
1923
  case 4: return [2 /*return*/];
1876
1924
  }