@microsoft/omnichannel-chat-sdk 0.2.1-main.c6982c2 → 0.3.1-main.31aff70

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 (33) hide show
  1. package/CHANGELOG.md +28 -1
  2. package/README.md +135 -9
  3. package/lib/OmnichannelChatSDK.d.ts +9 -1
  4. package/lib/OmnichannelChatSDK.js +342 -136
  5. package/lib/OmnichannelChatSDK.js.map +1 -1
  6. package/lib/api/createVoiceVideoCalling.d.ts +1 -0
  7. package/lib/api/createVoiceVideoCalling.js +91 -83
  8. package/lib/api/createVoiceVideoCalling.js.map +1 -1
  9. package/lib/config/settings.d.ts +2 -2
  10. package/lib/config/settings.js +2 -2
  11. package/lib/core/ChatReconnectContext.d.ts +4 -0
  12. package/lib/core/ChatReconnectContext.js +3 -0
  13. package/lib/core/ChatReconnectContext.js.map +1 -0
  14. package/lib/core/ChatReconnectOptionalParams.d.ts +3 -0
  15. package/lib/core/ChatReconnectOptionalParams.js +3 -0
  16. package/lib/core/ChatReconnectOptionalParams.js.map +1 -0
  17. package/lib/core/ConversationMode.d.ts +5 -0
  18. package/lib/core/ConversationMode.js +9 -0
  19. package/lib/core/ConversationMode.js.map +1 -0
  20. package/lib/core/IChatSDKConfig.d.ts +10 -1
  21. package/lib/core/IStartChatOptionalParams.d.ts +1 -0
  22. package/lib/core/MessageTags.d.ts +1 -0
  23. package/lib/core/MessageTags.js +5 -0
  24. package/lib/core/MessageTags.js.map +1 -0
  25. package/lib/telemetry/AriaTelemetry.js +10 -5
  26. package/lib/telemetry/AriaTelemetry.js.map +1 -1
  27. package/lib/telemetry/TelemetryEvent.d.ts +3 -1
  28. package/lib/telemetry/TelemetryEvent.js +2 -0
  29. package/lib/telemetry/TelemetryEvent.js.map +1 -1
  30. package/lib/tsconfig.tsbuildinfo +396 -379
  31. package/lib/validators/SDKConfigValidators.js +15 -0
  32. package/lib/validators/SDKConfigValidators.js.map +1 -1
  33. package/package.json +9 -9
@@ -47,30 +47,39 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
47
47
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
48
48
  }
49
49
  };
50
+ var __spreadArrays = (this && this.__spreadArrays) || function () {
51
+ for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
52
+ for (var r = Array(s), k = 0, i = 0; i < il; i++)
53
+ for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
54
+ r[k] = a[j];
55
+ return r;
56
+ };
50
57
  Object.defineProperty(exports, "__esModule", { value: true });
51
- var ocsdk_1 = require("@microsoft/ocsdk");
52
- var omnichannel_ic3core_1 = require("@microsoft/omnichannel-ic3core");
58
+ var CallingOptionsOptionSetNumber_1 = require("./core/CallingOptionsOptionSetNumber");
53
59
  var ChatAdapterProtocols_1 = require("./core/ChatAdapterProtocols");
60
+ var ConversationMode_1 = require("./core/ConversationMode");
61
+ var loggers_1 = require("./utils/loggers");
62
+ var createTelemetry_1 = require("./utils/createTelemetry");
63
+ var createVoiceVideoCalling_1 = require("./api/createVoiceVideoCalling");
64
+ var MessageTags_1 = require("./core/MessageTags");
54
65
  var DeliveryMode_1 = require("@microsoft/omnichannel-ic3core/lib/model/DeliveryMode");
55
66
  var FileSharingProtocolType_1 = require("@microsoft/omnichannel-ic3core/lib/model/FileSharingProtocolType");
56
67
  var HostType_1 = require("@microsoft/omnichannel-ic3core/lib/interfaces/HostType");
68
+ var utilities_1 = require("./utils/utilities");
69
+ var libraries_1 = require("./utils/libraries");
70
+ var LiveWorkItemState_1 = require("./core/LiveWorkItemState");
71
+ var WebUtils_1 = require("./utils/WebUtils");
57
72
  var MessageContentType_1 = require("@microsoft/omnichannel-ic3core/lib/model/MessageContentType");
58
73
  var MessageType_1 = require("@microsoft/omnichannel-ic3core/lib/model/MessageType");
59
74
  var PersonType_1 = require("@microsoft/omnichannel-ic3core/lib/model/PersonType");
60
75
  var platform_1 = require("./utils/platform");
61
76
  var ProtocoleType_1 = require("@microsoft/omnichannel-ic3core/lib/interfaces/ProtocoleType");
62
- var libraries_1 = require("./utils/libraries");
63
- var utilities_1 = require("./utils/utilities");
77
+ var ScenarioMarker_1 = require("./telemetry/ScenarioMarker");
78
+ var ocsdk_1 = require("@microsoft/ocsdk");
79
+ var omnichannel_ic3core_1 = require("@microsoft/omnichannel-ic3core");
80
+ var TelemetryEvent_1 = require("./telemetry/TelemetryEvent");
64
81
  var OmnichannelConfigValidator_1 = require("./validators/OmnichannelConfigValidator");
65
82
  var SDKConfigValidators_1 = require("./validators/SDKConfigValidators");
