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

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:
@@ -487,7 +520,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
487
520
  return [4 /*yield*/, (0, omnichannel_amsclient_1.default)({
488
521
  framedMode: (0, platform_1.isBrowser)(),
489
522
  multiClient: true,
490
- debug: this.debug,
523
+ debug: (this.detailedDebugEnabled ? this.debugAMS : this.debug),
491
524
  logger: this.amsClientLogger
492
525
  })];
493
526
  case 9:
@@ -649,7 +682,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
649
682
  _a.label = 1;
650
683
  case 1:
651
684
  _a.trys.push([1, 3, , 4]);
652
- return [4 /*yield*/, this.OCClient.getReconnectAvailability(optionalParams.reconnectId)];
685
+ return [4 /*yield*/, this.OCClient.getReconnectAvailability(optionalParams.reconnectId, { requestId: this.requestId })];
653
686
  case 2:
654
687
  reconnectAvailabilityResponse = _a.sent();
655
688
  // isReconnectAvailable , indicates if the chat is still valid, or the token has expired
@@ -699,6 +732,9 @@ var OmnichannelChatSDK = /** @class */ (function () {
699
732
  if (!this.isInitialized) {
700
733
  exceptionThrowers_1.default.throwUninitializedChatSDK(this.scenarioMarker, TelemetryEvent_1.default.GetChatReconnectContext);
701
734
  }
735
+ if (!this.requestId) {
736
+ this.requestId = (0, ocsdk_1.uuidv4)();
737
+ }
702
738
  context = {
703
739
  reconnectId: null,
704
740
  redirectURL: null
@@ -741,6 +777,9 @@ var OmnichannelChatSDK = /** @class */ (function () {
741
777
  if (!this.isInitialized) {
742
778
  exceptionThrowers_1.default.throwUninitializedChatSDK(this.scenarioMarker, TelemetryEvent_1.default.StartChat);
743
779
  }
780
+ if (!this.requestId) {
781
+ this.requestId = (0, ocsdk_1.uuidv4)();
782
+ }
744
783
  shouldReinitIC3Client = !platform_1.default.isNode() && !platform_1.default.isReactNative() && !this.IC3Client && this.liveChatVersion === LiveChatVersion_1.default.V1;
745
784
  if (!shouldReinitIC3Client) return [3 /*break*/, 2];
746
785
  _a = this;
@@ -1056,19 +1095,18 @@ var OmnichannelChatSDK = /** @class */ (function () {
1056
1095
  }
1057
1096
  });
1058
1097
  }); };
1059
- if (!!((_k = this.chatSDKConfig.useCreateConversation) === null || _k === void 0 ? void 0 : _k.disable)) return [3 /*break*/, 21];
1098
+ if (!!((_k = this.chatSDKConfig.useCreateConversation) === null || _k === void 0 ? void 0 : _k.disable)) return [3 /*break*/, 20];
1060
1099
  return [4 /*yield*/, createConversationPromise()];
1061
1100
  case 19:
1062
1101
  _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;
1102
+ return [3 /*break*/, 22];
1103
+ case 20: return [4 /*yield*/, sessionInitPromise()];
1104
+ case 21:
1105
+ _o.sent(); // Await the session initialization
1106
+ _o.label = 22;
1107
+ case 22: return [4 /*yield*/, Promise.all([messagingClientPromise(), attachmentClientPromise()])];
1071
1108
  case 23:
1109
+ _o.sent();
1072
1110
  if (this.isPersistentChat && !((_l = this.chatSDKConfig.persistentChat) === null || _l === void 0 ? void 0 : _l.disable)) {
1073
1111
  this.refreshTokenTimer = setInterval(function () { return __awaiter(_this, void 0, void 0, function () {
1074
1112
  return __generator(this, function (_a) {
@@ -1153,12 +1191,15 @@ var OmnichannelChatSDK = /** @class */ (function () {
1153
1191
  }
1154
1192
  _b.label = 1;
1155
1193
  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)];
1194
+ _b.trys.push([1, 6, , 7]);
1195
+ _b.label = 2;
1159
1196
  case 2:
1160
- // calling close chat, internally will handle the session close
1197
+ _b.trys.push([2, , 4, 5]);
1198
+ return [4 /*yield*/, this.closeChat(endChatOptionalParams)];
1199
+ case 3:
1161
1200
  _b.sent();
1201
+ return [3 /*break*/, 5];
1202
+ case 4:
1162
1203
  (_a = this.conversation) === null || _a === void 0 ? void 0 : _a.disconnect();
1163
1204
  this.conversation = null;
1164
1205
  this.requestId = (0, ocsdk_1.uuidv4)();
@@ -1179,17 +1220,22 @@ var OmnichannelChatSDK = /** @class */ (function () {
1179
1220
  clearInterval(this.refreshTokenTimer);
1180
1221
  this.refreshTokenTimer = null;
1181
1222
  }
1223
+ return [7 /*endfinally*/];
1224
+ case 5:
1182
1225
  this.scenarioMarker.completeScenario(TelemetryEvent_1.default.EndChat, cleanupMetadata);
1183
- return [3 /*break*/, 4];
1184
- case 3:
1226
+ return [3 /*break*/, 7];
1227
+ case 6:
1185
1228
  error_12 = _b.sent();
1186
1229
  telemetryData = {
1187
1230
  RequestId: this.requestId,
1188
1231
  ChatId: this.chatToken.chatId
1189
1232
  };
1233
+ if (error_12 instanceof ChatSDKError_1.ChatSDKError) {
1234
+ exceptionThrowers_1.default.throwConversationClosureFailure(new Error(JSON.stringify(error_12.exceptionDetails)), this.scenarioMarker, TelemetryEvent_1.default.EndChat, telemetryData);
1235
+ }
1190
1236
  exceptionThrowers_1.default.throwConversationClosureFailure(error_12, this.scenarioMarker, TelemetryEvent_1.default.EndChat, telemetryData);
1191
- return [3 /*break*/, 4];
1192
- case 4: return [2 /*return*/];
1237
+ return [3 /*break*/, 7];
1238
+ case 7: return [2 /*return*/];
1193
1239
  }
1194
1240
  });
1195
1241
  });
@@ -1245,6 +1291,10 @@ var OmnichannelChatSDK = /** @class */ (function () {
1245
1291
  chatId = chatToken.chatId;
1246
1292
  reconnectId = this.reconnectId;
1247
1293
  sessionId = this.sessionId;
1294
+ if (!this.requestId) {
1295
+ this.requestId = (0, ocsdk_1.uuidv4)();
1296
+ requestId = this.requestId;
1297
+ }
1248
1298
  if (optionalParams.liveChatContext) {
1249
1299
  requestId = optionalParams.liveChatContext.requestId;
1250
1300
  chatToken = optionalParams.liveChatContext.chatToken;
@@ -1695,7 +1745,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
1695
1745
  var id = event.id;
1696
1746
  var omnichannelMessage = (0, createOmnichannelMessage_1.default)(event, {
1697
1747
  liveChatVersion: _this.liveChatVersion,
1698
- debug: _this.debug
1748
+ debug: (_this.detailedDebugEnabled ? _this.debugACS : _this.debug),
1699
1749
  });
1700
1750
  if (!postedMessages_1.has(id)) {
1701
1751
  onNewMessageCallback(omnichannelMessage);
@@ -2209,6 +2259,12 @@ var OmnichannelChatSDK = /** @class */ (function () {
2209
2259
  sessionId = optionalParams.liveChatContext.sessionId;
2210
2260
  this.OCClient.sessionId = sessionId;
2211
2261
  }
2262
+ if (!chatId) {
2263
+ throw new ChatSDKError_1.ChatSDKError(ChatSDKError_1.ChatSDKErrorName.LiveChatTranscriptRetrievalFailure, undefined, {
2264
+ response: ChatSDKError_1.ChatSDKErrorName.LiveChatTranscriptRetrievalFailure,
2265
+ errorObject: "ChatId is not defined"
2266
+ });
2267
+ }
2212
2268
  this.scenarioMarker.startScenario(TelemetryEvent_1.default.GetLiveChatTranscript, {
2213
2269
  RequestId: requestId,
2214
2270
  ChatId: chatId
@@ -2483,7 +2539,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
2483
2539
  ChatId: (_g = this.chatToken) === null || _g === void 0 ? void 0 : _g.chatId,
2484
2540
  ExceptionDetails: "Post Chat Survey is disabled. Please check the Omnichannel Administration Portal."
2485
2541
  });
2486
- return [2 /*return*/, Promise.reject("Post Chat is disabled from admin side.")];
2542
+ return [2 /*return*/, Promise.reject("Post Chat is disabled from admin side, or chat doesnt have a survey as part of their configuration.")];
2487
2543
  case 7: return [3 /*break*/, 9];
2488
2544
  case 8:
2489
2545
  ex_1 = _j.sent();