@microsoft/omnichannel-chat-sdk 1.0.1-main.85b823d → 1.0.1-main.9e71fa6
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 +20 -3
- package/README.md +39 -50
- package/lib/OmnichannelChatSDK.d.ts +5 -4
- package/lib/OmnichannelChatSDK.js +244 -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 +4 -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/core/messaging/MessageTags.d.ts +2 -0
- package/lib/core/messaging/MessageTags.js +4 -2
- package/lib/core/messaging/MessageTags.js.map +1 -1
- package/lib/external/ACSAdapter/createChannelDataEgressMiddleware.d.ts +5 -0
- package/lib/external/ACSAdapter/createChannelDataEgressMiddleware.js +34 -0
- package/lib/external/ACSAdapter/createChannelDataEgressMiddleware.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 +885 -1120
- 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,9 @@ 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 createChannelDataEgressMiddleware_1 = require("./external/ACSAdapter/createChannelDataEgressMiddleware");
|
69
|
+
var createFormatEgressTagsMiddleware_1 = require("./external/ACSAdapter/createFormatEgressTagsMiddleware");
|
70
|
+
var createFormatIngressTagsMiddleware_1 = require("./external/ACSAdapter/createFormatIngressTagsMiddleware");
|
69
71
|
var DeliveryMode_1 = require("@microsoft/omnichannel-ic3core/lib/model/DeliveryMode");
|
70
72
|
var FileSharingProtocolType_1 = require("@microsoft/omnichannel-ic3core/lib/model/FileSharingProtocolType");
|
71
73
|
var HostType_1 = require("@microsoft/omnichannel-ic3core/lib/interfaces/HostType");
|
@@ -74,6 +76,7 @@ var LiveChatVersion_1 = require("./core/LiveChatVersion");
|
|
74
76
|
var LiveWorkItemState_1 = require("./core/LiveWorkItemState");
|
75
77
|
var MessageContentType_1 = require("@microsoft/omnichannel-ic3core/lib/model/MessageContentType");
|
76
78
|
var MessageType_1 = require("@microsoft/omnichannel-ic3core/lib/model/MessageType");
|
79
|
+
var OmnichannelErrorCodes_1 = require("./core/OmnichannelErrorCodes");
|
77
80
|
var PersonType_1 = require("@microsoft/omnichannel-ic3core/lib/model/PersonType");
|
78
81
|
var ProtocoleType_1 = require("@microsoft/omnichannel-ic3core/lib/interfaces/ProtocoleType");
|
79
82
|
var ScenarioMarker_1 = require("./telemetry/ScenarioMarker");
|
@@ -85,6 +88,7 @@ var createVoiceVideoCalling_1 = require("./api/createVoiceVideoCalling");
|
|
85
88
|
var MessageTags_1 = require("./core/messaging/MessageTags");
|
86
89
|
var locale_1 = require("./utils/locale");
|
87
90
|
var utilities_1 = require("./utils/utilities");
|
91
|
+
var libraries_1 = require("./utils/libraries");
|
88
92
|
var WebUtils_1 = require("./utils/WebUtils");
|
89
93
|
var OmnichannelConfigValidator_1 = require("./validators/OmnichannelConfigValidator");
|
90
94
|
var OmnichannelChatSDK = /** @class */ (function () {
|
@@ -107,11 +111,13 @@ var OmnichannelChatSDK = /** @class */ (function () {
|
|
107
111
|
this.reconnectId = null;
|
108
112
|
this.refreshTokenTimer = null;
|
109
113
|
this.debug = false;
|
114
|
+
this.runtimeId = ocsdk_1.uuidv4();
|
110
115
|
this.omnichannelConfig = omnichannelConfig;
|
111
116
|
this.chatSDKConfig = __assign(__assign({}, SDKConfigValidators_1.defaultChatSDKConfig), chatSDKConfig // overrides
|
112
117
|
);
|
113
118
|
this.isInitialized = false;
|
114
119
|
this.liveChatVersion = LiveChatVersion_1.default.V1;
|
120
|
+
this.localeId = locale_1.defaultLocaleId;
|
115
121
|
this.requestId = ocsdk_1.uuidv4();
|
116
122
|
this.chatToken = {};
|
117
123
|
this.liveChatConfig = {};
|
@@ -129,6 +135,11 @@ var OmnichannelChatSDK = /** @class */ (function () {
|
|
129
135
|
this.ocSdkLogger.useTelemetry(this.telemetry);
|
130
136
|
this.acsClientLogger.useTelemetry(this.telemetry);
|
131
137
|
this.acsAdapterLogger.useTelemetry(this.telemetry);
|
138
|
+
this.scenarioMarker.setRuntimeId(this.runtimeId);
|
139
|
+
this.ic3ClientLogger.setRuntimeId(this.runtimeId);
|
140
|
+
this.ocSdkLogger.setRuntimeId(this.runtimeId);
|
141
|
+
this.acsClientLogger.setRuntimeId(this.runtimeId);
|
142
|
+
this.acsAdapterLogger.setRuntimeId(this.runtimeId);
|
132
143
|
OmnichannelConfigValidator_1.default(omnichannelConfig);
|
133
144
|
SDKConfigValidators_1.default(chatSDKConfig);
|
134
145
|
((_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 +300,55 @@ var OmnichannelChatSDK = /** @class */ (function () {
|
|
289
300
|
});
|
290
301
|
};
|
291
302
|
OmnichannelChatSDK.prototype.startChat = function (optionalParams) {
|
292
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
|
303
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
|
293
304
|
if (optionalParams === void 0) { optionalParams = {}; }
|
294
305
|
return __awaiter(this, void 0, void 0, function () {
|
295
|
-
var reconnectableChatsParams, reconnectableChatsResponse,
|
306
|
+
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
307
|
var _this = this;
|
297
|
-
return __generator(this, function (
|
298
|
-
switch (
|
308
|
+
return __generator(this, function (_w) {
|
309
|
+
switch (_w.label) {
|
299
310
|
case 0:
|
300
311
|
this.scenarioMarker.startScenario(TelemetryEvent_1.default.StartChat, {
|
301
312
|
RequestId: this.requestId
|
302
313
|
});
|
314
|
+
shouldReinitIC3Client = !platform_1.default.isNode() && !platform_1.default.isReactNative() && !this.IC3Client && this.liveChatVersion === LiveChatVersion_1.default.V1;
|
315
|
+
if (!shouldReinitIC3Client) return [3 /*break*/, 2];
|
316
|
+
_s = this;
|
317
|
+
return [4 /*yield*/, this.getIC3Client()];
|
318
|
+
case 1:
|
319
|
+
_s.IC3Client = _w.sent();
|
320
|
+
_w.label = 2;
|
321
|
+
case 2:
|
303
322
|
if (this.isChatReconnect && !((_a = this.chatSDKConfig.chatReconnect) === null || _a === void 0 ? void 0 : _a.disable) && !this.isPersistentChat && optionalParams.reconnectId) {
|
304
323
|
this.reconnectId = optionalParams.reconnectId;
|
305
324
|
}
|
306
|
-
if (!(this.isPersistentChat && !((_b = this.chatSDKConfig.persistentChat) === null || _b === void 0 ? void 0 : _b.disable))) return [3 /*break*/,
|
307
|
-
|
308
|
-
case
|
309
|
-
|
325
|
+
if (!(this.isPersistentChat && !((_b = this.chatSDKConfig.persistentChat) === null || _b === void 0 ? void 0 : _b.disable))) return [3 /*break*/, 6];
|
326
|
+
_w.label = 3;
|
327
|
+
case 3:
|
328
|
+
_w.trys.push([3, 5, , 6]);
|
310
329
|
reconnectableChatsParams = {
|
311
330
|
authenticatedUserToken: this.authenticatedUserToken
|
312
331
|
};
|
313
332
|
return [4 /*yield*/, this.OCClient.getReconnectableChats(reconnectableChatsParams)];
|
314
|
-
case
|
315
|
-
reconnectableChatsResponse =
|
333
|
+
case 4:
|
334
|
+
reconnectableChatsResponse = _w.sent();
|
316
335
|
if (reconnectableChatsResponse && reconnectableChatsResponse.reconnectid) {
|
317
336
|
this.reconnectId = reconnectableChatsResponse.reconnectid;
|
318
337
|
}
|
319
|
-
return [3 /*break*/,
|
320
|
-
case
|
321
|
-
|
338
|
+
return [3 /*break*/, 6];
|
339
|
+
case 5:
|
340
|
+
_t = _w.sent();
|
322
341
|
exceptionDetails = {
|
323
342
|
response: "OCClientGetReconnectableChatsFailed"
|
324
343
|
};
|
325
344
|
throw Error(exceptionDetails.response);
|
326
|
-
case
|
327
|
-
if (!(optionalParams.liveChatContext && !this.
|
345
|
+
case 6:
|
346
|
+
if (!(optionalParams.liveChatContext && !this.reconnectId)) return [3 /*break*/, 8];
|
328
347
|
this.chatToken = optionalParams.liveChatContext.chatToken || {};
|
329
348
|
this.requestId = optionalParams.liveChatContext.requestId || ocsdk_1.uuidv4();
|
330
349
|
return [4 /*yield*/, this.getConversationDetails()];
|
331
|
-
case
|
332
|
-
conversationDetails =
|
350
|
+
case 7:
|
351
|
+
conversationDetails = _w.sent();
|
333
352
|
if (Object.keys(conversationDetails).length === 0) {
|
334
353
|
exceptionDetails = {
|
335
354
|
response: "InvalidConversation"
|
@@ -354,14 +373,14 @@ var OmnichannelChatSDK = /** @class */ (function () {
|
|
354
373
|
console.error("Unable to join conversation that's in '" + conversationDetails.state + "' state");
|
355
374
|
throw Error(exceptionDetails.response);
|
356
375
|
}
|
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;
|
376
|
+
_w.label = 8;
|
364
377
|
case 8:
|
378
|
+
if (!(this.chatToken && Object.keys(this.chatToken).length === 0)) return [3 /*break*/, 10];
|
379
|
+
return [4 /*yield*/, this.getChatToken(false)];
|
380
|
+
case 9:
|
381
|
+
_w.sent();
|
382
|
+
_w.label = 10;
|
383
|
+
case 10:
|
365
384
|
(_c = this.ic3ClientLogger) === null || _c === void 0 ? void 0 : _c.setChatId(this.chatToken.chatId || '');
|
366
385
|
(_d = this.ocSdkLogger) === null || _d === void 0 ? void 0 : _d.setChatId(this.chatToken.chatId || '');
|
367
386
|
(_e = this.acsClientLogger) === null || _e === void 0 ? void 0 : _e.setChatId(this.chatToken.chatId || '');
|
@@ -369,6 +388,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
|
|
369
388
|
sessionInitOptionalParams = {
|
370
389
|
initContext: {}
|
371
390
|
};
|
391
|
+
sessionInitOptionalParams.initContext.locale = locale_1.getLocaleStringFromId(this.localeId);
|
372
392
|
if (this.isPersistentChat && !((_g = this.chatSDKConfig.persistentChat) === null || _g === void 0 ? void 0 : _g.disable)) {
|
373
393
|
sessionInitOptionalParams.reconnectId = this.reconnectId;
|
374
394
|
}
|
@@ -400,27 +420,33 @@ var OmnichannelChatSDK = /** @class */ (function () {
|
|
400
420
|
if (this.authenticatedUserToken) {
|
401
421
|
sessionInitOptionalParams.authenticatedUserToken = this.authenticatedUserToken;
|
402
422
|
}
|
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];
|
423
|
+
if (!!optionalParams.liveChatContext) return [3 /*break*/, 14];
|
424
|
+
_w.label = 11;
|
410
425
|
case 11:
|
411
|
-
|
426
|
+
_w.trys.push([11, 13, , 14]);
|
427
|
+
return [4 /*yield*/, this.OCClient.sessionInit(this.requestId, sessionInitOptionalParams)];
|
428
|
+
case 12:
|
429
|
+
_w.sent();
|
430
|
+
return [3 /*break*/, 14];
|
431
|
+
case 13:
|
432
|
+
error_3 = _w.sent();
|
412
433
|
exceptionDetails = {
|
413
434
|
response: "OCClientSessionInitFailed"
|
414
435
|
};
|
436
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
437
|
+
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()) {
|
438
|
+
exceptionDetails.response = OmnichannelErrorCodes_1.default[OmnichannelErrorCodes_1.default.WidgetUseOutsideOperatingHour].toString();
|
439
|
+
exceptionDetails.message = 'Widget used outside of operating hours';
|
440
|
+
console.error(exceptionDetails.message);
|
441
|
+
}
|
415
442
|
this.scenarioMarker.failScenario(TelemetryEvent_1.default.StartChat, {
|
416
443
|
RequestId: this.requestId,
|
417
444
|
ChatId: this.chatToken.chatId,
|
418
445
|
ExceptionDetails: JSON.stringify(exceptionDetails)
|
419
446
|
});
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
if (!(this.liveChatVersion === LiveChatVersion_1.default.V2)) return [3 /*break*/, 23];
|
447
|
+
throw new Error(exceptionDetails.response);
|
448
|
+
case 14:
|
449
|
+
if (!(this.liveChatVersion === LiveChatVersion_1.default.V2)) return [3 /*break*/, 25];
|
424
450
|
chatAdapterConfig = {
|
425
451
|
token: this.chatToken.token,
|
426
452
|
id: this.chatToken.visitorId || 'teamsvisitor',
|
@@ -428,18 +454,18 @@ var OmnichannelChatSDK = /** @class */ (function () {
|
|
428
454
|
environmentUrl: this.chatToken.acsEndpoint,
|
429
455
|
pollingInterval: 1000
|
430
456
|
};
|
431
|
-
|
432
|
-
case
|
433
|
-
|
434
|
-
return [4 /*yield*/, ((
|
457
|
+
_w.label = 15;
|
458
|
+
case 15:
|
459
|
+
_w.trys.push([15, 17, , 18]);
|
460
|
+
return [4 /*yield*/, ((_m = this.ACSClient) === null || _m === void 0 ? void 0 : _m.initialize({
|
435
461
|
token: chatAdapterConfig.token,
|
436
462
|
environmentUrl: chatAdapterConfig.environmentUrl
|
437
463
|
}))];
|
438
|
-
case
|
439
|
-
|
440
|
-
return [3 /*break*/,
|
441
|
-
case
|
442
|
-
error_4 =
|
464
|
+
case 16:
|
465
|
+
_w.sent();
|
466
|
+
return [3 /*break*/, 18];
|
467
|
+
case 17:
|
468
|
+
error_4 = _w.sent();
|
443
469
|
exceptionDetails = {
|
444
470
|
response: "ACSClientInitializeFailed"
|
445
471
|
};
|
@@ -450,23 +476,23 @@ var OmnichannelChatSDK = /** @class */ (function () {
|
|
450
476
|
});
|
451
477
|
console.error("OmnichannelChatSDK/startChat/initialize/error " + error_4);
|
452
478
|
return [2 /*return*/, error_4];
|
453
|
-
case
|
454
|
-
|
455
|
-
|
456
|
-
return [4 /*yield*/, ((
|
479
|
+
case 18:
|
480
|
+
_w.trys.push([18, 20, , 21]);
|
481
|
+
_u = this;
|
482
|
+
return [4 /*yield*/, ((_o = this.ACSClient) === null || _o === void 0 ? void 0 : _o.joinConversation({
|
457
483
|
id: chatAdapterConfig.id,
|
458
484
|
threadId: chatAdapterConfig.threadId,
|
459
485
|
pollingInterval: chatAdapterConfig.pollingInterval
|
460
486
|
}))];
|
461
|
-
case
|
462
|
-
|
487
|
+
case 19:
|
488
|
+
_u.conversation = (_w.sent());
|
463
489
|
this.scenarioMarker.completeScenario(TelemetryEvent_1.default.StartChat, {
|
464
490
|
RequestId: this.requestId,
|
465
491
|
ChatId: this.chatToken.chatId
|
466
492
|
});
|
467
|
-
return [3 /*break*/,
|
468
|
-
case
|
469
|
-
error_5 =
|
493
|
+
return [3 /*break*/, 21];
|
494
|
+
case 20:
|
495
|
+
error_5 = _w.sent();
|
470
496
|
exceptionDetails = {
|
471
497
|
response: "ACSClientJoinConversationFailed"
|
472
498
|
};
|
@@ -477,16 +503,16 @@ var OmnichannelChatSDK = /** @class */ (function () {
|
|
477
503
|
});
|
478
504
|
console.error("OmnichannelChatSDK/startChat/joinConversation/error " + error_5);
|
479
505
|
throw Error(exceptionDetails.response);
|
480
|
-
case
|
481
|
-
|
482
|
-
return [4 /*yield*/, ((
|
506
|
+
case 21:
|
507
|
+
_w.trys.push([21, 23, , 24]);
|
508
|
+
return [4 /*yield*/, ((_p = this.AMSClient) === null || _p === void 0 ? void 0 : _p.initialize({
|
483
509
|
chatToken: this.chatToken
|
484
510
|
}))];
|
485
|
-
case
|
486
|
-
|
487
|
-
return [3 /*break*/,
|
488
|
-
case
|
489
|
-
error_6 =
|
511
|
+
case 22:
|
512
|
+
_w.sent();
|
513
|
+
return [3 /*break*/, 24];
|
514
|
+
case 23:
|
515
|
+
error_6 = _w.sent();
|
490
516
|
exceptionDetails = {
|
491
517
|
response: "AMSClientInitializeFailed"
|
492
518
|
};
|
@@ -496,19 +522,19 @@ var OmnichannelChatSDK = /** @class */ (function () {
|
|
496
522
|
ExceptionDetails: JSON.stringify(exceptionDetails)
|
497
523
|
});
|
498
524
|
throw Error(exceptionDetails.response);
|
499
|
-
case
|
500
|
-
case
|
501
|
-
|
525
|
+
case 24: return [3 /*break*/, 31];
|
526
|
+
case 25:
|
527
|
+
_w.trys.push([25, 27, , 28]);
|
502
528
|
return [4 /*yield*/, this.IC3Client.initialize({
|
503
529
|
token: this.chatToken.token,
|
504
530
|
regionGtms: this.chatToken.regionGTMS,
|
505
531
|
visitor: true
|
506
532
|
})];
|
507
|
-
case
|
508
|
-
|
509
|
-
return [3 /*break*/,
|
510
|
-
case
|
511
|
-
error_7 =
|
533
|
+
case 26:
|
534
|
+
_w.sent();
|
535
|
+
return [3 /*break*/, 28];
|
536
|
+
case 27:
|
537
|
+
error_7 = _w.sent();
|
512
538
|
exceptionDetails = {
|
513
539
|
response: "IC3ClientInitializeFailed"
|
514
540
|
};
|
@@ -519,19 +545,19 @@ var OmnichannelChatSDK = /** @class */ (function () {
|
|
519
545
|
});
|
520
546
|
console.error("OmnichannelChatSDK/startChat/initialize/error " + error_7);
|
521
547
|
return [2 /*return*/, error_7];
|
522
|
-
case
|
523
|
-
|
524
|
-
|
548
|
+
case 28:
|
549
|
+
_w.trys.push([28, 30, , 31]);
|
550
|
+
_v = this;
|
525
551
|
return [4 /*yield*/, this.IC3Client.joinConversation(this.chatToken.chatId)];
|
526
|
-
case
|
527
|
-
|
552
|
+
case 29:
|
553
|
+
_v.conversation = _w.sent();
|
528
554
|
this.scenarioMarker.completeScenario(TelemetryEvent_1.default.StartChat, {
|
529
555
|
RequestId: this.requestId,
|
530
556
|
ChatId: this.chatToken.chatId
|
531
557
|
});
|
532
|
-
return [3 /*break*/,
|
533
|
-
case
|
534
|
-
error_8 =
|
558
|
+
return [3 /*break*/, 31];
|
559
|
+
case 30:
|
560
|
+
error_8 = _w.sent();
|
535
561
|
exceptionDetails = {
|
536
562
|
response: "IC3ClientJoinConversationFailed"
|
537
563
|
};
|
@@ -542,8 +568,8 @@ var OmnichannelChatSDK = /** @class */ (function () {
|
|
542
568
|
});
|
543
569
|
console.error("OmnichannelChatSDK/startChat/joinConversation/error " + error_8);
|
544
570
|
return [2 /*return*/, error_8];
|
545
|
-
case
|
546
|
-
if (this.isPersistentChat && !((
|
571
|
+
case 31:
|
572
|
+
if (this.isPersistentChat && !((_q = this.chatSDKConfig.persistentChat) === null || _q === void 0 ? void 0 : _q.disable)) {
|
547
573
|
this.refreshTokenTimer = setInterval(function () { return __awaiter(_this, void 0, void 0, function () {
|
548
574
|
return __generator(this, function (_a) {
|
549
575
|
switch (_a.label) {
|
@@ -554,7 +580,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
|
|
554
580
|
return [2 /*return*/];
|
555
581
|
}
|
556
582
|
});
|
557
|
-
}); }, (
|
583
|
+
}); }, (_r = this.chatSDKConfig.persistentChat) === null || _r === void 0 ? void 0 : _r.tokenUpdateTime);
|
558
584
|
}
|
559
585
|
return [2 /*return*/];
|
560
586
|
}
|
@@ -580,6 +606,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
|
|
580
606
|
}
|
581
607
|
if (this.isChatReconnect && !((_b = this.chatSDKConfig.chatReconnect) === null || _b === void 0 ? void 0 : _b.disable) && !this.isPersistentChat) {
|
582
608
|
isChatReconnect = this.reconnectId !== null ? true : false;
|
609
|
+
this.requestId = isChatReconnect ? this.reconnectId : this.requestId; // Chat Reconnect session to close
|
583
610
|
sessionCloseOptionalParams.isReconnectChat = isChatReconnect;
|
584
611
|
}
|
585
612
|
if (this.authenticatedUserToken) {
|
@@ -600,6 +627,11 @@ var OmnichannelChatSDK = /** @class */ (function () {
|
|
600
627
|
this.requestId = ocsdk_1.uuidv4();
|
601
628
|
this.chatToken = {};
|
602
629
|
this.reconnectId = null;
|
630
|
+
if (this.IC3Client) {
|
631
|
+
this.IC3Client.dispose();
|
632
|
+
!platform_1.default.isNode() && !platform_1.default.isReactNative() && WebUtils_1.removeElementById(this.IC3Client.id);
|
633
|
+
this.IC3Client = null;
|
634
|
+
}
|
603
635
|
(_d = this.ic3ClientLogger) === null || _d === void 0 ? void 0 : _d.setRequestId(this.requestId);
|
604
636
|
(_e = this.ic3ClientLogger) === null || _e === void 0 ? void 0 : _e.setChatId('');
|
605
637
|
(_f = this.ocSdkLogger) === null || _f === void 0 ? void 0 : _f.setRequestId(this.requestId);
|
@@ -661,22 +693,32 @@ var OmnichannelChatSDK = /** @class */ (function () {
|
|
661
693
|
});
|
662
694
|
};
|
663
695
|
OmnichannelChatSDK.prototype.getConversationDetails = function () {
|
664
|
-
var _a, _b;
|
696
|
+
var _a, _b, _c, _d;
|
665
697
|
return __awaiter(this, void 0, void 0, function () {
|
666
|
-
var lwiDetails, state, conversationId, agentAcceptedOn, liveWorkItemDetails, error_10;
|
667
|
-
return __generator(this, function (
|
668
|
-
switch (
|
698
|
+
var getLWIDetailsOptionalParams, lwiDetails, state, conversationId, agentAcceptedOn, liveWorkItemDetails, error_10;
|
699
|
+
return __generator(this, function (_e) {
|
700
|
+
switch (_e.label) {
|
669
701
|
case 0:
|
670
702
|
this.scenarioMarker.startScenario(TelemetryEvent_1.default.GetConversationDetails, {
|
671
703
|
RequestId: this.requestId,
|
672
704
|
ChatId: ((_a = this.chatToken) === null || _a === void 0 ? void 0 : _a.chatId) || '',
|
673
705
|
});
|
674
|
-
|
706
|
+
getLWIDetailsOptionalParams = {};
|
707
|
+
if (this.isPersistentChat && !((_b = this.chatSDKConfig.persistentChat) === null || _b === void 0 ? void 0 : _b.disable) && this.reconnectId) {
|
708
|
+
getLWIDetailsOptionalParams.reconnectId = this.reconnectId;
|
709
|
+
}
|
710
|
+
if (this.isChatReconnect && !((_c = this.chatSDKConfig.chatReconnect) === null || _c === void 0 ? void 0 : _c.disable) && !this.isPersistentChat && this.reconnectId) {
|
711
|
+
getLWIDetailsOptionalParams.reconnectId = this.reconnectId;
|
712
|
+
}
|
713
|
+
if (this.authenticatedUserToken) {
|
714
|
+
getLWIDetailsOptionalParams.authenticatedUserToken = this.authenticatedUserToken;
|
715
|
+
}
|
716
|
+
_e.label = 1;
|
675
717
|
case 1:
|
676
|
-
|
677
|
-
return [4 /*yield*/, this.OCClient.getLWIDetails(this.requestId)];
|
718
|
+
_e.trys.push([1, 3, , 4]);
|
719
|
+
return [4 /*yield*/, this.OCClient.getLWIDetails(this.requestId, getLWIDetailsOptionalParams)];
|
678
720
|
case 2:
|
679
|
-
lwiDetails =
|
721
|
+
lwiDetails = _e.sent();
|
680
722
|
state = lwiDetails.State, conversationId = lwiDetails.ConversationId, agentAcceptedOn = lwiDetails.AgentAcceptedOn;
|
681
723
|
liveWorkItemDetails = {
|
682
724
|
state: state,
|
@@ -687,11 +729,11 @@ var OmnichannelChatSDK = /** @class */ (function () {
|
|
687
729
|
}
|
688
730
|
this.scenarioMarker.completeScenario(TelemetryEvent_1.default.GetConversationDetails, {
|
689
731
|
RequestId: this.requestId,
|
690
|
-
ChatId: ((
|
732
|
+
ChatId: ((_d = this.chatToken) === null || _d === void 0 ? void 0 : _d.chatId) || '',
|
691
733
|
});
|
692
734
|
return [2 /*return*/, liveWorkItemDetails];
|
693
735
|
case 3:
|
694
|
-
error_10 =
|
736
|
+
error_10 = _e.sent();
|
695
737
|
this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetConversationDetails, {
|
696
738
|
RequestId: this.requestId,
|
697
739
|
ChatId: this.chatToken.chatId || '',
|
@@ -897,6 +939,13 @@ var OmnichannelChatSDK = /** @class */ (function () {
|
|
897
939
|
sendMessageRequest = {
|
898
940
|
content: message.content,
|
899
941
|
};
|
942
|
+
sendMessageRequest.metadata = {
|
943
|
+
widgetId: this.omnichannelConfig.widgetId,
|
944
|
+
clientMessageId: Date.now().toString()
|
945
|
+
};
|
946
|
+
if (message.metadata) {
|
947
|
+
sendMessageRequest.metadata = __assign(__assign({}, sendMessageRequest.metadata), message.metadata);
|
948
|
+
}
|
900
949
|
_e.label = 1;
|
901
950
|
case 1:
|
902
951
|
_e.trys.push([1, 3, , 4]);
|
@@ -1279,7 +1328,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
|
|
1279
1328
|
};
|
1280
1329
|
sendMessageRequest = {
|
1281
1330
|
content: '',
|
1282
|
-
metadata: __assign(__assign({}, fileIdsProperty), fileMetaProperty)
|
1331
|
+
metadata: __assign(__assign({ widgetId: this.omnichannelConfig.widgetId, clientMessageId: Date.now().toString() }, fileIdsProperty), fileMetaProperty)
|
1283
1332
|
};
|
1284
1333
|
messageToSend = {
|
1285
1334
|
content: "",
|
@@ -1440,7 +1489,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
|
|
1440
1489
|
ChatId: this.chatToken.chatId,
|
1441
1490
|
EmailAddress: body.emailAddress,
|
1442
1491
|
DefaultAttachmentMessage: body.attachmentMessage,
|
1443
|
-
CustomerLocale: body.locale
|
1492
|
+
CustomerLocale: body.locale || locale_1.getLocaleStringFromId(this.localeId)
|
1444
1493
|
};
|
1445
1494
|
emailResponse = this.OCClient.emailTranscript(this.requestId, this.chatToken.token, emailRequestBody, emailTranscriptOptionalParams);
|
1446
1495
|
this.scenarioMarker.completeScenario(TelemetryEvent_1.default.EmailLiveChatTranscript, {
|
@@ -1490,32 +1539,36 @@ var OmnichannelChatSDK = /** @class */ (function () {
|
|
1490
1539
|
});
|
1491
1540
|
});
|
1492
1541
|
};
|
1493
|
-
OmnichannelChatSDK.prototype.createChatAdapter = function (
|
1494
|
-
if (
|
1542
|
+
OmnichannelChatSDK.prototype.createChatAdapter = function (optionalParams) {
|
1543
|
+
if (optionalParams === void 0) { optionalParams = {}; }
|
1495
1544
|
return __awaiter(this, void 0, void 0, function () {
|
1496
|
-
var supportedChatAdapterProtocols;
|
1545
|
+
var protocol, supportedChatAdapterProtocols;
|
1497
1546
|
var _this = this;
|
1498
1547
|
return __generator(this, function (_a) {
|
1499
1548
|
if (platform_1.default.isNode() || platform_1.default.isReactNative()) {
|
1500
1549
|
return [2 /*return*/, Promise.reject('ChatAdapter is only supported on browser')];
|
1501
1550
|
}
|
1551
|
+
protocol = optionalParams.protocol;
|
1502
1552
|
supportedChatAdapterProtocols = [ChatAdapterProtocols_1.default.ACS, ChatAdapterProtocols_1.default.IC3];
|
1503
1553
|
if (protocol && !supportedChatAdapterProtocols.includes(protocol)) {
|
1504
1554
|
return [2 /*return*/, Promise.reject("ChatAdapter for protocol " + protocol + " currently not supported")];
|
1505
1555
|
}
|
1506
1556
|
if (protocol === ChatAdapterProtocols_1.default.ACS || this.liveChatVersion === LiveChatVersion_1.default.V2) {
|
1507
1557
|
return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
|
1508
|
-
var featuresOption, acsAdapterCDNUrl;
|
1558
|
+
var options, defaultEgressMiddlewares, defaultIngressMiddlewares, egressMiddleware, ingressMiddleware, featuresOption, acsAdapterCDNUrl;
|
1509
1559
|
var _this = this;
|
1510
1560
|
var _a;
|
1511
1561
|
return __generator(this, function (_b) {
|
1512
1562
|
switch (_b.label) {
|
1513
1563
|
case 0:
|
1514
|
-
|
1515
|
-
|
1516
|
-
|
1517
|
-
|
1518
|
-
|
1564
|
+
options = optionalParams.ACSAdapter ? optionalParams.ACSAdapter.options : {};
|
1565
|
+
defaultEgressMiddlewares = [createChannelDataEgressMiddleware_1.default({ widgetId: this.omnichannelConfig.widgetId }), createFormatEgressTagsMiddleware_1.default()];
|
1566
|
+
defaultIngressMiddlewares = [createFormatIngressTagsMiddleware_1.default()];
|
1567
|
+
egressMiddleware = (options === null || options === void 0 ? void 0 : options.egressMiddleware) ? __spreadArrays(options.egressMiddleware, defaultEgressMiddlewares) : __spreadArrays(defaultEgressMiddlewares);
|
1568
|
+
ingressMiddleware = (options === null || options === void 0 ? void 0 : options.ingressMiddleware) ? __spreadArrays(options.egressMiddleware, defaultIngressMiddlewares) : __spreadArrays(defaultIngressMiddlewares);
|
1569
|
+
featuresOption = __assign(__assign({ enableAdaptiveCards: true, enableThreadMemberUpdateNotification: true, enableLeaveThreadOnWindowClosed: false }, options), { // overrides
|
1570
|
+
ingressMiddleware: ingressMiddleware,
|
1571
|
+
egressMiddleware: egressMiddleware });
|
1519
1572
|
acsAdapterCDNUrl = this.resolveChatAdapterUrl(protocol || ChatAdapterProtocols_1.default.ACS);
|
1520
1573
|
(_a = this.telemetry) === null || _a === void 0 ? void 0 : _a.setCDNPackages({
|
1521
1574
|
ACSAdapter: acsAdapterCDNUrl
|
@@ -1526,7 +1579,9 @@ var OmnichannelChatSDK = /** @class */ (function () {
|
|
1526
1579
|
try {
|
1527
1580
|
var ChatAdapter = window.ChatAdapter; // eslint-disable-line @typescript-eslint/no-explicit-any
|
1528
1581
|
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,
|
1582
|
+
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
|
1583
|
+
undefined, // logger
|
1584
|
+
featuresOption);
|
1530
1585
|
resolve(adapter);
|
1531
1586
|
}
|
1532
1587
|
catch (_a) {
|
@@ -1544,12 +1599,13 @@ var OmnichannelChatSDK = /** @class */ (function () {
|
|
1544
1599
|
}
|
1545
1600
|
else if (protocol === ChatAdapterProtocols_1.default.IC3 || this.liveChatVersion === LiveChatVersion_1.default.V1) {
|
1546
1601
|
return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
|
1547
|
-
var ic3AdapterCDNUrl;
|
1602
|
+
var options, ic3AdapterCDNUrl;
|
1548
1603
|
var _this = this;
|
1549
1604
|
var _a;
|
1550
1605
|
return __generator(this, function (_b) {
|
1551
1606
|
switch (_b.label) {
|
1552
1607
|
case 0:
|
1608
|
+
options = optionalParams.IC3Adapter ? optionalParams.IC3Adapter.options : {};
|
1553
1609
|
ic3AdapterCDNUrl = this.resolveChatAdapterUrl(protocol || ChatAdapterProtocols_1.default.IC3);
|
1554
1610
|
(_a = this.telemetry) === null || _a === void 0 ? void 0 : _a.setCDNPackages({
|
1555
1611
|
IC3Adapter: ic3AdapterCDNUrl
|
@@ -1558,17 +1614,10 @@ var OmnichannelChatSDK = /** @class */ (function () {
|
|
1558
1614
|
return [4 /*yield*/, WebUtils_1.loadScript(ic3AdapterCDNUrl, function () {
|
1559
1615
|
/* istanbul ignore next */
|
1560
1616
|
_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
|
-
};
|
1617
|
+
var adapterConfig = __assign({ chatToken: _this.chatToken, userDisplayName: 'Customer', userId: _this.chatToken.visitorId || 'teamsvisitor', sdkURL: _this.resolveIC3ClientUrl(), sdk: _this.IC3Client }, options // overrides
|
1618
|
+
);
|
1568
1619
|
var adapter = new window.Microsoft.BotFramework.WebChat.IC3Adapter(adapterConfig);
|
1569
1620
|
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
1621
|
_this.scenarioMarker.completeScenario(TelemetryEvent_1.default.CreateIC3Adapter);
|
1573
1622
|
resolve(adapter);
|
1574
1623
|
}, function () {
|
@@ -1662,7 +1711,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
|
|
1662
1711
|
};
|
1663
1712
|
OmnichannelChatSDK.prototype.getPostChatSurveyContext = function () {
|
1664
1713
|
return __awaiter(this, void 0, void 0, function () {
|
1665
|
-
var conversationId,
|
1714
|
+
var conversationId, liveWSAndLiveChatEngJoin, msdyn_postconversationsurveyenable, msfp_sourcesurveyidentifier, postConversationSurveyOwnerId, liveWorkItemDetails, participantJoined, surveyInviteLinkRequest, optionalParams, surveyInviteLinkResponse, surveyInviteLink, formsProLocale, postChatContext, ex_1;
|
1666
1715
|
return __generator(this, function (_a) {
|
1667
1716
|
switch (_a.label) {
|
1668
1717
|
case 0:
|
@@ -1672,11 +1721,8 @@ var OmnichannelChatSDK = /** @class */ (function () {
|
|
1672
1721
|
_a.label = 1;
|
1673
1722
|
case 1:
|
1674
1723
|
_a.trys.push([1, 6, , 7]);
|
1675
|
-
|
1676
|
-
liveWSAndLiveChatEngJoin = chatConfig.LiveWSAndLiveChatEngJoin, chatWidgetLanguage = chatConfig.ChatWidgetLanguage;
|
1724
|
+
liveWSAndLiveChatEngJoin = this.liveChatConfig.LiveWSAndLiveChatEngJoin;
|
1677
1725
|
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
1726
|
if (!msdyn_postconversationsurveyenable) return [3 /*break*/, 4];
|
1681
1727
|
return [4 /*yield*/, this.OCClient.getLWIDetails(this.requestId)];
|
1682
1728
|
case 2:
|
@@ -1686,7 +1732,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
|
|
1686
1732
|
surveyInviteLinkRequest = {
|
1687
1733
|
"FormId": msfp_sourcesurveyidentifier,
|
1688
1734
|
"ConversationId": conversationId,
|
1689
|
-
"OCLocaleCode": locale_1.getLocaleStringFromId(localeId)
|
1735
|
+
"OCLocaleCode": locale_1.getLocaleStringFromId(this.localeId) || locale_1.getLocaleStringFromId(locale_1.defaultLocaleId)
|
1690
1736
|
};
|
1691
1737
|
optionalParams = {
|
1692
1738
|
"requestId": this.requestId
|
@@ -1749,102 +1795,6 @@ var OmnichannelChatSDK = /** @class */ (function () {
|
|
1749
1795
|
});
|
1750
1796
|
});
|
1751
1797
|
};
|
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
1798
|
OmnichannelChatSDK.prototype.getIC3Client = function () {
|
1849
1799
|
return __awaiter(this, void 0, void 0, function () {
|
1850
1800
|
var IC3Client;
|
@@ -1871,7 +1821,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
|
|
1871
1821
|
this.debug && console.debug('IC3Client');
|
1872
1822
|
// Use IC3Client if browser is detected
|
1873
1823
|
return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
|
1874
|
-
var ic3ClientCDNUrl;
|
1824
|
+
var ic3ClientCDNUrl, IC3Client;
|
1875
1825
|
var _this = this;
|
1876
1826
|
var _a;
|
1877
1827
|
return __generator(this, function (_b) {
|
@@ -1882,6 +1832,16 @@ var OmnichannelChatSDK = /** @class */ (function () {
|
|
1882
1832
|
IC3Client: ic3ClientCDNUrl
|
1883
1833
|
});
|
1884
1834
|
this.scenarioMarker.startScenario(TelemetryEvent_1.default.GetIC3Client);
|
1835
|
+
if (!this.IC3SDKProvider) return [3 /*break*/, 2];
|
1836
|
+
return [4 /*yield*/, this.IC3SDKProvider.getSDK({
|
1837
|
+
hostType: HostType_1.default.IFrame,
|
1838
|
+
protocolType: ProtocoleType_1.default.IC3V1SDK,
|
1839
|
+
logger: this.ic3ClientLogger // eslint-disable-line @typescript-eslint/no-explicit-any
|
1840
|
+
})];
|
1841
|
+
case 1:
|
1842
|
+
IC3Client = _b.sent();
|
1843
|
+
return [2 /*return*/, resolve(IC3Client)];
|
1844
|
+
case 2:
|
1885
1845
|
window.addEventListener("ic3:sdk:load", function () { return __awaiter(_this, void 0, void 0, function () {
|
1886
1846
|
var ic3sdk, IC3SDKProvider, IC3Client;
|
1887
1847
|
return __generator(this, function (_a) {
|
@@ -1918,7 +1878,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
|
|
1918
1878
|
});
|
1919
1879
|
reject('Failed to load IC3Client');
|
1920
1880
|
})];
|
1921
|
-
case
|
1881
|
+
case 3:
|
1922
1882
|
_b.sent();
|
1923
1883
|
return [2 /*return*/];
|
1924
1884
|
}
|
@@ -1930,15 +1890,17 @@ var OmnichannelChatSDK = /** @class */ (function () {
|
|
1930
1890
|
};
|
1931
1891
|
OmnichannelChatSDK.prototype.getChatConfig = function () {
|
1932
1892
|
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 (
|
1893
|
+
var liveChatConfig, dataMaskingConfig, authSettings, liveWSAndLiveChatEngJoin, liveChatVersion, chatWidgetLanguage, msdyn_localeid, setting, preChatSurvey, msdyn_prechatenabled, msdyn_callingoptions, msdyn_conversationmode, msdyn_enablechatreconnect, isPreChatEnabled, isChatReconnectEnabled, error_18;
|
1894
|
+
return __generator(this, function (_a) {
|
1895
|
+
switch (_a.label) {
|
1936
1896
|
case 0:
|
1937
|
-
|
1897
|
+
_a.trys.push([0, 4, , 5]);
|
1938
1898
|
return [4 /*yield*/, this.OCClient.getChatConfig()];
|
1939
1899
|
case 1:
|
1940
|
-
liveChatConfig =
|
1941
|
-
dataMaskingConfig = liveChatConfig.DataMaskingInfo, authSettings = liveChatConfig.LiveChatConfigAuthSettings, liveWSAndLiveChatEngJoin = liveChatConfig.LiveWSAndLiveChatEngJoin, liveChatVersion = liveChatConfig.LiveChatVersion;
|
1900
|
+
liveChatConfig = _a.sent();
|
1901
|
+
dataMaskingConfig = liveChatConfig.DataMaskingInfo, authSettings = liveChatConfig.LiveChatConfigAuthSettings, liveWSAndLiveChatEngJoin = liveChatConfig.LiveWSAndLiveChatEngJoin, liveChatVersion = liveChatConfig.LiveChatVersion, chatWidgetLanguage = liveChatConfig.ChatWidgetLanguage;
|
1902
|
+
msdyn_localeid = chatWidgetLanguage.msdyn_localeid;
|
1903
|
+
this.localeId = msdyn_localeid || locale_1.defaultLocaleId;
|
1942
1904
|
this.liveChatVersion = liveChatVersion || LiveChatVersion_1.default.V1;
|
1943
1905
|
/* istanbul ignore next */
|
1944
1906
|
this.debug && console.log("[OmnichannelChatSDK][getChatConfig][liveChatVersion] " + this.liveChatVersion);
|
@@ -1961,47 +1923,12 @@ var OmnichannelChatSDK = /** @class */ (function () {
|
|
1961
1923
|
if (isPreChatEnabled && preChatSurvey && preChatSurvey.trim().length > 0) {
|
1962
1924
|
this.preChatSurvey = preChatSurvey;
|
1963
1925
|
}
|
1964
|
-
if (!this.authSettings) return [3 /*break*/,
|
1965
|
-
this.
|
1966
|
-
if (!this.chatSDKConfig.getAuthToken) return [3 /*break*/, 6];
|
1967
|
-
_b.label = 2;
|
1926
|
+
if (!this.authSettings) return [3 /*break*/, 3];
|
1927
|
+
return [4 /*yield*/, this.setAuthTokenProvider(this.chatSDKConfig.getAuthToken)];
|
1968
1928
|
case 2:
|
1969
|
-
|
1970
|
-
|
1929
|
+
_a.sent();
|
1930
|
+
_a.label = 3;
|
1971
1931
|
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
1932
|
if (this.preChatSurvey) {
|
2006
1933
|
/* istanbul ignore next */
|
2007
1934
|
this.debug && console.log('Prechat Survey!');
|
@@ -2009,11 +1936,11 @@ var OmnichannelChatSDK = /** @class */ (function () {
|
|
2009
1936
|
this.callingOption = msdyn_callingoptions;
|
2010
1937
|
this.liveChatConfig = liveChatConfig;
|
2011
1938
|
return [2 /*return*/, this.liveChatConfig];
|
2012
|
-
case
|
2013
|
-
error_18 =
|
1939
|
+
case 4:
|
1940
|
+
error_18 = _a.sent();
|
2014
1941
|
console.error("OmnichannelChatSDK/getChatConfig/error " + error_18);
|
2015
1942
|
return [2 /*return*/, error_18];
|
2016
|
-
case
|
1943
|
+
case 5: return [2 /*return*/];
|
2017
1944
|
}
|
2018
1945
|
});
|
2019
1946
|
});
|
@@ -2095,6 +2022,57 @@ var OmnichannelChatSDK = /** @class */ (function () {
|
|
2095
2022
|
});
|
2096
2023
|
});
|
2097
2024
|
};
|
2025
|
+
OmnichannelChatSDK.prototype.setAuthTokenProvider = function (provider) {
|
2026
|
+
return __awaiter(this, void 0, void 0, function () {
|
2027
|
+
var token, exceptionDetails, _a, exceptionDetails, exceptionDetails;
|
2028
|
+
return __generator(this, function (_b) {
|
2029
|
+
switch (_b.label) {
|
2030
|
+
case 0:
|
2031
|
+
this.scenarioMarker.startScenario(TelemetryEvent_1.default.GetAuthToken);
|
2032
|
+
this.chatSDKConfig.getAuthToken = provider;
|
2033
|
+
if (!this.chatSDKConfig.getAuthToken) return [3 /*break*/, 5];
|
2034
|
+
_b.label = 1;
|
2035
|
+
case 1:
|
2036
|
+
_b.trys.push([1, 3, , 4]);
|
2037
|
+
return [4 /*yield*/, this.chatSDKConfig.getAuthToken()];
|
2038
|
+
case 2:
|
2039
|
+
token = _b.sent();
|
2040
|
+
if (token) {
|
2041
|
+
this.authenticatedUserToken = token;
|
2042
|
+
this.scenarioMarker.completeScenario(TelemetryEvent_1.default.GetAuthToken);
|
2043
|
+
}
|
2044
|
+
else {
|
2045
|
+
exceptionDetails = {
|
2046
|
+
response: "UndefinedAuthToken"
|
2047
|
+
};
|
2048
|
+
this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetAuthToken, {
|
2049
|
+
ExceptionDetails: JSON.stringify(exceptionDetails)
|
2050
|
+
});
|
2051
|
+
}
|
2052
|
+
return [3 /*break*/, 4];
|
2053
|
+
case 3:
|
2054
|
+
_a = _b.sent();
|
2055
|
+
exceptionDetails = {
|
2056
|
+
response: "GetAuthTokenFailed"
|
2057
|
+
};
|
2058
|
+
this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetAuthToken, {
|
2059
|
+
ExceptionDetails: JSON.stringify(exceptionDetails)
|
2060
|
+
});
|
2061
|
+
return [3 /*break*/, 4];
|
2062
|
+
case 4: return [3 /*break*/, 6];
|
2063
|
+
case 5:
|
2064
|
+
exceptionDetails = {
|
2065
|
+
response: "GetAuthTokenNotFound"
|
2066
|
+
};
|
2067
|
+
this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetAuthToken, {
|
2068
|
+
ExceptionDetails: JSON.stringify(exceptionDetails)
|
2069
|
+
});
|
2070
|
+
_b.label = 6;
|
2071
|
+
case 6: return [2 /*return*/];
|
2072
|
+
}
|
2073
|
+
});
|
2074
|
+
});
|
2075
|
+
};
|
2098
2076
|
return OmnichannelChatSDK;
|
2099
2077
|
}());
|
2100
2078
|
exports.default = OmnichannelChatSDK;
|