@microsoft/omnichannel-chat-sdk 1.11.8 → 1.11.9-main.37a1dbb
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/README.md +4 -0
- package/lib/OmnichannelChatSDK.d.ts +21 -0
- package/lib/OmnichannelChatSDK.js +254 -77
- package/lib/OmnichannelChatSDK.js.map +1 -1
- package/lib/config/settings.d.ts +1 -1
- package/lib/config/settings.js +1 -1
- package/lib/core/messaging/ACSClient.d.ts +2 -0
- package/lib/core/messaging/ACSClient.js +22 -0
- package/lib/core/messaging/ACSClient.js.map +1 -1
- package/lib/telemetry/TelemetryEvent.d.ts +2 -1
- package/lib/telemetry/TelemetryEvent.js +1 -0
- package/lib/telemetry/TelemetryEvent.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
|
@@ -149,6 +149,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
|
|
|
149
149
|
this.debugACS = false;
|
|
150
150
|
this.detailedDebugEnabled = false;
|
|
151
151
|
this.regexCompiledForDataMasking = [];
|
|
152
|
+
this.isEndingChat = false;
|
|
152
153
|
this.populateInitChatOptionalParam = function (requestOptionalParams, optionalParams, telemetryEvent) {
|
|
153
154
|
requestOptionalParams.initContext.locale = (0, locale_1.getLocaleStringFromId)(_this.localeId);
|
|
154
155
|
if (optionalParams === null || optionalParams === void 0 ? void 0 : optionalParams.customContext) {
|
|
@@ -849,6 +850,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
|
|
|
849
850
|
return __generator(this, function (_o) {
|
|
850
851
|
switch (_o.label) {
|
|
851
852
|
case 0:
|
|
853
|
+
this.isEndingChat = false;
|
|
852
854
|
this.scenarioMarker.startScenario(TelemetryEvent_1.default.StartChat, {
|
|
853
855
|
RequestId: this.requestId
|
|
854
856
|
});
|
|
@@ -1276,6 +1278,18 @@ var OmnichannelChatSDK = /** @class */ (function () {
|
|
|
1276
1278
|
});
|
|
1277
1279
|
});
|
|
1278
1280
|
};
|
|
1281
|
+
/**
|
|
1282
|
+
* Ends the chat by closing the session and disconnecting from the conversation.
|
|
1283
|
+
*
|
|
1284
|
+
* On React Native, automatically waits for conversational survey completion if enabled.
|
|
1285
|
+
* On Web, disconnects immediately as the widget handles surveys independently.
|
|
1286
|
+
*
|
|
1287
|
+
* @param endChatOptionalParams - Optional parameters
|
|
1288
|
+
* @param endChatOptionalParams.isSessionEnded - Skip survey wait if session already ended
|
|
1289
|
+
* @example
|
|
1290
|
+
* await chatSDK.endChat();
|
|
1291
|
+
* await chatSDK.endChat({ isSessionEnded: true });
|
|
1292
|
+
*/
|
|
1279
1293
|
OmnichannelChatSDK.prototype.endChat = function () {
|
|
1280
1294
|
return __awaiter(this, arguments, void 0, function (endChatOptionalParams) {
|
|
1281
1295
|
var _this = this;
|
|
@@ -1287,11 +1301,11 @@ var OmnichannelChatSDK = /** @class */ (function () {
|
|
|
1287
1301
|
};
|
|
1288
1302
|
OmnichannelChatSDK.prototype.internalEndChat = function () {
|
|
1289
1303
|
return __awaiter(this, arguments, void 0, function (endChatOptionalParams) {
|
|
1290
|
-
var cleanupMetadata, error_15, telemetryData;
|
|
1291
|
-
var _a;
|
|
1304
|
+
var cleanupMetadata, isReactNative, isConversationalSurveyEnabled, shouldWaitForSurvey, telemetryData, surveyStarted, error_15, error_16, telemetryData;
|
|
1305
|
+
var _a, _b, _c;
|
|
1292
1306
|
if (endChatOptionalParams === void 0) { endChatOptionalParams = {}; }
|
|
1293
|
-
return __generator(this, function (
|
|
1294
|
-
switch (
|
|
1307
|
+
return __generator(this, function (_d) {
|
|
1308
|
+
switch (_d.label) {
|
|
1295
1309
|
case 0:
|
|
1296
1310
|
cleanupMetadata = {
|
|
1297
1311
|
RequestId: this.requestId,
|
|
@@ -1301,18 +1315,54 @@ var OmnichannelChatSDK = /** @class */ (function () {
|
|
|
1301
1315
|
if (!this.isInitialized) {
|
|
1302
1316
|
exceptionThrowers_1.default.throwUninitializedChatSDK(this.scenarioMarker, TelemetryEvent_1.default.EndChat);
|
|
1303
1317
|
}
|
|
1304
|
-
|
|
1318
|
+
this.isEndingChat = true;
|
|
1319
|
+
_d.label = 1;
|
|
1305
1320
|
case 1:
|
|
1306
|
-
|
|
1307
|
-
_b.label = 2;
|
|
1308
|
-
case 2:
|
|
1309
|
-
_b.trys.push([2, , 4, 5]);
|
|
1321
|
+
_d.trys.push([1, 9, 10, 11]);
|
|
1310
1322
|
return [4 /*yield*/, this.closeChat(endChatOptionalParams)];
|
|
1323
|
+
case 2:
|
|
1324
|
+
_d.sent();
|
|
1325
|
+
isReactNative = platform_1.default.isReactNative();
|
|
1326
|
+
isConversationalSurveyEnabled = ((_b = (_a = this.liveChatConfig.LiveWSAndLiveChatEngJoin) === null || _a === void 0 ? void 0 : _a.msdyn_isConversationalPostChatSurveyEnabled) === null || _b === void 0 ? void 0 : _b.toString().toLowerCase()) === 'true';
|
|
1327
|
+
shouldWaitForSurvey = isReactNative && isConversationalSurveyEnabled && !endChatOptionalParams.isSessionEnded;
|
|
1328
|
+
telemetryData = __assign(__assign({}, cleanupMetadata), { IsReactNative: isReactNative, SurveyEnabled: isConversationalSurveyEnabled, IsSessionEnded: endChatOptionalParams.isSessionEnded || false, WaitingForSurvey: shouldWaitForSurvey });
|
|
1329
|
+
if (!shouldWaitForSurvey) return [3 /*break*/, 8];
|
|
1330
|
+
this.scenarioMarker.startScenario(TelemetryEvent_1.default.WaitForConversationalSurvey, telemetryData);
|
|
1331
|
+
_d.label = 3;
|
|
1311
1332
|
case 3:
|
|
1312
|
-
|
|
1313
|
-
return [
|
|
1333
|
+
_d.trys.push([3, 7, , 8]);
|
|
1334
|
+
return [4 /*yield*/, this.waitForSurveyStart()];
|
|
1314
1335
|
case 4:
|
|
1315
|
-
|
|
1336
|
+
surveyStarted = _d.sent();
|
|
1337
|
+
if (!surveyStarted) return [3 /*break*/, 6];
|
|
1338
|
+
return [4 /*yield*/, this.waitForConversationalSurveyEnd()];
|
|
1339
|
+
case 5:
|
|
1340
|
+
_d.sent();
|
|
1341
|
+
_d.label = 6;
|
|
1342
|
+
case 6:
|
|
1343
|
+
this.scenarioMarker.completeScenario(TelemetryEvent_1.default.WaitForConversationalSurvey, telemetryData);
|
|
1344
|
+
return [3 /*break*/, 8];
|
|
1345
|
+
case 7:
|
|
1346
|
+
error_15 = _d.sent();
|
|
1347
|
+
return [3 /*break*/, 8];
|
|
1348
|
+
case 8:
|
|
1349
|
+
this.scenarioMarker.completeScenario(TelemetryEvent_1.default.EndChat, cleanupMetadata);
|
|
1350
|
+
return [3 /*break*/, 11];
|
|
1351
|
+
case 9:
|
|
1352
|
+
error_16 = _d.sent();
|
|
1353
|
+
telemetryData = {
|
|
1354
|
+
RequestId: this.requestId,
|
|
1355
|
+
ChatId: this.chatToken.chatId
|
|
1356
|
+
};
|
|
1357
|
+
if (error_16 instanceof ChatSDKError_1.ChatSDKError) {
|
|
1358
|
+
exceptionThrowers_1.default.throwConversationClosureFailure(new Error(JSON.stringify(error_16.exceptionDetails)), this.scenarioMarker, TelemetryEvent_1.default.EndChat, telemetryData);
|
|
1359
|
+
}
|
|
1360
|
+
exceptionThrowers_1.default.throwConversationClosureFailure(error_16, this.scenarioMarker, TelemetryEvent_1.default.EndChat, telemetryData);
|
|
1361
|
+
return [3 /*break*/, 11];
|
|
1362
|
+
case 10:
|
|
1363
|
+
// Cleanup always runs, regardless of success or failure
|
|
1364
|
+
// This ensures resources are released even if closeChat or survey waiting throws
|
|
1365
|
+
(_c = this.conversation) === null || _c === void 0 ? void 0 : _c.disconnect();
|
|
1316
1366
|
this.conversation = null;
|
|
1317
1367
|
this.requestId = (0, ocsdk_1.uuidv4)();
|
|
1318
1368
|
this.chatToken = {};
|
|
@@ -1332,22 +1382,104 @@ var OmnichannelChatSDK = /** @class */ (function () {
|
|
|
1332
1382
|
clearInterval(this.refreshTokenTimer);
|
|
1333
1383
|
this.refreshTokenTimer = null;
|
|
1334
1384
|
}
|
|
1385
|
+
this.isEndingChat = false;
|
|
1335
1386
|
return [7 /*endfinally*/];
|
|
1336
|
-
case
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1387
|
+
case 11: return [2 /*return*/];
|
|
1388
|
+
}
|
|
1389
|
+
});
|
|
1390
|
+
});
|
|
1391
|
+
};
|
|
1392
|
+
/**
|
|
1393
|
+
* Waits for a message with specific tags. Used for conversational survey detection.
|
|
1394
|
+
* Automatically unregisters the listener after the promise resolves to prevent memory leaks.
|
|
1395
|
+
* Includes timeout to prevent indefinite hanging if messages never arrive.
|
|
1396
|
+
*/
|
|
1397
|
+
OmnichannelChatSDK.prototype.waitForMessageTags = function (requiredTags, timeoutMs) {
|
|
1398
|
+
var _this = this;
|
|
1399
|
+
if (timeoutMs === void 0) { timeoutMs = 60000; }
|
|
1400
|
+
return new Promise(function (resolve, reject) {
|
|
1401
|
+
var resolved = false;
|
|
1402
|
+
var timeoutHandle = null;
|
|
1403
|
+
var checkForTags = function (event) {
|
|
1404
|
+
var _a;
|
|
1405
|
+
if (resolved)
|
|
1406
|
+
return;
|
|
1407
|
+
try {
|
|
1408
|
+
var tagsString = ((_a = event === null || event === void 0 ? void 0 : event.metadata) === null || _a === void 0 ? void 0 : _a.tags) || '';
|
|
1409
|
+
var tags_1 = tagsString.replace(/\"/g, "").split(",").filter(function (tag) { return tag.length > 0; }); // eslint-disable-line no-useless-escape
|
|
1410
|
+
var hasTags = requiredTags.every(function (tag) { return tags_1.includes(tag); });
|
|
1411
|
+
if (hasTags) {
|
|
1412
|
+
resolved = true;
|
|
1413
|
+
cleanup();
|
|
1414
|
+
resolve(true);
|
|
1415
|
+
}
|
|
1416
|
+
}
|
|
1417
|
+
catch (error) {
|
|
1418
|
+
// Silently continue listening on message processing errors
|
|
1419
|
+
}
|
|
1420
|
+
};
|
|
1421
|
+
var cleanup = function (clearTimer) {
|
|
1422
|
+
if (clearTimer === void 0) { clearTimer = true; }
|
|
1423
|
+
// Clear timeout if still active
|
|
1424
|
+
if (clearTimer && timeoutHandle) {
|
|
1425
|
+
clearTimeout(timeoutHandle);
|
|
1426
|
+
timeoutHandle = null;
|
|
1427
|
+
}
|
|
1428
|
+
// Remove listener to prevent memory leak
|
|
1429
|
+
if (_this.conversation && _this.liveChatVersion === LiveChatVersion_1.default.V2) {
|
|
1430
|
+
var acsConversation = _this.conversation;
|
|
1431
|
+
acsConversation.removeListener("chatMessageReceived", checkForTags);
|
|
1432
|
+
acsConversation.removeListener("chatMessageEdited", checkForTags);
|
|
1433
|
+
}
|
|
1434
|
+
};
|
|
1435
|
+
// Set timeout to prevent indefinite hang
|
|
1436
|
+
timeoutHandle = setTimeout(function () {
|
|
1437
|
+
var _a, _b;
|
|
1438
|
+
if (!resolved) {
|
|
1439
|
+
resolved = true;
|
|
1440
|
+
cleanup(false); // Don't clear timeout since we're in the timeout handler
|
|
1441
|
+
// Log telemetry for timeout
|
|
1442
|
+
(_a = _this.scenarioMarker) === null || _a === void 0 ? void 0 : _a.failScenario(TelemetryEvent_1.default.WaitForConversationalSurvey, {
|
|
1443
|
+
RequestId: _this.requestId,
|
|
1444
|
+
ChatId: (_b = _this.chatToken) === null || _b === void 0 ? void 0 : _b.chatId,
|
|
1445
|
+
Reason: 'Timeout',
|
|
1446
|
+
ExpectedTags: requiredTags.join(','),
|
|
1447
|
+
TimeoutMs: timeoutMs
|
|
1448
|
+
});
|
|
1449
|
+
reject(new Error("Timeout waiting for message with tags: ".concat(requiredTags.join(', '))));
|
|
1450
|
+
}
|
|
1451
|
+
}, timeoutMs);
|
|
1452
|
+
try {
|
|
1453
|
+
if (_this.conversation && _this.liveChatVersion === LiveChatVersion_1.default.V2) {
|
|
1454
|
+
var acsConversation = _this.conversation;
|
|
1455
|
+
acsConversation.addListener("chatMessageReceived", checkForTags);
|
|
1456
|
+
acsConversation.addListener("chatMessageEdited", checkForTags);
|
|
1457
|
+
}
|
|
1458
|
+
}
|
|
1459
|
+
catch (error) {
|
|
1460
|
+
if (!resolved) {
|
|
1461
|
+
resolved = true;
|
|
1462
|
+
cleanup();
|
|
1463
|
+
reject(error);
|
|
1464
|
+
}
|
|
1465
|
+
}
|
|
1466
|
+
});
|
|
1467
|
+
};
|
|
1468
|
+
OmnichannelChatSDK.prototype.waitForSurveyStart = function () {
|
|
1469
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1470
|
+
return __generator(this, function (_a) {
|
|
1471
|
+
return [2 /*return*/, this.waitForMessageTags(['system', 'startconversationalsurvey'])];
|
|
1472
|
+
});
|
|
1473
|
+
});
|
|
1474
|
+
};
|
|
1475
|
+
OmnichannelChatSDK.prototype.waitForConversationalSurveyEnd = function () {
|
|
1476
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1477
|
+
return __generator(this, function (_a) {
|
|
1478
|
+
switch (_a.label) {
|
|
1479
|
+
case 0: return [4 /*yield*/, this.waitForMessageTags(['system', 'endconversationalsurvey'])];
|
|
1480
|
+
case 1:
|
|
1481
|
+
_a.sent();
|
|
1482
|
+
return [2 /*return*/];
|
|
1351
1483
|
}
|
|
1352
1484
|
});
|
|
1353
1485
|
});
|
|
@@ -1392,7 +1524,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
|
|
|
1392
1524
|
};
|
|
1393
1525
|
OmnichannelChatSDK.prototype.getConversationDetails = function () {
|
|
1394
1526
|
return __awaiter(this, arguments, void 0, function (optionalParams) {
|
|
1395
|
-
var requestId, chatToken, chatId, reconnectId, sessionId, getLWIDetailsOptionalParams, lwiDetails, state, conversationId, agentAcceptedOn, canRenderPostChat, participantType, liveWorkItemDetails,
|
|
1527
|
+
var requestId, chatToken, chatId, reconnectId, sessionId, getLWIDetailsOptionalParams, lwiDetails, state, conversationId, agentAcceptedOn, canRenderPostChat, participantType, liveWorkItemDetails, error_17, telemetryData;
|
|
1396
1528
|
var _a, _b, _c, _d;
|
|
1397
1529
|
if (optionalParams === void 0) { optionalParams = {}; }
|
|
1398
1530
|
return __generator(this, function (_e) {
|
|
@@ -1465,15 +1597,15 @@ var OmnichannelChatSDK = /** @class */ (function () {
|
|
|
1465
1597
|
});
|
|
1466
1598
|
return [2 /*return*/, liveWorkItemDetails];
|
|
1467
1599
|
case 3:
|
|
1468
|
-
|
|
1600
|
+
error_17 = _e.sent();
|
|
1469
1601
|
telemetryData = {
|
|
1470
1602
|
RequestId: requestId,
|
|
1471
1603
|
ChatId: chatId
|
|
1472
1604
|
};
|
|
1473
|
-
if ((0, utilities_1.isClientIdNotFoundErrorMessage)(
|
|
1474
|
-
exceptionThrowers_1.default.throwAuthContactIdNotFoundFailure(
|
|
1605
|
+
if ((0, utilities_1.isClientIdNotFoundErrorMessage)(error_17)) {
|
|
1606
|
+
exceptionThrowers_1.default.throwAuthContactIdNotFoundFailure(error_17, this.scenarioMarker, TelemetryEvent_1.default.GetConversationDetails, telemetryData);
|
|
1475
1607
|
}
|
|
1476
|
-
exceptionSuppressors_1.default.suppressConversationDetailsRetrievalFailure(
|
|
1608
|
+
exceptionSuppressors_1.default.suppressConversationDetailsRetrievalFailure(error_17, this.scenarioMarker, TelemetryEvent_1.default.GetConversationDetails, telemetryData);
|
|
1477
1609
|
return [3 /*break*/, 4];
|
|
1478
1610
|
case 4: return [2 /*return*/, {}];
|
|
1479
1611
|
}
|
|
@@ -1514,7 +1646,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
|
|
|
1514
1646
|
};
|
|
1515
1647
|
OmnichannelChatSDK.prototype.getChatToken = function () {
|
|
1516
1648
|
return __awaiter(this, arguments, void 0, function (cached, optionalParams) {
|
|
1517
|
-
var getChatTokenOptionalParams, chatToken,
|
|
1649
|
+
var getChatTokenOptionalParams, chatToken, error_18, telemetryData;
|
|
1518
1650
|
var _a, _b, _c;
|
|
1519
1651
|
if (cached === void 0) { cached = true; }
|
|
1520
1652
|
return __generator(this, function (_d) {
|
|
@@ -1556,16 +1688,16 @@ var OmnichannelChatSDK = /** @class */ (function () {
|
|
|
1556
1688
|
});
|
|
1557
1689
|
return [3 /*break*/, 4];
|
|
1558
1690
|
case 3:
|
|
1559
|
-
|
|
1691
|
+
error_18 = _d.sent();
|
|
1560
1692
|
telemetryData = {
|
|
1561
1693
|
RequestId: this.requestId,
|
|
1562
1694
|
ChatId: (_c = this.chatToken) === null || _c === void 0 ? void 0 : _c.chatId,
|
|
1563
1695
|
};
|
|
1564
|
-
if ((0, utilities_1.isClientIdNotFoundErrorMessage)(
|
|
1565
|
-
exceptionThrowers_1.default.throwAuthContactIdNotFoundFailure(
|
|
1696
|
+
if ((0, utilities_1.isClientIdNotFoundErrorMessage)(error_18)) {
|
|
1697
|
+
exceptionThrowers_1.default.throwAuthContactIdNotFoundFailure(error_18, this.scenarioMarker, TelemetryEvent_1.default.GetChatToken, telemetryData);
|
|
1566
1698
|
}
|
|
1567
1699
|
else {
|
|
1568
|
-
exceptionThrowers_1.default.throwChatTokenRetrievalFailure(
|
|
1700
|
+
exceptionThrowers_1.default.throwChatTokenRetrievalFailure(error_18, this.scenarioMarker, TelemetryEvent_1.default.GetChatToken, telemetryData);
|
|
1569
1701
|
}
|
|
1570
1702
|
return [3 /*break*/, 4];
|
|
1571
1703
|
case 4: return [3 /*break*/, 6];
|
|
@@ -1724,7 +1856,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
|
|
|
1724
1856
|
};
|
|
1725
1857
|
OmnichannelChatSDK.prototype.sendMessage = function (message) {
|
|
1726
1858
|
return __awaiter(this, void 0, void 0, function () {
|
|
1727
|
-
var sendMessageRequest, chatMessage,
|
|
1859
|
+
var sendMessageRequest, chatMessage, error_19, exceptionDetails;
|
|
1728
1860
|
var _a;
|
|
1729
1861
|
return __generator(this, function (_b) {
|
|
1730
1862
|
switch (_b.label) {
|
|
@@ -1759,10 +1891,10 @@ var OmnichannelChatSDK = /** @class */ (function () {
|
|
|
1759
1891
|
});
|
|
1760
1892
|
return [2 /*return*/, chatMessage];
|
|
1761
1893
|
case 3:
|
|
1762
|
-
|
|
1894
|
+
error_19 = _b.sent();
|
|
1763
1895
|
exceptionDetails = {
|
|
1764
1896
|
response: ChatSDKError_1.ChatSDKErrorName.ChatSDKSendMessageFailed,
|
|
1765
|
-
errorObject: "".concat(
|
|
1897
|
+
errorObject: "".concat(error_19)
|
|
1766
1898
|
};
|
|
1767
1899
|
this.scenarioMarker.failScenario(TelemetryEvent_1.default.SendMessages, {
|
|
1768
1900
|
RequestId: this.requestId,
|
|
@@ -1771,7 +1903,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
|
|
|
1771
1903
|
});
|
|
1772
1904
|
throw new ChatSDKError_1.ChatSDKError(ChatSDKError_1.ChatSDKErrorName.ChatSDKSendMessageFailed, undefined, {
|
|
1773
1905
|
response: ChatSDKError_1.ChatSDKErrorName.ChatSDKSendMessageFailed,
|
|
1774
|
-
errorObject: "".concat(
|
|
1906
|
+
errorObject: "".concat(error_19)
|
|
1775
1907
|
});
|
|
1776
1908
|
case 4: return [2 /*return*/];
|
|
1777
1909
|
}
|
|
@@ -1857,7 +1989,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
|
|
|
1857
1989
|
};
|
|
1858
1990
|
OmnichannelChatSDK.prototype.sendTypingEvent = function () {
|
|
1859
1991
|
return __awaiter(this, void 0, void 0, function () {
|
|
1860
|
-
var
|
|
1992
|
+
var error_20;
|
|
1861
1993
|
return __generator(this, function (_a) {
|
|
1862
1994
|
switch (_a.label) {
|
|
1863
1995
|
case 0:
|
|
@@ -1886,7 +2018,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
|
|
|
1886
2018
|
});
|
|
1887
2019
|
return [3 /*break*/, 5];
|
|
1888
2020
|
case 4:
|
|
1889
|
-
|
|
2021
|
+
error_20 = _a.sent();
|
|
1890
2022
|
this.scenarioMarker.failScenario(TelemetryEvent_1.default.SendTypingEvent, {
|
|
1891
2023
|
RequestId: this.requestId,
|
|
1892
2024
|
ChatId: this.chatToken.chatId
|
|
@@ -1953,6 +2085,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
|
|
|
1953
2085
|
};
|
|
1954
2086
|
OmnichannelChatSDK.prototype.onAgentEndSession = function (onAgentEndSessionCallback) {
|
|
1955
2087
|
return __awaiter(this, void 0, void 0, function () {
|
|
2088
|
+
var agentEndSessionFired_1;
|
|
1956
2089
|
var _this = this;
|
|
1957
2090
|
return __generator(this, function (_a) {
|
|
1958
2091
|
this.scenarioMarker.startScenario(TelemetryEvent_1.default.OnAgentEndSession, {
|
|
@@ -1963,18 +2096,62 @@ var OmnichannelChatSDK = /** @class */ (function () {
|
|
|
1963
2096
|
exceptionThrowers_1.default.throwUninitializedChatSDK(this.scenarioMarker, TelemetryEvent_1.default.OnAgentEndSession);
|
|
1964
2097
|
}
|
|
1965
2098
|
try {
|
|
2099
|
+
agentEndSessionFired_1 = false;
|
|
1966
2100
|
this.conversation.registerOnThreadUpdate(function (event) { return __awaiter(_this, void 0, void 0, function () {
|
|
1967
|
-
var liveWorkItemDetails;
|
|
1968
|
-
return __generator(this, function (
|
|
1969
|
-
switch (
|
|
1970
|
-
case 0:
|
|
2101
|
+
var maxRetries, retryDelayMs, attempt, liveWorkItemDetails, _a;
|
|
2102
|
+
return __generator(this, function (_b) {
|
|
2103
|
+
switch (_b.label) {
|
|
2104
|
+
case 0:
|
|
2105
|
+
if (this.isEndingChat) {
|
|
2106
|
+
return [2 /*return*/];
|
|
2107
|
+
}
|
|
2108
|
+
if (agentEndSessionFired_1) {
|
|
2109
|
+
return [2 /*return*/];
|
|
2110
|
+
}
|
|
2111
|
+
maxRetries = 3;
|
|
2112
|
+
retryDelayMs = 2000;
|
|
2113
|
+
attempt = 1;
|
|
2114
|
+
_b.label = 1;
|
|
1971
2115
|
case 1:
|
|
1972
|
-
|
|
2116
|
+
if (!(attempt <= maxRetries)) return [3 /*break*/, 10];
|
|
2117
|
+
liveWorkItemDetails = void 0;
|
|
2118
|
+
_b.label = 2;
|
|
2119
|
+
case 2:
|
|
2120
|
+
_b.trys.push([2, 4, , 7]);
|
|
2121
|
+
return [4 /*yield*/, this.getConversationDetails()];
|
|
2122
|
+
case 3:
|
|
2123
|
+
liveWorkItemDetails = _b.sent();
|
|
2124
|
+
return [3 /*break*/, 7];
|
|
2125
|
+
case 4:
|
|
2126
|
+
_a = _b.sent();
|
|
2127
|
+
if (!(attempt < maxRetries)) return [3 /*break*/, 6];
|
|
2128
|
+
return [4 /*yield*/, new Promise(function (resolve) { return setTimeout(resolve, retryDelayMs); })];
|
|
2129
|
+
case 5:
|
|
2130
|
+
_b.sent();
|
|
2131
|
+
return [3 /*break*/, 9];
|
|
2132
|
+
case 6: return [2 /*return*/];
|
|
2133
|
+
case 7:
|
|
1973
2134
|
if (Object.keys(liveWorkItemDetails).length === 0 || liveWorkItemDetails.state == LiveWorkItemState_1.default.WrapUp || liveWorkItemDetails.state == LiveWorkItemState_1.default.Closed) {
|
|
2135
|
+
if (agentEndSessionFired_1) {
|
|
2136
|
+
return [2 /*return*/];
|
|
2137
|
+
}
|
|
2138
|
+
agentEndSessionFired_1 = true;
|
|
1974
2139
|
onAgentEndSessionCallback(event);
|
|
1975
2140
|
this.stopPolling();
|
|
2141
|
+
return [2 /*return*/];
|
|
1976
2142
|
}
|
|
1977
|
-
return [
|
|
2143
|
+
if (!(attempt < maxRetries)) return [3 /*break*/, 9];
|
|
2144
|
+
return [4 /*yield*/, new Promise(function (resolve) { return setTimeout(resolve, retryDelayMs); })];
|
|
2145
|
+
case 8:
|
|
2146
|
+
_b.sent();
|
|
2147
|
+
if (this.isEndingChat) {
|
|
2148
|
+
return [2 /*return*/];
|
|
2149
|
+
}
|
|
2150
|
+
_b.label = 9;
|
|
2151
|
+
case 9:
|
|
2152
|
+
attempt++;
|
|
2153
|
+
return [3 /*break*/, 1];
|
|
2154
|
+
case 10: return [2 /*return*/];
|
|
1978
2155
|
}
|
|
1979
2156
|
});
|
|
1980
2157
|
}); });
|
|
@@ -1995,7 +2172,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
|
|
|
1995
2172
|
};
|
|
1996
2173
|
OmnichannelChatSDK.prototype.uploadFileAttachment = function (fileInfo) {
|
|
1997
2174
|
return __awaiter(this, void 0, void 0, function () {
|
|
1998
|
-
var amsClient, createObjectResponse, documentId, uploadDocumentResponse, fileIdsProperty, fileMetaProperty, sendMessageRequest, messageToSend,
|
|
2175
|
+
var amsClient, createObjectResponse, documentId, uploadDocumentResponse, fileIdsProperty, fileMetaProperty, sendMessageRequest, messageToSend, error_21, fileMetadata, messageToSend, error_22;
|
|
1999
2176
|
var _a, _b;
|
|
2000
2177
|
return __generator(this, function (_c) {
|
|
2001
2178
|
switch (_c.label) {
|
|
@@ -2064,7 +2241,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
|
|
|
2064
2241
|
});
|
|
2065
2242
|
return [2 /*return*/, messageToSend];
|
|
2066
2243
|
case 6:
|
|
2067
|
-
|
|
2244
|
+
error_21 = _c.sent();
|
|
2068
2245
|
console.error("OmnichannelChatSDK/uploadFileAttachment/sendMessage/error");
|
|
2069
2246
|
this.scenarioMarker.failScenario(TelemetryEvent_1.default.UploadFileAttachment, {
|
|
2070
2247
|
RequestId: this.requestId,
|
|
@@ -2110,8 +2287,8 @@ var OmnichannelChatSDK = /** @class */ (function () {
|
|
|
2110
2287
|
});
|
|
2111
2288
|
return [2 /*return*/, messageToSend];
|
|
2112
2289
|
case 15:
|
|
2113
|
-
|
|
2114
|
-
console.error("OmnichannelChatSDK/uploadFileAttachment/error: ".concat(
|
|
2290
|
+
error_22 = _c.sent();
|
|
2291
|
+
console.error("OmnichannelChatSDK/uploadFileAttachment/error: ".concat(error_22));
|
|
2115
2292
|
this.scenarioMarker.failScenario(TelemetryEvent_1.default.UploadFileAttachment, {
|
|
2116
2293
|
RequestId: this.requestId,
|
|
2117
2294
|
ChatId: this.chatToken.chatId
|
|
@@ -2124,7 +2301,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
|
|
|
2124
2301
|
};
|
|
2125
2302
|
OmnichannelChatSDK.prototype.downloadFileAttachment = function (fileMetadata) {
|
|
2126
2303
|
return __awaiter(this, void 0, void 0, function () {
|
|
2127
|
-
var amsClient, response, view_location, viewResponse, ex_1, downloadedFile,
|
|
2304
|
+
var amsClient, response, view_location, viewResponse, ex_1, downloadedFile, error_23;
|
|
2128
2305
|
return __generator(this, function (_a) {
|
|
2129
2306
|
switch (_a.label) {
|
|
2130
2307
|
case 0:
|
|
@@ -2185,8 +2362,8 @@ var OmnichannelChatSDK = /** @class */ (function () {
|
|
|
2185
2362
|
});
|
|
2186
2363
|
return [2 /*return*/, downloadedFile];
|
|
2187
2364
|
case 9:
|
|
2188
|
-
|
|
2189
|
-
console.error("OmnichannelChatSDK/downloadFileAttachment/error: ".concat(
|
|
2365
|
+
error_23 = _a.sent();
|
|
2366
|
+
console.error("OmnichannelChatSDK/downloadFileAttachment/error: ".concat(error_23));
|
|
2190
2367
|
this.scenarioMarker.failScenario(TelemetryEvent_1.default.DownloadFileAttachment, {
|
|
2191
2368
|
RequestId: this.requestId,
|
|
2192
2369
|
ChatId: this.chatToken.chatId
|
|
@@ -2199,7 +2376,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
|
|
|
2199
2376
|
};
|
|
2200
2377
|
OmnichannelChatSDK.prototype.emailLiveChatTranscript = function (body_1) {
|
|
2201
2378
|
return __awaiter(this, arguments, void 0, function (body, optionalParams) {
|
|
2202
|
-
var emailTranscriptOptionalParams, requestId, chatToken, chatId, sessionId, emailRequestBody,
|
|
2379
|
+
var emailTranscriptOptionalParams, requestId, chatToken, chatId, sessionId, emailRequestBody, error_24;
|
|
2203
2380
|
var _a;
|
|
2204
2381
|
if (optionalParams === void 0) { optionalParams = {}; }
|
|
2205
2382
|
return __generator(this, function (_b) {
|
|
@@ -2250,8 +2427,8 @@ var OmnichannelChatSDK = /** @class */ (function () {
|
|
|
2250
2427
|
});
|
|
2251
2428
|
return [3 /*break*/, 4];
|
|
2252
2429
|
case 3:
|
|
2253
|
-
|
|
2254
|
-
console.error("OmnichannelChatSDK/emailLiveChatTranscript/error: ".concat(
|
|
2430
|
+
error_24 = _b.sent();
|
|
2431
|
+
console.error("OmnichannelChatSDK/emailLiveChatTranscript/error: ".concat(error_24));
|
|
2255
2432
|
this.scenarioMarker.failScenario(TelemetryEvent_1.default.EmailLiveChatTranscript, {
|
|
2256
2433
|
RequestId: requestId,
|
|
2257
2434
|
ChatId: chatId
|
|
@@ -2264,7 +2441,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
|
|
|
2264
2441
|
};
|
|
2265
2442
|
OmnichannelChatSDK.prototype.getLiveChatTranscript = function () {
|
|
2266
2443
|
return __awaiter(this, arguments, void 0, function (optionalParams) {
|
|
2267
|
-
var getChatTranscriptOptionalParams, requestId, chatToken, chatId, sessionId, transcriptResponse,
|
|
2444
|
+
var getChatTranscriptOptionalParams, requestId, chatToken, chatId, sessionId, transcriptResponse, error_25, telemetryData;
|
|
2268
2445
|
var _a, _b;
|
|
2269
2446
|
if (optionalParams === void 0) { optionalParams = {}; }
|
|
2270
2447
|
return __generator(this, function (_c) {
|
|
@@ -2321,12 +2498,12 @@ var OmnichannelChatSDK = /** @class */ (function () {
|
|
|
2321
2498
|
});
|
|
2322
2499
|
return [2 /*return*/, transcriptResponse];
|
|
2323
2500
|
case 3:
|
|
2324
|
-
|
|
2501
|
+
error_25 = _c.sent();
|
|
2325
2502
|
telemetryData = {
|
|
2326
2503
|
RequestId: requestId,
|
|
2327
2504
|
ChatId: chatId
|
|
2328
2505
|
};
|
|
2329
|
-
exceptionThrowers_1.default.throwLiveChatTranscriptRetrievalFailure(
|
|
2506
|
+
exceptionThrowers_1.default.throwLiveChatTranscriptRetrievalFailure(error_25, this.scenarioMarker, TelemetryEvent_1.default.GetLiveChatTranscript, telemetryData);
|
|
2330
2507
|
return [3 /*break*/, 4];
|
|
2331
2508
|
case 4: return [2 /*return*/];
|
|
2332
2509
|
}
|
|
@@ -2876,7 +3053,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
|
|
|
2876
3053
|
};
|
|
2877
3054
|
OmnichannelChatSDK.prototype.getChatConfig = function () {
|
|
2878
3055
|
return __awaiter(this, arguments, void 0, function (optionalParams) {
|
|
2879
|
-
var sendCacheHeaders, bypassCache, liveChatConfig,
|
|
3056
|
+
var sendCacheHeaders, bypassCache, liveChatConfig, error_26, _a;
|
|
2880
3057
|
var _b, _c;
|
|
2881
3058
|
if (optionalParams === void 0) { optionalParams = {}; }
|
|
2882
3059
|
return __generator(this, function (_d) {
|
|
@@ -2897,8 +3074,8 @@ var OmnichannelChatSDK = /** @class */ (function () {
|
|
|
2897
3074
|
this.debug && console.log("[OmnichannelChatSDK][getChatConfig][liveChatVersion] ".concat(this.liveChatVersion));
|
|
2898
3075
|
return [2 /*return*/, this.liveChatConfig];
|
|
2899
3076
|
case 3:
|
|
2900
|
-
|
|
2901
|
-
if (!(0, internalUtils_1.isCoreServicesOrgUrlDNSError)(
|
|
3077
|
+
error_26 = _d.sent();
|
|
3078
|
+
if (!(0, internalUtils_1.isCoreServicesOrgUrlDNSError)(error_26, this.coreServicesOrgUrl, this.dynamicsLocationCode)) return [3 /*break*/, 6];
|
|
2902
3079
|
this.omnichannelConfig.orgUrl = this.unqServicesOrgUrl;
|
|
2903
3080
|
_a = this;
|
|
2904
3081
|
return [4 /*yield*/, ocsdk_1.SDKProvider.getSDK(this.omnichannelConfig, (0, createOcSDKConfiguration_1.default)(false), this.ocSdkLogger)];
|
|
@@ -2910,10 +3087,10 @@ var OmnichannelChatSDK = /** @class */ (function () {
|
|
|
2910
3087
|
return [3 /*break*/, 7];
|
|
2911
3088
|
case 6:
|
|
2912
3089
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
2913
|
-
if (((_c = (_b =
|
|
3090
|
+
if (((_c = (_b = error_26.response) === null || _b === void 0 ? void 0 : _b.headers) === null || _c === void 0 ? void 0 : _c.errorcode) && parseInt(error_26.response.headers.errorcode) === OmnichannelErrorCodes_1.default.WidgetNotFound) {
|
|
2914
3091
|
console.warn("No widget with the given app id is present in the system.");
|
|
2915
3092
|
}
|
|
2916
|
-
throw
|
|
3093
|
+
throw error_26; // Bubble up error by default to throw ChatConfigRetrievalFailure
|
|
2917
3094
|
case 7: return [3 /*break*/, 8];
|
|
2918
3095
|
case 8: return [2 /*return*/, this.liveChatConfig];
|
|
2919
3096
|
}
|
|
@@ -2948,7 +3125,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
|
|
|
2948
3125
|
};
|
|
2949
3126
|
OmnichannelChatSDK.prototype.updateChatToken = function (newToken, newRegionGTMS) {
|
|
2950
3127
|
return __awaiter(this, void 0, void 0, function () {
|
|
2951
|
-
var sessionInfo,
|
|
3128
|
+
var sessionInfo, error_27, exceptionDetails;
|
|
2952
3129
|
return __generator(this, function (_a) {
|
|
2953
3130
|
switch (_a.label) {
|
|
2954
3131
|
case 0:
|
|
@@ -2976,7 +3153,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
|
|
|
2976
3153
|
});
|
|
2977
3154
|
return [3 /*break*/, 5];
|
|
2978
3155
|
case 4:
|
|
2979
|
-
|
|
3156
|
+
error_27 = _a.sent();
|
|
2980
3157
|
exceptionDetails = {
|
|
2981
3158
|
response: "UpdateChatTokenFailed"
|
|
2982
3159
|
};
|
|
@@ -2993,7 +3170,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
|
|
|
2993
3170
|
};
|
|
2994
3171
|
OmnichannelChatSDK.prototype.setAuthTokenProvider = function (provider_1) {
|
|
2995
3172
|
return __awaiter(this, arguments, void 0, function (provider, optionalParams) {
|
|
2996
|
-
var token, exceptionDetails,
|
|
3173
|
+
var token, exceptionDetails, error_28, exceptionDetails, exceptionDetails;
|
|
2997
3174
|
if (optionalParams === void 0) { optionalParams = {}; }
|
|
2998
3175
|
return __generator(this, function (_a) {
|
|
2999
3176
|
switch (_a.label) {
|
|
@@ -3025,12 +3202,12 @@ var OmnichannelChatSDK = /** @class */ (function () {
|
|
|
3025
3202
|
}
|
|
3026
3203
|
return [3 /*break*/, 4];
|
|
3027
3204
|
case 3:
|
|
3028
|
-
|
|
3205
|
+
error_28 = _a.sent();
|
|
3029
3206
|
exceptionDetails = {
|
|
3030
3207
|
response: ChatSDKError_1.ChatSDKErrorName.GetAuthTokenFailed
|
|
3031
3208
|
};
|
|
3032
|
-
if (
|
|
3033
|
-
exceptionDetails.response =
|
|
3209
|
+
if (error_28.message == ChatSDKError_1.ChatSDKErrorName.UndefinedAuthToken) {
|
|
3210
|
+
exceptionDetails.response = error_28.message;
|
|
3034
3211
|
}
|
|
3035
3212
|
this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetAuthToken, {
|
|
3036
3213
|
ExceptionDetails: JSON.stringify(exceptionDetails)
|
|
@@ -3129,7 +3306,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
|
|
|
3129
3306
|
*/
|
|
3130
3307
|
OmnichannelChatSDK.prototype.getPersistentChatHistory = function () {
|
|
3131
3308
|
return __awaiter(this, arguments, void 0, function (getPersistentChatHistoryOptionalParams) {
|
|
3132
|
-
var params, result,
|
|
3309
|
+
var params, result, error_29, telemetryData;
|
|
3133
3310
|
var _a, _b, _c, _d, _e;
|
|
3134
3311
|
if (getPersistentChatHistoryOptionalParams === void 0) { getPersistentChatHistoryOptionalParams = {}; }
|
|
3135
3312
|
return __generator(this, function (_f) {
|
|
@@ -3171,13 +3348,13 @@ var OmnichannelChatSDK = /** @class */ (function () {
|
|
|
3171
3348
|
});
|
|
3172
3349
|
return [2 /*return*/, result];
|
|
3173
3350
|
case 3:
|
|
3174
|
-
|
|
3351
|
+
error_29 = _f.sent();
|
|
3175
3352
|
telemetryData = {
|
|
3176
3353
|
RequestId: this.requestId,
|
|
3177
3354
|
ChatId: (_e = this.chatToken) === null || _e === void 0 ? void 0 : _e.chatId,
|
|
3178
|
-
ErrorMessage: (
|
|
3355
|
+
ErrorMessage: (error_29 === null || error_29 === void 0 ? void 0 : error_29.message) || 'Unknown error' // Added error message for better debugging
|
|
3179
3356
|
};
|
|
3180
|
-
exceptionThrowers_1.default.throwPersistentChatConversationRetrievalFailure(
|
|
3357
|
+
exceptionThrowers_1.default.throwPersistentChatConversationRetrievalFailure(error_29, this.scenarioMarker, TelemetryEvent_1.default.GetPersistentChatHistory, telemetryData);
|
|
3181
3358
|
return [3 /*break*/, 4];
|
|
3182
3359
|
case 4: return [2 /*return*/];
|
|
3183
3360
|
}
|