@microsoft/omnichannel-chat-sdk 1.2.1-main.2a7572c → 1.2.1-main.30dca50

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/README.md +21 -4
  3. package/lib/OmnichannelChatSDK.d.ts +5 -1
  4. package/lib/OmnichannelChatSDK.js +302 -292
  5. package/lib/OmnichannelChatSDK.js.map +1 -1
  6. package/lib/config/settings.d.ts +3 -2
  7. package/lib/config/settings.js +4 -2
  8. package/lib/config/settings.js.map +1 -1
  9. package/lib/core/ChatSDKErrors.d.ts +6 -0
  10. package/lib/core/ChatSDKErrors.js +10 -0
  11. package/lib/core/ChatSDKErrors.js.map +1 -0
  12. package/lib/core/ChatSDKExceptionDetails.d.ts +1 -0
  13. package/lib/core/GetAgentAvailabilityOptionalParams.d.ts +13 -0
  14. package/lib/core/GetAgentAvailabilityOptionalParams.js +3 -0
  15. package/lib/core/GetAgentAvailabilityOptionalParams.js.map +1 -0
  16. package/lib/core/PostChatContext.d.ts +2 -0
  17. package/lib/core/StartChatOptionalParams.d.ts +4 -0
  18. package/lib/core/messaging/ACSClient.js +5 -0
  19. package/lib/core/messaging/ACSClient.js.map +1 -1
  20. package/lib/core/messaging/ChatAdapterConfig.d.ts +2 -0
  21. package/lib/core/messaging/ChatAdapterOptionalParams.d.ts +5 -0
  22. package/lib/external/ACSAdapter/AMSFileManager.js +2 -1
  23. package/lib/external/ACSAdapter/AMSFileManager.js.map +1 -1
  24. package/lib/telemetry/AriaTelemetry.d.ts +2 -0
  25. package/lib/telemetry/AriaTelemetry.js +49 -0
  26. package/lib/telemetry/AriaTelemetry.js.map +1 -1
  27. package/lib/telemetry/ScenarioType.d.ts +1 -0
  28. package/lib/telemetry/ScenarioType.js +1 -0
  29. package/lib/telemetry/ScenarioType.js.map +1 -1
  30. package/lib/telemetry/TelemetryEvent.d.ts +4 -1
  31. package/lib/telemetry/TelemetryEvent.js +3 -0
  32. package/lib/telemetry/TelemetryEvent.js.map +1 -1
  33. package/lib/tsconfig.tsbuildinfo +318 -171
  34. package/lib/utils/WebUtils.d.ts +2 -2
  35. package/lib/utils/WebUtils.js +30 -4
  36. package/lib/utils/WebUtils.js.map +1 -1
  37. package/lib/utils/chatAdapterCreators.d.ts +20 -0
  38. package/lib/utils/chatAdapterCreators.js +230 -0
  39. package/lib/utils/chatAdapterCreators.js.map +1 -0
  40. package/lib/utils/libraries.d.ts +3 -1
  41. package/lib/utils/libraries.js +9 -2
  42. package/lib/utils/libraries.js.map +1 -1
  43. package/lib/utils/location.d.ts +7 -0
  44. package/lib/utils/location.js +96 -0
  45. package/lib/utils/location.js.map +1 -0
  46. package/lib/utils/loggers.d.ts +16 -0
  47. package/lib/utils/loggers.js +69 -1
  48. package/lib/utils/loggers.js.map +1 -1
  49. package/lib/utils/sleep.d.ts +2 -0
  50. package/lib/utils/sleep.js +5 -0
  51. package/lib/utils/sleep.js.map +1 -0
  52. package/lib/utils/urlResolvers.d.ts +10 -0
  53. package/lib/utils/urlResolvers.js +65 -0
  54. package/lib/utils/urlResolvers.js.map +1 -0
  55. package/package.json +3 -3
@@ -58,6 +58,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
58
58
  var loggers_1 = require("./utils/loggers");
59
59
  var ACSClient_1 = require("./core/messaging/ACSClient");
60
60
  var ocsdk_1 = require("@microsoft/ocsdk");
61
+ var chatAdapterCreators_1 = require("./utils/chatAdapterCreators");
61
62
  var locale_1 = require("./utils/locale");
62
63
  var WebUtils_1 = require("./utils/WebUtils");
63
64
  var platform_1 = require("./utils/platform");
