@microsoft/omnichannel-chat-sdk 1.10.20-main.d4110c8 → 1.11.0

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;
@@ -1152,12 +1194,15 @@ var OmnichannelChatSDK = /** @class */ (function () {
1152
1194
  }
1153
1195
  _b.label = 1;
1154
1196
  case 1:
1155
- _b.trys.push([1, 3, , 4]);
1156
- // calling close chat, internally will handle the session close
1157
- return [4 /*yield*/, this.closeChat(endChatOptionalParams)];
1197
+ _b.trys.push([1, 6, , 7]);
1198
+ _b.label = 2;
1158
1199
  case 2:
1159
- // 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:
1160
1203
  _b.sent();
1204
+ return [3 /*break*/, 5];
1205
+ case 4:
1161
1206
  (_a = this.conversation) === null || _a === void 0 ? void 0 : _a.disconnect();
1162
1207
  this.conversation = null;
1163
1208
  this.requestId = (0, ocsdk_1.uuidv4)();
@@ -1178,9 +1223,11 @@ var OmnichannelChatSDK = /** @class */ (function () {
1178
1223
  clearInterval(this.refreshTokenTimer);
1179
1224
  this.refreshTokenTimer = null;
1180
1225
  }
1226
+ return [7 /*endfinally*/];
1227
+ case 5:
1181
1228
  this.scenarioMarker.completeScenario(TelemetryEvent_1.default.EndChat, cleanupMetadata);
1182
- return [3 /*break*/, 4];
1183
- case 3:
1229
+ return [3 /*break*/, 7];
1230
+ case 6:
1184
1231
  error_12 = _b.sent();
1185
1232
  telemetryData = {
1186
1233
  RequestId: this.requestId,
@@ -1190,8 +1237,8 @@ var OmnichannelChatSDK = /** @class */ (function () {
1190
1237
  exceptionThrowers_1.default.throwConversationClosureFailure(new Error(JSON.stringify(error_12.exceptionDetails)), this.scenarioMarker, TelemetryEvent_1.default.EndChat, telemetryData);
1191
1238
  }
1192
1239
  exceptionThrowers_1.default.throwConversationClosureFailure(error_12, this.scenarioMarker, TelemetryEvent_1.default.EndChat, telemetryData);
1193
- return [3 /*break*/, 4];
1194
- case 4: return [2 /*return*/];
1240
+ return [3 /*break*/, 7];
1241
+ case 7: return [2 /*return*/];
1195
1242
  }
1196
1243
  });
1197
1244
  });
@@ -1247,6 +1294,10 @@ var OmnichannelChatSDK = /** @class */ (function () {
1247
1294
  chatId = chatToken.chatId;
1248
1295
  reconnectId = this.reconnectId;
1249
1296
  sessionId = this.sessionId;
1297
+ if (!this.requestId) {
1298
+ this.requestId = (0, ocsdk_1.uuidv4)();
1299
+ requestId = this.requestId;
1300
+ }
1250
1301
  if (optionalParams.liveChatContext) {
1251
1302
  requestId = optionalParams.liveChatContext.requestId;
1252
1303
  chatToken = optionalParams.liveChatContext.chatToken;
@@ -1697,7 +1748,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
1697
1748
  var id = event.id;
1698
1749
  var omnichannelMessage = (0, createOmnichannelMessage_1.default)(event, {
1699
1750
  liveChatVersion: _this.liveChatVersion,
1700
- debug: _this.debug
1751
+ debug: (_this.detailedDebugEnabled ? _this.debugACS : _this.debug),
1701
1752
  });
1702
1753
  if (!postedMessages_1.has(id)) {
1703
1754
  onNewMessageCallback(omnichannelMessage);
@@ -2211,6 +2262,12 @@ var OmnichannelChatSDK = /** @class */ (function () {
2211
2262
  sessionId = optionalParams.liveChatContext.sessionId;
2212
2263
  this.OCClient.sessionId = sessionId;
2213
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
+ }
2214
2271
  this.scenarioMarker.startScenario(TelemetryEvent_1.default.GetLiveChatTranscript, {
2215
2272
  RequestId: requestId,
2216
2273
  ChatId: chatId
@@ -2485,7 +2542,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
2485
2542
  ChatId: (_g = this.chatToken) === null || _g === void 0 ? void 0 : _g.chatId,
2486
2543
  ExceptionDetails: "Post Chat Survey is disabled. Please check the Omnichannel Administration Portal."
2487
2544
  });
2488
- 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.")];
2489
2546
  case 7: return [3 /*break*/, 9];
2490
2547
  case 8:
2491
2548
  ex_1 = _j.sent();