@microsoft/omnichannel-chat-sdk 1.11.7-main.6fd4ccf → 1.11.7-main.82eaf09

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.
@@ -1,6 +1,6 @@
1
1
  import ACSClient from "./core/messaging/ACSClient";
2
2
  import { VoiceVideoCallingOptionalParams } from "./types/config";
3
- import { ChatAdapter, GetAgentAvailabilityResponse, GetCurrentLiveChatContextResponse, GetLiveChatTranscriptResponse, GetMessagesResponse, GetPreChatSurveyResponse, GetVoiceVideoCallingResponse, MaskingRules, UploadFileAttachmentResponse } from "./types/response";
3
+ import { ChatAdapter, GetAgentAvailabilityResponse, GetCurrentLiveChatContextResponse, GetLiveChatTranscriptResponse, GetMessagesResponse, GetPersistentChatHistoryResponse, GetPreChatSurveyResponse, GetVoiceVideoCallingResponse, MaskingRules, UploadFileAttachmentResponse } from "./types/response";
4
4
  import { ParticipantsRemovedEvent } from '@azure/communication-signaling';
5
5
  import ChatAdapterOptionalParams from "./core/messaging/ChatAdapterOptionalParams";
6
6
  import ChatConfig from "./core/ChatConfig";
@@ -21,6 +21,7 @@ import GetChatTokenOptionalParams from "./core/GetChatTokenOptionalParams";
21
21
  import GetConversationDetailsOptionalParams from "./core/GetConversationDetailsOptionalParams";
22
22
  import GetLiveChatConfigOptionalParams from "./core/GetLiveChatConfigOptionalParams";
23
23
  import GetLiveChatTranscriptOptionalParams from "./core/GetLiveChatTranscriptOptionalParams";
24
+ import GetPersistentChatHistoryOptionalParams from "./core/GetPersistentChatHistoryOptionalParams";
24
25
  import IChatToken from "./external/IC3Adapter/IChatToken";
25
26
  import IFileInfo from "@microsoft/omnichannel-ic3core/lib/interfaces/IFileInfo";
26
27
  import IFileMetadata from "@microsoft/omnichannel-ic3core/lib/model/IFileMetadata";
@@ -83,6 +84,7 @@ declare class OmnichannelChatSDK {
83
84
  private debugAMS;
84
85
  private debugACS;
85
86
  private detailedDebugEnabled;
87
+ private regexCompiledForDataMasking;
86
88
  constructor(omnichannelConfig: OmnichannelConfig, chatSDKConfig?: ChatSDKConfig);
87
89
  /**
88
90
  * Executes an operation with mutual exclusion to prevent race conditions
@@ -164,6 +166,7 @@ declare class OmnichannelChatSDK {
164
166
  private getIC3Client;
165
167
  private setPrechatConfigurations;
166
168
  private setDataMaskingConfiguration;
169
+ private compileDataMaskingRegex;
167
170
  private setAuthSettingConfig;
168
171
  private setPersistentChatConfiguration;
169
172
  private setLocaleIdConfiguration;
@@ -186,5 +189,10 @@ declare class OmnichannelChatSDK {
186
189
  * @private
187
190
  */
188
191
  private handleConversationJoinFailure;
192
+ /**
193
+ * Get persistent chat history for authenticated users.
194
+ * @param getPersistentChatHistoryOptionalParams Optional parameters for persistent chat history retrieval.
195
+ */
196
+ getPersistentChatHistory(getPersistentChatHistoryOptionalParams?: GetPersistentChatHistoryOptionalParams): Promise<GetPersistentChatHistoryResponse | undefined>;
189
197
  }
190
198
  export default OmnichannelChatSDK;
@@ -150,6 +150,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
150
150
  this.debugAMS = false;
151
151
  this.debugACS = false;
152
152
  this.detailedDebugEnabled = false;