66
- var WebUtils_1 = require("./utils/WebUtils");
67
- var createVoiceVideoCalling_1 = require("./api/createVoiceVideoCalling");
68
- var CallingOptionsOptionSetNumber_1 = require("./core/CallingOptionsOptionSetNumber");
69
- var createTelemetry_1 = require("./utils/createTelemetry");
70
- var TelemetryEvent_1 = require("./telemetry/TelemetryEvent");
71
- var ScenarioMarker_1 = require("./telemetry/ScenarioMarker");
72
- var loggers_1 = require("./utils/loggers");
73
- var LiveWorkItemState_1 = require("./core/LiveWorkItemState");
74
83
  var OmnichannelChatSDK = /** @class */ (function () {
75
84
  function OmnichannelChatSDK(omnichannelConfig, chatSDKConfig) {
76
85
  if (chatSDKConfig === void 0) { chatSDKConfig = SDKConfigValidators_1.defaultChatSDKConfig; }
@@ -82,6 +91,10 @@ var OmnichannelChatSDK = /** @class */ (function () {
82
91
  this.telemetry = null;
83
92
  this.ic3ClientLogger = null;
84
93
  this.ocSdkLogger = null;
94
+ this.isPersistentChat = false;
95
+ this.isChatReconnect = false;
96
+ this.reconnectId = null;
97
+ this.refreshTokenTimer = null;
85
98
  this.debug = false;
86
99
  this.omnichannelConfig = omnichannelConfig;
87
100
  this.chatSDKConfig = __assign(__assign({}, SDKConfigValidators_1.defaultChatSDKConfig), chatSDKConfig // overrides
@@ -157,23 +170,132 @@ var OmnichannelChatSDK = /** @class */ (function () {
157
170
  });
158
171
  });
159
172
  };
173
+ OmnichannelChatSDK.prototype.getChatReconnectContext = function (optionalParams) {
174
+ if (optionalParams === void 0) { optionalParams = {}; }
175
+ return __awaiter(this, void 0, void 0, function () {
176
+ var context, reconnectableChatsParams, reconnectableChatsResponse, error_1, exceptionDetails, reconnectAvailabilityResponse, error_2, exceptionDetails;
177
+ return __generator(this, function (_a) {
178
+ switch (_a.label) {
179
+ case 0:
180
+ this.scenarioMarker.startScenario(TelemetryEvent_1.default.GetChatReconnectContext, {
181
+ RequestId: this.requestId,
182
+ ChatId: this.chatToken.chatId
183
+ });
184
+ context = {
185
+ reconnectId: null,
186
+ redirectURL: null
187
+ };
188
+ if (!this.authenticatedUserToken) return [3 /*break*/, 5];
189
+ _a.label = 1;
190
+ case 1:
191
+ _a.trys.push([1, 3, , 4]);
192
+ reconnectableChatsParams = {
193
+ authenticatedUserToken: this.authenticatedUserToken
194
+ };
195
+ return [4 /*yield*/, this.OCClient.getReconnectableChats(reconnectableChatsParams)];
196
+ case 2:
197
+ reconnectableChatsResponse = _a.sent();
198
+ if (reconnectableChatsResponse && reconnectableChatsResponse.reconnectid) {
199
+ context.reconnectId = reconnectableChatsResponse.reconnectid;
200
+ }
201
+ this.scenarioMarker.completeScenario(TelemetryEvent_1.default.GetChatReconnectContext, {
202
+ RequestId: this.requestId,
203
+ ChatId: this.chatToken.chatId
204
+ });
205
+ return [3 /*break*/, 4];
206
+ case 3:
207
+ error_1 = _a.sent();
208
+ exceptionDetails = {
209
+ response: "OCClientGetReconnectableChatsFailed"
210
+ };
211
+ this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetChatReconnectContext, {
212
+ RequestId: this.requestId,
213
+ ChatId: this.chatToken.chatId,
214
+ ExceptionDetails: JSON.stringify(exceptionDetails)
215
+ });
216
+ console.error("OmnichannelChatSDK/GetChatReconnectContext/error " + error_1);
217
+ return [3 /*break*/, 4];
218
+ case 4: return [3 /*break*/, 9];
219
+ case 5:
220
+ if (!optionalParams.reconnectId) return [3 /*break*/, 9];
221
+ _a.label = 6;
222
+ case 6:
223
+ _a.trys.push([6, 8, , 9]);
224
+ return [4 /*yield*/, this.OCClient.getReconnectAvailability(optionalParams.reconnectId)];
225
+ case 7:
226
+ reconnectAvailabilityResponse = _a.sent();
227
+ if (reconnectAvailabilityResponse && !reconnectAvailabilityResponse.isReconnectAvailable) {
228
+ if (reconnectAvailabilityResponse.reconnectRedirectionURL) {
229
+ context.redirectURL = reconnectAvailabilityResponse.reconnectRedirectionURL;
230
+ }
231
+ }
232
+ else {
233
+ context.reconnectId = optionalParams.reconnectId;
234
+ }
235
+ this.scenarioMarker.completeScenario(TelemetryEvent_1.default.GetChatReconnectContext, {
236
+ RequestId: this.requestId,
237
+ ChatId: this.chatToken.chatId
238
+ });
239
+ return [3 /*break*/, 9];
240
+ case 8:
241
+ error_2 = _a.sent();
242
+ exceptionDetails = {
243
+ response: "OCClientGetReconnectAvailabilityFailed"
244
+ };
245
+ this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetChatReconnectContext, {
246
+ RequestId: this.requestId,
247
+ ChatId: this.chatToken.chatId,
248
+ ExceptionDetails: JSON.stringify(exceptionDetails)
249
+ });
250
+ console.error("OmnichannelChatSDK/GetChatReconnectContext/error " + error_2);
251
+ return [3 /*break*/, 9];
252
+ case 9: return [2 /*return*/, context];
253
+ }
254
+ });
255
+ });
256
+ };
160
257
  OmnichannelChatSDK.prototype.startChat = function (optionalParams) {
161
- var _a, _b;
258
+ var _a, _b, _c, _d, _e, _f, _g, _h;
162
259
  if (optionalParams === void 0) { optionalParams = {}; }
163
260
  return __awaiter(this, void 0, void 0, function () {
164
- var conversationDetails, exceptionDetails, exceptionDetails, sessionInitOptionalParams, error_1, exceptionDetails, error_2, exceptionDetails, _c, error_3, exceptionDetails;
165
- return __generator(this, function (_d) {
166
- switch (_d.label) {
261
+ var reconnectableChatsParams, reconnectableChatsResponse, _j, exceptionDetails, conversationDetails, exceptionDetails, exceptionDetails, sessionInitOptionalParams, error_3, exceptionDetails, error_4, exceptionDetails, _k, error_5, exceptionDetails;
262
+ var _this = this;
263
+ return __generator(this, function (_l) {
264
+ switch (_l.label) {
167
265
  case 0:
168
266
  this.scenarioMarker.startScenario(TelemetryEvent_1.default.StartChat, {
169
267
  RequestId: this.requestId
170
268
  });
171
- if (!optionalParams.liveChatContext) return [3 /*break*/, 2];
269
+ if (this.isChatReconnect && !((_a = this.chatSDKConfig.chatReconnect) === null || _a === void 0 ? void 0 : _a.disable) && !this.isPersistentChat && optionalParams.reconnectId) {
270
+ this.reconnectId = optionalParams.reconnectId;
271
+ }
272
+ if (!(this.isPersistentChat && !((_b = this.chatSDKConfig.persistentChat) === null || _b === void 0 ? void 0 : _b.disable))) return [3 /*break*/, 4];
273
+ _l.label = 1;
274
+ case 1:
275
+ _l.trys.push([1, 3, , 4]);
276
+ reconnectableChatsParams = {
277
+ authenticatedUserToken: this.authenticatedUserToken
278
+ };
279
+ return [4 /*yield*/, this.OCClient.getReconnectableChats(reconnectableChatsParams)];
280
+ case 2:
281
+ reconnectableChatsResponse = _l.sent();
282
+ if (reconnectableChatsResponse && reconnectableChatsResponse.reconnectid) {
283
+ this.reconnectId = reconnectableChatsResponse.reconnectid;
284
+ }
285
+ return [3 /*break*/, 4];
286
+ case 3:
287
+ _j = _l.sent();
288
+ exceptionDetails = {
289
+ response: "OCClientGetReconnectableChatsFailed"
290
+ };
291
+ throw Error(exceptionDetails.response);
292
+ case 4:
293
+ if (!(optionalParams.liveChatContext && !this.isPersistentChat && !this.isChatReconnect)) return [3 /*break*/, 6];
172
294
  this.chatToken = optionalParams.liveChatContext.chatToken || {};
173
295
  this.requestId = optionalParams.liveChatContext.requestId || ocsdk_1.uuidv4();
174
296
  return [4 /*yield*/, this.getConversationDetails()];
175
- case 1:
176
- conversationDetails = _d.sent();
297
+ case 5:
298
+ conversationDetails = _l.sent();
177
299
  if (Object.keys(conversationDetails).length === 0) {
178
300
  exceptionDetails = {
179
301
  response: "InvalidConversation"
@@ -198,19 +320,25 @@ var OmnichannelChatSDK = /** @class */ (function () {
198
320
  console.error("Unable to join conversation that's in '" + conversationDetails.state + "' state");
199
321
  throw Error(exceptionDetails.response);
200
322
  }
201
- _d.label = 2;
202
- case 2:
203
- if (!(this.chatToken && Object.keys(this.chatToken).length === 0)) return [3 /*break*/, 4];
323
+ _l.label = 6;
324
+ case 6:
325
+ if (!(this.chatToken && Object.keys(this.chatToken).length === 0)) return [3 /*break*/, 8];
204
326
  return [4 /*yield*/, this.getChatToken(false)];
205
- case 3:
206
- _d.sent();
207
- _d.label = 4;
208
- case 4:
209
- (_a = this.ic3ClientLogger) === null || _a === void 0 ? void 0 : _a.setChatId(this.chatToken.chatId || '');
210
- (_b = this.ocSdkLogger) === null || _b === void 0 ? void 0 : _b.setChatId(this.chatToken.chatId || '');
327
+ case 7:
328
+ _l.sent();
329
+ _l.label = 8;
330
+ case 8:
331
+ (_c = this.ic3ClientLogger) === null || _c === void 0 ? void 0 : _c.setChatId(this.chatToken.chatId || '');
332
+ (_d = this.ocSdkLogger) === null || _d === void 0 ? void 0 : _d.setChatId(this.chatToken.chatId || '');
211
333
  sessionInitOptionalParams = {
212
334
  initContext: {}
213
335
  };
336
+ if (this.isPersistentChat && !((_e = this.chatSDKConfig.persistentChat) === null || _e === void 0 ? void 0 : _e.disable)) {
337
+ sessionInitOptionalParams.reconnectId = this.reconnectId;
338
+ }
339
+ if (this.isChatReconnect && !((_f = this.chatSDKConfig.chatReconnect) === null || _f === void 0 ? void 0 : _f.disable) && !this.isPersistentChat) {
340
+ sessionInitOptionalParams.reconnectId = this.reconnectId;
341
+ }
214
342
  if (optionalParams.customContext) {
215
343
  sessionInitOptionalParams.initContext.customContextData = optionalParams.customContext; // eslint-disable-line @typescript-eslint/no-explicit-any
216
344
  }
@@ -236,15 +364,15 @@ var OmnichannelChatSDK = /** @class */ (function () {
236
364
  if (this.authenticatedUserToken) {
237
365
  sessionInitOptionalParams.authenticatedUserToken = this.authenticatedUserToken;
238
366
  }
239
- _d.label = 5;
240
- case 5:
241
- _d.trys.push([5, 7, , 8]);
367
+ _l.label = 9;
368
+ case 9:
369
+ _l.trys.push([9, 11, , 12]);
242
370
  return [4 /*yield*/, this.OCClient.sessionInit(this.requestId, sessionInitOptionalParams)];
243
- case 6:
244
- _d.sent();
245
- return [3 /*break*/, 8];
246
- case 7:
247
- error_1 = _d.sent();
371
+ case 10:
372
+ _l.sent();
373
+ return [3 /*break*/, 12];
374
+ case 11:
375
+ error_3 = _l.sent();
248
376
  exceptionDetails = {
249
377
  response: "OCClientSessionInitFailed"
250
378
  };
@@ -253,20 +381,20 @@ var OmnichannelChatSDK = /** @class */ (function () {
253
381
  ChatId: this.chatToken.chatId,
254
382
  ExceptionDetails: JSON.stringify(exceptionDetails)
255
383
  });
256
- console.error("OmnichannelChatSDK/startChat/sessionInit/error " + error_1);
257
- return [2 /*return*/, error_1];
258
- case 8:
259
- _d.trys.push([8, 10, , 11]);
384
+ console.error("OmnichannelChatSDK/startChat/sessionInit/error " + error_3);
385
+ return [2 /*return*/, error_3];
386
+ case 12:
387
+ _l.trys.push([12, 14, , 15]);
260
388
  return [4 /*yield*/, this.IC3Client.initialize({
261
389
  token: this.chatToken.token,
262
390
  regionGtms: this.chatToken.regionGTMS,
263
391
  visitor: true
264
392
  })];
265
- case 9:
266
- _d.sent();
267
- return [3 /*break*/, 11];
268
- case 10:
269
- error_2 = _d.sent();
393
+ case 13:
394
+ _l.sent();
395
+ return [3 /*break*/, 15];
396
+ case 14:
397
+ error_4 = _l.sent();
270
398
  exceptionDetails = {
271
399
  response: "IC3ClientInitializeFailed"
272
400
  };
@@ -275,21 +403,21 @@ var OmnichannelChatSDK = /** @class */ (function () {
275
403
  ChatId: this.chatToken.chatId,
276
404
  ExceptionDetails: JSON.stringify(exceptionDetails)
277
405
  });
278
- console.error("OmnichannelChatSDK/startChat/initialize/error " + error_2);
279
- return [2 /*return*/, error_2];
280
- case 11:
281
- _d.trys.push([11, 13, , 14]);
282
- _c = this;
406
+ console.error("OmnichannelChatSDK/startChat/initialize/error " + error_4);
407
+ return [2 /*return*/, error_4];
408
+ case 15:
409
+ _l.trys.push([15, 17, , 18]);
410
+ _k = this;
283
411
  return [4 /*yield*/, this.IC3Client.joinConversation(this.chatToken.chatId)];
284
- case 12:
285
- _c.conversation = _d.sent();
412
+ case 16:
413
+ _k.conversation = _l.sent();
286
414
  this.scenarioMarker.completeScenario(TelemetryEvent_1.default.StartChat, {
287
415
  RequestId: this.requestId,
288
416
  ChatId: this.chatToken.chatId
289
417
  });
290
- return [3 /*break*/, 14];
291
- case 13:
292
- error_3 = _d.sent();
418
+ return [3 /*break*/, 18];
419
+ case 17:
420
+ error_5 = _l.sent();
293
421
  exceptionDetails = {
294
422
  response: "IC3ClientJoinConversationFailed"
295
423
  };
@@ -298,49 +426,73 @@ var OmnichannelChatSDK = /** @class */ (function () {
298
426
  ChatId: this.chatToken.chatId,
299
427
  ExceptionDetails: JSON.stringify(exceptionDetails)
300
428
  });
301
- console.error("OmnichannelChatSDK/startChat/joinConversation/error " + error_3);
302
- return [2 /*return*/, error_3];
303
- case 14: return [2 /*return*/];
429
+ console.error("OmnichannelChatSDK/startChat/joinConversation/error " + error_5);
430
+ return [2 /*return*/, error_5];
431
+ case 18:
432
+ if (this.isPersistentChat && !((_g = this.chatSDKConfig.persistentChat) === null || _g === void 0 ? void 0 : _g.disable)) {
433
+ this.refreshTokenTimer = setInterval(function () { return __awaiter(_this, void 0, void 0, function () {
434
+ return __generator(this, function (_a) {
435
+ switch (_a.label) {
436
+ case 0: return [4 /*yield*/, this.getChatToken(false)];
437
+ case 1:
438
+ _a.sent();
439
+ this.updateChatToken(this.chatToken.token, this.chatToken.regionGTMS);
440
+ return [2 /*return*/];
441
+ }
442
+ });
443
+ }); }, (_h = this.chatSDKConfig.persistentChat) === null || _h === void 0 ? void 0 : _h.tokenUpdateTime);
444
+ }
445
+ return [2 /*return*/];
304
446
  }
305
447
  });
306
448
  });
307
449
  };
308
450
  OmnichannelChatSDK.prototype.endChat = function () {
309
- var _a, _b, _c, _d;
451
+ var _a, _b, _c, _d, _e, _f, _g;
310
452
  return __awaiter(this, void 0, void 0, function () {
311
- var sessionCloseOptionalParams, error_4, exceptionDetails;
312
- return __generator(this, function (_e) {
313
- switch (_e.label) {
453
+ var sessionCloseOptionalParams, isReconnectChat, isChatReconnect, error_6, exceptionDetails;
454
+ return __generator(this, function (_h) {
455
+ switch (_h.label) {
314
456
  case 0:
315
457
  this.scenarioMarker.startScenario(TelemetryEvent_1.default.EndChat, {
316
458
  RequestId: this.requestId,
317
459
  ChatId: this.chatToken.chatId
318
460
  });
319
461
  sessionCloseOptionalParams = {};
462
+ if (this.isPersistentChat && !((_a = this.chatSDKConfig.persistentChat) === null || _a === void 0 ? void 0 : _a.disable)) {
463
+ isReconnectChat = this.reconnectId !== null ? true : false;
464
+ sessionCloseOptionalParams.isPersistentChat = this.isPersistentChat;
465
+ sessionCloseOptionalParams.isReconnectChat = isReconnectChat;
466
+ }
467
+ if (this.isChatReconnect && !((_b = this.chatSDKConfig.chatReconnect) === null || _b === void 0 ? void 0 : _b.disable) && !this.isPersistentChat) {
468
+ isChatReconnect = this.reconnectId !== null ? true : false;
469
+ sessionCloseOptionalParams.isReconnectChat = isChatReconnect;
470
+ }
320
471
  if (this.authenticatedUserToken) {
321
472
  sessionCloseOptionalParams.authenticatedUserToken = this.authenticatedUserToken;
322
473
  }
323
- _e.label = 1;
474
+ _h.label = 1;
324
475
  case 1:
325
- _e.trys.push([1, 3, , 4]);
476
+ _h.trys.push([1, 3, , 4]);
326
477
  return [4 /*yield*/, this.OCClient.sessionClose(this.requestId, sessionCloseOptionalParams)];
327
478
  case 2:
328
- _e.sent();
479
+ _h.sent();
329
480
  this.scenarioMarker.completeScenario(TelemetryEvent_1.default.EndChat, {
330
481
  RequestId: this.requestId,
331
482
  ChatId: this.chatToken.chatId
332
483
  });
333
- this.conversation.disconnect();
484
+ (_c = this.conversation) === null || _c === void 0 ? void 0 : _c.disconnect();
334
485
  this.conversation = null;
335
486
  this.requestId = ocsdk_1.uuidv4();
336
487
  this.chatToken = {};
337
- (_a = this.ic3ClientLogger) === null || _a === void 0 ? void 0 : _a.setRequestId(this.requestId);
338
- (_b = this.ic3ClientLogger) === null || _b === void 0 ? void 0 : _b.setChatId('');
339
- (_c = this.ocSdkLogger) === null || _c === void 0 ? void 0 : _c.setRequestId(this.requestId);
340
- (_d = this.ocSdkLogger) === null || _d === void 0 ? void 0 : _d.setChatId('');
488
+ this.reconnectId = null;
489
+ (_d = this.ic3ClientLogger) === null || _d === void 0 ? void 0 : _d.setRequestId(this.requestId);
490
+ (_e = this.ic3ClientLogger) === null || _e === void 0 ? void 0 : _e.setChatId('');
491
+ (_f = this.ocSdkLogger) === null || _f === void 0 ? void 0 : _f.setRequestId(this.requestId);
492
+ (_g = this.ocSdkLogger) === null || _g === void 0 ? void 0 : _g.setChatId('');
341
493
  return [3 /*break*/, 4];
342
494
  case 3:
343
- error_4 = _e.sent();
495
+ error_6 = _h.sent();
344
496
  exceptionDetails = {
345
497
  response: "OCClientSessionCloseFailed"
346
498
  };
@@ -349,9 +501,14 @@ var OmnichannelChatSDK = /** @class */ (function () {
349
501
  ChatId: this.chatToken.chatId,
350
502
  ExceptionDetails: JSON.stringify(exceptionDetails),
351
503
  });
352
- console.error("OmnichannelChatSDK/endChat/error " + error_4);
353
- return [2 /*return*/, error_4];
354
- case 4: return [2 /*return*/];
504
+ console.error("OmnichannelChatSDK/endChat/error " + error_6);
505
+ return [2 /*return*/, error_6];
506
+ case 4:
507
+ if (this.refreshTokenTimer !== null) {
508
+ clearInterval(this.refreshTokenTimer);
509
+ this.refreshTokenTimer = null;
510
+ }
511
+ return [2 /*return*/];
355
512
  }
356
513
  });
357
514
  });
@@ -380,7 +537,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
380
537
  OmnichannelChatSDK.prototype.getConversationDetails = function () {
381
538
  var _a, _b;
382
539
  return __awaiter(this, void 0, void 0, function () {
383
- var lwiDetails, state, conversationId, agentAcceptedOn, liveWorkItemDetails, error_5;
540
+ var lwiDetails, state, conversationId, agentAcceptedOn, liveWorkItemDetails, error_7;
384
541
  return __generator(this, function (_c) {
385
542
  switch (_c.label) {
386
543
  case 0:
@@ -408,12 +565,12 @@ var OmnichannelChatSDK = /** @class */ (function () {
408
565
  });
409
566
  return [2 /*return*/, liveWorkItemDetails];
410
567
  case 3:
411
- error_5 = _c.sent();
568
+ error_7 = _c.sent();
412
569
  this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetConversationDetails, {
413
570
  RequestId: this.requestId,
414
571
  ChatId: this.chatToken.chatId || '',
415
572
  });
416
- console.error("OmnichannelChatSDK/getConversationDetails/error " + error_5);
573
+ console.error("OmnichannelChatSDK/getConversationDetails/error " + error_7);
417
574
  return [3 /*break*/, 4];
418
575
  case 4: return [2 /*return*/, {}];
419
576
  }
@@ -444,26 +601,33 @@ var OmnichannelChatSDK = /** @class */ (function () {
444
601
  });
445
602
  };
446
603
  OmnichannelChatSDK.prototype.getChatToken = function (cached) {
604
+ var _a, _b;
447
605
  if (cached === void 0) { cached = true; }
448
606
  return __awaiter(this, void 0, void 0, function () {
449
- var getChatTokenOptionalParams, chatToken, chatId, token, regionGtms, expiresIn, visitorId, voiceVideoCallToken, error_6, exceptionDetails;
450
- return __generator(this, function (_a) {
451
- switch (_a.label) {
607
+ var getChatTokenOptionalParams, chatToken, chatId, token, regionGtms, expiresIn, visitorId, voiceVideoCallToken, error_8, exceptionDetails;
608
+ return __generator(this, function (_c) {
609
+ switch (_c.label) {
452
610
  case 0:
453
611
  this.scenarioMarker.startScenario(TelemetryEvent_1.default.GetChatToken, {
454
612
  RequestId: this.requestId
455
613
  });
456
614
  if (!!cached) return [3 /*break*/, 5];
457
- _a.label = 1;
615
+ _c.label = 1;
458
616
  case 1:
459
- _a.trys.push([1, 3, , 4]);
617
+ _c.trys.push([1, 3, , 4]);
460
618
  getChatTokenOptionalParams = {};
461
619
  if (this.authenticatedUserToken) {
462
620
  getChatTokenOptionalParams.authenticatedUserToken = this.authenticatedUserToken;
463
621
  }
622
+ if (this.isPersistentChat && !((_a = this.chatSDKConfig.persistentChat) === null || _a === void 0 ? void 0 : _a.disable)) {
623
+ getChatTokenOptionalParams.reconnectId = this.reconnectId;
624
+ }
625
+ if (this.isChatReconnect && !((_b = this.chatSDKConfig.chatReconnect) === null || _b === void 0 ? void 0 : _b.disable) && !this.isPersistentChat) {
626
+ getChatTokenOptionalParams.reconnectId = this.reconnectId;
627
+ }
464
628
  return [4 /*yield*/, this.OCClient.getChatToken(this.requestId, getChatTokenOptionalParams)];
465
629
  case 2:
466
- chatToken = _a.sent();
630
+ chatToken = _c.sent();
467
631
  chatId = chatToken.ChatId, token = chatToken.Token, regionGtms = chatToken.RegionGtms, expiresIn = chatToken.ExpiresIn, visitorId = chatToken.VisitorId, voiceVideoCallToken = chatToken.VoiceVideoCallToken;
468
632
  this.chatToken = {
469
633
  chatId: chatId,
@@ -480,7 +644,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
480
644
  });
481
645
  return [3 /*break*/, 4];
482
646
  case 3:
483
- error_6 = _a.sent();
647
+ error_8 = _c.sent();
484
648
  exceptionDetails = {
485
649
  response: "OCClientGetChatTokenFailed"
486
650
  };
@@ -489,7 +653,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
489
653
  ChatId: this.chatToken.chatId,
490
654
  ExceptionDetails: JSON.stringify(exceptionDetails),
491
655
  });
492
- console.error("OmnichannelChatSDK/getChatToken/error " + error_6);
656
+ console.error("OmnichannelChatSDK/getChatToken/error " + error_8);
493
657
  return [3 /*break*/, 4];
494
658
  case 4: return [3 /*break*/, 6];
495
659
  case 5:
@@ -497,7 +661,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
497
661
  RequestId: this.requestId,
498
662
  ChatId: this.chatToken.chatId
499
663
  });
500
- _a.label = 6;
664
+ _c.label = 6;
501
665
  case 6: return [2 /*return*/, this.chatToken];
502
666
  }
503
667
  });
@@ -561,7 +725,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
561
725
  deliveryMode: DeliveryMode_1.default.Bridged,
562
726
  messageType: MessageType_1.default.UserMessage,
563
727
  properties: undefined,
564
- tags: [],
728
+ tags: __spreadArrays(MessageTags_1.defaultMessageTags),
565
729
  sender: {
566
730
  displayName: "Customer",
567
731
  id: "customer",
@@ -592,14 +756,16 @@ var OmnichannelChatSDK = /** @class */ (function () {
592
756
  return [4 /*yield*/, this.getMessages()];
593
757
  case 1:
594
758
  messages = _c.sent();
595
- for (_i = 0, _b = messages.reverse(); _i < _b.length; _i++) {
596
- message = _b[_i];
597
- clientmessageid = message.clientmessageid;
598
- if (postedMessages.has(clientmessageid)) {
599
- continue;
759
+ if (messages) {
760
+ for (_i = 0, _b = messages.reverse(); _i < _b.length; _i++) {
761
+ message = _b[_i];
762
+ clientmessageid = message.clientmessageid;
763
+ if (postedMessages.has(clientmessageid)) {
764
+ continue;
765
+ }
766
+ postedMessages.add(clientmessageid);
767
+ onNewMessageCallback(message);
600
768
  }
601
- postedMessages.add(clientmessageid);
602
- onNewMessageCallback(message);
603
769
  }
604
770
  _c.label = 2;
605
771
  case 2:
@@ -624,7 +790,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
624
790
  };
625
791
  OmnichannelChatSDK.prototype.sendTypingEvent = function () {
626
792
  return __awaiter(this, void 0, void 0, function () {
627
- var typingPayload, members, botMembers, error_7;
793
+ var typingPayload, members, botMembers, error_9;
628
794
  return __generator(this, function (_a) {
629
795
  switch (_a.label) {
630
796
  case 0:
@@ -652,13 +818,13 @@ var OmnichannelChatSDK = /** @class */ (function () {
652
818
  });
653
819
  return [3 /*break*/, 6];
654
820
  case 5:
655
- error_7 = _a.sent();
821
+ error_9 = _a.sent();
656
822
  console.error("OmnichannelChatSDK/sendTypingEvent/error");
657
823
  this.scenarioMarker.failScenario(TelemetryEvent_1.default.SendTypingEvent, {
658
824
  RequestId: this.requestId,
659
825
  ChatId: this.chatToken.chatId
660
826
  });
661
- return [2 /*return*/, error_7];
827
+ return [2 /*return*/, error_9];
662
828
  case 6: return [2 /*return*/];
663
829
  }
664
830
  });
@@ -685,6 +851,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
685
851
  OmnichannelChatSDK.prototype.onAgentEndSession = function (onAgentEndSessionCallback) {
686
852
  var _a;
687
853
  return __awaiter(this, void 0, void 0, function () {
854
+ var _this = this;
688
855
  return __generator(this, function (_b) {
689
856
  this.scenarioMarker.startScenario(TelemetryEvent_1.default.OnAgentEndSession, {
690
857
  RequestId: this.requestId,
@@ -696,6 +863,10 @@ var OmnichannelChatSDK = /** @class */ (function () {
696
863
  // Agent ending conversation would have 1 member left in the chat thread
697
864
  if (members.length === 1) {
698
865
  onAgentEndSessionCallback(message);
866
+ if (_this.refreshTokenTimer !== null) {
867
+ clearInterval(_this.refreshTokenTimer);
868
+ _this.refreshTokenTimer = null;
869
+ }
699
870
  }
700
871
  });
701
872
  this.scenarioMarker.completeScenario(TelemetryEvent_1.default.OnAgentEndSession, {
@@ -715,7 +886,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
715
886
  };
716
887
  OmnichannelChatSDK.prototype.uploadFileAttachment = function (fileInfo) {
717
888
  return __awaiter(this, void 0, void 0, function () {
718
- var fileMetadata, messageToSend, error_8;
889
+ var fileMetadata, messageToSend, error_10;
719
890
  return __generator(this, function (_a) {
720
891
  switch (_a.label) {
721
892
  case 0:
@@ -739,7 +910,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
739
910
  contentType: MessageContentType_1.default.Text,
740
911
  deliveryMode: DeliveryMode_1.default.Bridged,
741
912
  messageType: MessageType_1.default.UserMessage,
742
- tags: [],
913
+ tags: __spreadArrays(MessageTags_1.defaultMessageTags),
743
914
  sender: {
744
915
  displayName: "Customer",
745
916
  id: "customer",
@@ -759,13 +930,13 @@ var OmnichannelChatSDK = /** @class */ (function () {
759
930
  });
760
931
  return [2 /*return*/, messageToSend];
761
932
  case 7:
762
- error_8 = _a.sent();
763
- console.error("OmnichannelChatSDK/uploadFileAttachment/error: " + error_8);
933
+ error_10 = _a.sent();
934
+ console.error("OmnichannelChatSDK/uploadFileAttachment/error: " + error_10);
764
935
  this.scenarioMarker.failScenario(TelemetryEvent_1.default.UploadFileAttachment, {
765
936
  RequestId: this.requestId,
766
937
  ChatId: this.chatToken.chatId
767
938
  });
768
- return [2 /*return*/, error_8];
939
+ return [2 /*return*/, error_10];
769
940
  case 8: return [2 /*return*/];
770
941
  }
771
942
  });
@@ -773,7 +944,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
773
944
  };
774
945
  OmnichannelChatSDK.prototype.downloadFileAttachment = function (fileMetadata) {
775
946
  return __awaiter(this, void 0, void 0, function () {
776
- var downloadedFile, error_9;
947
+ var downloadedFile, error_11;
777
948
  return __generator(this, function (_a) {
778
949
  switch (_a.label) {
779
950
  case 0:
@@ -793,8 +964,8 @@ var OmnichannelChatSDK = /** @class */ (function () {
793
964
  });
794
965
  return [2 /*return*/, downloadedFile];
795
966
  case 3:
796
- error_9 = _a.sent();
797
- console.error("OmnichannelChatSDK/downloadFileAttachment/error: " + error_9);
967
+ error_11 = _a.sent();
968
+ console.error("OmnichannelChatSDK/downloadFileAttachment/error: " + error_11);
798
969
  this.scenarioMarker.failScenario(TelemetryEvent_1.default.DownloadFileAttachment, {
799
970
  RequestId: this.requestId,
800
971
  ChatId: this.chatToken.chatId
@@ -906,6 +1077,9 @@ var OmnichannelChatSDK = /** @class */ (function () {
906
1077
  sdk: _this.IC3Client
907
1078
  };
908
1079
  var adapter = new window.Microsoft.BotFramework.WebChat.IC3Adapter(adapterConfig);
1080
+ adapter.logger = _this.ic3ClientLogger;
1081
+ // Keep iframe communication alive to reuse the same IC3Client instance
1082
+ window.Microsoft.BotFramework.WebChat.IC3SDKProvider.disposeSdk = function () { }; // eslint-disable-line @typescript-eslint/no-empty-function
909
1083
  _this.scenarioMarker.completeScenario(TelemetryEvent_1.default.CreateIC3Adapter);
910
1084
  resolve(adapter);
911
1085
  }, function () {
@@ -944,33 +1118,15 @@ var OmnichannelChatSDK = /** @class */ (function () {
944
1118
  result = msdyn_widgetsnippet.match(widgetSnippetSourceRegex);
945
1119
  if (result && result.length) {
946
1120
  return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
947
- var spoolSDKCDNUrl, LiveChatWidgetLibCDNUrl;
1121
+ var LiveChatWidgetLibCDNUrl;
948
1122
  var _this = this;
949
- var _a, _b;
950
- return __generator(this, function (_c) {
951
- switch (_c.label) {
1123
+ var _a;
1124
+ return __generator(this, function (_b) {
1125
+ switch (_b.label) {
952
1126
  case 0:
953
- spoolSDKCDNUrl = result[1] + "/livechatwidget/WebChatControl/lib/spool-sdk/sdk.bundle.js";
954
- (_a = this.telemetry) === null || _a === void 0 ? void 0 : _a.setCDNPackages({
955
- SpoolSDK: spoolSDKCDNUrl
956
- });
957
1127
  this.scenarioMarker.startScenario(TelemetryEvent_1.default.GetVoiceVideoCalling);
958
- return [4 /*yield*/, WebUtils_1.loadScript(spoolSDKCDNUrl, function () {
959
- /* istanbul ignore next */
960
- _this.debug && console.debug(spoolSDKCDNUrl + " loaded!");
961
- }, function () {
962
- var exceptionDetails = {
963
- response: "SpoolSDKLoadFailed"
964
- };
965
- _this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetVoiceVideoCalling, {
966
- ExceptionDetails: JSON.stringify(exceptionDetails)
967
- });
968
- reject('Failed to load SpoolSDK');
969
- })];
970
- case 1:
971
- _c.sent();
972
- LiveChatWidgetLibCDNUrl = result[1] + "/livechatwidget/WebChatControl/lib/LiveChatWidgetLibs.min.js";
973
- (_b = this.telemetry) === null || _b === void 0 ? void 0 : _b.setCDNPackages({
1128
+ LiveChatWidgetLibCDNUrl = result[1] + "/livechatwidget/WebChatControl/lib/CallingBundle.js";
1129
+ (_a = this.telemetry) === null || _a === void 0 ? void 0 : _a.setCDNPackages({
974
1130
  VoiceVideoCalling: LiveChatWidgetLibCDNUrl
975
1131
  });
976
1132
  return [4 /*yield*/, WebUtils_1.loadScript(LiveChatWidgetLibCDNUrl, function () { return __awaiter(_this, void 0, void 0, function () {
@@ -1001,8 +1157,8 @@ var OmnichannelChatSDK = /** @class */ (function () {
1001
1157
  return [2 /*return*/];
1002
1158
  });
1003
1159
  }); })];
1004
- case 2:
1005
- _c.sent();
1160
+ case 1:
1161
+ _b.sent();
1006
1162
  return [2 /*return*/];
1007
1163
  }
1008
1164
  });
@@ -1098,7 +1254,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
1098
1254
  };
1099
1255
  OmnichannelChatSDK.prototype.getChatConfig = function () {
1100
1256
  return __awaiter(this, void 0, void 0, function () {
1101
- var liveChatConfig, dataMaskingConfig, authSettings, liveWSAndLiveChatEngJoin, setting, preChatSurvey, msdyn_prechatenabled, msdyn_callingoptions, isPreChatEnabled, token, error_10;
1257
+ var liveChatConfig, dataMaskingConfig, authSettings, liveWSAndLiveChatEngJoin, setting, preChatSurvey, msdyn_prechatenabled, msdyn_callingoptions, msdyn_conversationmode, msdyn_enablechatreconnect, isPreChatEnabled, isChatReconnectEnabled, token, error_12;
1102
1258
  return __generator(this, function (_a) {
1103
1259
  switch (_a.label) {
1104
1260
  case 0:
@@ -1114,8 +1270,15 @@ var OmnichannelChatSDK = /** @class */ (function () {
1114
1270
  if (authSettings) {
1115
1271
  this.authSettings = authSettings;
1116
1272
  }
1117
- preChatSurvey = liveWSAndLiveChatEngJoin.PreChatSurvey, msdyn_prechatenabled = liveWSAndLiveChatEngJoin.msdyn_prechatenabled, msdyn_callingoptions = liveWSAndLiveChatEngJoin.msdyn_callingoptions;
1273
+ preChatSurvey = liveWSAndLiveChatEngJoin.PreChatSurvey, msdyn_prechatenabled = liveWSAndLiveChatEngJoin.msdyn_prechatenabled, msdyn_callingoptions = liveWSAndLiveChatEngJoin.msdyn_callingoptions, msdyn_conversationmode = liveWSAndLiveChatEngJoin.msdyn_conversationmode, msdyn_enablechatreconnect = liveWSAndLiveChatEngJoin.msdyn_enablechatreconnect;
1118
1274
  isPreChatEnabled = msdyn_prechatenabled === true || msdyn_prechatenabled == "true";
1275
+ isChatReconnectEnabled = msdyn_enablechatreconnect === true || msdyn_enablechatreconnect == "true";
1276
+ if ((msdyn_conversationmode === null || msdyn_conversationmode === void 0 ? void 0 : msdyn_conversationmode.toString()) === ConversationMode_1.default.PersistentChat.toString()) {
1277
+ this.isPersistentChat = true;
1278
+ }
1279
+ if (isChatReconnectEnabled && !this.isPersistentChat) {
1280
+ this.isChatReconnect = true;
1281
+ }
1119
1282
  if (isPreChatEnabled && preChatSurvey && preChatSurvey.trim().length > 0) {
1120
1283
  this.preChatSurvey = preChatSurvey;
1121
1284
  }
@@ -1144,9 +1307,9 @@ var OmnichannelChatSDK = /** @class */ (function () {
1144
1307
  this.liveChatConfig = liveChatConfig;
1145
1308
  return [2 /*return*/, this.liveChatConfig];
1146
1309
  case 5:
1147
- error_10 = _a.sent();
1148
- console.error("OmnichannelChatSDK/getChatConfig/error " + error_10);
1149
- return [2 /*return*/, error_10];
1310
+ error_12 = _a.sent();
1311
+ console.error("OmnichannelChatSDK/getChatConfig/error " + error_12);
1312
+ return [2 /*return*/, error_12];
1150
1313
  case 6: return [2 /*return*/];
1151
1314
  }
1152
1315
  });
@@ -1173,6 +1336,49 @@ var OmnichannelChatSDK = /** @class */ (function () {
1173
1336
  }
1174
1337
  return libraries_1.default.getIC3AdapterCDNUrl();
1175
1338
  };
1339
+ OmnichannelChatSDK.prototype.updateChatToken = function (newToken, newRegionGTMS) {
1340
+ return __awaiter(this, void 0, void 0, function () {
1341
+ var sessionInfo, error_13, exceptionDetails;
1342
+ return __generator(this, function (_a) {
1343
+ switch (_a.label) {
1344
+ case 0:
1345
+ this.scenarioMarker.startScenario(TelemetryEvent_1.default.UpdateChatToken, {
1346
+ RequestId: this.requestId,
1347
+ ChatId: this.chatToken.chatId
1348
+ });
1349
+ _a.label = 1;
1350
+ case 1:
1351
+ _a.trys.push([1, 3, , 4]);
1352
+ sessionInfo = {
1353
+ token: newToken,
1354
+ regionGtms: newRegionGTMS,
1355
+ visitor: true
1356
+ };
1357
+ return [4 /*yield*/, this.IC3Client.initialize(sessionInfo)];
1358
+ case 2:
1359
+ _a.sent();
1360
+ this.scenarioMarker.completeScenario(TelemetryEvent_1.default.UpdateChatToken, {
1361
+ RequestId: this.requestId,
1362
+ ChatId: this.chatToken.chatId
1363
+ });
1364
+ return [3 /*break*/, 4];
1365
+ case 3:
1366
+ error_13 = _a.sent();
1367
+ exceptionDetails = {
1368
+ response: "UpdateChatTokenFailed"
1369
+ };
1370
+ this.scenarioMarker.failScenario(TelemetryEvent_1.default.UpdateChatToken, {
1371
+ RequestId: this.requestId,
1372
+ ChatId: this.chatToken.chatId,
1373
+ ExceptionDetails: JSON.stringify(exceptionDetails)
1374
+ });
1375
+ console.error("OmnichannelChatSDK/updateChatToken/error " + error_13);
1376
+ return [3 /*break*/, 4];
1377
+ case 4: return [2 /*return*/];
1378
+ }
1379
+ });
1380
+ });
1381
+ };
1176
1382
  return OmnichannelChatSDK;
1177
1383
  }());
1178
1384
  exports.default = OmnichannelChatSDK;