@microsoft/omnichannel-chat-sdk 1.10.19 → 1.10.20-main.1177050

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 CHANGED
@@ -54,7 +54,7 @@ Please make sure you have a chat widget configured before using this package or
54
54
  - [Persistent Chat](#persistent-chat)
55
55
  - [Chat Reconnect with Authenticated User](#chat-reconnect-with-authenticated-user)
56
56
  - [Chat Reconnect with Unauthenticated User](#chat-reconnect-with-unauthenticated-user)
57
- - [Best Practices for Chat Session Management: Handling Disconnections and Network Instability](#best-practices-for-chat-session-management:-handling-disconnections-and-network-instability)
57
+ - [Best Practices for Chat Session Management: Handling Disconnections and Network Instabilit(#best-practices-for-chat-session-management:-handling-disconnections-and-network-instability)
58
58
  - [Operating Hours](#operating-hours)
59
59
  - [Single Sign-on for Bots](/docs/scenarios/SINGLE_SIGN_ON_FOR_BOTS.md)
60
60
  - [Sample Apps](https://github.com/microsoft/omnichannel-chat-sdk-samples)
@@ -625,7 +625,9 @@ const agentAvailability = await chatSDK.getAgentAvailability();
625
625
 
626
626
  > See <https://docs.microsoft.com/en-us/dynamics365/customer-service/configure-post-conversation-survey?tabs=customerserviceadmincenter> on how to set up post-conversation surveys
627
627
 
628
- > `chatSDK.getPostChatSurveyContext()` needs to be called before `chatSDK.endChat()` is called
628
+ __NOTE : It should be called ONLY when the chat contains a post-survey as part of their configuration, otherwise it will throw an error.__
629
+
630
+ > ❗ `chatSDK.getPostChatSurveyContext()` needs to be called before `chatSDK.endChat()` is called.
629
631
 
630
632
  ```ts
631
633
  // 1. Start chat
@@ -9,6 +9,7 @@ import ChatReconnectOptionalParams from "./core/ChatReconnectOptionalParams";
9
9
  import ChatSDKConfig from "./core/ChatSDKConfig";
10
10
  import ChatSDKMessage from "./core/messaging/ChatSDKMessage";
11
11
  import ChatTranscriptBody from "./core/ChatTranscriptBody";
12
+ import DebugOptionalParams from "./core/DebugOptionalParams";
12
13
  import EmailLiveChatTranscriptOptionaParams from "./core/EmailLiveChatTranscriptOptionalParams";
13
14
  import EndChatOptionalParams from "./core/EndChatOptionalParams";
14
15
  import FetchChatTokenResponse from "@microsoft/ocsdk/lib/Model/FetchChatTokenResponse";
@@ -75,8 +76,23 @@ declare class OmnichannelChatSDK {
75
76
  private maskingCharacter;
76
77
  private botCSPId;
77
78
  private isAMSClientAllowed;
79
+ private debugSDK;
80
+ private debugAMS;
81
+ private debugACS;
82
+ private detailedDebugEnabled;
78
83
  constructor(omnichannelConfig: OmnichannelConfig, chatSDKConfig?: ChatSDKConfig);
84
+ /**
85
+ * @param flag Flag to enable/disable debug log telemetry, will be applied to all components
86
+ * @description Set the debug flag to enable/disable debug log telemetry
87
+ */
79
88
  setDebug(flag: boolean): void;
89
+ /**
90
+ * @description Allow to target specific components to enable/disable debug log telemetry, reducing the noise in the logs.
91
+ * @param flagSDK Flag to enable disable SDK debug log telemetry
92
+ * @param flagAcs Flag to enable/disable debugg log telemetry for Acs components (ACSClient and ACSAdapter)
93
+ * @param flagAttachment Flag to enable/disable debug log telemetry for Attachment components)
94
+ */
95
+ setDebugDetailed(optionalParams: DebugOptionalParams): void;
80
96
  private retryLoadAMSClient;
81
97
  private getAMSClient;
82
98
  private loadInitComponents;
@@ -59,6 +59,7 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
59
59
  Object.defineProperty(exports, "__esModule", { value: true });
60
60
  var loggers_1 = require("./utils/loggers");
61
61
  var ACSClient_1 = require("./core/messaging/ACSClient");
62
+ var ChatSDKError_1 = require("./core/ChatSDKError");
62
63
  var MessagePrinterFactory_1 = require("./utils/printers/MessagePrinterFactory");
63
64
  var ocsdk_1 = require("@microsoft/ocsdk");
64
65
  var chatAdapterCreators_1 = require("./utils/chatAdapterCreators");
@@ -74,7 +75,6 @@ var AMSClientLoadStates_1 = require("./utils/AMSClientLoadStates");
74
75
  var AMSFileManager_1 = require("./external/ACSAdapter/AMSFileManager");
75
76
  var CallingOptionsOptionSetNumber_1 = require("./core/CallingOptionsOptionSetNumber");
76
77
  var ChatAdapterProtocols_1 = require("./core/messaging/ChatAdapterProtocols");
77
- var ChatSDKError_1 = require("./core/ChatSDKError");
78
78
  var ConversationMode_1 = require("./core/ConversationMode");
79
79
  var DeliveryMode_1 = require("@microsoft/omnichannel-ic3core/lib/model/DeliveryMode");
80
80
  var FileSharingProtocolType_1 = require("@microsoft/omnichannel-ic3core/lib/model/FileSharingProtocolType");
@@ -140,6 +140,10 @@ var OmnichannelChatSDK = /** @class */ (function () {
140
140
  this.maskingCharacter = "#";
141
141
  this.botCSPId = null;
142
142
  this.isAMSClientAllowed = false;
143
+ this.debugSDK = false;
144
+ this.debugAMS = false;
145
+ this.debugACS = false;
146
+ this.detailedDebugEnabled = false;
143
147
  this.populateInitChatOptionalParam = function (requestOptionalParams, optionalParams, telemetryEvent) {
144
148
  requestOptionalParams.initContext.locale = (0, locale_1.getLocaleStringFromId)(_this.localeId);
145
149
  if (optionalParams === null || optionalParams === void 0 ? void 0 : optionalParams.customContext) {
@@ -197,6 +201,10 @@ var OmnichannelChatSDK = /** @class */ (function () {
197
201
  return requestOptionalParams;
198
202
  };
199
203
  this.debug = false;
204
+ this.debugSDK = false;
205
+ this.debugAMS = false;
206
+ this.debugACS = false;
207
+ this.detailedDebugEnabled = false;
200
208
  this.runtimeId = (0, utilities_1.getRuntimeId)((_b = (_a = chatSDKConfig === null || chatSDKConfig === void 0 ? void 0 : chatSDKConfig.telemetry) === null || _a === void 0 ? void 0 : _a.runtimeId) !== null && _b !== void 0 ? _b : null);
201
209
  this.omnichannelConfig = omnichannelConfig;
202
210
  this.chatSDKConfig = __assign(__assign({}, SDKConfigValidators_1.defaultChatSDKConfig), chatSDKConfig // overrides
@@ -243,9 +251,14 @@ var OmnichannelChatSDK = /** @class */ (function () {
243
251
  }
244
252
  loggerUtils_1.default.setRequestId(this.requestId, this.ocSdkLogger, this.acsClientLogger, this.acsAdapterLogger, this.callingSdkLogger, this.amsClientLogger, this.ic3ClientLogger);
245
253
  }
254
+ /**
255
+ * @param flag Flag to enable/disable debug log telemetry, will be applied to all components
256
+ * @description Set the debug flag to enable/disable debug log telemetry
257
+ */
246
258
  /* istanbul ignore next */
247
259
  OmnichannelChatSDK.prototype.setDebug = function (flag) {
248
260
  var _a;
261
+ this.detailedDebugEnabled = false;
249
262
  this.debug = flag;
250
263
  (_a = this.telemetry) === null || _a === void 0 ? void 0 : _a.setDebug(flag);
251
264
  this.scenarioMarker.setDebug(flag);
@@ -254,6 +267,26 @@ var OmnichannelChatSDK = /** @class */ (function () {
254
267
  }
255
268
  loggerUtils_1.default.setDebug(flag, this.ocSdkLogger, this.acsClientLogger, this.acsAdapterLogger, this.callingSdkLogger, this.amsClientLogger, this.ic3ClientLogger);
256
269
  };
270
+ /**
271
+ * @description Allow to target specific components to enable/disable debug log telemetry, reducing the noise in the logs.
272
+ * @param flagSDK Flag to enable disable SDK debug log telemetry
273
+ * @param flagAcs Flag to enable/disable debugg log telemetry for Acs components (ACSClient and ACSAdapter)
274
+ * @param flagAttachment Flag to enable/disable debug log telemetry for Attachment components)
275
+ */
276
+ /* istanbul ignore next */
277
+ OmnichannelChatSDK.prototype.setDebugDetailed = function (optionalParams) {
278
+ var _a;
279
+ this.detailedDebugEnabled = true;
280
+ this.debug = (optionalParams === null || optionalParams === void 0 ? void 0 : optionalParams.flagSDK) === true;
281
+ this.debugACS = (optionalParams === null || optionalParams === void 0 ? void 0 : optionalParams.flagACS) === true;
282
+ this.debugAMS = (optionalParams === null || optionalParams === void 0 ? void 0 : optionalParams.flagAttachment) === true;
283
+ (_a = this.telemetry) === null || _a === void 0 ? void 0 : _a.setDebug(this.debug);
284
+ this.scenarioMarker.setDebug(this.debug);
285
+ if (this.AMSClient) {
286
+ this.AMSClient.setDebug(this.debugAMS);
287
+ }
288
+ loggerUtils_1.default.setDebugDetailed(this.debug, this.debugACS, this.debugAMS, this.ocSdkLogger, this.acsClientLogger, this.acsAdapterLogger, this.callingSdkLogger, this.amsClientLogger);
289
+ };
257
290
  OmnichannelChatSDK.prototype.retryLoadAMSClient = function () {
258
291
  return __awaiter(this, void 0, void 0, function () {
259
292
  var RETRY_DELAY_MS, MAX_RETRY_COUNT, retryCount;
@@ -376,7 +409,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
376
409
  return [4 /*yield*/, (0, omnichannel_amsclient_1.default)({
377
410
  framedMode: (0, platform_1.isBrowser)(),
378
411
  multiClient: true,
379
- debug: this.debug,
412
+ debug: (this.detailedDebugEnabled ? this.debugAMS : this.debug),
380
413
  logger: this.amsClientLogger
381
414
  })];
382
415
  case 2:
@@ -399,7 +432,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
399
432
  };
400
433
  OmnichannelChatSDK.prototype.parallelInitialization = function () {
401
434
  return __awaiter(this, arguments, void 0, function (optionalParams) {
402
- var error_1;
435
+ var error_1, telemetryData;
403
436
  if (optionalParams === void 0) { optionalParams = {}; }
404
437
  return __generator(this, function (_a) {
405
438
  switch (_a.label) {
@@ -421,8 +454,11 @@ var OmnichannelChatSDK = /** @class */ (function () {
421
454
  return [3 /*break*/, 3];
422
455
  case 2:
423
456
  error_1 = _a.sent();
424
- // Handle the error appropriately
425
- this.scenarioMarker.failScenario(TelemetryEvent_1.default.InitializeChatSDKParallel);
457
+ telemetryData = {
458
+ RequestId: this.requestId,
459
+ ExceptionDetails: (error_1 instanceof ChatSDKError_1.ChatSDKError) ? JSON.stringify(error_1.exceptionDetails) : "".concat(error_1)
460
+ };
461
+ this.scenarioMarker.failScenario(TelemetryEvent_1.default.InitializeChatSDKParallel, telemetryData);
426
462
  throw error_1;
427
463
  case 3: return [2 /*return*/, this.liveChatConfig];
428
464
  }
@@ -487,7 +523,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
487
523
  return [4 /*yield*/, (0, omnichannel_amsclient_1.default)({
488
524
  framedMode: (0, platform_1.isBrowser)(),
489
525
  multiClient: true,
490
- debug: this.debug,
526
+ debug: (this.detailedDebugEnabled ? this.debugAMS : this.debug),
491
527
  logger: this.amsClientLogger
492
528
  })];
493
529
  case 9:
@@ -649,7 +685,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
649
685
  _a.label = 1;
650
686
  case 1:
651
687
  _a.trys.push([1, 3, , 4]);
652
- return [4 /*yield*/, this.OCClient.getReconnectAvailability(optionalParams.reconnectId)];
688
+ return [4 /*yield*/, this.OCClient.getReconnectAvailability(optionalParams.reconnectId, { requestId: this.requestId })];
653
689
  case 2:
654
690
  reconnectAvailabilityResponse = _a.sent();
655
691
  // isReconnectAvailable , indicates if the chat is still valid, or the token has expired
@@ -699,6 +735,9 @@ var OmnichannelChatSDK = /** @class */ (function () {
699
735
  if (!this.isInitialized) {
700
736
  exceptionThrowers_1.default.throwUninitializedChatSDK(this.scenarioMarker, TelemetryEvent_1.default.GetChatReconnectContext);
701
737
  }
738
+ if (!this.requestId) {
739
+ this.requestId = (0, ocsdk_1.uuidv4)();
740
+ }
702
741
  context = {
703
742
  reconnectId: null,
704
743
  redirectURL: null
@@ -741,6 +780,9 @@ var OmnichannelChatSDK = /** @class */ (function () {
741
780
  if (!this.isInitialized) {
742
781
  exceptionThrowers_1.default.throwUninitializedChatSDK(this.scenarioMarker, TelemetryEvent_1.default.StartChat);
743
782
  }
783
+ if (!this.requestId) {
784
+ this.requestId = (0, ocsdk_1.uuidv4)();
785
+ }
744
786
  shouldReinitIC3Client = !platform_1.default.isNode() && !platform_1.default.isReactNative() && !this.IC3Client && this.liveChatVersion === LiveChatVersion_1.default.V1;
745
787
  if (!shouldReinitIC3Client) return [3 /*break*/, 2];
746
788
  _a = this;
@@ -1056,19 +1098,18 @@ var OmnichannelChatSDK = /** @class */ (function () {
1056
1098
  }
1057
1099
  });
1058
1100
  }); };
1059
- if (!!((_k = this.chatSDKConfig.useCreateConversation) === null || _k === void 0 ? void 0 : _k.disable)) return [3 /*break*/, 21];
1101
+ if (!!((_k = this.chatSDKConfig.useCreateConversation) === null || _k === void 0 ? void 0 : _k.disable)) return [3 /*break*/, 20];
1060
1102
  return [4 /*yield*/, createConversationPromise()];
1061
1103
  case 19:
1062
1104
  _o.sent();
1063
- return [4 /*yield*/, Promise.all([messagingClientPromise(), attachmentClientPromise()])];
1064
- case 20:
1065
- _o.sent();
1066
- return [3 /*break*/, 23];
1067
- case 21: return [4 /*yield*/, Promise.all([sessionInitPromise(), messagingClientPromise(), attachmentClientPromise()])];
1068
- case 22:
1069
- _o.sent();
1070
- _o.label = 23;
1105
+ return [3 /*break*/, 22];
1106
+ case 20: return [4 /*yield*/, sessionInitPromise()];
1107
+ case 21:
1108
+ _o.sent(); // Await the session initialization
1109
+ _o.label = 22;
1110
+ case 22: return [4 /*yield*/, Promise.all([messagingClientPromise(), attachmentClientPromise()])];
1071
1111
  case 23:
1112
+ _o.sent();
1072
1113
  if (this.isPersistentChat && !((_l = this.chatSDKConfig.persistentChat) === null || _l === void 0 ? void 0 : _l.disable)) {
1073
1114
  this.refreshTokenTimer = setInterval(function () { return __awaiter(_this, void 0, void 0, function () {
1074
1115
  return __generator(this, function (_a) {
@@ -1153,12 +1194,15 @@ var OmnichannelChatSDK = /** @class */ (function () {
1153
1194
  }
1154
1195
  _b.label = 1;
1155
1196
  case 1:
1156
- _b.trys.push([1, 3, , 4]);
1157
- // calling close chat, internally will handle the session close
1158
- return [4 /*yield*/, this.closeChat(endChatOptionalParams)];
1197
+ _b.trys.push([1, 6, , 7]);
1198
+ _b.label = 2;
1159
1199
  case 2:
1160
- // calling close chat, internally will handle the session close
1200
+ _b.trys.push([2, , 4, 5]);
1201
+ return [4 /*yield*/, this.closeChat(endChatOptionalParams)];
1202
+ case 3:
1161
1203
  _b.sent();
1204
+ return [3 /*break*/, 5];
1205
+ case 4:
1162
1206
  (_a = this.conversation) === null || _a === void 0 ? void 0 : _a.disconnect();
1163
1207
  this.conversation = null;
1164
1208
  this.requestId = (0, ocsdk_1.uuidv4)();
@@ -1179,17 +1223,22 @@ var OmnichannelChatSDK = /** @class */ (function () {
1179
1223
  clearInterval(this.refreshTokenTimer);
1180
1224
  this.refreshTokenTimer = null;
1181
1225
  }
1226
+ return [7 /*endfinally*/];
1227
+ case 5:
1182
1228
  this.scenarioMarker.completeScenario(TelemetryEvent_1.default.EndChat, cleanupMetadata);
1183
- return [3 /*break*/, 4];
1184
- case 3:
1229
+ return [3 /*break*/, 7];
1230
+ case 6:
1185
1231
  error_12 = _b.sent();
1186
1232
  telemetryData = {
1187
1233
  RequestId: this.requestId,
1188
1234
  ChatId: this.chatToken.chatId
1189
1235
  };
1236
+ if (error_12 instanceof ChatSDKError_1.ChatSDKError) {
1237
+ exceptionThrowers_1.default.throwConversationClosureFailure(new Error(JSON.stringify(error_12.exceptionDetails)), this.scenarioMarker, TelemetryEvent_1.default.EndChat, telemetryData);
1238
+ }
1190
1239
  exceptionThrowers_1.default.throwConversationClosureFailure(error_12, this.scenarioMarker, TelemetryEvent_1.default.EndChat, telemetryData);
1191
- return [3 /*break*/, 4];
1192
- case 4: return [2 /*return*/];
1240
+ return [3 /*break*/, 7];
1241
+ case 7: return [2 /*return*/];
1193
1242
  }
1194
1243
  });
1195
1244
  });
@@ -1245,6 +1294,10 @@ var OmnichannelChatSDK = /** @class */ (function () {
1245
1294
  chatId = chatToken.chatId;
1246
1295
  reconnectId = this.reconnectId;
1247
1296
  sessionId = this.sessionId;
1297
+ if (!this.requestId) {
1298
+ this.requestId = (0, ocsdk_1.uuidv4)();
1299
+ requestId = this.requestId;
1300
+ }
1248
1301
  if (optionalParams.liveChatContext) {
1249
1302
  requestId = optionalParams.liveChatContext.requestId;
1250
1303
  chatToken = optionalParams.liveChatContext.chatToken;
@@ -1695,7 +1748,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
1695
1748
  var id = event.id;
1696
1749
  var omnichannelMessage = (0, createOmnichannelMessage_1.default)(event, {
1697
1750
  liveChatVersion: _this.liveChatVersion,
1698
- debug: _this.debug
1751
+ debug: (_this.detailedDebugEnabled ? _this.debugACS : _this.debug),
1699
1752
  });
1700
1753
  if (!postedMessages_1.has(id)) {
1701
1754
  onNewMessageCallback(omnichannelMessage);
@@ -2209,6 +2262,12 @@ var OmnichannelChatSDK = /** @class */ (function () {
2209
2262
  sessionId = optionalParams.liveChatContext.sessionId;
2210
2263
  this.OCClient.sessionId = sessionId;
2211
2264
  }
2265
+ if (!chatId) {
2266
+ throw new ChatSDKError_1.ChatSDKError(ChatSDKError_1.ChatSDKErrorName.LiveChatTranscriptRetrievalFailure, undefined, {
2267
+ response: ChatSDKError_1.ChatSDKErrorName.LiveChatTranscriptRetrievalFailure,
2268
+ errorObject: "ChatId is not defined"
2269
+ });
2270
+ }
2212
2271
  this.scenarioMarker.startScenario(TelemetryEvent_1.default.GetLiveChatTranscript, {
2213
2272
  RequestId: requestId,
2214
2273
  ChatId: chatId
@@ -2483,7 +2542,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
2483
2542
  ChatId: (_g = this.chatToken) === null || _g === void 0 ? void 0 : _g.chatId,
2484
2543
  ExceptionDetails: "Post Chat Survey is disabled. Please check the Omnichannel Administration Portal."
2485
2544
  });
2486
- return [2 /*return*/, Promise.reject("Post Chat is disabled from admin side.")];
2545
+ return [2 /*return*/, Promise.reject("Post Chat is disabled from admin side, or chat doesnt have a survey as part of their configuration.")];
2487
2546
  case 7: return [3 /*break*/, 9];
2488
2547
  case 8:
2489
2548
  ex_1 = _j.sent();