153
+ this.regexCompiledForDataMasking = [];
153
154
  this.populateInitChatOptionalParam = function (requestOptionalParams, optionalParams, telemetryEvent) {
154
155
  requestOptionalParams.initContext.locale = (0, locale_1.getLocaleStringFromId)(_this.localeId);
155
156
  if (optionalParams === null || optionalParams === void 0 ? void 0 : optionalParams.customContext) {
@@ -1687,21 +1688,36 @@ var OmnichannelChatSDK = /** @class */ (function () {
1687
1688
  }
1688
1689
  var content = message.content;
1689
1690
  var match;
1690
- for (var _i = 0, _a = this.dataMaskingRules.rules; _i < _a.length; _i++) {
1691
- var maskingRule = _a[_i];
1692
- var regex = new RegExp(maskingRule.regex, 'g');
1693
- while ((match = regex.exec(content)) !== null) {
1694
- var replaceStr = match[0].replace(/./g, this.maskingCharacter);
1695
- content = content.replace(match[0], replaceStr);
1691
+ if (this.regexCompiledForDataMasking.length === 0) {
1692
+ return message;
1693
+ }
1694
+ for (var _i = 0, _a = this.regexCompiledForDataMasking; _i < _a.length; _i++) {
1695
+ var regex = _a[_i];
1696
+ try {
1697
+ var lastIndex = -1;
1698
+ while ((match = regex.exec(content)) !== null) {
1699
+ // Prevent infinite loop from zero-width matches
1700
+ if (regex.lastIndex === lastIndex) {
1701
+ this.debug && console.warn("[OmnichannelChatSDK][transformMessage] Data masking regex caused zero-width match, skipping rule ".concat(regex));
1702
+ break;
1703
+ }
1704
+ lastIndex = regex.lastIndex;
1705
+ var replaceStr = match[0].replace(/./g, this.maskingCharacter);
1706
+ content = content.replace(match[0], replaceStr);
1707
+ }
1708
+ match = null;
1709
+ }
1710
+ catch (error) {
1711
+ // Log error for invalid regex but continue processing other rules
1712
+ this.debug && console.error("[OmnichannelChatSDK][transformMessage] Data masking regex failed for rule ".concat(regex, ": ").concat(error));
1696
1713
  }
1697
- match = null;
1698
1714
  }
1699
1715
  message.content = content;
1700
1716
  return message;
1701
1717
  };
1702
1718
  OmnichannelChatSDK.prototype.sendMessage = function (message) {
1703
1719
  return __awaiter(this, void 0, void 0, function () {
1704
- var sendMessageRequest, chatMessage, error_17, exceptionDetails, messageToSend, error_18, exceptionDetails;
1720
+ var sendMessageRequest, chatMessage, error_17, exceptionDetails;
1705
1721
  var _a;
1706
1722
  return __generator(this, function (_b) {
1707
1723
  switch (_b.label) {
@@ -1714,7 +1730,6 @@ var OmnichannelChatSDK = /** @class */ (function () {
1714
1730
  exceptionThrowers_1.default.throwUninitializedChatSDK(this.scenarioMarker, TelemetryEvent_1.default.SendMessages);
1715
1731
  }
1716
1732
  this.transformMessage(message);
1717
- if (!(this.liveChatVersion === LiveChatVersion_1.default.V2)) return [3 /*break*/, 5];
1718
1733
  sendMessageRequest = {
1719
1734
  content: message.content,
1720
1735
  };
@@ -1751,52 +1766,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
1751
1766
  response: ChatSDKError_1.ChatSDKErrorName.ChatSDKSendMessageFailed,
1752
1767
  errorObject: "".concat(error_17)
1753
1768
  });
1754
- case 4: return [3 /*break*/, 9];
1755
- case 5:
1756
- messageToSend = {
1757
- content: message.content,
1758
- timestamp: new Date(),
1759
- contentType: MessageContentType_1.default.Text,
1760
- deliveryMode: DeliveryMode_1.default.Bridged,
1761
- messageType: MessageType_1.default.UserMessage,
1762
- properties: undefined,
1763
- tags: __spreadArray([], MessageTags_1.defaultMessageTags, true),
1764
- sender: {
1765
- displayName: "Customer",
1766
- id: "customer",
1767
- type: PersonType_1.default.User
1768
- }
1769
- };
1770
- if (message.tags) {
1771
- messageToSend.tags = message.tags;
1772
- }
1773
- if (message.timestamp) {
1774
- messageToSend.timestamp = message.timestamp;
1775
- }
1776
- _b.label = 6;
1777
- case 6:
1778
- _b.trys.push([6, 8, , 9]);
1779
- return [4 /*yield*/, this.conversation.sendMessage(messageToSend)];
1780
- case 7:
1781
- _b.sent();
1782
- this.scenarioMarker.completeScenario(TelemetryEvent_1.default.SendMessages, {
1783
- RequestId: this.requestId,
1784
- ChatId: this.chatToken.chatId
1785
- });
1786
- return [3 /*break*/, 9];
1787
- case 8:
1788
- error_18 = _b.sent();
1789
- exceptionDetails = {
1790
- response: ChatSDKError_1.ChatSDKErrorName.ChatSDKSendMessageFailed,
1791
- errorObject: "".concat(error_18)
1792
- };
1793
- this.scenarioMarker.failScenario(TelemetryEvent_1.default.SendMessages, {
1794
- RequestId: this.requestId,
1795
- ChatId: this.chatToken.chatId,
1796
- ExceptionDetails: JSON.stringify(exceptionDetails)
1797
- });
1798
- throw new Error(ChatSDKError_1.ChatSDKErrorName.ChatSDKSendMessageFailed);
1799
- case 9: return [2 /*return*/];
1769
+ case 4: return [2 /*return*/];
1800
1770
  }
1801
1771
  });
1802
1772
  });
@@ -1847,12 +1817,17 @@ var OmnichannelChatSDK = /** @class */ (function () {
1847
1817
  }
1848
1818
  (_b = this.conversation) === null || _b === void 0 ? void 0 : _b.registerOnNewMessage(function (event) {
1849
1819
  var id = event.id;
1820
+ var isChatMessageEditedEvent = Object.keys(event).includes("editedOn");
1821
+ console.log("[OmnichannelChatSDK][onNewMessage] New message received", event);
1822
+ console.log("[OmnichannelChatSDK][onNewMessage] isChatMessageEditedEvent=>", isChatMessageEditedEvent);
1850
1823
  var omnichannelMessage = (0, createOmnichannelMessage_1.default)(event, {
1851
1824
  liveChatVersion: _this.liveChatVersion,
1852
1825
  debug: (_this.detailedDebugEnabled ? _this.debugACS : _this.debug),
1853
1826
  });
1854
- if (!postedMessages_1.has(id)) {
1827
+ // send callback for new messages or edited existent messages
1828
+ if (!postedMessages_1.has(id) || isChatMessageEditedEvent) {
1855
1829
  onNewMessageCallback(omnichannelMessage);
1830
+ console.log("[OmnichannelChatSDK][onNewMessage] Message posted");
1856
1831
  postedMessages_1.add(id);
1857
1832
  }
1858
1833
  }, registerOnNewMessageOptionalParams);
@@ -1875,7 +1850,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
1875
1850
  };
1876
1851
  OmnichannelChatSDK.prototype.sendTypingEvent = function () {
1877
1852
  return __awaiter(this, void 0, void 0, function () {
1878
- var error_19;
1853
+ var error_18;
1879
1854
  return __generator(this, function (_a) {
1880
1855
  switch (_a.label) {
1881
1856
  case 0:
@@ -1904,7 +1879,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
1904
1879
  });
1905
1880
  return [3 /*break*/, 5];
1906
1881
  case 4:
1907
- error_19 = _a.sent();
1882
+ error_18 = _a.sent();
1908
1883
  this.scenarioMarker.failScenario(TelemetryEvent_1.default.SendTypingEvent, {
1909
1884
  RequestId: this.requestId,
1910
1885
  ChatId: this.chatToken.chatId
@@ -1972,8 +1947,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
1972
1947
  OmnichannelChatSDK.prototype.onAgentEndSession = function (onAgentEndSessionCallback) {
1973
1948
  return __awaiter(this, void 0, void 0, function () {
1974
1949
  var _this = this;
1975
- var _a;
1976
- return __generator(this, function (_b) {
1950
+ return __generator(this, function (_a) {
1977
1951
  this.scenarioMarker.startScenario(TelemetryEvent_1.default.OnAgentEndSession, {
1978
1952
  RequestId: this.requestId,
1979
1953
  ChatId: this.chatToken.chatId
@@ -1981,59 +1955,32 @@ var OmnichannelChatSDK = /** @class */ (function () {
1981
1955
  if (!this.isInitialized) {
1982
1956
  exceptionThrowers_1.default.throwUninitializedChatSDK(this.scenarioMarker, TelemetryEvent_1.default.OnAgentEndSession);
1983
1957
  }
1984
- if (this.liveChatVersion === LiveChatVersion_1.default.V2) {
1985
- try {
1986
- this.conversation.registerOnThreadUpdate(function (event) { return __awaiter(_this, void 0, void 0, function () {
1987
- var liveWorkItemDetails;
1988
- return __generator(this, function (_a) {
1989
- switch (_a.label) {
1990
- case 0: return [4 /*yield*/, this.getConversationDetails()];
1991
- case 1:
1992
- liveWorkItemDetails = _a.sent();
1993
- if (Object.keys(liveWorkItemDetails).length === 0 || liveWorkItemDetails.state == LiveWorkItemState_1.default.WrapUp || liveWorkItemDetails.state == LiveWorkItemState_1.default.Closed) {
1994
- onAgentEndSessionCallback(event);
1995
- this.stopPolling();
1996
- }
1997
- return [2 /*return*/];
1998
- }
1999
- });
2000
- }); });
2001
- this.scenarioMarker.completeScenario(TelemetryEvent_1.default.OnAgentEndSession, {
2002
- RequestId: this.requestId,
2003
- ChatId: this.chatToken.chatId
2004
- });
2005
- }
2006
- catch (error) {
2007
- this.scenarioMarker.failScenario(TelemetryEvent_1.default.OnAgentEndSession, {
2008
- RequestId: this.requestId,
2009
- ChatId: this.chatToken.chatId
2010
- });
2011
- }
2012
- }
2013
- else {
2014
- try {
2015
- (_a = this.conversation) === null || _a === void 0 ? void 0 : _a.registerOnThreadUpdate(function (message) {
2016
- var members = message.members;
2017
- // Agent ending conversation would have 1 member left in the chat thread
2018
- if (members.length === 1) {
2019
- onAgentEndSessionCallback(message);
2020
- if (_this.refreshTokenTimer !== null) {
2021
- clearInterval(_this.refreshTokenTimer);
2022
- _this.refreshTokenTimer = null;
2023
- }
1958
+ try {
1959
+ this.conversation.registerOnThreadUpdate(function (event) { return __awaiter(_this, void 0, void 0, function () {
1960
+ var liveWorkItemDetails;
1961
+ return __generator(this, function (_a) {
1962
+ switch (_a.label) {
1963
+ case 0: return [4 /*yield*/, this.getConversationDetails()];
1964
+ case 1:
1965
+ liveWorkItemDetails = _a.sent();
1966
+ if (Object.keys(liveWorkItemDetails).length === 0 || liveWorkItemDetails.state == LiveWorkItemState_1.default.WrapUp || liveWorkItemDetails.state == LiveWorkItemState_1.default.Closed) {
1967
+ onAgentEndSessionCallback(event);
1968
+ this.stopPolling();
1969
+ }
1970
+ return [2 /*return*/];
2024
1971
  }
2025
1972
  });
2026
- this.scenarioMarker.completeScenario(TelemetryEvent_1.default.OnAgentEndSession, {
2027
- RequestId: this.requestId,
2028
- ChatId: this.chatToken.chatId
2029
- });
2030
- }
2031
- catch (error) {
2032
- this.scenarioMarker.failScenario(TelemetryEvent_1.default.OnAgentEndSession, {
2033
- RequestId: this.requestId,
2034
- ChatId: this.chatToken.chatId
2035
- });
2036
- }
1973
+ }); });
1974
+ this.scenarioMarker.completeScenario(TelemetryEvent_1.default.OnAgentEndSession, {
1975
+ RequestId: this.requestId,
1976
+ ChatId: this.chatToken.chatId
1977
+ });
1978
+ }
1979
+ catch (error) {
1980
+ this.scenarioMarker.failScenario(TelemetryEvent_1.default.OnAgentEndSession, {
1981
+ RequestId: this.requestId,
1982
+ ChatId: this.chatToken.chatId
1983
+ });
2037
1984
  }
2038
1985
  return [2 /*return*/];
2039
1986
  });
@@ -2041,7 +1988,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
2041
1988
  };
2042
1989
  OmnichannelChatSDK.prototype.uploadFileAttachment = function (fileInfo) {
2043
1990
  return __awaiter(this, void 0, void 0, function () {
2044
- var amsClient, createObjectResponse, documentId, uploadDocumentResponse, fileIdsProperty, fileMetaProperty, sendMessageRequest, messageToSend, error_20, fileMetadata, messageToSend, error_21;
1991
+ var amsClient, createObjectResponse, documentId, uploadDocumentResponse, fileIdsProperty, fileMetaProperty, sendMessageRequest, messageToSend, error_19, fileMetadata, messageToSend, error_20;
2045
1992
  var _a, _b;
2046
1993
  return __generator(this, function (_c) {
2047
1994
  switch (_c.label) {
@@ -2110,7 +2057,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
2110
2057
  });
2111
2058
  return [2 /*return*/, messageToSend];
2112
2059
  case 6:
2113
- error_20 = _c.sent();
2060
+ error_19 = _c.sent();
2114
2061
  console.error("OmnichannelChatSDK/uploadFileAttachment/sendMessage/error");
2115
2062
  this.scenarioMarker.failScenario(TelemetryEvent_1.default.UploadFileAttachment, {
2116
2063
  RequestId: this.requestId,
@@ -2156,8 +2103,8 @@ var OmnichannelChatSDK = /** @class */ (function () {
2156
2103
  });
2157
2104
  return [2 /*return*/, messageToSend];
2158
2105
  case 15:
2159
- error_21 = _c.sent();
2160
- console.error("OmnichannelChatSDK/uploadFileAttachment/error: ".concat(error_21));
2106
+ error_20 = _c.sent();
2107
+ console.error("OmnichannelChatSDK/uploadFileAttachment/error: ".concat(error_20));
2161
2108
  this.scenarioMarker.failScenario(TelemetryEvent_1.default.UploadFileAttachment, {
2162
2109
  RequestId: this.requestId,
2163
2110
  ChatId: this.chatToken.chatId
@@ -2170,7 +2117,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
2170
2117
  };
2171
2118
  OmnichannelChatSDK.prototype.downloadFileAttachment = function (fileMetadata) {
2172
2119
  return __awaiter(this, void 0, void 0, function () {
2173
- var amsClient, response, view_location, viewResponse, _a, downloadedFile, error_22;
2120
+ var amsClient, response, view_location, viewResponse, _a, downloadedFile, error_21;
2174
2121
  return __generator(this, function (_b) {
2175
2122
  switch (_b.label) {
2176
2123
  case 0:
@@ -2230,8 +2177,8 @@ var OmnichannelChatSDK = /** @class */ (function () {
2230
2177
  });
2231
2178
  return [2 /*return*/, downloadedFile];
2232
2179
  case 9:
2233
- error_22 = _b.sent();
2234
- console.error("OmnichannelChatSDK/downloadFileAttachment/error: ".concat(error_22));
2180
+ error_21 = _b.sent();
2181
+ console.error("OmnichannelChatSDK/downloadFileAttachment/error: ".concat(error_21));
2235
2182
  this.scenarioMarker.failScenario(TelemetryEvent_1.default.DownloadFileAttachment, {
2236
2183
  RequestId: this.requestId,
2237
2184
  ChatId: this.chatToken.chatId
@@ -2244,7 +2191,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
2244
2191
  };
2245
2192
  OmnichannelChatSDK.prototype.emailLiveChatTranscript = function (body_1) {
2246
2193
  return __awaiter(this, arguments, void 0, function (body, optionalParams) {
2247
- var emailTranscriptOptionalParams, requestId, chatToken, chatId, sessionId, emailRequestBody, error_23;
2194
+ var emailTranscriptOptionalParams, requestId, chatToken, chatId, sessionId, emailRequestBody, error_22;
2248
2195
  var _a;
2249
2196
  if (optionalParams === void 0) { optionalParams = {}; }
2250
2197
  return __generator(this, function (_b) {
@@ -2295,8 +2242,8 @@ var OmnichannelChatSDK = /** @class */ (function () {
2295
2242
  });
2296
2243
  return [3 /*break*/, 4];
2297
2244
  case 3:
2298
- error_23 = _b.sent();
2299
- console.error("OmnichannelChatSDK/emailLiveChatTranscript/error: ".concat(error_23));
2245
+ error_22 = _b.sent();
2246
+ console.error("OmnichannelChatSDK/emailLiveChatTranscript/error: ".concat(error_22));
2300
2247
  this.scenarioMarker.failScenario(TelemetryEvent_1.default.EmailLiveChatTranscript, {
2301
2248
  RequestId: requestId,
2302
2249
  ChatId: chatId
@@ -2309,7 +2256,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
2309
2256
  };
2310
2257
  OmnichannelChatSDK.prototype.getLiveChatTranscript = function () {
2311
2258
  return __awaiter(this, arguments, void 0, function (optionalParams) {
2312
- var getChatTranscriptOptionalParams, requestId, chatToken, chatId, sessionId, transcriptResponse, error_24, telemetryData;
2259
+ var getChatTranscriptOptionalParams, requestId, chatToken, chatId, sessionId, transcriptResponse, error_23, telemetryData;
2313
2260
  var _a, _b;
2314
2261
  if (optionalParams === void 0) { optionalParams = {}; }
2315
2262
  return __generator(this, function (_c) {
@@ -2366,12 +2313,12 @@ var OmnichannelChatSDK = /** @class */ (function () {
2366
2313
  });
2367
2314
  return [2 /*return*/, transcriptResponse];
2368
2315
  case 3:
2369
- error_24 = _c.sent();
2316
+ error_23 = _c.sent();
2370
2317
  telemetryData = {
2371
2318
  RequestId: requestId,
2372
2319
  ChatId: chatId
2373
2320
  };
2374
- exceptionThrowers_1.default.throwLiveChatTranscriptRetrievalFailure(error_24, this.scenarioMarker, TelemetryEvent_1.default.GetLiveChatTranscript, telemetryData);
2321
+ exceptionThrowers_1.default.throwLiveChatTranscriptRetrievalFailure(error_23, this.scenarioMarker, TelemetryEvent_1.default.GetLiveChatTranscript, telemetryData);
2375
2322
  return [3 /*break*/, 4];
2376
2323
  case 4: return [2 /*return*/];
2377
2324
  }
@@ -2823,12 +2770,26 @@ var OmnichannelChatSDK = /** @class */ (function () {
2823
2770
  regex: value
2824
2771
  });
2825
2772
  }
2773
+ this.compileDataMaskingRegex();
2826
2774
  }
2827
2775
  }
2828
2776
  return [2 /*return*/];
2829
2777
  });
2830
2778
  });
2831
2779
  };
2780
+ OmnichannelChatSDK.prototype.compileDataMaskingRegex = function () {
2781
+ this.regexCompiledForDataMasking = [];
2782
+ for (var _i = 0, _a = this.dataMaskingRules.rules; _i < _a.length; _i++) {
2783
+ var rule = _a[_i];
2784
+ try {
2785
+ var regex = new RegExp(rule.regex, 'g');
2786
+ this.regexCompiledForDataMasking.push(regex);
2787
+ }
2788
+ catch (e) {
2789
+ console.error("Error compiling regex for data masking rule id ".concat(rule.id, ": ").concat(e));
2790
+ }
2791
+ }
2792
+ };
2832
2793
  OmnichannelChatSDK.prototype.setAuthSettingConfig = function (authSettings) {
2833
2794
  return __awaiter(this, void 0, void 0, function () {
2834
2795
  return __generator(this, function (_a) {
@@ -2907,7 +2868,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
2907
2868
  };
2908
2869
  OmnichannelChatSDK.prototype.getChatConfig = function () {
2909
2870
  return __awaiter(this, arguments, void 0, function (optionalParams) {
2910
- var sendCacheHeaders, bypassCache, liveChatConfig, error_25, _a;
2871
+ var sendCacheHeaders, bypassCache, liveChatConfig, error_24, _a;
2911
2872
  var _b, _c;
2912
2873
  if (optionalParams === void 0) { optionalParams = {}; }
2913
2874
  return __generator(this, function (_d) {
@@ -2928,8 +2889,8 @@ var OmnichannelChatSDK = /** @class */ (function () {
2928
2889
  this.debug && console.log("[OmnichannelChatSDK][getChatConfig][liveChatVersion] ".concat(this.liveChatVersion));
2929
2890
  return [2 /*return*/, this.liveChatConfig];
2930
2891
  case 3:
2931
- error_25 = _d.sent();
2932
- if (!(0, internalUtils_1.isCoreServicesOrgUrlDNSError)(error_25, this.coreServicesOrgUrl, this.dynamicsLocationCode)) return [3 /*break*/, 6];
2892
+ error_24 = _d.sent();
2893
+ if (!(0, internalUtils_1.isCoreServicesOrgUrlDNSError)(error_24, this.coreServicesOrgUrl, this.dynamicsLocationCode)) return [3 /*break*/, 6];
2933
2894
  this.omnichannelConfig.orgUrl = this.unqServicesOrgUrl;
2934
2895
  _a = this;
2935
2896
  return [4 /*yield*/, ocsdk_1.SDKProvider.getSDK(this.omnichannelConfig, (0, createOcSDKConfiguration_1.default)(false), this.ocSdkLogger)];
@@ -2941,10 +2902,10 @@ var OmnichannelChatSDK = /** @class */ (function () {
2941
2902
  return [3 /*break*/, 7];
2942
2903
  case 6:
2943
2904
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
2944
- if (((_c = (_b = error_25.response) === null || _b === void 0 ? void 0 : _b.headers) === null || _c === void 0 ? void 0 : _c.errorcode) && parseInt(error_25.response.headers.errorcode) === OmnichannelErrorCodes_1.default.WidgetNotFound) {
2905
+ if (((_c = (_b = error_24.response) === null || _b === void 0 ? void 0 : _b.headers) === null || _c === void 0 ? void 0 : _c.errorcode) && parseInt(error_24.response.headers.errorcode) === OmnichannelErrorCodes_1.default.WidgetNotFound) {
2945
2906
  console.warn("No widget with the given app id is present in the system.");
2946
2907
  }
2947
- throw error_25; // Bubble up error by default to throw ChatConfigRetrievalFailure
2908
+ throw error_24; // Bubble up error by default to throw ChatConfigRetrievalFailure
2948
2909
  case 7: return [3 /*break*/, 8];
2949
2910
  case 8: return [2 /*return*/, this.liveChatConfig];
2950
2911
  }
@@ -2979,7 +2940,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
2979
2940
  };
2980
2941
  OmnichannelChatSDK.prototype.updateChatToken = function (newToken, newRegionGTMS) {
2981
2942
  return __awaiter(this, void 0, void 0, function () {
2982
- var sessionInfo, error_26, exceptionDetails;
2943
+ var sessionInfo, error_25, exceptionDetails;
2983
2944
  return __generator(this, function (_a) {
2984
2945
  switch (_a.label) {
2985
2946
  case 0:
@@ -3007,7 +2968,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
3007
2968
  });
3008
2969
  return [3 /*break*/, 5];
3009
2970
  case 4:
3010
- error_26 = _a.sent();
2971
+ error_25 = _a.sent();
3011
2972
  exceptionDetails = {
3012
2973
  response: "UpdateChatTokenFailed"
3013
2974
  };
@@ -3024,7 +2985,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
3024
2985
  };
3025
2986
  OmnichannelChatSDK.prototype.setAuthTokenProvider = function (provider_1) {
3026
2987
  return __awaiter(this, arguments, void 0, function (provider, optionalParams) {
3027
- var token, exceptionDetails, error_27, exceptionDetails, exceptionDetails;
2988
+ var token, exceptionDetails, error_26, exceptionDetails, exceptionDetails;
3028
2989
  if (optionalParams === void 0) { optionalParams = {}; }
3029
2990
  return __generator(this, function (_a) {
3030
2991
  switch (_a.label) {
@@ -3056,12 +3017,12 @@ var OmnichannelChatSDK = /** @class */ (function () {
3056
3017
  }
3057
3018
  return [3 /*break*/, 4];
3058
3019
  case 3:
3059
- error_27 = _a.sent();
3020
+ error_26 = _a.sent();
3060
3021
  exceptionDetails = {
3061
3022
  response: ChatSDKError_1.ChatSDKErrorName.GetAuthTokenFailed
3062
3023
  };
3063
- if (error_27.message == ChatSDKError_1.ChatSDKErrorName.UndefinedAuthToken) {
3064
- exceptionDetails.response = error_27.message;
3024
+ if (error_26.message == ChatSDKError_1.ChatSDKErrorName.UndefinedAuthToken) {
3025
+ exceptionDetails.response = error_26.message;
3065
3026
  }
3066
3027
  this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetAuthToken, {
3067
3028
  ExceptionDetails: JSON.stringify(exceptionDetails)
@@ -3154,6 +3115,67 @@ var OmnichannelChatSDK = /** @class */ (function () {
3154
3115
  });
3155
3116
  });
3156
3117
  };
3118
+ /**
3119
+ * Get persistent chat history for authenticated users.
3120
+ * @param getPersistentChatHistoryOptionalParams Optional parameters for persistent chat history retrieval.
3121
+ */
3122
+ OmnichannelChatSDK.prototype.getPersistentChatHistory = function () {
3123
+ return __awaiter(this, arguments, void 0, function (getPersistentChatHistoryOptionalParams) {
3124
+ var params, result, error_27, telemetryData;
3125
+ var _a, _b, _c, _d, _e;
3126
+ if (getPersistentChatHistoryOptionalParams === void 0) { getPersistentChatHistoryOptionalParams = {}; }
3127
+ return __generator(this, function (_f) {
3128
+ switch (_f.label) {
3129
+ case 0:
3130
+ if (!this.requestId) {
3131
+ this.requestId = (0, ocsdk_1.uuidv4)();
3132
+ }
3133
+ this.scenarioMarker.startScenario(TelemetryEvent_1.default.GetPersistentChatHistory, {
3134
+ RequestId: this.requestId
3135
+ });
3136
+ if (!this.isInitialized) {
3137
+ exceptionThrowers_1.default.throwUninitializedChatSDK(this.scenarioMarker, TelemetryEvent_1.default.GetPersistentChatHistory);
3138
+ }
3139
+ if (!this.isPersistentChat || ((_a = this.chatSDKConfig.persistentChat) === null || _a === void 0 ? void 0 : _a.disable) === true) {
3140
+ exceptionThrowers_1.default.throwNotPersistentChatEnabled(this.scenarioMarker, TelemetryEvent_1.default.GetPersistentChatHistory, {
3141
+ RequestId: this.requestId,
3142
+ ChatId: (_b = this.chatToken) === null || _b === void 0 ? void 0 : _b.chatId
3143
+ });
3144
+ }
3145
+ if (!this.authenticatedUserToken) {
3146
+ exceptionThrowers_1.default.throwChatSDKError(ChatSDKError_1.ChatSDKErrorName.AuthenticatedUserTokenNotFound, new Error('Authenticated user token not found'), this.scenarioMarker, TelemetryEvent_1.default.GetPersistentChatHistory, {
3147
+ RequestId: this.requestId,
3148
+ ChatId: (_c = this.chatToken) === null || _c === void 0 ? void 0 : _c.chatId
3149
+ });
3150
+ }
3151
+ _f.label = 1;
3152
+ case 1:
3153
+ _f.trys.push([1, 3, , 4]);
3154
+ params = {};
3155
+ params.pageSize = getPersistentChatHistoryOptionalParams.pageSize || undefined;
3156
+ params.pageToken = getPersistentChatHistoryOptionalParams.pageToken || undefined;
3157
+ return [4 /*yield*/, this.OCClient.getPersistentChatHistory(this.requestId, __assign(__assign({}, params), { authenticatedUserToken: this.authenticatedUserToken }))];
3158
+ case 2:
3159
+ result = _f.sent();
3160
+ this.scenarioMarker.completeScenario(TelemetryEvent_1.default.GetPersistentChatHistory, {
3161
+ RequestId: this.requestId,
3162
+ ChatId: (_d = this.chatToken) === null || _d === void 0 ? void 0 : _d.chatId
3163
+ });
3164
+ return [2 /*return*/, result];
3165
+ case 3:
3166
+ error_27 = _f.sent();
3167
+ telemetryData = {
3168
+ RequestId: this.requestId,
3169
+ ChatId: (_e = this.chatToken) === null || _e === void 0 ? void 0 : _e.chatId,
3170
+ ErrorMessage: (error_27 === null || error_27 === void 0 ? void 0 : error_27.message) || 'Unknown error' // Added error message for better debugging
3171
+ };
3172
+ exceptionThrowers_1.default.throwPersistentChatConversationRetrievalFailure(error_27, this.scenarioMarker, TelemetryEvent_1.default.GetPersistentChatHistory, telemetryData);
3173
+ return [3 /*break*/, 4];
3174
+ case 4: return [2 /*return*/];
3175
+ }
3176
+ });
3177
+ });
3178
+ };
3157
3179
  return OmnichannelChatSDK;
3158
3180
  }());
3159
3181
  exports.default = OmnichannelChatSDK;