@microsoft/omnichannel-chat-sdk 1.0.1-main.24821cd → 1.0.1-main.2b06a3d
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.
- package/CHANGELOG.md +17 -3
- package/README.md +41 -20
- package/lib/OmnichannelChatSDK.d.ts +5 -4
- package/lib/OmnichannelChatSDK.js +238 -266
- package/lib/OmnichannelChatSDK.js.map +1 -1
- package/lib/config/settings.d.ts +1 -1
- package/lib/config/settings.js +1 -1
- package/lib/config/settings.js.map +1 -1
- package/lib/core/ChatConfig.d.ts +3 -0
- package/lib/core/ChatSDKExceptionDetails.d.ts +5 -0
- package/lib/core/ChatSDKExceptionDetails.js +3 -0
- package/lib/core/ChatSDKExceptionDetails.js.map +1 -0
- package/lib/core/OmnichannelErrorCodes.d.ts +4 -0
- package/lib/core/OmnichannelErrorCodes.js +8 -0
- package/lib/core/OmnichannelErrorCodes.js.map +1 -0
- package/lib/core/messaging/ACSClient.js +1 -1
- package/lib/core/messaging/ACSClient.js.map +1 -1
- package/lib/core/messaging/ChatAdapterOptionalParams.d.ts +14 -0
- package/lib/core/messaging/ChatAdapterOptionalParams.js +3 -0
- package/lib/core/messaging/ChatAdapterOptionalParams.js.map +1 -0
- package/lib/external/ACSAdapter/createFormatEgressTagsMiddleware.d.ts +2 -0
- package/lib/external/ACSAdapter/createFormatEgressTagsMiddleware.js +31 -0
- package/lib/external/ACSAdapter/createFormatEgressTagsMiddleware.js.map +1 -0
- package/lib/external/ACSAdapter/createFormatIngressTagsMiddleware.d.ts +2 -0
- package/lib/external/ACSAdapter/createFormatIngressTagsMiddleware.js +25 -0
- package/lib/external/ACSAdapter/createFormatIngressTagsMiddleware.js.map +1 -0
- package/lib/external/IC3Adapter/IIC3AdapterOptions.d.ts +12 -0
- package/lib/telemetry/AriaTelemetry.js +5 -0
- package/lib/telemetry/AriaTelemetry.js.map +1 -1
- package/lib/telemetry/ScenarioMarker.d.ts +2 -0
- package/lib/telemetry/ScenarioMarker.js +7 -3
- package/lib/telemetry/ScenarioMarker.js.map +1 -1
- package/lib/telemetry/TelemetryEvent.d.ts +1 -3
- package/lib/telemetry/TelemetryEvent.js +0 -2
- package/lib/telemetry/TelemetryEvent.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +839 -1089
- package/lib/utils/WebUtils.d.ts +3 -1
- package/lib/utils/WebUtils.js +8 -2
- package/lib/utils/WebUtils.js.map +1 -1
- package/lib/utils/libraries.d.ts +1 -3
- package/lib/utils/libraries.js +2 -11
- package/lib/utils/libraries.js.map +1 -1
- package/lib/utils/locale.d.ts +1 -0
- package/lib/utils/locale.js +2 -1
- package/lib/utils/locale.js.map +1 -1
- package/lib/utils/loggers.d.ts +8 -0
- package/lib/utils/loggers.js +24 -0
- package/lib/utils/loggers.js.map +1 -1
- package/package.json +2 -2
@@ -58,7 +58,6 @@ 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 libraries_1 = require("./utils/libraries");
|
62
61
|
var platform_1 = require("./utils/platform");
|
63
62
|
var SDKConfigValidators_1 = require("./validators/SDKConfigValidators");
|
64
63
|
var ACSParticipantDisplayName_1 = require("./core/messaging/ACSParticipantDisplayName");
|
@@ -66,6 +65,8 @@ var AMSFileManager_1 = require("./external/ACSAdapter/AMSFileManager");
|
|
66
65
|
var CallingOptionsOptionSetNumber_1 = require("./core/CallingOptionsOptionSetNumber");
|
67
66
|
var ChatAdapterProtocols_1 = require("./core/messaging/ChatAdapterProtocols");
|
68
67
|
var ConversationMode_1 = require("./core/ConversationMode");
|
68
|
+
var createFormatEgressTagsMiddleware_1 = require("./external/ACSAdapter/createFormatEgressTagsMiddleware");
|
69
|
+
var createFormatIngressTagsMiddleware_1 = require("./external/ACSAdapter/createFormatIngressTagsMiddleware");
|
69
70
|
var DeliveryMode_1 = require("@microsoft/omnichannel-ic3core/lib/model/DeliveryMode");
|
70
71
|
var FileSharingProtocolType_1 = require("@microsoft/omnichannel-ic3core/lib/model/FileSharingProtocolType");
|
71
72
|
var HostType_1 = require("@microsoft/omnichannel-ic3core/lib/interfaces/HostType");
|
@@ -74,6 +75,7 @@ var LiveChatVersion_1 = require("./core/LiveChatVersion");
|
|
74
75
|
var LiveWorkItemState_1 = require("./core/LiveWorkItemState");
|
75
76
|
var MessageContentType_1 = require("@microsoft/omnichannel-ic3core/lib/model/MessageContentType");
|
76
77
|
var MessageType_1 = require("@microsoft/omnichannel-ic3core/lib/model/MessageType");
|
78
|
+
var OmnichannelErrorCodes_1 = require("./core/OmnichannelErrorCodes");
|
77
79
|
var PersonType_1 = require("@microsoft/omnichannel-ic3core/lib/model/PersonType");
|
78
80
|
var ProtocoleType_1 = require("@microsoft/omnichannel-ic3core/lib/interfaces/ProtocoleType");
|
79
81
|
var ScenarioMarker_1 = require("./telemetry/ScenarioMarker");
|
@@ -85,6 +87,7 @@ var createVoiceVideoCalling_1 = require("./api/createVoiceVideoCalling");
|
|
85
87
|
var MessageTags_1 = require("./core/messaging/MessageTags");
|
86
88
|
var locale_1 = require("./utils/locale");
|
87
89
|
var utilities_1 = require("./utils/utilities");
|
90
|
+
var libraries_1 = require("./utils/libraries");
|
88
91
|
var WebUtils_1 = require("./utils/WebUtils");
|
89
92
|
var OmnichannelConfigValidator_1 = require("./validators/OmnichannelConfigValidator");
|
90
93
|
var OmnichannelChatSDK = /** @class */ (function () {
|
@@ -107,11 +110,13 @@ var OmnichannelChatSDK = /** @class */ (function () {
|
|
107
110
|
this.reconnectId = null;
|
108
111
|
this.refreshTokenTimer = null;
|
109
112
|
this.debug = false;
|
113
|
+
this.runtimeId = ocsdk_1.uuidv4();
|
110
114
|
this.omnichannelConfig = omnichannelConfig;
|
111
115
|
this.chatSDKConfig = __assign(__assign({}, SDKConfigValidators_1.defaultChatSDKConfig), chatSDKConfig // overrides
|
112
116
|
);
|
113
117
|
this.isInitialized = false;
|
114
118
|
this.liveChatVersion = LiveChatVersion_1.default.V1;
|
119
|
+
this.localeId = locale_1.defaultLocaleId;
|
115
120
|
this.requestId = ocsdk_1.uuidv4();
|
116
121
|
this.chatToken = {};
|
117
122
|
this.liveChatConfig = {};
|
@@ -129,6 +134,11 @@ var OmnichannelChatSDK = /** @class */ (function () {
|
|
129
134
|
this.ocSdkLogger.useTelemetry(this.telemetry);
|
130
135
|
this.acsClientLogger.useTelemetry(this.telemetry);
|
131
136
|
this.acsAdapterLogger.useTelemetry(this.telemetry);
|
137
|
+
this.scenarioMarker.setRuntimeId(this.runtimeId);
|
138
|
+
this.ic3ClientLogger.setRuntimeId(this.runtimeId);
|
139
|
+
this.ocSdkLogger.setRuntimeId(this.runtimeId);
|
140
|
+
this.acsClientLogger.setRuntimeId(this.runtimeId);
|
141
|
+
this.acsAdapterLogger.setRuntimeId(this.runtimeId);
|
132
142
|
OmnichannelConfigValidator_1.default(omnichannelConfig);
|
133
143
|
SDKConfigValidators_1.default(chatSDKConfig);
|
134
144
|
((_a = this.chatSDKConfig.telemetry) === null || _a === void 0 ? void 0 : _a.disable) && ((_b = this.telemetry) === null || _b === void 0 ? void 0 : _b.disable());
|
@@ -289,47 +299,55 @@ var OmnichannelChatSDK = /** @class */ (function () {
|
|
289
299
|
});
|
290
300
|
};
|
291
301
|
OmnichannelChatSDK.prototype.startChat = function (optionalParams) {
|
292
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
|
302
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
|
293
303
|
if (optionalParams === void 0) { optionalParams = {}; }
|
294
304
|
return __awaiter(this, void 0, void 0, function () {
|
295
|
-
var reconnectableChatsParams, reconnectableChatsResponse,
|
305
|
+
var shouldReinitIC3Client, _s, reconnectableChatsParams, reconnectableChatsResponse, _t, exceptionDetails, conversationDetails, exceptionDetails, exceptionDetails, sessionInitOptionalParams, error_3, exceptionDetails, chatAdapterConfig, error_4, exceptionDetails, _u, error_5, exceptionDetails, error_6, exceptionDetails, error_7, exceptionDetails, _v, error_8, exceptionDetails;
|
296
306
|
var _this = this;
|
297
|
-
return __generator(this, function (
|
298
|
-
switch (
|
307
|
+
return __generator(this, function (_w) {
|
308
|
+
switch (_w.label) {
|
299
309
|
case 0:
|
300
310
|
this.scenarioMarker.startScenario(TelemetryEvent_1.default.StartChat, {
|
301
311
|
RequestId: this.requestId
|
302
312
|
});
|
313
|
+
shouldReinitIC3Client = !platform_1.default.isNode() && !platform_1.default.isReactNative() && !this.IC3Client && this.liveChatVersion === LiveChatVersion_1.default.V1;
|
314
|
+
if (!shouldReinitIC3Client) return [3 /*break*/, 2];
|
315
|
+
_s = this;
|
316
|
+
return [4 /*yield*/, this.getIC3Client()];
|
317
|
+
case 1:
|
318
|
+
_s.IC3Client = _w.sent();
|
319
|
+
_w.label = 2;
|
320
|
+
case 2:
|
303
321
|
if (this.isChatReconnect && !((_a = this.chatSDKConfig.chatReconnect) === null || _a === void 0 ? void 0 : _a.disable) && !this.isPersistentChat && optionalParams.reconnectId) {
|
304
322
|
this.reconnectId = optionalParams.reconnectId;
|
305
323
|
}
|
306
|
-
if (!(this.isPersistentChat && !((_b = this.chatSDKConfig.persistentChat) === null || _b === void 0 ? void 0 : _b.disable))) return [3 /*break*/,
|
307
|
-
|
308
|
-
case
|
309
|
-
|
324
|
+
if (!(this.isPersistentChat && !((_b = this.chatSDKConfig.persistentChat) === null || _b === void 0 ? void 0 : _b.disable))) return [3 /*break*/, 6];
|
325
|
+
_w.label = 3;
|
326
|
+
case 3:
|
327
|
+
_w.trys.push([3, 5, , 6]);
|
310
328
|
reconnectableChatsParams = {
|
311
329
|
authenticatedUserToken: this.authenticatedUserToken
|
312
330
|
};
|
313
331
|
return [4 /*yield*/, this.OCClient.getReconnectableChats(reconnectableChatsParams)];
|
314
|
-
case
|
315
|
-
reconnectableChatsResponse =
|
332
|
+
case 4:
|
333
|
+
reconnectableChatsResponse = _w.sent();
|
316
334
|
if (reconnectableChatsResponse && reconnectableChatsResponse.reconnectid) {
|
317
335
|
this.reconnectId = reconnectableChatsResponse.reconnectid;
|
318
336
|
}
|
319
|
-
return [3 /*break*/,
|
320
|
-
case
|
321
|
-
|
337
|
+
return [3 /*break*/, 6];
|
338
|
+
case 5:
|
339
|
+
_t = _w.sent();
|
322
340
|
exceptionDetails = {
|
323
341
|
response: "OCClientGetReconnectableChatsFailed"
|
324
342
|
};
|
325
343
|
throw Error(exceptionDetails.response);
|
326
|
-
case
|
327
|
-
if (!(optionalParams.liveChatContext && !this.
|
344
|
+
case 6:
|
345
|
+
if (!(optionalParams.liveChatContext && !this.reconnectId)) return [3 /*break*/, 8];
|
328
346
|
this.chatToken = optionalParams.liveChatContext.chatToken || {};
|
329
347
|
this.requestId = optionalParams.liveChatContext.requestId || ocsdk_1.uuidv4();
|
330
348
|
return [4 /*yield*/, this.getConversationDetails()];
|
331
|
-
case
|
332
|
-
conversationDetails =
|
349
|
+
case 7:
|
350
|
+
conversationDetails = _w.sent();
|
333
351
|
if (Object.keys(conversationDetails).length === 0) {
|
334
352
|
exceptionDetails = {
|
335
353
|
response: "InvalidConversation"
|
@@ -354,14 +372,14 @@ var OmnichannelChatSDK = /** @class */ (function () {
|
|
354
372
|
console.error("Unable to join conversation that's in '" + conversationDetails.state + "' state");
|
355
373
|
throw Error(exceptionDetails.response);
|
356
374
|
}
|
357
|
-
|
358
|
-
case 6:
|
359
|
-
if (!(this.chatToken && Object.keys(this.chatToken).length === 0)) return [3 /*break*/, 8];
|
360
|
-
return [4 /*yield*/, this.getChatToken(false)];
|
361
|
-
case 7:
|
362
|
-
_s.sent();
|
363
|
-
_s.label = 8;
|
375
|
+
_w.label = 8;
|
364
376
|
case 8:
|
377
|
+
if (!(this.chatToken && Object.keys(this.chatToken).length === 0)) return [3 /*break*/, 10];
|
378
|
+
return [4 /*yield*/, this.getChatToken(false)];
|
379
|
+
case 9:
|
380
|
+
_w.sent();
|
381
|
+
_w.label = 10;
|
382
|
+
case 10:
|
365
383
|
(_c = this.ic3ClientLogger) === null || _c === void 0 ? void 0 : _c.setChatId(this.chatToken.chatId || '');
|
366
384
|
(_d = this.ocSdkLogger) === null || _d === void 0 ? void 0 : _d.setChatId(this.chatToken.chatId || '');
|
367
385
|
(_e = this.acsClientLogger) === null || _e === void 0 ? void 0 : _e.setChatId(this.chatToken.chatId || '');
|
@@ -369,6 +387,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
|
|
369
387
|
sessionInitOptionalParams = {
|
370
388
|
initContext: {}
|
371
389
|
};
|
390
|
+
sessionInitOptionalParams.initContext.locale = locale_1.getLocaleStringFromId(this.localeId);
|
372
391
|
if (this.isPersistentChat && !((_g = this.chatSDKConfig.persistentChat) === null || _g === void 0 ? void 0 : _g.disable)) {
|
373
392
|
sessionInitOptionalParams.reconnectId = this.reconnectId;
|
374
393
|
}
|
@@ -400,27 +419,33 @@ var OmnichannelChatSDK = /** @class */ (function () {
|
|
400
419
|
if (this.authenticatedUserToken) {
|
401
420
|
sessionInitOptionalParams.authenticatedUserToken = this.authenticatedUserToken;
|
402
421
|
}
|
403
|
-
|
404
|
-
|
405
|
-
_s.trys.push([9, 11, , 12]);
|
406
|
-
return [4 /*yield*/, this.OCClient.sessionInit(this.requestId, sessionInitOptionalParams)];
|
407
|
-
case 10:
|
408
|
-
_s.sent();
|
409
|
-
return [3 /*break*/, 12];
|
422
|
+
if (!!optionalParams.liveChatContext) return [3 /*break*/, 14];
|
423
|
+
_w.label = 11;
|
410
424
|
case 11:
|
411
|
-
|
425
|
+
_w.trys.push([11, 13, , 14]);
|
426
|
+
return [4 /*yield*/, this.OCClient.sessionInit(this.requestId, sessionInitOptionalParams)];
|
427
|
+
case 12:
|
428
|
+
_w.sent();
|
429
|
+
return [3 /*break*/, 14];
|
430
|
+
case 13:
|
431
|
+
error_3 = _w.sent();
|
412
432
|
exceptionDetails = {
|
413
433
|
response: "OCClientSessionInitFailed"
|
414
434
|
};
|
435
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
436
|
+
if (((_j = error_3) === null || _j === void 0 ? void 0 : _j.isAxiosError) && ((_l = (_k = error_3.response) === null || _k === void 0 ? void 0 : _k.headers) === null || _l === void 0 ? void 0 : _l.errorcode.toString()) === OmnichannelErrorCodes_1.default.WidgetUseOutsideOperatingHour.toString()) {
|
437
|
+
exceptionDetails.response = OmnichannelErrorCodes_1.default[OmnichannelErrorCodes_1.default.WidgetUseOutsideOperatingHour].toString();
|
438
|
+
exceptionDetails.message = 'Widget used outside of operating hours';
|
439
|
+
console.error(exceptionDetails.message);
|
440
|
+
}
|
415
441
|
this.scenarioMarker.failScenario(TelemetryEvent_1.default.StartChat, {
|
416
442
|
RequestId: this.requestId,
|
417
443
|
ChatId: this.chatToken.chatId,
|
418
444
|
ExceptionDetails: JSON.stringify(exceptionDetails)
|
419
445
|
});
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
if (!(this.liveChatVersion === LiveChatVersion_1.default.V2)) return [3 /*break*/, 23];
|
446
|
+
throw new Error(exceptionDetails.response);
|
447
|
+
case 14:
|
448
|
+
if (!(this.liveChatVersion === LiveChatVersion_1.default.V2)) return [3 /*break*/, 25];
|
424
449
|
chatAdapterConfig = {
|
425
450
|
token: this.chatToken.token,
|
426
451
|
id: this.chatToken.visitorId || 'teamsvisitor',
|
@@ -428,18 +453,18 @@ var OmnichannelChatSDK = /** @class */ (function () {
|
|
428
453
|
environmentUrl: this.chatToken.acsEndpoint,
|
429
454
|
pollingInterval: 1000
|
430
455
|
};
|
431
|
-
|
432
|
-
case
|
433
|
-
|
434
|
-
return [4 /*yield*/, ((
|
456
|
+
_w.label = 15;
|
457
|
+
case 15:
|
458
|
+
_w.trys.push([15, 17, , 18]);
|
459
|
+
return [4 /*yield*/, ((_m = this.ACSClient) === null || _m === void 0 ? void 0 : _m.initialize({
|
435
460
|
token: chatAdapterConfig.token,
|
436
461
|
environmentUrl: chatAdapterConfig.environmentUrl
|
437
462
|
}))];
|
438
|
-
case
|
439
|
-
|
440
|
-
return [3 /*break*/,
|
441
|
-
case
|
442
|
-
error_4 =
|
463
|
+
case 16:
|
464
|
+
_w.sent();
|
465
|
+
return [3 /*break*/, 18];
|
466
|
+
case 17:
|
467
|
+
error_4 = _w.sent();
|
443
468
|
exceptionDetails = {
|
444
469
|
response: "ACSClientInitializeFailed"
|
445
470
|
};
|
@@ -450,23 +475,23 @@ var OmnichannelChatSDK = /** @class */ (function () {
|
|
450
475
|
});
|
451
476
|
console.error("OmnichannelChatSDK/startChat/initialize/error " + error_4);
|
452
477
|
return [2 /*return*/, error_4];
|
453
|
-
case
|
454
|
-
|
455
|
-
|
456
|
-
return [4 /*yield*/, ((
|
478
|
+
case 18:
|
479
|
+
_w.trys.push([18, 20, , 21]);
|
480
|
+
_u = this;
|
481
|
+
return [4 /*yield*/, ((_o = this.ACSClient) === null || _o === void 0 ? void 0 : _o.joinConversation({
|
457
482
|
id: chatAdapterConfig.id,
|
458
483
|
threadId: chatAdapterConfig.threadId,
|
459
484
|
pollingInterval: chatAdapterConfig.pollingInterval
|
460
485
|
}))];
|
461
|
-
case
|
462
|
-
|
486
|
+
case 19:
|
487
|
+
_u.conversation = (_w.sent());
|
463
488
|
this.scenarioMarker.completeScenario(TelemetryEvent_1.default.StartChat, {
|
464
489
|
RequestId: this.requestId,
|
465
490
|
ChatId: this.chatToken.chatId
|
466
491
|
});
|
467
|
-
return [3 /*break*/,
|
468
|
-
case
|
469
|
-
error_5 =
|
492
|
+
return [3 /*break*/, 21];
|
493
|
+
case 20:
|
494
|
+
error_5 = _w.sent();
|
470
495
|
exceptionDetails = {
|
471
496
|
response: "ACSClientJoinConversationFailed"
|
472
497
|
};
|
@@ -477,16 +502,16 @@ var OmnichannelChatSDK = /** @class */ (function () {
|
|
477
502
|
});
|
478
503
|
console.error("OmnichannelChatSDK/startChat/joinConversation/error " + error_5);
|
479
504
|
throw Error(exceptionDetails.response);
|
480
|
-
case
|
481
|
-
|
482
|
-
return [4 /*yield*/, ((
|
505
|
+
case 21:
|
506
|
+
_w.trys.push([21, 23, , 24]);
|
507
|
+
return [4 /*yield*/, ((_p = this.AMSClient) === null || _p === void 0 ? void 0 : _p.initialize({
|
483
508
|
chatToken: this.chatToken
|
484
509
|
}))];
|
485
|
-
case
|
486
|
-
|
487
|
-
return [3 /*break*/,
|
488
|
-
case
|
489
|
-
error_6 =
|
510
|
+
case 22:
|
511
|
+
_w.sent();
|
512
|
+
return [3 /*break*/, 24];
|
513
|
+
case 23:
|
514
|
+
error_6 = _w.sent();
|
490
515
|
exceptionDetails = {
|
491
516
|
response: "AMSClientInitializeFailed"
|
492
517
|
};
|
@@ -496,19 +521,19 @@ var OmnichannelChatSDK = /** @class */ (function () {
|
|
496
521
|
ExceptionDetails: JSON.stringify(exceptionDetails)
|
497
522
|
});
|
498
523
|
throw Error(exceptionDetails.response);
|
499
|
-
case
|
500
|
-
case
|
501
|
-
|
524
|
+
case 24: return [3 /*break*/, 31];
|
525
|
+
case 25:
|
526
|
+
_w.trys.push([25, 27, , 28]);
|
502
527
|
return [4 /*yield*/, this.IC3Client.initialize({
|
503
528
|
token: this.chatToken.token,
|
504
529
|
regionGtms: this.chatToken.regionGTMS,
|
505
530
|
visitor: true
|
506
531
|
})];
|
507
|
-
case
|
508
|
-
|
509
|
-
return [3 /*break*/,
|
510
|
-
case
|
511
|
-
error_7 =
|
532
|
+
case 26:
|
533
|
+
_w.sent();
|
534
|
+
return [3 /*break*/, 28];
|
535
|
+
case 27:
|
536
|
+
error_7 = _w.sent();
|
512
537
|
exceptionDetails = {
|
513
538
|
response: "IC3ClientInitializeFailed"
|
514
539
|
};
|
@@ -519,19 +544,19 @@ var OmnichannelChatSDK = /** @class */ (function () {
|
|
519
544
|
});
|
520
545
|
console.error("OmnichannelChatSDK/startChat/initialize/error " + error_7);
|
521
546
|
return [2 /*return*/, error_7];
|
522
|
-
case
|
523
|
-
|
524
|
-
|
547
|
+
case 28:
|
548
|
+
_w.trys.push([28, 30, , 31]);
|
549
|
+
_v = this;
|
525
550
|
return [4 /*yield*/, this.IC3Client.joinConversation(this.chatToken.chatId)];
|
526
|
-
case
|
527
|
-
|
551
|
+
case 29:
|
552
|
+
_v.conversation = _w.sent();
|
528
553
|
this.scenarioMarker.completeScenario(TelemetryEvent_1.default.StartChat, {
|
529
554
|
RequestId: this.requestId,
|
530
555
|
ChatId: this.chatToken.chatId
|
531
556
|
});
|
532
|
-
return [3 /*break*/,
|
533
|
-
case
|
534
|
-
error_8 =
|
557
|
+
return [3 /*break*/, 31];
|
558
|
+
case 30:
|
559
|
+
error_8 = _w.sent();
|
535
560
|
exceptionDetails = {
|
536
561
|
response: "IC3ClientJoinConversationFailed"
|
537
562
|
};
|
@@ -542,8 +567,8 @@ var OmnichannelChatSDK = /** @class */ (function () {
|
|
542
567
|
});
|
543
568
|
console.error("OmnichannelChatSDK/startChat/joinConversation/error " + error_8);
|
544
569
|
return [2 /*return*/, error_8];
|
545
|
-
case
|
546
|
-
if (this.isPersistentChat && !((
|
570
|
+
case 31:
|
571
|
+
if (this.isPersistentChat && !((_q = this.chatSDKConfig.persistentChat) === null || _q === void 0 ? void 0 : _q.disable)) {
|
547
572
|
this.refreshTokenTimer = setInterval(function () { return __awaiter(_this, void 0, void 0, function () {
|
548
573
|
return __generator(this, function (_a) {
|
549
574
|
switch (_a.label) {
|
@@ -554,7 +579,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
|
|
554
579
|
return [2 /*return*/];
|
555
580
|
}
|
556
581
|
});
|
557
|
-
}); }, (
|
582
|
+
}); }, (_r = this.chatSDKConfig.persistentChat) === null || _r === void 0 ? void 0 : _r.tokenUpdateTime);
|
558
583
|
}
|
559
584
|
return [2 /*return*/];
|
560
585
|
}
|
@@ -580,6 +605,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
|
|
580
605
|
}
|
581
606
|
if (this.isChatReconnect && !((_b = this.chatSDKConfig.chatReconnect) === null || _b === void 0 ? void 0 : _b.disable) && !this.isPersistentChat) {
|
582
607
|
isChatReconnect = this.reconnectId !== null ? true : false;
|
608
|
+
this.requestId = isChatReconnect ? this.reconnectId : this.requestId; // Chat Reconnect session to close
|
583
609
|
sessionCloseOptionalParams.isReconnectChat = isChatReconnect;
|
584
610
|
}
|
585
611
|
if (this.authenticatedUserToken) {
|
@@ -600,6 +626,9 @@ var OmnichannelChatSDK = /** @class */ (function () {
|
|
600
626
|
this.requestId = ocsdk_1.uuidv4();
|
601
627
|
this.chatToken = {};
|
602
628
|
this.reconnectId = null;
|
629
|
+
this.IC3Client.dispose();
|
630
|
+
!platform_1.default.isNode() && !platform_1.default.isReactNative() && WebUtils_1.removeElementById(this.IC3Client.id);
|
631
|
+
this.IC3Client = null;
|
603
632
|
(_d = this.ic3ClientLogger) === null || _d === void 0 ? void 0 : _d.setRequestId(this.requestId);
|
604
633
|
(_e = this.ic3ClientLogger) === null || _e === void 0 ? void 0 : _e.setChatId('');
|
605
634
|
(_f = this.ocSdkLogger) === null || _f === void 0 ? void 0 : _f.setRequestId(this.requestId);
|
@@ -661,22 +690,32 @@ var OmnichannelChatSDK = /** @class */ (function () {
|
|
661
690
|
});
|
662
691
|
};
|
663
692
|
OmnichannelChatSDK.prototype.getConversationDetails = function () {
|
664
|
-
var _a, _b;
|
693
|
+
var _a, _b, _c, _d;
|
665
694
|
return __awaiter(this, void 0, void 0, function () {
|
666
|
-
var lwiDetails, state, conversationId, agentAcceptedOn, liveWorkItemDetails, error_10;
|
667
|
-
return __generator(this, function (
|
668
|
-
switch (
|
695
|
+
var getLWIDetailsOptionalParams, lwiDetails, state, conversationId, agentAcceptedOn, liveWorkItemDetails, error_10;
|
696
|
+
return __generator(this, function (_e) {
|
697
|
+
switch (_e.label) {
|
669
698
|
case 0:
|
670
699
|
this.scenarioMarker.startScenario(TelemetryEvent_1.default.GetConversationDetails, {
|
671
700
|
RequestId: this.requestId,
|
672
701
|
ChatId: ((_a = this.chatToken) === null || _a === void 0 ? void 0 : _a.chatId) || '',
|
673
702
|
});
|
674
|
-
|
703
|
+
getLWIDetailsOptionalParams = {};
|
704
|
+
if (this.isPersistentChat && !((_b = this.chatSDKConfig.persistentChat) === null || _b === void 0 ? void 0 : _b.disable) && this.reconnectId) {
|
705
|
+
getLWIDetailsOptionalParams.reconnectId = this.reconnectId;
|
706
|
+
}
|
707
|
+
if (this.isChatReconnect && !((_c = this.chatSDKConfig.chatReconnect) === null || _c === void 0 ? void 0 : _c.disable) && !this.isPersistentChat && this.reconnectId) {
|
708
|
+
getLWIDetailsOptionalParams.reconnectId = this.reconnectId;
|
709
|
+
}
|
710
|
+
if (this.authenticatedUserToken) {
|
711
|
+
getLWIDetailsOptionalParams.authenticatedUserToken = this.authenticatedUserToken;
|
712
|
+
}
|
713
|
+
_e.label = 1;
|
675
714
|
case 1:
|
676
|
-
|
677
|
-
return [4 /*yield*/, this.OCClient.getLWIDetails(this.requestId)];
|
715
|
+
_e.trys.push([1, 3, , 4]);
|
716
|
+
return [4 /*yield*/, this.OCClient.getLWIDetails(this.requestId, getLWIDetailsOptionalParams)];
|
678
717
|
case 2:
|
679
|
-
lwiDetails =
|
718
|
+
lwiDetails = _e.sent();
|
680
719
|
state = lwiDetails.State, conversationId = lwiDetails.ConversationId, agentAcceptedOn = lwiDetails.AgentAcceptedOn;
|
681
720
|
liveWorkItemDetails = {
|
682
721
|
state: state,
|
@@ -687,11 +726,11 @@ var OmnichannelChatSDK = /** @class */ (function () {
|
|
687
726
|
}
|
688
727
|
this.scenarioMarker.completeScenario(TelemetryEvent_1.default.GetConversationDetails, {
|
689
728
|
RequestId: this.requestId,
|
690
|
-
ChatId: ((
|
729
|
+
ChatId: ((_d = this.chatToken) === null || _d === void 0 ? void 0 : _d.chatId) || '',
|
691
730
|
});
|
692
731
|
return [2 /*return*/, liveWorkItemDetails];
|
693
732
|
case 3:
|
694
|
-
error_10 =
|
733
|
+
error_10 = _e.sent();
|
695
734
|
this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetConversationDetails, {
|
696
735
|
RequestId: this.requestId,
|
697
736
|
ChatId: this.chatToken.chatId || '',
|
@@ -897,6 +936,13 @@ var OmnichannelChatSDK = /** @class */ (function () {
|
|
897
936
|
sendMessageRequest = {
|
898
937
|
content: message.content,
|
899
938
|
};
|
939
|
+
sendMessageRequest.metadata = {
|
940
|
+
widgetId: this.omnichannelConfig.widgetId,
|
941
|
+
clientMessageId: Date.now().toString()
|
942
|
+
};
|
943
|
+
if (message.metadata) {
|
944
|
+
sendMessageRequest.metadata = __assign(__assign({}, sendMessageRequest.metadata), message.metadata);
|
945
|
+
}
|
900
946
|
_e.label = 1;
|
901
947
|
case 1:
|
902
948
|
_e.trys.push([1, 3, , 4]);
|
@@ -1279,7 +1325,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
|
|
1279
1325
|
};
|
1280
1326
|
sendMessageRequest = {
|
1281
1327
|
content: '',
|
1282
|
-
metadata: __assign(__assign({}, fileIdsProperty), fileMetaProperty)
|
1328
|
+
metadata: __assign(__assign({ widgetId: this.omnichannelConfig.widgetId, clientMessageId: Date.now().toString() }, fileIdsProperty), fileMetaProperty)
|
1283
1329
|
};
|
1284
1330
|
messageToSend = {
|
1285
1331
|
content: "",
|
@@ -1440,7 +1486,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
|
|
1440
1486
|
ChatId: this.chatToken.chatId,
|
1441
1487
|
EmailAddress: body.emailAddress,
|
1442
1488
|
DefaultAttachmentMessage: body.attachmentMessage,
|
1443
|
-
CustomerLocale: body.locale
|
1489
|
+
CustomerLocale: body.locale || locale_1.getLocaleStringFromId(this.localeId)
|
1444
1490
|
};
|
1445
1491
|
emailResponse = this.OCClient.emailTranscript(this.requestId, this.chatToken.token, emailRequestBody, emailTranscriptOptionalParams);
|
1446
1492
|
this.scenarioMarker.completeScenario(TelemetryEvent_1.default.EmailLiveChatTranscript, {
|
@@ -1490,32 +1536,33 @@ var OmnichannelChatSDK = /** @class */ (function () {
|
|
1490
1536
|
});
|
1491
1537
|
});
|
1492
1538
|
};
|
1493
|
-
OmnichannelChatSDK.prototype.createChatAdapter = function (
|
1494
|
-
if (
|
1539
|
+
OmnichannelChatSDK.prototype.createChatAdapter = function (optionalParams) {
|
1540
|
+
if (optionalParams === void 0) { optionalParams = {}; }
|
1495
1541
|
return __awaiter(this, void 0, void 0, function () {
|
1496
|
-
var supportedChatAdapterProtocols;
|
1542
|
+
var protocol, supportedChatAdapterProtocols;
|
1497
1543
|
var _this = this;
|
1498
1544
|
return __generator(this, function (_a) {
|
1499
1545
|
if (platform_1.default.isNode() || platform_1.default.isReactNative()) {
|
1500
1546
|
return [2 /*return*/, Promise.reject('ChatAdapter is only supported on browser')];
|
1501
1547
|
}
|
1548
|
+
protocol = optionalParams.protocol;
|
1502
1549
|
supportedChatAdapterProtocols = [ChatAdapterProtocols_1.default.ACS, ChatAdapterProtocols_1.default.IC3];
|
1503
1550
|
if (protocol && !supportedChatAdapterProtocols.includes(protocol)) {
|
1504
1551
|
return [2 /*return*/, Promise.reject("ChatAdapter for protocol " + protocol + " currently not supported")];
|
1505
1552
|
}
|
1506
1553
|
if (protocol === ChatAdapterProtocols_1.default.ACS || this.liveChatVersion === LiveChatVersion_1.default.V2) {
|
1507
1554
|
return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
|
1508
|
-
var featuresOption, acsAdapterCDNUrl;
|
1555
|
+
var options, egressMiddlewares, ingressMiddlewares, featuresOption, acsAdapterCDNUrl;
|
1509
1556
|
var _this = this;
|
1510
1557
|
var _a;
|
1511
1558
|
return __generator(this, function (_b) {
|
1512
1559
|
switch (_b.label) {
|
1513
1560
|
case 0:
|
1514
|
-
|
1515
|
-
|
1516
|
-
|
1517
|
-
|
1518
|
-
|
1561
|
+
options = optionalParams.ACSAdapter ? optionalParams.ACSAdapter.options : {};
|
1562
|
+
egressMiddlewares = [createFormatEgressTagsMiddleware_1.default()];
|
1563
|
+
ingressMiddlewares = [createFormatIngressTagsMiddleware_1.default()];
|
1564
|
+
featuresOption = __assign({ enableAdaptiveCards: true, enableThreadMemberUpdateNotification: true, enableLeaveThreadOnWindowClosed: false, egressMiddleware: egressMiddlewares, ingressMiddleware: ingressMiddlewares }, options // overrides
|
1565
|
+
);
|
1519
1566
|
acsAdapterCDNUrl = this.resolveChatAdapterUrl(protocol || ChatAdapterProtocols_1.default.ACS);
|
1520
1567
|
(_a = this.telemetry) === null || _a === void 0 ? void 0 : _a.setCDNPackages({
|
1521
1568
|
ACSAdapter: acsAdapterCDNUrl
|
@@ -1526,7 +1573,9 @@ var OmnichannelChatSDK = /** @class */ (function () {
|
|
1526
1573
|
try {
|
1527
1574
|
var ChatAdapter = window.ChatAdapter; // eslint-disable-line @typescript-eslint/no-explicit-any
|
1528
1575
|
var fileManager = new AMSFileManager_1.default(_this.AMSClient, _this.acsAdapterLogger);
|
1529
|
-
var adapter = ChatAdapter.createACSAdapter(_this.chatToken.token, _this.chatToken.visitorId || 'teamsvisitor', _this.chatToken.chatId, _this.chatToken.acsEndpoint, fileManager, 1000, ACSParticipantDisplayName_1.default.Customer, undefined,
|
1576
|
+
var adapter = ChatAdapter.createACSAdapter(_this.chatToken.token, _this.chatToken.visitorId || 'teamsvisitor', _this.chatToken.chatId, _this.chatToken.acsEndpoint, fileManager, 1000, ACSParticipantDisplayName_1.default.Customer, undefined, // chatClient
|
1577
|
+
undefined, // logger
|
1578
|
+
featuresOption);
|
1530
1579
|
resolve(adapter);
|
1531
1580
|
}
|
1532
1581
|
catch (_a) {
|
@@ -1544,12 +1593,13 @@ var OmnichannelChatSDK = /** @class */ (function () {
|
|
1544
1593
|
}
|
1545
1594
|
else if (protocol === ChatAdapterProtocols_1.default.IC3 || this.liveChatVersion === LiveChatVersion_1.default.V1) {
|
1546
1595
|
return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
|
1547
|
-
var ic3AdapterCDNUrl;
|
1596
|
+
var options, ic3AdapterCDNUrl;
|
1548
1597
|
var _this = this;
|
1549
1598
|
var _a;
|
1550
1599
|
return __generator(this, function (_b) {
|
1551
1600
|
switch (_b.label) {
|
1552
1601
|
case 0:
|
1602
|
+
options = optionalParams.IC3Adapter ? optionalParams.IC3Adapter.options : {};
|
1553
1603
|
ic3AdapterCDNUrl = this.resolveChatAdapterUrl(protocol || ChatAdapterProtocols_1.default.IC3);
|
1554
1604
|
(_a = this.telemetry) === null || _a === void 0 ? void 0 : _a.setCDNPackages({
|
1555
1605
|
IC3Adapter: ic3AdapterCDNUrl
|
@@ -1558,17 +1608,10 @@ var OmnichannelChatSDK = /** @class */ (function () {
|
|
1558
1608
|
return [4 /*yield*/, WebUtils_1.loadScript(ic3AdapterCDNUrl, function () {
|
1559
1609
|
/* istanbul ignore next */
|
1560
1610
|
_this.debug && console.debug('IC3Adapter loaded!');
|
1561
|
-
var adapterConfig = {
|
1562
|
-
|
1563
|
-
userDisplayName: 'Customer',
|
1564
|
-
userId: 'teamsvisitor',
|
1565
|
-
sdkURL: _this.resolveIC3ClientUrl(),
|
1566
|
-
sdk: _this.IC3Client
|
1567
|
-
};
|
1611
|
+
var adapterConfig = __assign({ chatToken: _this.chatToken, userDisplayName: 'Customer', userId: _this.chatToken.visitorId || 'teamsvisitor', sdkURL: _this.resolveIC3ClientUrl(), sdk: _this.IC3Client }, options // overrides
|
1612
|
+
);
|
1568
1613
|
var adapter = new window.Microsoft.BotFramework.WebChat.IC3Adapter(adapterConfig);
|
1569
1614
|
adapter.logger = _this.ic3ClientLogger;
|
1570
|
-
// Keep iframe communication alive to reuse the same IC3Client instance
|
1571
|
-
window.Microsoft.BotFramework.WebChat.IC3SDKProvider.disposeSdk = function () { }; // eslint-disable-line @typescript-eslint/no-empty-function
|
1572
1615
|
_this.scenarioMarker.completeScenario(TelemetryEvent_1.default.CreateIC3Adapter);
|
1573
1616
|
resolve(adapter);
|
1574
1617
|
}, function () {
|
@@ -1662,7 +1705,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
|
|
1662
1705
|
};
|
1663
1706
|
OmnichannelChatSDK.prototype.getPostChatSurveyContext = function () {
|
1664
1707
|
return __awaiter(this, void 0, void 0, function () {
|
1665
|
-
var conversationId,
|
1708
|
+
var conversationId, liveWSAndLiveChatEngJoin, msdyn_postconversationsurveyenable, msfp_sourcesurveyidentifier, postConversationSurveyOwnerId, liveWorkItemDetails, participantJoined, surveyInviteLinkRequest, optionalParams, surveyInviteLinkResponse, surveyInviteLink, formsProLocale, postChatContext, ex_1;
|
1666
1709
|
return __generator(this, function (_a) {
|
1667
1710
|
switch (_a.label) {
|
1668
1711
|
case 0:
|
@@ -1672,11 +1715,8 @@ var OmnichannelChatSDK = /** @class */ (function () {
|
|
1672
1715
|
_a.label = 1;
|
1673
1716
|
case 1:
|
1674
1717
|
_a.trys.push([1, 6, , 7]);
|
1675
|
-
|
1676
|
-
liveWSAndLiveChatEngJoin = chatConfig.LiveWSAndLiveChatEngJoin, chatWidgetLanguage = chatConfig.ChatWidgetLanguage;
|
1718
|
+
liveWSAndLiveChatEngJoin = this.liveChatConfig.LiveWSAndLiveChatEngJoin;
|
1677
1719
|
msdyn_postconversationsurveyenable = liveWSAndLiveChatEngJoin.msdyn_postconversationsurveyenable, msfp_sourcesurveyidentifier = liveWSAndLiveChatEngJoin.msfp_sourcesurveyidentifier, postConversationSurveyOwnerId = liveWSAndLiveChatEngJoin.postConversationSurveyOwnerId;
|
1678
|
-
msdyn_localeid = chatWidgetLanguage.msdyn_localeid;
|
1679
|
-
localeId = msdyn_localeid !== null && msdyn_localeid !== void 0 ? msdyn_localeid : "1033";
|
1680
1720
|
if (!msdyn_postconversationsurveyenable) return [3 /*break*/, 4];
|
1681
1721
|
return [4 /*yield*/, this.OCClient.getLWIDetails(this.requestId)];
|
1682
1722
|
case 2:
|
@@ -1686,7 +1726,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
|
|
1686
1726
|
surveyInviteLinkRequest = {
|
1687
1727
|
"FormId": msfp_sourcesurveyidentifier,
|
1688
1728
|
"ConversationId": conversationId,
|
1689
|
-
"OCLocaleCode": locale_1.getLocaleStringFromId(localeId)
|
1729
|
+
"OCLocaleCode": locale_1.getLocaleStringFromId(this.localeId) || locale_1.getLocaleStringFromId(locale_1.defaultLocaleId)
|
1690
1730
|
};
|
1691
1731
|
optionalParams = {
|
1692
1732
|
"requestId": this.requestId
|
@@ -1749,102 +1789,6 @@ var OmnichannelChatSDK = /** @class */ (function () {
|
|
1749
1789
|
});
|
1750
1790
|
});
|
1751
1791
|
};
|
1752
|
-
OmnichannelChatSDK.prototype.initializePostChatRenderer = function () {
|
1753
|
-
return __awaiter(this, void 0, void 0, function () {
|
1754
|
-
var msfpEmbedScript, elm, scriptNodes, styleNodes, i, node, tmpNode, tmpNode, i, node, tmpNode;
|
1755
|
-
return __generator(this, function (_a) {
|
1756
|
-
if (!platform_1.isBrowser()) {
|
1757
|
-
return [2 /*return*/, Promise.reject("In-line rendering is only supported on web browsers")];
|
1758
|
-
}
|
1759
|
-
this.scenarioMarker.startScenario(TelemetryEvent_1.default.InitializePostChatRenderer, {
|
1760
|
-
RequestId: this.requestId
|
1761
|
-
});
|
1762
|
-
try {
|
1763
|
-
msfpEmbedScript = libraries_1.getMsfpEmbedScript();
|
1764
|
-
elm = document.createElement('div');
|
1765
|
-
elm.innerHTML = msfpEmbedScript;
|
1766
|
-
scriptNodes = elm.getElementsByTagName('script');
|
1767
|
-
styleNodes = elm.getElementsByTagName('link');
|
1768
|
-
for (i = 0; i < scriptNodes.length; i++) {
|
1769
|
-
node = scriptNodes[i];
|
1770
|
-
if (node.src) {
|
1771
|
-
tmpNode = document.createElement('script');
|
1772
|
-
tmpNode.type = node.type;
|
1773
|
-
tmpNode.src = node.src;
|
1774
|
-
tmpNode.async = false;
|
1775
|
-
if (!window.document.head.contains(tmpNode)) {
|
1776
|
-
document.getElementsByTagName('head')[0].appendChild(tmpNode);
|
1777
|
-
}
|
1778
|
-
}
|
1779
|
-
if (node.innerHTML) {
|
1780
|
-
tmpNode = document.createElement('script');
|
1781
|
-
tmpNode.innerHTML = node.innerHTML;
|
1782
|
-
tmpNode.async = false;
|
1783
|
-
if (!window.document.head.contains(tmpNode)) {
|
1784
|
-
window.document.head.appendChild(tmpNode);
|
1785
|
-
}
|
1786
|
-
}
|
1787
|
-
}
|
1788
|
-
for (i = 0; i < styleNodes.length; i++) {
|
1789
|
-
node = styleNodes[i];
|
1790
|
-
if (node.href) {
|
1791
|
-
tmpNode = document.createElement('link');
|
1792
|
-
tmpNode.type = node.type;
|
1793
|
-
tmpNode.rel = node.rel;
|
1794
|
-
tmpNode.href = node.href;
|
1795
|
-
if (!window.document.head.contains(tmpNode)) {
|
1796
|
-
document.getElementsByTagName('head')[0].appendChild(tmpNode);
|
1797
|
-
}
|
1798
|
-
}
|
1799
|
-
}
|
1800
|
-
}
|
1801
|
-
catch (ex) {
|
1802
|
-
this.scenarioMarker.failScenario(TelemetryEvent_1.default.InitializePostChatRenderer, {
|
1803
|
-
RequestId: this.requestId,
|
1804
|
-
ExceptionDetails: JSON.stringify(ex)
|
1805
|
-
});
|
1806
|
-
return [2 /*return*/, Promise.reject("Error occurred when initializer post chat renderer. " + JSON.stringify(ex))];
|
1807
|
-
}
|
1808
|
-
return [2 /*return*/];
|
1809
|
-
});
|
1810
|
-
});
|
1811
|
-
};
|
1812
|
-
OmnichannelChatSDK.prototype.renderPostChatSurvey = function (containerId, postChatContext) {
|
1813
|
-
return __awaiter(this, void 0, void 0, function () {
|
1814
|
-
var ex_2;
|
1815
|
-
return __generator(this, function (_a) {
|
1816
|
-
switch (_a.label) {
|
1817
|
-
case 0:
|
1818
|
-
if (!platform_1.isBrowser()) {
|
1819
|
-
return [2 /*return*/, Promise.reject("In-line rendering is only supported on web browsers")];
|
1820
|
-
}
|
1821
|
-
this.scenarioMarker.startScenario(TelemetryEvent_1.default.RenderPostChatSurvey, {
|
1822
|
-
RequestId: this.requestId
|
1823
|
-
});
|
1824
|
-
_a.label = 1;
|
1825
|
-
case 1:
|
1826
|
-
_a.trys.push([1, 3, , 4]);
|
1827
|
-
if (!postChatContext) {
|
1828
|
-
this.scenarioMarker.failScenario(TelemetryEvent_1.default.RenderPostChatSurvey, {
|
1829
|
-
RequestId: this.requestId,
|
1830
|
-
ExceptionDetails: "Post Chat Context is null."
|
1831
|
-
});
|
1832
|
-
return [2 /*return*/, Promise.reject("Post Chat Context is null.")];
|
1833
|
-
}
|
1834
|
-
return [4 /*yield*/, renderSurvey(containerId, postChatContext === null || postChatContext === void 0 ? void 0 : postChatContext.surveyInviteLink, "", "", postChatContext === null || postChatContext === void 0 ? void 0 : postChatContext.formsProLocale)];
|
1835
|
-
case 2: return [2 /*return*/, _a.sent()];
|
1836
|
-
case 3:
|
1837
|
-
ex_2 = _a.sent();
|
1838
|
-
this.scenarioMarker.failScenario(TelemetryEvent_1.default.RenderPostChatSurvey, {
|
1839
|
-
RequestId: this.requestId,
|
1840
|
-
ExceptionDetails: JSON.stringify(ex_2)
|
1841
|
-
});
|
1842
|
-
return [2 /*return*/, Promise.reject("Error occurred when rendering post chat survey. " + JSON.stringify(ex_2))];
|
1843
|
-
case 4: return [2 /*return*/];
|
1844
|
-
}
|
1845
|
-
});
|
1846
|
-
});
|
1847
|
-
};
|
1848
1792
|
OmnichannelChatSDK.prototype.getIC3Client = function () {
|
1849
1793
|
return __awaiter(this, void 0, void 0, function () {
|
1850
1794
|
var IC3Client;
|
@@ -1871,7 +1815,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
|
|
1871
1815
|
this.debug && console.debug('IC3Client');
|
1872
1816
|
// Use IC3Client if browser is detected
|
1873
1817
|
return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
|
1874
|
-
var ic3ClientCDNUrl;
|
1818
|
+
var ic3ClientCDNUrl, IC3Client;
|
1875
1819
|
var _this = this;
|
1876
1820
|
var _a;
|
1877
1821
|
return __generator(this, function (_b) {
|
@@ -1882,6 +1826,16 @@ var OmnichannelChatSDK = /** @class */ (function () {
|
|
1882
1826
|
IC3Client: ic3ClientCDNUrl
|
1883
1827
|
});
|
1884
1828
|
this.scenarioMarker.startScenario(TelemetryEvent_1.default.GetIC3Client);
|
1829
|
+
if (!this.IC3SDKProvider) return [3 /*break*/, 2];
|
1830
|
+
return [4 /*yield*/, this.IC3SDKProvider.getSDK({
|
1831
|
+
hostType: HostType_1.default.IFrame,
|
1832
|
+
protocolType: ProtocoleType_1.default.IC3V1SDK,
|
1833
|
+
logger: this.ic3ClientLogger // eslint-disable-line @typescript-eslint/no-explicit-any
|
1834
|
+
})];
|
1835
|
+
case 1:
|
1836
|
+
IC3Client = _b.sent();
|
1837
|
+
return [2 /*return*/, resolve(IC3Client)];
|
1838
|
+
case 2:
|
1885
1839
|
window.addEventListener("ic3:sdk:load", function () { return __awaiter(_this, void 0, void 0, function () {
|
1886
1840
|
var ic3sdk, IC3SDKProvider, IC3Client;
|
1887
1841
|
return __generator(this, function (_a) {
|
@@ -1918,7 +1872,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
|
|
1918
1872
|
});
|
1919
1873
|
reject('Failed to load IC3Client');
|
1920
1874
|
})];
|
1921
|
-
case
|
1875
|
+
case 3:
|
1922
1876
|
_b.sent();
|
1923
1877
|
return [2 /*return*/];
|
1924
1878
|
}
|
@@ -1930,15 +1884,17 @@ var OmnichannelChatSDK = /** @class */ (function () {
|
|
1930
1884
|
};
|
1931
1885
|
OmnichannelChatSDK.prototype.getChatConfig = function () {
|
1932
1886
|
return __awaiter(this, void 0, void 0, function () {
|
1933
|
-
var liveChatConfig, dataMaskingConfig, authSettings, liveWSAndLiveChatEngJoin, liveChatVersion, setting, preChatSurvey, msdyn_prechatenabled, msdyn_callingoptions, msdyn_conversationmode, msdyn_enablechatreconnect, isPreChatEnabled, isChatReconnectEnabled,
|
1934
|
-
return __generator(this, function (
|
1935
|
-
switch (
|
1887
|
+
var liveChatConfig, dataMaskingConfig, authSettings, liveWSAndLiveChatEngJoin, liveChatVersion, chatWidgetLanguage, msdyn_localeid, setting, preChatSurvey, msdyn_prechatenabled, msdyn_callingoptions, msdyn_conversationmode, msdyn_enablechatreconnect, isPreChatEnabled, isChatReconnectEnabled, error_18;
|
1888
|
+
return __generator(this, function (_a) {
|
1889
|
+
switch (_a.label) {
|
1936
1890
|
case 0:
|
1937
|
-
|
1891
|
+
_a.trys.push([0, 4, , 5]);
|
1938
1892
|
return [4 /*yield*/, this.OCClient.getChatConfig()];
|
1939
1893
|
case 1:
|
1940
|
-
liveChatConfig =
|
1941
|
-
dataMaskingConfig = liveChatConfig.DataMaskingInfo, authSettings = liveChatConfig.LiveChatConfigAuthSettings, liveWSAndLiveChatEngJoin = liveChatConfig.LiveWSAndLiveChatEngJoin, liveChatVersion = liveChatConfig.LiveChatVersion;
|
1894
|
+
liveChatConfig = _a.sent();
|
1895
|
+
dataMaskingConfig = liveChatConfig.DataMaskingInfo, authSettings = liveChatConfig.LiveChatConfigAuthSettings, liveWSAndLiveChatEngJoin = liveChatConfig.LiveWSAndLiveChatEngJoin, liveChatVersion = liveChatConfig.LiveChatVersion, chatWidgetLanguage = liveChatConfig.ChatWidgetLanguage;
|
1896
|
+
msdyn_localeid = chatWidgetLanguage.msdyn_localeid;
|
1897
|
+
this.localeId = msdyn_localeid || locale_1.defaultLocaleId;
|
1942
1898
|
this.liveChatVersion = liveChatVersion || LiveChatVersion_1.default.V1;
|
1943
1899
|
/* istanbul ignore next */
|
1944
1900
|
this.debug && console.log("[OmnichannelChatSDK][getChatConfig][liveChatVersion] " + this.liveChatVersion);
|
@@ -1961,47 +1917,12 @@ var OmnichannelChatSDK = /** @class */ (function () {
|
|
1961
1917
|
if (isPreChatEnabled && preChatSurvey && preChatSurvey.trim().length > 0) {
|
1962
1918
|
this.preChatSurvey = preChatSurvey;
|
1963
1919
|
}
|
1964
|
-
if (!this.authSettings) return [3 /*break*/,
|
1965
|
-
this.
|
1966
|
-
if (!this.chatSDKConfig.getAuthToken) return [3 /*break*/, 6];
|
1967
|
-
_b.label = 2;
|
1920
|
+
if (!this.authSettings) return [3 /*break*/, 3];
|
1921
|
+
return [4 /*yield*/, this.setAuthTokenProvider(this.chatSDKConfig.getAuthToken)];
|
1968
1922
|
case 2:
|
1969
|
-
|
1970
|
-
|
1923
|
+
_a.sent();
|
1924
|
+
_a.label = 3;
|
1971
1925
|
case 3:
|
1972
|
-
token = _b.sent();
|
1973
|
-
if (token) {
|
1974
|
-
this.authenticatedUserToken = token;
|
1975
|
-
this.scenarioMarker.completeScenario(TelemetryEvent_1.default.GetAuthToken);
|
1976
|
-
}
|
1977
|
-
else {
|
1978
|
-
exceptionDetails = {
|
1979
|
-
response: "UndefinedAuthToken"
|
1980
|
-
};
|
1981
|
-
this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetAuthToken, {
|
1982
|
-
ExceptionDetails: JSON.stringify(exceptionDetails)
|
1983
|
-
});
|
1984
|
-
}
|
1985
|
-
return [3 /*break*/, 5];
|
1986
|
-
case 4:
|
1987
|
-
_a = _b.sent();
|
1988
|
-
exceptionDetails = {
|
1989
|
-
response: "GetAuthTokenFailed"
|
1990
|
-
};
|
1991
|
-
this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetAuthToken, {
|
1992
|
-
ExceptionDetails: JSON.stringify(exceptionDetails)
|
1993
|
-
});
|
1994
|
-
return [3 /*break*/, 5];
|
1995
|
-
case 5: return [3 /*break*/, 7];
|
1996
|
-
case 6:
|
1997
|
-
exceptionDetails = {
|
1998
|
-
response: "GetAuthTokenNotFound"
|
1999
|
-
};
|
2000
|
-
this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetAuthToken, {
|
2001
|
-
ExceptionDetails: JSON.stringify(exceptionDetails)
|
2002
|
-
});
|
2003
|
-
_b.label = 7;
|
2004
|
-
case 7:
|
2005
1926
|
if (this.preChatSurvey) {
|
2006
1927
|
/* istanbul ignore next */
|
2007
1928
|
this.debug && console.log('Prechat Survey!');
|
@@ -2009,11 +1930,11 @@ var OmnichannelChatSDK = /** @class */ (function () {
|
|
2009
1930
|
this.callingOption = msdyn_callingoptions;
|
2010
1931
|
this.liveChatConfig = liveChatConfig;
|
2011
1932
|
return [2 /*return*/, this.liveChatConfig];
|
2012
|
-
case
|
2013
|
-
error_18 =
|
1933
|
+
case 4:
|
1934
|
+
error_18 = _a.sent();
|
2014
1935
|
console.error("OmnichannelChatSDK/getChatConfig/error " + error_18);
|
2015
1936
|
return [2 /*return*/, error_18];
|
2016
|
-
case
|
1937
|
+
case 5: return [2 /*return*/];
|
2017
1938
|
}
|
2018
1939
|
});
|
2019
1940
|
});
|
@@ -2095,6 +2016,57 @@ var OmnichannelChatSDK = /** @class */ (function () {
|
|
2095
2016
|
});
|
2096
2017
|
});
|
2097
2018
|
};
|
2019
|
+
OmnichannelChatSDK.prototype.setAuthTokenProvider = function (provider) {
|
2020
|
+
return __awaiter(this, void 0, void 0, function () {
|
2021
|
+
var token, exceptionDetails, _a, exceptionDetails, exceptionDetails;
|
2022
|
+
return __generator(this, function (_b) {
|
2023
|
+
switch (_b.label) {
|
2024
|
+
case 0:
|
2025
|
+
this.scenarioMarker.startScenario(TelemetryEvent_1.default.GetAuthToken);
|
2026
|
+
this.chatSDKConfig.getAuthToken = provider;
|
2027
|
+
if (!this.chatSDKConfig.getAuthToken) return [3 /*break*/, 5];
|
2028
|
+
_b.label = 1;
|
2029
|
+
case 1:
|
2030
|
+
_b.trys.push([1, 3, , 4]);
|
2031
|
+
return [4 /*yield*/, this.chatSDKConfig.getAuthToken()];
|
2032
|
+
case 2:
|
2033
|
+
token = _b.sent();
|
2034
|
+
if (token) {
|
2035
|
+
this.authenticatedUserToken = token;
|
2036
|
+
this.scenarioMarker.completeScenario(TelemetryEvent_1.default.GetAuthToken);
|
2037
|
+
}
|
2038
|
+
else {
|
2039
|
+
exceptionDetails = {
|
2040
|
+
response: "UndefinedAuthToken"
|
2041
|
+
};
|
2042
|
+
this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetAuthToken, {
|
2043
|
+
ExceptionDetails: JSON.stringify(exceptionDetails)
|
2044
|
+
});
|
2045
|
+
}
|
2046
|
+
return [3 /*break*/, 4];
|
2047
|
+
case 3:
|
2048
|
+
_a = _b.sent();
|
2049
|
+
exceptionDetails = {
|
2050
|
+
response: "GetAuthTokenFailed"
|
2051
|
+
};
|
2052
|
+
this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetAuthToken, {
|
2053
|
+
ExceptionDetails: JSON.stringify(exceptionDetails)
|
2054
|
+
});
|
2055
|
+
return [3 /*break*/, 4];
|
2056
|
+
case 4: return [3 /*break*/, 6];
|
2057
|
+
case 5:
|
2058
|
+
exceptionDetails = {
|
2059
|
+
response: "GetAuthTokenNotFound"
|
2060
|
+
};
|
2061
|
+
this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetAuthToken, {
|
2062
|
+
ExceptionDetails: JSON.stringify(exceptionDetails)
|
2063
|
+
});
|
2064
|
+
_b.label = 6;
|
2065
|
+
case 6: return [2 /*return*/];
|
2066
|
+
}
|
2067
|
+
});
|
2068
|
+
});
|
2069
|
+
};
|
2098
2070
|
return OmnichannelChatSDK;
|
2099
2071
|
}());
|
2100
2072
|
exports.default = OmnichannelChatSDK;
|