@@ -66,6 +67,7 @@ var ACSParticipantDisplayName_1 = require("./core/messaging/ACSParticipantDispla
66
67
  var AMSFileManager_1 = require("./external/ACSAdapter/AMSFileManager");
67
68
  var CallingOptionsOptionSetNumber_1 = require("./core/CallingOptionsOptionSetNumber");
68
69
  var ChatAdapterProtocols_1 = require("./core/messaging/ChatAdapterProtocols");
70
+ var ChatSDKErrors_1 = require("./core/ChatSDKErrors");
69
71
  var ConversationMode_1 = require("./core/ConversationMode");
70
72
  var DeliveryMode_1 = require("@microsoft/omnichannel-ic3core/lib/model/DeliveryMode");
71
73
  var FileSharingProtocolType_1 = require("@microsoft/omnichannel-ic3core/lib/model/FileSharingProtocolType");
@@ -81,20 +83,19 @@ var ProtocoleType_1 = require("@microsoft/omnichannel-ic3core/lib/interfaces/Pro
81
83
  var ScenarioMarker_1 = require("./telemetry/ScenarioMarker");
82
84
  var TelemetryEvent_1 = require("./telemetry/TelemetryEvent");
83
85
  var omnichannel_amsclient_1 = require("@microsoft/omnichannel-amsclient");
84
- var createChannelDataEgressMiddleware_1 = require("./external/ACSAdapter/createChannelDataEgressMiddleware");
85
- var createFormatEgressTagsMiddleware_1 = require("./external/ACSAdapter/createFormatEgressTagsMiddleware");
86
- var createFormatIngressTagsMiddleware_1 = require("./external/ACSAdapter/createFormatIngressTagsMiddleware");
87
86
  var createOmnichannelMessage_1 = require("./utils/createOmnichannelMessage");
88
87
  var createTelemetry_1 = require("./utils/createTelemetry");
89
88
  var createVoiceVideoCalling_1 = require("./api/createVoiceVideoCalling");
90
89
  var MessageTags_1 = require("./core/messaging/MessageTags");
90
+ var location_1 = require("./utils/location");
91
91
  var utilities_1 = require("./utils/utilities");
92
- var libraries_1 = require("./utils/libraries");
92
+ var urlResolvers_1 = require("./utils/urlResolvers");
93
93
  var OmnichannelConfigValidator_1 = require("./validators/OmnichannelConfigValidator");
94
94
  var OmnichannelChatSDK = /** @class */ (function () {
95
95
  function OmnichannelChatSDK(omnichannelConfig, chatSDKConfig) {
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,17 +108,70 @@ 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;
113
115
  this.refreshTokenTimer = null;
116
+ this.populateInitChatOptionalParam = function (requestOptionalParams, optionalParams) {
117
+ requestOptionalParams.initContext.locale = locale_1.getLocaleStringFromId(_this.localeId);
118
+ if (optionalParams.customContext) {
119
+ requestOptionalParams.initContext.customContextData = optionalParams.customContext; // eslint-disable-line @typescript-eslint/no-explicit-any
120
+ }
121
+ if (optionalParams.browser) {
122
+ requestOptionalParams.initContext.browser = optionalParams.browser;
123
+ }
124
+ if (optionalParams.os) {
125
+ requestOptionalParams.initContext.os = optionalParams.os;
126
+ }
127
+ if (optionalParams.locale) {
128
+ requestOptionalParams.initContext.locale = optionalParams.locale;
129
+ }
130
+ if (optionalParams.device) {
131
+ requestOptionalParams.initContext.device = optionalParams.device;
132
+ }
133
+ if (optionalParams.preChatResponse) {
134
+ requestOptionalParams.initContext.preChatResponse = optionalParams.preChatResponse;
135
+ }
136
+ if (optionalParams.portalContactId) {
137
+ requestOptionalParams.initContext.portalcontactid = optionalParams.portalContactId;
138
+ }
139
+ if (optionalParams.sendDefaultInitContext) {
140
+ if (platform_1.default.isNode() || platform_1.default.isReactNative()) {
141
+ var exceptionDetails = {
142
+ response: ChatSDKErrors_1.default.UnsupportedPlatform,
143
+ message: "sendDefaultInitContext is only supported on browser"
144
+ };
145
+ console.error(exceptionDetails.message);
146
+ _this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetAgentAvailability, {
147
+ RequestId: _this.requestId,
148
+ ChatId: _this.chatToken.chatId,
149
+ ExceptionDetails: JSON.stringify(exceptionDetails)
150
+ });
151
+ throw new Error(exceptionDetails.response);
152
+ }
153
+ requestOptionalParams.getContext = true;
154
+ }
155
+ // Override initContext completely
156
+ if (optionalParams.initContext) {
157
+ requestOptionalParams.initContext = optionalParams.initContext;
158
+ }
159
+ if (_this.authenticatedUserToken) {
160
+ requestOptionalParams.authenticatedUserToken = _this.authenticatedUserToken;
161
+ }
162
+ if (_this.chatToken.chatId) {
163
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
164
+ requestOptionalParams.initContext.chatId = _this.chatToken.chatId;
165
+ }
166
+ return requestOptionalParams;
167
+ };
114
168
  this.debug = false;
115
169
  this.runtimeId = ocsdk_1.uuidv4();
116
170
  this.omnichannelConfig = omnichannelConfig;
117
171
  this.chatSDKConfig = __assign(__assign({}, SDKConfigValidators_1.defaultChatSDKConfig), chatSDKConfig // overrides
118
172
  );
119
173
  this.isInitialized = false;
120
- this.liveChatVersion = LiveChatVersion_1.default.V1;
174
+ this.liveChatVersion = LiveChatVersion_1.default.V2;
121
175
  this.localeId = locale_1.defaultLocaleId;
122
176
  this.requestId = ocsdk_1.uuidv4();
123
177
  this.chatToken = {};
@@ -132,18 +186,21 @@ var OmnichannelChatSDK = /** @class */ (function () {
132
186
  this.acsClientLogger = loggers_1.createACSClientLogger(this.omnichannelConfig);
133
187
  this.acsAdapterLogger = loggers_1.createACSAdapterLogger(this.omnichannelConfig);
134
188
  this.callingSdkLogger = loggers_1.createCallingSDKLogger(this.omnichannelConfig);
189
+ this.amsClientLogger = loggers_1.createAMSClientLogger(this.omnichannelConfig);
135
190
  this.scenarioMarker.useTelemetry(this.telemetry);
136
191
  this.ic3ClientLogger.useTelemetry(this.telemetry);
137
192
  this.ocSdkLogger.useTelemetry(this.telemetry);
138
193
  this.acsClientLogger.useTelemetry(this.telemetry);
139
194
  this.acsAdapterLogger.useTelemetry(this.telemetry);
140
195
  this.callingSdkLogger.useTelemetry(this.telemetry);
196
+ this.amsClientLogger.useTelemetry(this.telemetry);
141
197
  this.scenarioMarker.setRuntimeId(this.runtimeId);
142
198
  this.ic3ClientLogger.setRuntimeId(this.runtimeId);
143
199
  this.ocSdkLogger.setRuntimeId(this.runtimeId);
144
200
  this.acsClientLogger.setRuntimeId(this.runtimeId);
145
201
  this.acsAdapterLogger.setRuntimeId(this.runtimeId);
146
202
  this.callingSdkLogger.setRuntimeId(this.runtimeId);
203
+ this.amsClientLogger.setRuntimeId(this.runtimeId);
147
204
  OmnichannelConfigValidator_1.default(omnichannelConfig);
148
205
  SDKConfigValidators_1.default(chatSDKConfig);
149
206
  ((_a = this.chatSDKConfig.telemetry) === null || _a === void 0 ? void 0 : _a.disable) && ((_b = this.telemetry) === null || _b === void 0 ? void 0 : _b.disable());
@@ -155,10 +212,11 @@ var OmnichannelChatSDK = /** @class */ (function () {
155
212
  (_f = this.acsClientLogger) === null || _f === void 0 ? void 0 : _f.setRequestId(this.requestId);
156
213
  (_g = this.acsAdapterLogger) === null || _g === void 0 ? void 0 : _g.setRequestId(this.requestId);
157
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);
158
216
  }
159
217
  /* istanbul ignore next */
160
218
  OmnichannelChatSDK.prototype.setDebug = function (flag) {
161
- var _a, _b, _c, _d, _e, _f, _g;
219
+ var _a, _b, _c, _d, _e, _f, _g, _h;
162
220
  this.debug = flag;
163
221
  (_a = this.AMSClient) === null || _a === void 0 ? void 0 : _a.setDebug(flag);
164
222
  (_b = this.telemetry) === null || _b === void 0 ? void 0 : _b.setDebug(flag);
@@ -168,31 +226,32 @@ var OmnichannelChatSDK = /** @class */ (function () {
168
226
  (_e = this.acsClientLogger) === null || _e === void 0 ? void 0 : _e.setDebug(flag);
169
227
  (_f = this.acsAdapterLogger) === null || _f === void 0 ? void 0 : _f.setDebug(flag);
170
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);
171
230
  };
172
231
  OmnichannelChatSDK.prototype.initialize = function (optionalParams) {
173
232
  if (optionalParams === void 0) { optionalParams = {}; }
174
233
  return __awaiter(this, void 0, void 0, function () {
175
- var _a, getLiveChatConfigOptionalParams, _b, _c, _d;
176
- return __generator(this, function (_e) {
177
- switch (_e.label) {
234
+ var _a, getLiveChatConfigOptionalParams, _b, _c, e_1;
235
+ return __generator(this, function (_d) {
236
+ switch (_d.label) {
178
237
  case 0:
179
238
  this.scenarioMarker.startScenario(TelemetryEvent_1.default.InitializeChatSDK);
180
239
  if (this.isInitialized) {
181
240
  this.scenarioMarker.completeScenario(TelemetryEvent_1.default.InitializeChatSDK);
182
241
  return [2 /*return*/, this.liveChatConfig];
183
242
  }
184
- _e.label = 1;
243
+ _d.label = 1;
185
244
  case 1:
186
- _e.trys.push([1, 8, , 9]);
245
+ _d.trys.push([1, 9, , 10]);
187
246
  this.OCSDKProvider = ocsdk_1.SDKProvider;
188
247
  _a = this;
189
248
  return [4 /*yield*/, ocsdk_1.SDKProvider.getSDK(this.omnichannelConfig, {}, this.ocSdkLogger)];
190
249
  case 2:
191
- _a.OCClient = _e.sent();
250
+ _a.OCClient = _d.sent();
192
251
  getLiveChatConfigOptionalParams = optionalParams.getLiveChatConfigOptionalParams;
193
252
  return [4 /*yield*/, this.getChatConfig(getLiveChatConfigOptionalParams || {})];
194
253
  case 3:
195
- _e.sent();
254
+ _d.sent();
196
255
  if (!(this.liveChatVersion === LiveChatVersion_1.default.V2)) return [3 /*break*/, 5];
197
256
  this.ACSClient = new ACSClient_1.default(this.acsClientLogger);
198
257
  _b = this;
@@ -200,26 +259,30 @@ var OmnichannelChatSDK = /** @class */ (function () {
200
259
  framedMode: platform_1.isBrowser(),
201
260
  multiClient: true,
202
261
  debug: false,
203
- logger: undefined
262
+ logger: this.amsClientLogger
204
263
  })];
205
264
  case 4:
206
- _b.AMSClient = _e.sent();
207
- return [3 /*break*/, 7];
265
+ _b.AMSClient = _d.sent();
266
+ return [3 /*break*/, 8];
208
267
  case 5:
268
+ if (!(this.liveChatVersion === LiveChatVersion_1.default.V1)) return [3 /*break*/, 7];
209
269
  _c = this;
210
270
  return [4 /*yield*/, this.getIC3Client()];
211
271
  case 6:
212
- _c.IC3Client = _e.sent();
213
- _e.label = 7;
214
- case 7:
272
+ _c.IC3Client = _d.sent();
273
+ return [3 /*break*/, 8];
274
+ case 7: throw new Error("Unsupported LiveChatVersion");
275
+ case 8:
215
276
  this.isInitialized = true;
216
277
  this.scenarioMarker.completeScenario(TelemetryEvent_1.default.InitializeChatSDK);
217
- return [3 /*break*/, 9];
218
- case 8:
219
- _d = _e.sent();
220
- this.scenarioMarker.failScenario(TelemetryEvent_1.default.InitializeChatSDK);
221
- return [3 /*break*/, 9];
222
- 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];
223
286
  }
224
287
  });
225
288
  });
@@ -309,44 +372,44 @@ var OmnichannelChatSDK = /** @class */ (function () {
309
372
  });
310
373
  };
311
374
  OmnichannelChatSDK.prototype.startChat = function (optionalParams) {
312
- 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;
313
376
  if (optionalParams === void 0) { optionalParams = {}; }
314
377
  return __awaiter(this, void 0, void 0, function () {
315
- var shouldReinitIC3Client, _t, reconnectableChatsParams, reconnectableChatsResponse, _u, exceptionDetails, conversationDetails, exceptionDetails, exceptionDetails, _v, exceptionDetails, sessionInitOptionalParams, exceptionDetails, 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;
316
379
  var _this = this;
317
- return __generator(this, function (_y) {
318
- switch (_y.label) {
380
+ return __generator(this, function (_1) {
381
+ switch (_1.label) {
319
382
  case 0:
320
383
  this.scenarioMarker.startScenario(TelemetryEvent_1.default.StartChat, {
321
384
  RequestId: this.requestId
322
385
  });
323
386
  shouldReinitIC3Client = !platform_1.default.isNode() && !platform_1.default.isReactNative() && !this.IC3Client && this.liveChatVersion === LiveChatVersion_1.default.V1;
324
387
  if (!shouldReinitIC3Client) return [3 /*break*/, 2];
325
- _t = this;
388
+ _w = this;
326
389
  return [4 /*yield*/, this.getIC3Client()];
327
390
  case 1:
328
- _t.IC3Client = _y.sent();
329
- _y.label = 2;
391
+ _w.IC3Client = _1.sent();
392
+ _1.label = 2;
330
393
  case 2:
331
394
  if (this.isChatReconnect && !((_a = this.chatSDKConfig.chatReconnect) === null || _a === void 0 ? void 0 : _a.disable) && !this.isPersistentChat && optionalParams.reconnectId) {
332
395
  this.reconnectId = optionalParams.reconnectId;
333
396
  }
334
397
  if (!(this.isPersistentChat && !((_b = this.chatSDKConfig.persistentChat) === null || _b === void 0 ? void 0 : _b.disable))) return [3 /*break*/, 6];
335
- _y.label = 3;
398
+ _1.label = 3;
336
399
  case 3:
337
- _y.trys.push([3, 5, , 6]);
400
+ _1.trys.push([3, 5, , 6]);
338
401
  reconnectableChatsParams = {
339
402
  authenticatedUserToken: this.authenticatedUserToken
340
403
  };
341
404
  return [4 /*yield*/, this.OCClient.getReconnectableChats(reconnectableChatsParams)];
342
405
  case 4:
343
- reconnectableChatsResponse = _y.sent();
406
+ reconnectableChatsResponse = _1.sent();
344
407
  if (reconnectableChatsResponse && reconnectableChatsResponse.reconnectid) {
345
408
  this.reconnectId = reconnectableChatsResponse.reconnectid;
346
409
  }
347
410
  return [3 /*break*/, 6];
348
411
  case 5:
349
- _u = _y.sent();
412
+ _x = _1.sent();
350
413
  exceptionDetails = {
351
414
  response: "OCClientGetReconnectableChatsFailed"
352
415
  };
@@ -357,7 +420,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
357
420
  this.requestId = optionalParams.liveChatContext.requestId || ocsdk_1.uuidv4();
358
421
  return [4 /*yield*/, this.getConversationDetails()];
359
422
  case 7:
360
- conversationDetails = _y.sent();
423
+ conversationDetails = _1.sent();
361
424
  if (Object.keys(conversationDetails).length === 0) {
362
425
  exceptionDetails = {
363
426
  response: "InvalidConversation"
@@ -382,30 +445,30 @@ var OmnichannelChatSDK = /** @class */ (function () {
382
445
  console.error("Unable to join conversation that's in '" + conversationDetails.state + "' state");
383
446
  throw Error(exceptionDetails.response);
384
447
  }
385
- _y.label = 8;
448
+ _1.label = 8;
386
449
  case 8:
387
450
  if (!this.authSettings) return [3 /*break*/, 14];
388
451
  if (!!this.authenticatedUserToken) return [3 /*break*/, 10];
389
452
  return [4 /*yield*/, this.setAuthTokenProvider(this.chatSDKConfig.getAuthToken)];
390
453
  case 9:
391
- _y.sent();
392
- _y.label = 10;
454
+ _1.sent();
455
+ _1.label = 10;
393
456
  case 10:
394
457
  if (!(optionalParams.liveChatContext && Object.keys(optionalParams.liveChatContext).length > 0)) return [3 /*break*/, 14];
395
458
  this.chatToken = optionalParams.liveChatContext.chatToken || {};
396
459
  this.requestId = optionalParams.liveChatContext.requestId || ocsdk_1.uuidv4();
397
- _y.label = 11;
460
+ _1.label = 11;
398
461
  case 11:
399
- _y.trys.push([11, 13, , 14]);
462
+ _1.trys.push([11, 13, , 14]);
400
463
  return [4 /*yield*/, this.OCClient.validateAuthChatRecord(this.requestId, {
401
464
  authenticatedUserToken: this.authenticatedUserToken,
402
465
  chatId: this.chatToken.chatId
403
466
  })];
404
467
  case 12:
405
- _y.sent();
468
+ _1.sent();
406
469
  return [3 /*break*/, 14];
407
470
  case 13:
408
- _v = _y.sent();
471
+ _y = _1.sent();
409
472
  exceptionDetails = {
410
473
  response: "OCClientValidateAuthChatRecordFailed",
411
474
  message: "InvalidAuthChatRecord"
@@ -420,84 +483,49 @@ var OmnichannelChatSDK = /** @class */ (function () {
420
483
  if (!(this.chatToken && Object.keys(this.chatToken).length === 0)) return [3 /*break*/, 16];
421
484
  return [4 /*yield*/, this.getChatToken(false)];
422
485
  case 15:
423
- _y.sent();
424
- _y.label = 16;
486
+ _1.sent();
487
+ _1.label = 16;
425
488
  case 16:
426
489
  (_c = this.ic3ClientLogger) === null || _c === void 0 ? void 0 : _c.setChatId(this.chatToken.chatId || '');
427
490
  (_d = this.ocSdkLogger) === null || _d === void 0 ? void 0 : _d.setChatId(this.chatToken.chatId || '');
428
491
  (_e = this.acsClientLogger) === null || _e === void 0 ? void 0 : _e.setChatId(this.chatToken.chatId || '');
429
492
  (_f = this.acsAdapterLogger) === null || _f === void 0 ? void 0 : _f.setChatId(this.chatToken.chatId || '');
430
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 || '');
431
495
  sessionInitOptionalParams = {
432
496
  initContext: {}
433
497
  };
434
- sessionInitOptionalParams.initContext.locale = locale_1.getLocaleStringFromId(this.localeId);
435
- if (this.isPersistentChat && !((_h = this.chatSDKConfig.persistentChat) === null || _h === void 0 ? void 0 : _h.disable)) {
498
+ sessionInitOptionalParams = this.populateInitChatOptionalParam(sessionInitOptionalParams, optionalParams);
499
+ sessionInitOptionalParams.initContext.isProactiveChat = !!optionalParams.isProactiveChat;
500
+ if (this.isPersistentChat && !((_j = this.chatSDKConfig.persistentChat) === null || _j === void 0 ? void 0 : _j.disable)) {
436
501
  sessionInitOptionalParams.reconnectId = this.reconnectId;
437
502
  }
438
- 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) {
439
504
  sessionInitOptionalParams.reconnectId = this.reconnectId;
440
505
  }
441
- if (optionalParams.customContext) {
442
- sessionInitOptionalParams.initContext.customContextData = optionalParams.customContext; // eslint-disable-line @typescript-eslint/no-explicit-any
443
- }
444
- if (optionalParams.browser) {
445
- sessionInitOptionalParams.initContext.browser = optionalParams.browser;
446
- }
447
- if (optionalParams.os) {
448
- sessionInitOptionalParams.initContext.os = optionalParams.os;
449
- }
450
- if (optionalParams.locale) {
451
- sessionInitOptionalParams.initContext.locale = optionalParams.locale;
452
- }
453
- if (optionalParams.device) {
454
- sessionInitOptionalParams.initContext.device = optionalParams.device;
455
- }
456
- if (optionalParams.preChatResponse) {
457
- sessionInitOptionalParams.initContext.preChatResponse = optionalParams.preChatResponse;
458
- }
459
- if (optionalParams.sendDefaultInitContext) {
460
- if (platform_1.default.isNode() || platform_1.default.isReactNative()) {
461
- exceptionDetails = {
462
- response: "UnsupportedPlatform",
463
- message: "sendDefaultInitContext is only supported on browser"
464
- };
465
- console.error(exceptionDetails.message);
466
- this.scenarioMarker.failScenario(TelemetryEvent_1.default.StartChat, {
467
- RequestId: this.requestId,
468
- ChatId: this.chatToken.chatId,
469
- ExceptionDetails: JSON.stringify(exceptionDetails)
470
- });
471
- throw new Error(exceptionDetails.response);
472
- }
473
- sessionInitOptionalParams.getContext = true;
474
- }
475
- // Override initContext completely
476
- if (optionalParams.initContext) {
477
- sessionInitOptionalParams.initContext = optionalParams.initContext;
478
- }
479
- if (this.authenticatedUserToken) {
480
- sessionInitOptionalParams.authenticatedUserToken = this.authenticatedUserToken;
481
- }
482
- if (this.chatToken.chatId) {
483
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
484
- sessionInitOptionalParams.initContext.chatId = this.chatToken.chatId;
485
- }
486
- if (!!optionalParams.liveChatContext) return [3 /*break*/, 20];
487
- _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)];
488
508
  case 17:
489
- _y.trys.push([17, 19, , 20]);
490
- 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;
491
513
  case 18:
492
- _y.sent();
493
- return [3 /*break*/, 20];
514
+ if (!!optionalParams.liveChatContext) return [3 /*break*/, 22];
515
+ _1.label = 19;
494
516
  case 19:
495
- 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();
496
524
  exceptionDetails = {
497
525
  response: "OCClientSessionInitFailed"
498
526
  };
499
527
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
500
- 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()) {
501
529
  exceptionDetails.response = OmnichannelErrorCodes_1.default[OmnichannelErrorCodes_1.default.WidgetUseOutsideOperatingHour].toString();
502
530
  exceptionDetails.message = 'Widget used outside of operating hours';
503
531
  console.error(exceptionDetails.message);
@@ -508,8 +536,8 @@ var OmnichannelChatSDK = /** @class */ (function () {
508
536
  ExceptionDetails: JSON.stringify(exceptionDetails)
509
537
  });
510
538
  throw new Error(exceptionDetails.response);
511
- case 20:
512
- 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];
513
541
  chatAdapterConfig = {
514
542
  token: this.chatToken.token,
515
543
  id: this.chatToken.visitorId || 'teamsvisitor',
@@ -517,18 +545,18 @@ var OmnichannelChatSDK = /** @class */ (function () {
517
545
  environmentUrl: this.chatToken.acsEndpoint,
518
546
  pollingInterval: 30000
519
547
  };
520
- _y.label = 21;
521
- case 21:
522
- _y.trys.push([21, 23, , 24]);
523
- 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({
524
552
  token: chatAdapterConfig.token,
525
553
  environmentUrl: chatAdapterConfig.environmentUrl
526
554
  }))];
527
- case 22:
528
- _y.sent();
529
- return [3 /*break*/, 24];
530
- case 23:
531
- error_4 = _y.sent();
555
+ case 24:
556
+ _1.sent();
557
+ return [3 /*break*/, 26];
558
+ case 25:
559
+ error_4 = _1.sent();
532
560
  exceptionDetails = {
533
561
  response: "ACSClientInitializeFailed"
534
562
  };
@@ -539,23 +567,23 @@ var OmnichannelChatSDK = /** @class */ (function () {
539
567
  });
540
568
  console.error("OmnichannelChatSDK/startChat/initialize/error " + error_4);
541
569
  return [2 /*return*/, error_4];
542
- case 24:
543
- _y.trys.push([24, 26, , 27]);
544
- _w = this;
545
- 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({
546
574
  id: chatAdapterConfig.id,
547
575
  threadId: chatAdapterConfig.threadId,
548
576
  pollingInterval: chatAdapterConfig.pollingInterval
549
577
  }))];
550
- case 25:
551
- _w.conversation = (_y.sent());
578
+ case 27:
579
+ _z.conversation = (_1.sent());
552
580
  this.scenarioMarker.completeScenario(TelemetryEvent_1.default.StartChat, {
553
581
  RequestId: this.requestId,
554
582
  ChatId: this.chatToken.chatId
555
583
  });
556
- return [3 /*break*/, 27];
557
- case 26:
558
- error_5 = _y.sent();
584
+ return [3 /*break*/, 29];
585
+ case 28:
586
+ error_5 = _1.sent();
559
587
  exceptionDetails = {
560
588
  response: "ACSClientJoinConversationFailed"
561
589
  };
@@ -566,16 +594,16 @@ var OmnichannelChatSDK = /** @class */ (function () {
566
594
  });
567
595
  console.error("OmnichannelChatSDK/startChat/joinConversation/error " + error_5);
568
596
  throw Error(exceptionDetails.response);
569
- case 27:
570
- _y.trys.push([27, 29, , 30]);
571
- 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({
572
600
  chatToken: this.chatToken
573
601
  }))];
574
- case 28:
575
- _y.sent();
576
- return [3 /*break*/, 30];
577
- case 29:
578
- error_6 = _y.sent();
602
+ case 30:
603
+ _1.sent();
604
+ return [3 /*break*/, 32];
605
+ case 31:
606
+ error_6 = _1.sent();
579
607
  exceptionDetails = {
580
608
  response: "AMSClientInitializeFailed"
581
609
  };
@@ -585,19 +613,19 @@ var OmnichannelChatSDK = /** @class */ (function () {
585
613
  ExceptionDetails: JSON.stringify(exceptionDetails)
586
614
  });
587
615
  throw Error(exceptionDetails.response);
588
- case 30: return [3 /*break*/, 37];
589
- case 31:
590
- _y.trys.push([31, 33, , 34]);
616
+ case 32: return [3 /*break*/, 39];
617
+ case 33:
618
+ _1.trys.push([33, 35, , 36]);
591
619
  return [4 /*yield*/, this.IC3Client.initialize({
592
620
  token: this.chatToken.token,
593
621
  regionGtms: this.chatToken.regionGTMS,
594
622
  visitor: true
595
623
  })];
596
- case 32:
597
- _y.sent();
598
- return [3 /*break*/, 34];
599
- case 33:
600
- error_7 = _y.sent();
624
+ case 34:
625
+ _1.sent();
626
+ return [3 /*break*/, 36];
627
+ case 35:
628
+ error_7 = _1.sent();
601
629
  exceptionDetails = {
602
630
  response: "IC3ClientInitializeFailed"
603
631
  };
@@ -608,19 +636,19 @@ var OmnichannelChatSDK = /** @class */ (function () {
608
636
  });
609
637
  console.error("OmnichannelChatSDK/startChat/initialize/error " + error_7);
610
638
  return [2 /*return*/, error_7];
611
- case 34:
612
- _y.trys.push([34, 36, , 37]);
613
- _x = this;
639
+ case 36:
640
+ _1.trys.push([36, 38, , 39]);
641
+ _0 = this;
614
642
  return [4 /*yield*/, this.IC3Client.joinConversation(this.chatToken.chatId)];
615
- case 35:
616
- _x.conversation = _y.sent();
643
+ case 37:
644
+ _0.conversation = _1.sent();
617
645
  this.scenarioMarker.completeScenario(TelemetryEvent_1.default.StartChat, {
618
646
  RequestId: this.requestId,
619
647
  ChatId: this.chatToken.chatId
620
648
  });
621
- return [3 /*break*/, 37];
622
- case 36:
623
- error_8 = _y.sent();
649
+ return [3 /*break*/, 39];
650
+ case 38:
651
+ error_8 = _1.sent();
624
652
  exceptionDetails = {
625
653
  response: "IC3ClientJoinConversationFailed"
626
654
  };
@@ -631,8 +659,8 @@ var OmnichannelChatSDK = /** @class */ (function () {
631
659
  });
632
660
  console.error("OmnichannelChatSDK/startChat/joinConversation/error " + error_8);
633
661
  return [2 /*return*/, error_8];
634
- case 37:
635
- 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)) {
636
664
  this.refreshTokenTimer = setInterval(function () { return __awaiter(_this, void 0, void 0, function () {
637
665
  return __generator(this, function (_a) {
638
666
  switch (_a.label) {
@@ -643,7 +671,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
643
671
  return [2 /*return*/];
644
672
  }
645
673
  });
646
- }); }, (_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);
647
675
  }
648
676
  return [2 /*return*/];
649
677
  }
@@ -651,11 +679,11 @@ var OmnichannelChatSDK = /** @class */ (function () {
651
679
  });
652
680
  };
653
681
  OmnichannelChatSDK.prototype.endChat = function () {
654
- 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;
655
683
  return __awaiter(this, void 0, void 0, function () {
656
684
  var sessionCloseOptionalParams, isReconnectChat, isChatReconnect, error_9, exceptionDetails;
657
- return __generator(this, function (_p) {
658
- switch (_p.label) {
685
+ return __generator(this, function (_r) {
686
+ switch (_r.label) {
659
687
  case 0:
660
688
  this.scenarioMarker.startScenario(TelemetryEvent_1.default.EndChat, {
661
689
  RequestId: this.requestId,
@@ -675,12 +703,12 @@ var OmnichannelChatSDK = /** @class */ (function () {
675
703
  if (this.authenticatedUserToken) {
676
704
  sessionCloseOptionalParams.authenticatedUserToken = this.authenticatedUserToken;
677
705
  }
678
- _p.label = 1;
706
+ _r.label = 1;
679
707
  case 1:
680
- _p.trys.push([1, 3, , 4]);
708
+ _r.trys.push([1, 3, , 4]);
681
709
  return [4 /*yield*/, this.OCClient.sessionClose(this.requestId, sessionCloseOptionalParams)];
682
710
  case 2:
683
- _p.sent();
711
+ _r.sent();
684
712
  this.scenarioMarker.completeScenario(TelemetryEvent_1.default.EndChat, {
685
713
  RequestId: this.requestId,
686
714
  ChatId: this.chatToken.chatId
@@ -705,9 +733,11 @@ var OmnichannelChatSDK = /** @class */ (function () {
705
733
  (_l = this.acsAdapterLogger) === null || _l === void 0 ? void 0 : _l.setChatId('');
706
734
  (_m = this.callingSdkLogger) === null || _m === void 0 ? void 0 : _m.setRequestId(this.requestId);
707
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('');
708
738
  return [3 /*break*/, 4];
709
739
  case 3:
710
- error_9 = _p.sent();
740
+ error_9 = _r.sent();
711
741
  exceptionDetails = {
712
742
  response: "OCClientSessionCloseFailed"
713
743
  };
@@ -1611,96 +1641,28 @@ var OmnichannelChatSDK = /** @class */ (function () {
1611
1641
  });
1612
1642
  };
1613
1643
  OmnichannelChatSDK.prototype.createChatAdapter = function (optionalParams) {
1644
+ var _a;
1614
1645
  if (optionalParams === void 0) { optionalParams = {}; }
1615
1646
  return __awaiter(this, void 0, void 0, function () {
1616
- var protocol, supportedChatAdapterProtocols;
1617
- var _this = this;
1618
- return __generator(this, function (_a) {
1647
+ var protocol, supportedChatAdapterProtocols, fileManager;
1648
+ return __generator(this, function (_b) {
1619
1649
  if (platform_1.default.isNode() || platform_1.default.isReactNative()) {
1620
1650
  return [2 /*return*/, Promise.reject('ChatAdapter is only supported on browser')];
1621
1651
  }
1622
1652
  protocol = optionalParams.protocol;
1623
- supportedChatAdapterProtocols = [ChatAdapterProtocols_1.default.ACS, ChatAdapterProtocols_1.default.IC3];
1653
+ supportedChatAdapterProtocols = [ChatAdapterProtocols_1.default.ACS, ChatAdapterProtocols_1.default.IC3, ChatAdapterProtocols_1.default.DirectLine];
1624
1654
  if (protocol && !supportedChatAdapterProtocols.includes(protocol)) {
1625
1655
  return [2 /*return*/, Promise.reject("ChatAdapter for protocol " + protocol + " currently not supported")];
1626
1656
  }
1627
- if (protocol === ChatAdapterProtocols_1.default.ACS || this.liveChatVersion === LiveChatVersion_1.default.V2) {
1628
- return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
1629
- var options, defaultEgressMiddlewares, defaultIngressMiddlewares, egressMiddleware, ingressMiddleware, featuresOption, acsAdapterCDNUrl;
1630
- var _this = this;
1631
- var _a;
1632
- return __generator(this, function (_b) {
1633
- switch (_b.label) {
1634
- case 0:
1635
- options = optionalParams.ACSAdapter ? optionalParams.ACSAdapter.options : {};
1636
- defaultEgressMiddlewares = [createChannelDataEgressMiddleware_1.default({ widgetId: this.omnichannelConfig.widgetId }), createFormatEgressTagsMiddleware_1.default()];
1637
- defaultIngressMiddlewares = [createFormatIngressTagsMiddleware_1.default()];
1638
- egressMiddleware = (options === null || options === void 0 ? void 0 : options.egressMiddleware) ? __spreadArrays(options.egressMiddleware, defaultEgressMiddlewares) : __spreadArrays(defaultEgressMiddlewares);
1639
- ingressMiddleware = (options === null || options === void 0 ? void 0 : options.ingressMiddleware) ? __spreadArrays(options.egressMiddleware, defaultIngressMiddlewares) : __spreadArrays(defaultIngressMiddlewares);
1640
- featuresOption = __assign(__assign({ enableAdaptiveCards: true, enableThreadMemberUpdateNotification: true, enableLeaveThreadOnWindowClosed: false }, options), { // overrides
1641
- ingressMiddleware: ingressMiddleware,
1642
- egressMiddleware: egressMiddleware });
1643
- acsAdapterCDNUrl = this.resolveChatAdapterUrl(protocol || ChatAdapterProtocols_1.default.ACS);
1644
- (_a = this.telemetry) === null || _a === void 0 ? void 0 : _a.setCDNPackages({
1645
- ACSAdapter: acsAdapterCDNUrl
1646
- });
1647
- return [4 /*yield*/, WebUtils_1.loadScript(acsAdapterCDNUrl, function () {
1648
- var _a;
1649
- /* istanbul ignore next */
1650
- _this.debug && console.debug('ACSAdapter loaded!');
1651
- try {
1652
- var ChatAdapter = window.ChatAdapter; // eslint-disable-line @typescript-eslint/no-explicit-any
1653
- var fileManager = new AMSFileManager_1.default(_this.AMSClient, _this.acsAdapterLogger);
1654
- var adapter = ChatAdapter.createACSAdapter(_this.chatToken.token, _this.chatToken.visitorId || 'teamsvisitor', _this.chatToken.chatId, _this.chatToken.acsEndpoint, fileManager, 30000, ACSParticipantDisplayName_1.default.Customer, (_a = _this.ACSClient) === null || _a === void 0 ? void 0 : _a.getChatClient(), _this.acsAdapterLogger, // logger
1655
- featuresOption);
1656
- resolve(adapter);
1657
- }
1658
- catch (_b) {
1659
- throw new Error('Failed to load ACSAdapter');
1660
- }
1661
- }, function () {
1662
- reject('Failed to load ACSADapter');
1663
- })];
1664
- case 1:
1665
- _b.sent();
1666
- return [2 /*return*/];
1667
- }
1668
- });
1669
- }); })];
1657
+ if (protocol === ChatAdapterProtocols_1.default.DirectLine) {
1658
+ return [2 /*return*/, chatAdapterCreators_1.createDirectLine(optionalParams, this.chatSDKConfig, this.liveChatVersion, ChatAdapterProtocols_1.default.DirectLine, this.telemetry, this.scenarioMarker)];
1659
+ }
1660
+ else if (protocol === ChatAdapterProtocols_1.default.ACS || this.liveChatVersion === LiveChatVersion_1.default.V2) {
1661
+ fileManager = new AMSFileManager_1.default(this.AMSClient, this.acsAdapterLogger);
1662
+ return [2 /*return*/, chatAdapterCreators_1.createACSAdapter(optionalParams, this.chatSDKConfig, this.liveChatVersion, ChatAdapterProtocols_1.default.ACS, this.telemetry, this.scenarioMarker, this.omnichannelConfig, this.chatToken, fileManager, (_a = this.ACSClient) === null || _a === void 0 ? void 0 : _a.getChatClient(), this.acsAdapterLogger)];
1670
1663
  }
1671
1664
  else if (protocol === ChatAdapterProtocols_1.default.IC3 || this.liveChatVersion === LiveChatVersion_1.default.V1) {
1672
- return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
1673
- var options, ic3AdapterCDNUrl;
1674
- var _this = this;
1675
- var _a;
1676
- return __generator(this, function (_b) {
1677
- switch (_b.label) {
1678
- case 0:
1679
- options = optionalParams.IC3Adapter ? optionalParams.IC3Adapter.options : {};
1680
- ic3AdapterCDNUrl = this.resolveChatAdapterUrl(protocol || ChatAdapterProtocols_1.default.IC3);
1681
- (_a = this.telemetry) === null || _a === void 0 ? void 0 : _a.setCDNPackages({
1682
- IC3Adapter: ic3AdapterCDNUrl
1683
- });
1684
- this.scenarioMarker.startScenario(TelemetryEvent_1.default.CreateIC3Adapter);
1685
- return [4 /*yield*/, WebUtils_1.loadScript(ic3AdapterCDNUrl, function () {
1686
- /* istanbul ignore next */
1687
- _this.debug && console.debug('IC3Adapter loaded!');
1688
- var adapterConfig = __assign({ chatToken: _this.chatToken, userDisplayName: 'Customer', userId: _this.chatToken.visitorId || 'teamsvisitor', sdkURL: _this.resolveIC3ClientUrl(), sdk: _this.IC3Client }, options // overrides
1689
- );
1690
- var adapter = new window.Microsoft.BotFramework.WebChat.IC3Adapter(adapterConfig);
1691
- adapter.logger = _this.ic3ClientLogger;
1692
- _this.scenarioMarker.completeScenario(TelemetryEvent_1.default.CreateIC3Adapter);
1693
- resolve(adapter);
1694
- }, function () {
1695
- _this.scenarioMarker.failScenario(TelemetryEvent_1.default.CreateIC3Adapter);
1696
- reject('Failed to load IC3Adapter');
1697
- })];
1698
- case 1:
1699
- _b.sent();
1700
- return [2 /*return*/];
1701
- }
1702
- });
1703
- }); })];
1665
+ return [2 /*return*/, chatAdapterCreators_1.createIC3Adapter(optionalParams, this.chatSDKConfig, this.liveChatVersion, ChatAdapterProtocols_1.default.IC3, this.telemetry, this.scenarioMarker, this.chatToken, this.IC3Client, this.ic3ClientLogger)];
1704
1666
  }
1705
1667
  return [2 /*return*/, Promise.reject("ChatAdapter for protocol " + protocol + " currently not supported")];
1706
1668
  });
@@ -1799,28 +1761,33 @@ var OmnichannelChatSDK = /** @class */ (function () {
1799
1761
  };
1800
1762
  OmnichannelChatSDK.prototype.getPostChatSurveyContext = function () {
1801
1763
  return __awaiter(this, void 0, void 0, function () {
1802
- var conversationId, chatConfig, liveWSAndLiveChatEngJoin, msdyn_postconversationsurveyenable, msfp_sourcesurveyidentifier, msfp_botsourcesurveyidentifier, postConversationSurveyOwnerId, postConversationBotSurveyOwnerId, liveWorkItemDetails, participantJoined, participantType, surveyInviteLinkRequest, optionalParams, ownerId, surveyInviteLinkResponse, surveyInviteLink, formsProLocale, postChatContext, ex_1;
1803
- return __generator(this, function (_a) {
1804
- 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) {
1805
1767
  case 0:
1806
1768
  this.scenarioMarker.startScenario(TelemetryEvent_1.default.GetPostChatSurveyContext, {
1807
1769
  RequestId: this.requestId
1808
1770
  });
1809
- _a.label = 1;
1771
+ _b.label = 1;
1810
1772
  case 1:
1811
- _a.trys.push([1, 6, , 7]);
1773
+ _b.trys.push([1, 8, , 9]);
1812
1774
  chatConfig = this.liveChatConfig;
1813
1775
  liveWSAndLiveChatEngJoin = chatConfig.LiveWSAndLiveChatEngJoin;
1814
1776
  msdyn_postconversationsurveyenable = liveWSAndLiveChatEngJoin.msdyn_postconversationsurveyenable, msfp_sourcesurveyidentifier = liveWSAndLiveChatEngJoin.msfp_sourcesurveyidentifier, msfp_botsourcesurveyidentifier = liveWSAndLiveChatEngJoin.msfp_botsourcesurveyidentifier, postConversationSurveyOwnerId = liveWSAndLiveChatEngJoin.postConversationSurveyOwnerId, postConversationBotSurveyOwnerId = liveWSAndLiveChatEngJoin.postConversationBotSurveyOwnerId;
1815
- if (!(msdyn_postconversationsurveyenable === "true")) return [3 /*break*/, 4];
1777
+ if (!(msdyn_postconversationsurveyenable === "true")) return [3 /*break*/, 6];
1816
1778
  return [4 /*yield*/, this.getConversationDetails()];
1817
1779
  case 2:
1818
- liveWorkItemDetails = _a.sent();
1780
+ liveWorkItemDetails = _b.sent();
1819
1781
  participantJoined = (liveWorkItemDetails === null || liveWorkItemDetails === void 0 ? void 0 : liveWorkItemDetails.canRenderPostChat) === "True";
1820
1782
  participantType = liveWorkItemDetails === null || liveWorkItemDetails === void 0 ? void 0 : liveWorkItemDetails.participantType;
1821
1783
  conversationId = liveWorkItemDetails === null || liveWorkItemDetails === void 0 ? void 0 : liveWorkItemDetails.conversationId;
1822
- surveyInviteLinkRequest = {
1823
- "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,
1824
1791
  "ConversationId": conversationId,
1825
1792
  "OCLocaleCode": locale_1.getLocaleStringFromId(this.localeId)
1826
1793
  };
@@ -1830,14 +1797,21 @@ var OmnichannelChatSDK = /** @class */ (function () {
1830
1797
  if (this.authenticatedUserToken) {
1831
1798
  optionalParams.authenticatedUserToken = this.authenticatedUserToken;
1832
1799
  }
1833
- ownerId = participantType === "Bot" ? postConversationBotSurveyOwnerId : postConversationSurveyOwnerId;
1834
- return [4 /*yield*/, this.OCClient.getSurveyInviteLink(ownerId, surveyInviteLinkRequest, optionalParams)];
1800
+ return [4 /*yield*/, this.OCClient.getSurveyInviteLink(postConversationSurveyOwnerId, agentSurveyInviteLinkRequest, optionalParams)];
1835
1801
  case 3:
1836
- surveyInviteLinkResponse = _a.sent();
1837
- surveyInviteLink = void 0, formsProLocale = void 0;
1838
- if (surveyInviteLinkResponse != null) {
1839
- if (surveyInviteLinkResponse.inviteList != null && surveyInviteLinkResponse.inviteList.length == 1) {
1840
- 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;
1841
1815
  }
1842
1816
  else {
1843
1817
  this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetPostChatSurveyContext, {
@@ -1847,14 +1821,24 @@ var OmnichannelChatSDK = /** @class */ (function () {
1847
1821
  });
1848
1822
  return [2 /*return*/, Promise.reject("Survey Invite link failed to send response.")];
1849
1823
  }
1850
- if (surveyInviteLinkResponse.formsProLocaleCode != null) {
1851
- 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
+ }
1852
1834
  }
1853
1835
  postChatContext = {
1854
1836
  participantJoined: participantJoined,
1855
1837
  participantType: participantType,
1856
- surveyInviteLink: surveyInviteLink,
1857
- formsProLocale: formsProLocale
1838
+ surveyInviteLink: agentSurveyInviteLink,
1839
+ botSurveyInviteLink: botSurveyInviteLink,
1840
+ formsProLocale: agentFormsProLocale,
1841
+ botFormsProLocale: botFormsProLocale
1858
1842
  };
1859
1843
  return [2 /*return*/, Promise.resolve(postChatContext)];
1860
1844
  }
@@ -1866,23 +1850,77 @@ var OmnichannelChatSDK = /** @class */ (function () {
1866
1850
  });
1867
1851
  return [2 /*return*/, Promise.reject("surveyInviteLinkResponse is null.")];
1868
1852
  }
1869
- return [3 /*break*/, 5];
1870
- case 4:
1853
+ return [3 /*break*/, 7];
1854
+ case 6:
1871
1855
  this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetPostChatSurveyContext, {
1872
1856
  RequestId: this.requestId,
1873
1857
  ExceptionDetails: "Post Chat Survey is disabled. Please check the Omnichannel Administration Portal."
1874
1858
  });
1875
1859
  return [2 /*return*/, Promise.reject("Post Chat is disabled from admin side.")];
1876
- case 5: return [3 /*break*/, 7];
1877
- case 6:
1878
- ex_1 = _a.sent();
1860
+ case 7: return [3 /*break*/, 9];
1861
+ case 8:
1862
+ ex_1 = _b.sent();
1879
1863
  this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetPostChatSurveyContext, {
1880
1864
  ConversationId: conversationId !== null && conversationId !== void 0 ? conversationId : "",
1881
1865
  RequestId: this.requestId,
1882
1866
  ExceptionDetails: JSON.stringify(ex_1)
1883
1867
  });
1884
1868
  return [2 /*return*/, Promise.reject("Retrieving post chat context failed " + JSON.stringify(ex_1))];
1885
- case 7: return [2 /*return*/];
1869
+ case 9: return [2 /*return*/];
1870
+ }
1871
+ });
1872
+ });
1873
+ };
1874
+ OmnichannelChatSDK.prototype.getAgentAvailability = function (optionalParams) {
1875
+ if (optionalParams === void 0) { optionalParams = {}; }
1876
+ return __awaiter(this, void 0, void 0, function () {
1877
+ var reportError, getAgentAvailabilityOptionalParams, response, e_2;
1878
+ var _this = this;
1879
+ return __generator(this, function (_a) {
1880
+ switch (_a.label) {
1881
+ case 0:
1882
+ reportError = function (response, message, chatId) {
1883
+ if (chatId === void 0) { chatId = ""; }
1884
+ var exceptionDetails = {
1885
+ response: response,
1886
+ message: message
1887
+ };
1888
+ _this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetAgentAvailability, {
1889
+ RequestId: _this.requestId,
1890
+ ExceptionDetails: JSON.stringify(exceptionDetails),
1891
+ ChatId: chatId
1892
+ });
1893
+ throw new Error(exceptionDetails.message);
1894
+ };
1895
+ this.scenarioMarker.startScenario(TelemetryEvent_1.default.GetAgentAvailability, {
1896
+ RequestId: this.requestId
1897
+ });
1898
+ if (!this.authSettings) {
1899
+ reportError("Unsupported", "GetAgentAvailability is supported only for authenticated live chat widget.");
1900
+ }
1901
+ if (!this.authenticatedUserToken) {
1902
+ reportError("UndefinedAuthToken", "Missing AuthToken for GetAgentAvailability.");
1903
+ }
1904
+ if (this.conversation) {
1905
+ reportError("InvalidOperation", "GetAgentAvailability can only be called before a chat has started.", this.chatToken.chatId);
1906
+ }
1907
+ getAgentAvailabilityOptionalParams = {
1908
+ initContext: {}
1909
+ };
1910
+ getAgentAvailabilityOptionalParams = this.populateInitChatOptionalParam(getAgentAvailabilityOptionalParams, optionalParams);
1911
+ _a.label = 1;
1912
+ case 1:
1913
+ _a.trys.push([1, 3, , 4]);
1914
+ return [4 /*yield*/, this.OCClient.getAgentAvailability(this.requestId, getAgentAvailabilityOptionalParams)];
1915
+ case 2:
1916
+ response = _a.sent();
1917
+ return [2 /*return*/, response];
1918
+ case 3:
1919
+ e_2 = _a.sent();
1920
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1921
+ reportError("GetAgentAvailabilityFailed", e_2.message);
1922
+ return [3 /*break*/, 4];
1923
+ case 4: return [2 /*return*/];
1886
1924
  }
1887
1925
  });
1888
1926
  });
@@ -2043,38 +2081,10 @@ var OmnichannelChatSDK = /** @class */ (function () {
2043
2081
  });
2044
2082
  };
2045
2083
  OmnichannelChatSDK.prototype.resolveIC3ClientUrl = function () {
2046
- if (this.chatSDKConfig.ic3Config && 'ic3ClientCDNUrl' in this.chatSDKConfig.ic3Config) {
2047
- return this.chatSDKConfig.ic3Config.ic3ClientCDNUrl;
2048
- }
2049
- if (this.chatSDKConfig.ic3Config && 'ic3ClientVersion' in this.chatSDKConfig.ic3Config) {
2050
- return libraries_1.default.getIC3ClientCDNUrl(this.chatSDKConfig.ic3Config.ic3ClientVersion);
2051
- }
2052
- return libraries_1.default.getIC3ClientCDNUrl();
2084
+ return urlResolvers_1.default.resolveIC3ClientUrl(this.chatSDKConfig);
2053
2085
  };
2054
2086
  OmnichannelChatSDK.prototype.resolveChatAdapterUrl = function (protocol) {
2055
- var supportedChatAdapterProtocols = [ChatAdapterProtocols_1.default.ACS, ChatAdapterProtocols_1.default.IC3];
2056
- if (protocol && !supportedChatAdapterProtocols.includes(protocol)) {
2057
- throw new Error("ChatAdapter for protocol " + protocol + " currently not supported");
2058
- }
2059
- if (protocol === ChatAdapterProtocols_1.default.ACS || this.liveChatVersion === LiveChatVersion_1.default.V2) {
2060
- if (this.chatSDKConfig.chatAdapterConfig && 'webChatACSAdapterCDNUrl' in this.chatSDKConfig.chatAdapterConfig) {
2061
- return this.chatSDKConfig.chatAdapterConfig.webChatACSAdapterCDNUrl;
2062
- }
2063
- if (this.chatSDKConfig.chatAdapterConfig && 'webChatACSAdapterVersion' in this.chatSDKConfig.chatAdapterConfig) {
2064
- return libraries_1.default.getACSAdapterCDNUrl(this.chatSDKConfig.chatAdapterConfig.webChatACSAdapterVersion);
2065
- }
2066
- return libraries_1.default.getACSAdapterCDNUrl();
2067
- }
2068
- else if (protocol === ChatAdapterProtocols_1.default.IC3 || this.liveChatVersion === LiveChatVersion_1.default.V1) {
2069
- if (this.chatSDKConfig.chatAdapterConfig && 'webChatIC3AdapterCDNUrl' in this.chatSDKConfig.chatAdapterConfig) {
2070
- return this.chatSDKConfig.chatAdapterConfig.webChatIC3AdapterCDNUrl;
2071
- }
2072
- if (this.chatSDKConfig.chatAdapterConfig && 'webChatIC3AdapterVersion' in this.chatSDKConfig.chatAdapterConfig) {
2073
- return libraries_1.default.getIC3AdapterCDNUrl(this.chatSDKConfig.chatAdapterConfig.webChatIC3AdapterVersion);
2074
- }
2075
- return libraries_1.default.getIC3AdapterCDNUrl();
2076
- }
2077
- return '';
2087
+ return urlResolvers_1.default.resolveChatAdapterUrl(this.chatSDKConfig, this.liveChatVersion, protocol);
2078
2088
  };
2079
2089
  OmnichannelChatSDK.prototype.updateChatToken = function (newToken, newRegionGTMS) {
2080
2090
  return __awaiter(this, void 0, void 0, function () {