@microsoft/omnichannel-chat-sdk 0.2.1-main.f5ff432 → 0.3.1-main.c474307

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.
@@ -47,31 +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
- var ConversationMode_1 = require("./core/ConversationMode");
75
83
  var OmnichannelChatSDK = /** @class */ (function () {
76
84
  function OmnichannelChatSDK(omnichannelConfig, chatSDKConfig) {
77
85
  if (chatSDKConfig === void 0) { chatSDKConfig = SDKConfigValidators_1.defaultChatSDKConfig; }
@@ -84,7 +92,9 @@ var OmnichannelChatSDK = /** @class */ (function () {
84
92
  this.ic3ClientLogger = null;
85
93
  this.ocSdkLogger = null;
86
94
  this.isPersistentChat = false;
95
+ this.isChatReconnect = false;
87
96
  this.reconnectId = null;
97
+ this.refreshTokenTimer = null;
88
98
  this.debug = false;
89
99
  this.omnichannelConfig = omnichannelConfig;
90
100
  this.chatSDKConfig = __assign(__assign({}, SDKConfigValidators_1.defaultChatSDKConfig), chatSDKConfig // overrides
@@ -160,44 +170,132 @@ var OmnichannelChatSDK = /** @class */ (function () {
160
170
  });
161
171
  });
162
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
+ };
163
257
  OmnichannelChatSDK.prototype.startChat = function (optionalParams) {
164
- var _a, _b, _c, _d;
258
+ var _a, _b, _c, _d, _e, _f, _g, _h;
165
259
  if (optionalParams === void 0) { optionalParams = {}; }
166
260
  return __awaiter(this, void 0, void 0, function () {
167
- var reconnectableChatsParams, reconnectableChatsResponse, _e, exceptionDetails, conversationDetails, exceptionDetails, exceptionDetails, sessionInitOptionalParams, error_1, exceptionDetails, error_2, exceptionDetails, _f, error_3, exceptionDetails;
168
- return __generator(this, function (_g) {
169
- switch (_g.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) {
170
265
  case 0:
171
266
  this.scenarioMarker.startScenario(TelemetryEvent_1.default.StartChat, {
172
267
  RequestId: this.requestId
173
268
  });
174
- if (!(this.isPersistentChat && !((_a = this.chatSDKConfig.persistentChat) === null || _a === void 0 ? void 0 : _a.disable))) return [3 /*break*/, 4];
175
- _g.label = 1;
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;
176
274
  case 1:
177
- _g.trys.push([1, 3, , 4]);
275
+ _l.trys.push([1, 3, , 4]);
178
276
  reconnectableChatsParams = {
179
277
  authenticatedUserToken: this.authenticatedUserToken
180
278
  };
181
279
  return [4 /*yield*/, this.OCClient.getReconnectableChats(reconnectableChatsParams)];
182
280
  case 2:
183
- reconnectableChatsResponse = _g.sent();
281
+ reconnectableChatsResponse = _l.sent();
184
282
  if (reconnectableChatsResponse && reconnectableChatsResponse.reconnectid) {
185
283
  this.reconnectId = reconnectableChatsResponse.reconnectid;
186
284
  }
187
285
  return [3 /*break*/, 4];
188
286
  case 3:
189
- _e = _g.sent();
287
+ _j = _l.sent();
190
288
  exceptionDetails = {
191
289
  response: "OCClientGetReconnectableChatsFailed"
192
290
  };
193
291
  throw Error(exceptionDetails.response);
194
292
  case 4:
195
- if (!(optionalParams.liveChatContext && !this.isPersistentChat)) return [3 /*break*/, 6];
293
+ if (!(optionalParams.liveChatContext && !this.isPersistentChat && !this.isChatReconnect)) return [3 /*break*/, 6];
196
294
  this.chatToken = optionalParams.liveChatContext.chatToken || {};
197
295
  this.requestId = optionalParams.liveChatContext.requestId || ocsdk_1.uuidv4();
198
296
  return [4 /*yield*/, this.getConversationDetails()];
199
297
  case 5:
200
- conversationDetails = _g.sent();
298
+ conversationDetails = _l.sent();
201
299
  if (Object.keys(conversationDetails).length === 0) {
202
300
  exceptionDetails = {
203
301
  response: "InvalidConversation"
@@ -222,20 +320,23 @@ var OmnichannelChatSDK = /** @class */ (function () {
222
320
  console.error("Unable to join conversation that's in '" + conversationDetails.state + "' state");
223
321
  throw Error(exceptionDetails.response);
224
322
  }
225
- _g.label = 6;
323
+ _l.label = 6;
226
324
  case 6:
227
325
  if (!(this.chatToken && Object.keys(this.chatToken).length === 0)) return [3 /*break*/, 8];
228
326
  return [4 /*yield*/, this.getChatToken(false)];
229
327
  case 7:
230
- _g.sent();
231
- _g.label = 8;
328
+ _l.sent();
329
+ _l.label = 8;
232
330
  case 8:
233
- (_b = this.ic3ClientLogger) === null || _b === void 0 ? void 0 : _b.setChatId(this.chatToken.chatId || '');
234
- (_c = this.ocSdkLogger) === null || _c === void 0 ? void 0 : _c.setChatId(this.chatToken.chatId || '');
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 || '');
235
333
  sessionInitOptionalParams = {
236
334
  initContext: {}
237
335
  };
238
- if (this.isPersistentChat && !((_d = this.chatSDKConfig.persistentChat) === null || _d === void 0 ? void 0 : _d.disable)) {
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) {
239
340
  sessionInitOptionalParams.reconnectId = this.reconnectId;
240
341
  }
241
342
  if (optionalParams.customContext) {
@@ -263,15 +364,15 @@ var OmnichannelChatSDK = /** @class */ (function () {
263
364
  if (this.authenticatedUserToken) {
264
365
  sessionInitOptionalParams.authenticatedUserToken = this.authenticatedUserToken;
265
366
  }
266
- _g.label = 9;
367
+ _l.label = 9;
267
368
  case 9:
268
- _g.trys.push([9, 11, , 12]);
369
+ _l.trys.push([9, 11, , 12]);
269
370
  return [4 /*yield*/, this.OCClient.sessionInit(this.requestId, sessionInitOptionalParams)];
270
371
  case 10:
271
- _g.sent();
372
+ _l.sent();
272
373
  return [3 /*break*/, 12];
273
374
  case 11:
274
- error_1 = _g.sent();
375
+ error_3 = _l.sent();
275
376
  exceptionDetails = {
276
377
  response: "OCClientSessionInitFailed"
277
378
  };
@@ -280,20 +381,20 @@ var OmnichannelChatSDK = /** @class */ (function () {
280
381
  ChatId: this.chatToken.chatId,
281
382
  ExceptionDetails: JSON.stringify(exceptionDetails)
282
383
  });
283
- console.error("OmnichannelChatSDK/startChat/sessionInit/error " + error_1);
284
- return [2 /*return*/, error_1];
384
+ console.error("OmnichannelChatSDK/startChat/sessionInit/error " + error_3);
385
+ return [2 /*return*/, error_3];
285
386
  case 12:
286
- _g.trys.push([12, 14, , 15]);
387
+ _l.trys.push([12, 14, , 15]);
287
388
  return [4 /*yield*/, this.IC3Client.initialize({
288
389
  token: this.chatToken.token,
289
390
  regionGtms: this.chatToken.regionGTMS,
290
391
  visitor: true
291
392
  })];
292
393
  case 13:
293
- _g.sent();
394
+ _l.sent();
294
395
  return [3 /*break*/, 15];
295
396
  case 14:
296
- error_2 = _g.sent();
397
+ error_4 = _l.sent();
297
398
  exceptionDetails = {
298
399
  response: "IC3ClientInitializeFailed"
299
400
  };
@@ -302,21 +403,21 @@ var OmnichannelChatSDK = /** @class */ (function () {
302
403
  ChatId: this.chatToken.chatId,
303
404
  ExceptionDetails: JSON.stringify(exceptionDetails)
304
405
  });
305
- console.error("OmnichannelChatSDK/startChat/initialize/error " + error_2);
306
- return [2 /*return*/, error_2];
406
+ console.error("OmnichannelChatSDK/startChat/initialize/error " + error_4);
407
+ return [2 /*return*/, error_4];
307
408
  case 15:
308
- _g.trys.push([15, 17, , 18]);
309
- _f = this;
409
+ _l.trys.push([15, 17, , 18]);
410
+ _k = this;
310
411
  return [4 /*yield*/, this.IC3Client.joinConversation(this.chatToken.chatId)];
311
412
  case 16:
312
- _f.conversation = _g.sent();
413
+ _k.conversation = _l.sent();
313
414
  this.scenarioMarker.completeScenario(TelemetryEvent_1.default.StartChat, {
314
415
  RequestId: this.requestId,
315
416
  ChatId: this.chatToken.chatId
316
417
  });
317
418
  return [3 /*break*/, 18];
318
419
  case 17:
319
- error_3 = _g.sent();
420
+ error_5 = _l.sent();
320
421
  exceptionDetails = {
321
422
  response: "IC3ClientJoinConversationFailed"
322
423
  };
@@ -325,19 +426,33 @@ var OmnichannelChatSDK = /** @class */ (function () {
325
426
  ChatId: this.chatToken.chatId,
326
427
  ExceptionDetails: JSON.stringify(exceptionDetails)
327
428
  });
328
- console.error("OmnichannelChatSDK/startChat/joinConversation/error " + error_3);
329
- return [2 /*return*/, error_3];
330
- case 18: 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*/];
331
446
  }
332
447
  });
333
448
  });
334
449
  };
335
450
  OmnichannelChatSDK.prototype.endChat = function () {
336
- var _a, _b, _c, _d, _e;
451
+ var _a, _b, _c, _d, _e, _f;
337
452
  return __awaiter(this, void 0, void 0, function () {
338
- var sessionCloseOptionalParams, isReconnectChat, error_4, exceptionDetails;
339
- return __generator(this, function (_f) {
340
- switch (_f.label) {
453
+ var sessionCloseOptionalParams, isReconnectChat, isChatReconnect, error_6, exceptionDetails;
454
+ return __generator(this, function (_g) {
455
+ switch (_g.label) {
341
456
  case 0:
342
457
  this.scenarioMarker.startScenario(TelemetryEvent_1.default.EndChat, {
343
458
  RequestId: this.requestId,
@@ -349,15 +464,19 @@ var OmnichannelChatSDK = /** @class */ (function () {
349
464
  sessionCloseOptionalParams.isPersistentChat = this.isPersistentChat;
350
465
  sessionCloseOptionalParams.isReconnectChat = isReconnectChat;
351
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
+ }
352
471
  if (this.authenticatedUserToken) {
353
472
  sessionCloseOptionalParams.authenticatedUserToken = this.authenticatedUserToken;
354
473
  }
355
- _f.label = 1;
474
+ _g.label = 1;
356
475
  case 1:
357
- _f.trys.push([1, 3, , 4]);
476
+ _g.trys.push([1, 3, , 4]);
358
477
  return [4 /*yield*/, this.OCClient.sessionClose(this.requestId, sessionCloseOptionalParams)];
359
478
  case 2:
360
- _f.sent();
479
+ _g.sent();
361
480
  this.scenarioMarker.completeScenario(TelemetryEvent_1.default.EndChat, {
362
481
  RequestId: this.requestId,
363
482
  ChatId: this.chatToken.chatId
@@ -366,13 +485,14 @@ var OmnichannelChatSDK = /** @class */ (function () {
366
485
  this.conversation = null;
367
486
  this.requestId = ocsdk_1.uuidv4();
368
487
  this.chatToken = {};
369
- (_b = this.ic3ClientLogger) === null || _b === void 0 ? void 0 : _b.setRequestId(this.requestId);
370
- (_c = this.ic3ClientLogger) === null || _c === void 0 ? void 0 : _c.setChatId('');
371
- (_d = this.ocSdkLogger) === null || _d === void 0 ? void 0 : _d.setRequestId(this.requestId);
372
- (_e = this.ocSdkLogger) === null || _e === void 0 ? void 0 : _e.setChatId('');
488
+ this.reconnectId = null;
489
+ (_c = this.ic3ClientLogger) === null || _c === void 0 ? void 0 : _c.setRequestId(this.requestId);
490
+ (_d = this.ic3ClientLogger) === null || _d === void 0 ? void 0 : _d.setChatId('');
491
+ (_e = this.ocSdkLogger) === null || _e === void 0 ? void 0 : _e.setRequestId(this.requestId);
492
+ (_f = this.ocSdkLogger) === null || _f === void 0 ? void 0 : _f.setChatId('');
373
493
  return [3 /*break*/, 4];
374
494
  case 3:
375
- error_4 = _f.sent();
495
+ error_6 = _g.sent();
376
496
  exceptionDetails = {
377
497
  response: "OCClientSessionCloseFailed"
378
498
  };
@@ -381,9 +501,14 @@ var OmnichannelChatSDK = /** @class */ (function () {
381
501
  ChatId: this.chatToken.chatId,
382
502
  ExceptionDetails: JSON.stringify(exceptionDetails),
383
503
  });
384
- console.error("OmnichannelChatSDK/endChat/error " + error_4);
385
- return [2 /*return*/, error_4];
386
- 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*/];
387
512
  }
388
513
  });
389
514
  });
@@ -412,7 +537,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
412
537
  OmnichannelChatSDK.prototype.getConversationDetails = function () {
413
538
  var _a, _b;
414
539
  return __awaiter(this, void 0, void 0, function () {
415
- var lwiDetails, state, conversationId, agentAcceptedOn, liveWorkItemDetails, error_5;
540
+ var lwiDetails, state, conversationId, agentAcceptedOn, liveWorkItemDetails, error_7;
416
541
  return __generator(this, function (_c) {
417
542
  switch (_c.label) {
418
543
  case 0:
@@ -440,12 +565,12 @@ var OmnichannelChatSDK = /** @class */ (function () {
440
565
  });
441
566
  return [2 /*return*/, liveWorkItemDetails];
442
567
  case 3:
443
- error_5 = _c.sent();
568
+ error_7 = _c.sent();
444
569
  this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetConversationDetails, {
445
570
  RequestId: this.requestId,
446
571
  ChatId: this.chatToken.chatId || '',
447
572
  });
448
- console.error("OmnichannelChatSDK/getConversationDetails/error " + error_5);
573
+ console.error("OmnichannelChatSDK/getConversationDetails/error " + error_7);
449
574
  return [3 /*break*/, 4];
450
575
  case 4: return [2 /*return*/, {}];
451
576
  }
@@ -476,20 +601,20 @@ var OmnichannelChatSDK = /** @class */ (function () {
476
601
  });
477
602
  };
478
603
  OmnichannelChatSDK.prototype.getChatToken = function (cached) {
479
- var _a;
604
+ var _a, _b;
480
605
  if (cached === void 0) { cached = true; }
481
606
  return __awaiter(this, void 0, void 0, function () {
482
- var getChatTokenOptionalParams, chatToken, chatId, token, regionGtms, expiresIn, visitorId, voiceVideoCallToken, error_6, exceptionDetails;
483
- return __generator(this, function (_b) {
484
- switch (_b.label) {
607
+ var getChatTokenOptionalParams, chatToken, chatId, token, regionGtms, expiresIn, visitorId, voiceVideoCallToken, error_8, exceptionDetails;
608
+ return __generator(this, function (_c) {
609
+ switch (_c.label) {
485
610
  case 0:
486
611
  this.scenarioMarker.startScenario(TelemetryEvent_1.default.GetChatToken, {
487
612
  RequestId: this.requestId
488
613
  });
489
614
  if (!!cached) return [3 /*break*/, 5];
490
- _b.label = 1;
615
+ _c.label = 1;
491
616
  case 1:
492
- _b.trys.push([1, 3, , 4]);
617
+ _c.trys.push([1, 3, , 4]);
493
618
  getChatTokenOptionalParams = {};
494
619
  if (this.authenticatedUserToken) {
495
620
  getChatTokenOptionalParams.authenticatedUserToken = this.authenticatedUserToken;
@@ -497,9 +622,12 @@ var OmnichannelChatSDK = /** @class */ (function () {
497
622
  if (this.isPersistentChat && !((_a = this.chatSDKConfig.persistentChat) === null || _a === void 0 ? void 0 : _a.disable)) {
498
623
  getChatTokenOptionalParams.reconnectId = this.reconnectId;
499
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
+ }
500
628
  return [4 /*yield*/, this.OCClient.getChatToken(this.requestId, getChatTokenOptionalParams)];
501
629
  case 2:
502
- chatToken = _b.sent();
630
+ chatToken = _c.sent();
503
631
  chatId = chatToken.ChatId, token = chatToken.Token, regionGtms = chatToken.RegionGtms, expiresIn = chatToken.ExpiresIn, visitorId = chatToken.VisitorId, voiceVideoCallToken = chatToken.VoiceVideoCallToken;
504
632
  this.chatToken = {
505
633
  chatId: chatId,
@@ -516,7 +644,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
516
644
  });
517
645
  return [3 /*break*/, 4];
518
646
  case 3:
519
- error_6 = _b.sent();
647
+ error_8 = _c.sent();
520
648
  exceptionDetails = {
521
649
  response: "OCClientGetChatTokenFailed"
522
650
  };
@@ -525,7 +653,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
525
653
  ChatId: this.chatToken.chatId,
526
654
  ExceptionDetails: JSON.stringify(exceptionDetails),
527
655
  });
528
- console.error("OmnichannelChatSDK/getChatToken/error " + error_6);
656
+ console.error("OmnichannelChatSDK/getChatToken/error " + error_8);
529
657
  return [3 /*break*/, 4];
530
658
  case 4: return [3 /*break*/, 6];
531
659
  case 5:
@@ -533,7 +661,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
533
661
  RequestId: this.requestId,
534
662
  ChatId: this.chatToken.chatId
535
663
  });
536
- _b.label = 6;
664
+ _c.label = 6;
537
665
  case 6: return [2 /*return*/, this.chatToken];
538
666
  }
539
667
  });
@@ -597,7 +725,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
597
725
  deliveryMode: DeliveryMode_1.default.Bridged,
598
726
  messageType: MessageType_1.default.UserMessage,
599
727
  properties: undefined,
600
- tags: [],
728
+ tags: __spreadArrays(MessageTags_1.defaultMessageTags),
601
729
  sender: {
602
730
  displayName: "Customer",
603
731
  id: "customer",
@@ -628,14 +756,16 @@ var OmnichannelChatSDK = /** @class */ (function () {
628
756
  return [4 /*yield*/, this.getMessages()];
629
757
  case 1:
630
758
  messages = _c.sent();
631
- for (_i = 0, _b = messages.reverse(); _i < _b.length; _i++) {
632
- message = _b[_i];
633
- clientmessageid = message.clientmessageid;
634
- if (postedMessages.has(clientmessageid)) {
635
- 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);
636
768
  }
637
- postedMessages.add(clientmessageid);
638
- onNewMessageCallback(message);
639
769
  }
640
770
  _c.label = 2;
641
771
  case 2:
@@ -660,7 +790,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
660
790
  };
661
791
  OmnichannelChatSDK.prototype.sendTypingEvent = function () {
662
792
  return __awaiter(this, void 0, void 0, function () {
663
- var typingPayload, members, botMembers, error_7;
793
+ var typingPayload, members, botMembers, error_9;
664
794
  return __generator(this, function (_a) {
665
795
  switch (_a.label) {
666
796
  case 0:
@@ -688,13 +818,13 @@ var OmnichannelChatSDK = /** @class */ (function () {
688
818
  });
689
819
  return [3 /*break*/, 6];
690
820
  case 5:
691
- error_7 = _a.sent();
821
+ error_9 = _a.sent();
692
822
  console.error("OmnichannelChatSDK/sendTypingEvent/error");
693
823
  this.scenarioMarker.failScenario(TelemetryEvent_1.default.SendTypingEvent, {
694
824
  RequestId: this.requestId,
695
825
  ChatId: this.chatToken.chatId
696
826
  });
697
- return [2 /*return*/, error_7];
827
+ return [2 /*return*/, error_9];
698
828
  case 6: return [2 /*return*/];
699
829
  }
700
830
  });
@@ -721,6 +851,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
721
851
  OmnichannelChatSDK.prototype.onAgentEndSession = function (onAgentEndSessionCallback) {
722
852
  var _a;
723
853
  return __awaiter(this, void 0, void 0, function () {
854
+ var _this = this;
724
855
  return __generator(this, function (_b) {
725
856
  this.scenarioMarker.startScenario(TelemetryEvent_1.default.OnAgentEndSession, {
726
857
  RequestId: this.requestId,
@@ -732,6 +863,10 @@ var OmnichannelChatSDK = /** @class */ (function () {
732
863
  // Agent ending conversation would have 1 member left in the chat thread
733
864
  if (members.length === 1) {
734
865
  onAgentEndSessionCallback(message);
866
+ if (_this.refreshTokenTimer !== null) {
867
+ clearInterval(_this.refreshTokenTimer);
868
+ _this.refreshTokenTimer = null;
869
+ }
735
870
  }
736
871
  });
737
872
  this.scenarioMarker.completeScenario(TelemetryEvent_1.default.OnAgentEndSession, {
@@ -751,7 +886,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
751
886
  };
752
887
  OmnichannelChatSDK.prototype.uploadFileAttachment = function (fileInfo) {
753
888
  return __awaiter(this, void 0, void 0, function () {
754
- var fileMetadata, messageToSend, error_8;
889
+ var fileMetadata, messageToSend, error_10;
755
890
  return __generator(this, function (_a) {
756
891
  switch (_a.label) {
757
892
  case 0:
@@ -775,7 +910,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
775
910
  contentType: MessageContentType_1.default.Text,
776
911
  deliveryMode: DeliveryMode_1.default.Bridged,
777
912
  messageType: MessageType_1.default.UserMessage,
778
- tags: [],
913
+ tags: __spreadArrays(MessageTags_1.defaultMessageTags),
779
914
  sender: {
780
915
  displayName: "Customer",
781
916
  id: "customer",
@@ -795,13 +930,13 @@ var OmnichannelChatSDK = /** @class */ (function () {
795
930
  });
796
931
  return [2 /*return*/, messageToSend];
797
932
  case 7:
798
- error_8 = _a.sent();
799
- console.error("OmnichannelChatSDK/uploadFileAttachment/error: " + error_8);
933
+ error_10 = _a.sent();
934
+ console.error("OmnichannelChatSDK/uploadFileAttachment/error: " + error_10);
800
935
  this.scenarioMarker.failScenario(TelemetryEvent_1.default.UploadFileAttachment, {
801
936
  RequestId: this.requestId,
802
937
  ChatId: this.chatToken.chatId
803
938
  });
804
- return [2 /*return*/, error_8];
939
+ return [2 /*return*/, error_10];
805
940
  case 8: return [2 /*return*/];
806
941
  }
807
942
  });
@@ -809,7 +944,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
809
944
  };
810
945
  OmnichannelChatSDK.prototype.downloadFileAttachment = function (fileMetadata) {
811
946
  return __awaiter(this, void 0, void 0, function () {
812
- var downloadedFile, error_9;
947
+ var downloadedFile, error_11;
813
948
  return __generator(this, function (_a) {
814
949
  switch (_a.label) {
815
950
  case 0:
@@ -829,8 +964,8 @@ var OmnichannelChatSDK = /** @class */ (function () {
829
964
  });
830
965
  return [2 /*return*/, downloadedFile];
831
966
  case 3:
832
- error_9 = _a.sent();
833
- console.error("OmnichannelChatSDK/downloadFileAttachment/error: " + error_9);
967
+ error_11 = _a.sent();
968
+ console.error("OmnichannelChatSDK/downloadFileAttachment/error: " + error_11);
834
969
  this.scenarioMarker.failScenario(TelemetryEvent_1.default.DownloadFileAttachment, {
835
970
  RequestId: this.requestId,
836
971
  ChatId: this.chatToken.chatId
@@ -942,6 +1077,9 @@ var OmnichannelChatSDK = /** @class */ (function () {
942
1077
  sdk: _this.IC3Client
943
1078
  };
944
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
945
1083
  _this.scenarioMarker.completeScenario(TelemetryEvent_1.default.CreateIC3Adapter);
946
1084
  resolve(adapter);
947
1085
  }, function () {
@@ -1134,7 +1272,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
1134
1272
  };
1135
1273
  OmnichannelChatSDK.prototype.getChatConfig = function () {
1136
1274
  return __awaiter(this, void 0, void 0, function () {
1137
- var liveChatConfig, dataMaskingConfig, authSettings, liveWSAndLiveChatEngJoin, setting, preChatSurvey, msdyn_prechatenabled, msdyn_callingoptions, msdyn_conversationmode, isPreChatEnabled, token, error_10;
1275
+ var liveChatConfig, dataMaskingConfig, authSettings, liveWSAndLiveChatEngJoin, setting, preChatSurvey, msdyn_prechatenabled, msdyn_callingoptions, msdyn_conversationmode, msdyn_enablechatreconnect, isPreChatEnabled, isChatReconnectEnabled, token, error_12;
1138
1276
  return __generator(this, function (_a) {
1139
1277
  switch (_a.label) {
1140
1278
  case 0:
@@ -1150,11 +1288,15 @@ var OmnichannelChatSDK = /** @class */ (function () {
1150
1288
  if (authSettings) {
1151
1289
  this.authSettings = authSettings;
1152
1290
  }
1153
- preChatSurvey = liveWSAndLiveChatEngJoin.PreChatSurvey, msdyn_prechatenabled = liveWSAndLiveChatEngJoin.msdyn_prechatenabled, msdyn_callingoptions = liveWSAndLiveChatEngJoin.msdyn_callingoptions, msdyn_conversationmode = liveWSAndLiveChatEngJoin.msdyn_conversationmode;
1291
+ preChatSurvey = liveWSAndLiveChatEngJoin.PreChatSurvey, msdyn_prechatenabled = liveWSAndLiveChatEngJoin.msdyn_prechatenabled, msdyn_callingoptions = liveWSAndLiveChatEngJoin.msdyn_callingoptions, msdyn_conversationmode = liveWSAndLiveChatEngJoin.msdyn_conversationmode, msdyn_enablechatreconnect = liveWSAndLiveChatEngJoin.msdyn_enablechatreconnect;
1154
1292
  isPreChatEnabled = msdyn_prechatenabled === true || msdyn_prechatenabled == "true";
1293
+ isChatReconnectEnabled = msdyn_enablechatreconnect === true || msdyn_enablechatreconnect == "true";
1155
1294
  if ((msdyn_conversationmode === null || msdyn_conversationmode === void 0 ? void 0 : msdyn_conversationmode.toString()) === ConversationMode_1.default.PersistentChat.toString()) {
1156
1295
  this.isPersistentChat = true;
1157
1296
  }
1297
+ if (isChatReconnectEnabled && !this.isPersistentChat) {
1298
+ this.isChatReconnect = true;
1299
+ }
1158
1300
  if (isPreChatEnabled && preChatSurvey && preChatSurvey.trim().length > 0) {
1159
1301
  this.preChatSurvey = preChatSurvey;
1160
1302
  }
@@ -1183,9 +1325,9 @@ var OmnichannelChatSDK = /** @class */ (function () {
1183
1325
  this.liveChatConfig = liveChatConfig;
1184
1326
  return [2 /*return*/, this.liveChatConfig];
1185
1327
  case 5:
1186
- error_10 = _a.sent();
1187
- console.error("OmnichannelChatSDK/getChatConfig/error " + error_10);
1188
- return [2 /*return*/, error_10];
1328
+ error_12 = _a.sent();
1329
+ console.error("OmnichannelChatSDK/getChatConfig/error " + error_12);
1330
+ return [2 /*return*/, error_12];
1189
1331
  case 6: return [2 /*return*/];
1190
1332
  }
1191
1333
  });
@@ -1212,6 +1354,49 @@ var OmnichannelChatSDK = /** @class */ (function () {
1212
1354
  }
1213
1355
  return libraries_1.default.getIC3AdapterCDNUrl();
1214
1356
  };
1357
+ OmnichannelChatSDK.prototype.updateChatToken = function (newToken, newRegionGTMS) {
1358
+ return __awaiter(this, void 0, void 0, function () {
1359
+ var sessionInfo, error_13, exceptionDetails;
1360
+ return __generator(this, function (_a) {
1361
+ switch (_a.label) {
1362
+ case 0:
1363
+ this.scenarioMarker.startScenario(TelemetryEvent_1.default.UpdateChatToken, {
1364
+ RequestId: this.requestId,
1365
+ ChatId: this.chatToken.chatId
1366
+ });
1367
+ _a.label = 1;
1368
+ case 1:
1369
+ _a.trys.push([1, 3, , 4]);
1370
+ sessionInfo = {
1371
+ token: newToken,
1372
+ regionGtms: newRegionGTMS,
1373
+ visitor: true
1374
+ };
1375
+ return [4 /*yield*/, this.IC3Client.initialize(sessionInfo)];
1376
+ case 2:
1377
+ _a.sent();
1378
+ this.scenarioMarker.completeScenario(TelemetryEvent_1.default.UpdateChatToken, {
1379
+ RequestId: this.requestId,
1380
+ ChatId: this.chatToken.chatId
1381
+ });
1382
+ return [3 /*break*/, 4];
1383
+ case 3:
1384
+ error_13 = _a.sent();
1385
+ exceptionDetails = {
1386
+ response: "UpdateChatTokenFailed"
1387
+ };
1388
+ this.scenarioMarker.failScenario(TelemetryEvent_1.default.UpdateChatToken, {
1389
+ RequestId: this.requestId,
1390
+ ChatId: this.chatToken.chatId,
1391
+ ExceptionDetails: JSON.stringify(exceptionDetails)
1392
+ });
1393
+ console.error("OmnichannelChatSDK/updateChatToken/error " + error_13);
1394
+ return [3 /*break*/, 4];
1395
+ case 4: return [2 /*return*/];
1396
+ }
1397
+ });
1398
+ });
1399
+ };
1215
1400
  return OmnichannelChatSDK;
1216
1401
  }());
1217
1402
  exports.default = OmnichannelChatSDK;