@microsoft/omnichannel-chat-widget 1.8.4-main.424a580 → 1.8.4-main.6672d3a

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.
Files changed (46) hide show
  1. package/README.md +27 -0
  2. package/lib/cjs/common/Constants.js +2 -0
  3. package/lib/cjs/common/telemetry/AppInsightsEvents.js +11 -5
  4. package/lib/cjs/common/telemetry/TelemetryConstants.js +2 -0
  5. package/lib/cjs/common/telemetry/TelemetryManager.js +10 -7
  6. package/lib/cjs/components/livechatwidget/common/ChatWidgetEvents.js +1 -1
  7. package/lib/cjs/components/livechatwidget/common/PersistentConversationHandler.js +24 -21
  8. package/lib/cjs/components/livechatwidget/common/defaultProps/defaultPersistentChatHistoryProps.js +1 -2
  9. package/lib/cjs/components/livechatwidget/common/endChat.js +21 -9
  10. package/lib/cjs/components/livechatwidget/common/registerTelemetryLoggers.js +3 -0
  11. package/lib/cjs/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +102 -26
  12. package/lib/cjs/components/postchatsurveypanestateful/PostChatSurveyPaneStateful.js +2 -2
  13. package/lib/cjs/components/webchatcontainerstateful/WebChatContainerStateful.js +3 -11
  14. package/lib/cjs/components/webchatcontainerstateful/common/activityConverters/convertPersistentChatHistoryMessageToActivity.js +8 -2
  15. package/lib/cjs/components/webchatcontainerstateful/hooks/usePersistentChatHistory.js +1 -3
  16. package/lib/cjs/components/webchatcontainerstateful/interfaces/IExtendedChatConffig.js +1 -0
  17. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/WebChatEventSubscribers.js +6 -7
  18. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activities/LazyLoadActivity.js +21 -1
  19. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/citationsMiddleware.js +6 -1
  20. package/lib/esm/common/Constants.js +2 -0
  21. package/lib/esm/common/telemetry/AppInsightsEvents.js +11 -5
  22. package/lib/esm/common/telemetry/TelemetryConstants.js +2 -0
  23. package/lib/esm/common/telemetry/TelemetryManager.js +10 -7
  24. package/lib/esm/components/livechatwidget/common/ChatWidgetEvents.js +1 -1
  25. package/lib/esm/components/livechatwidget/common/PersistentConversationHandler.js +24 -21
  26. package/lib/esm/components/livechatwidget/common/defaultProps/defaultPersistentChatHistoryProps.js +1 -2
  27. package/lib/esm/components/livechatwidget/common/endChat.js +21 -9
  28. package/lib/esm/components/livechatwidget/common/registerTelemetryLoggers.js +3 -0
  29. package/lib/esm/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +102 -26
  30. package/lib/esm/components/postchatsurveypanestateful/PostChatSurveyPaneStateful.js +2 -2
  31. package/lib/esm/components/webchatcontainerstateful/WebChatContainerStateful.js +3 -14
  32. package/lib/esm/components/webchatcontainerstateful/common/activityConverters/convertPersistentChatHistoryMessageToActivity.js +8 -2
  33. package/lib/esm/components/webchatcontainerstateful/hooks/usePersistentChatHistory.js +1 -3
  34. package/lib/esm/components/webchatcontainerstateful/interfaces/IExtendedChatConffig.js +1 -0
  35. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/WebChatEventSubscribers.js +6 -7
  36. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activities/LazyLoadActivity.js +21 -1
  37. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/citationsMiddleware.js +6 -1
  38. package/lib/types/common/Constants.d.ts +2 -0
  39. package/lib/types/common/telemetry/TelemetryConstants.d.ts +2 -0
  40. package/lib/types/common/telemetry/interfaces/IInternalTelemetryData.d.ts +1 -0
  41. package/lib/types/components/livechatwidget/common/ChatWidgetEvents.d.ts +1 -1
  42. package/lib/types/components/livechatwidget/interfaces/IPersistentChatHistoryProps.d.ts +0 -1
  43. package/lib/types/components/webchatcontainerstateful/interfaces/IExtendedChatConffig.d.ts +15 -0
  44. package/lib/types/components/webchatcontainerstateful/webchatcontroller/WebChatEventSubscribers.d.ts +1 -2
  45. package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activities/LazyLoadActivity.d.ts +1 -1
  46. package/package.json +1 -1
package/README.md CHANGED
@@ -268,6 +268,33 @@ const customizedFooterProp: IFooterProps = {
268
268
  setOnCustomEvent((event) => console.log(event));
269
269
  ```
270
270
 
271
+ #### Trigger initiateEndChat event
272
+ Customer can trigger the initiateEndChat event via BroadcastService to end a chat session.
273
+ When needed, the payload below could be triggered:
274
+ ```js
275
+ const endChatEvent = {
276
+ eventName: "InitiateEndChat",
277
+ payload: {
278
+ skipSessionCloseForPersistentChat: true
279
+ } //optional payload
280
+ };
281
+ BroadcastService.postMessage(endChatEvent);
282
+ ```
283
+
284
+ The payload of the event is optional, only needed when force closing of a persistent chat session is not required.
285
+ When chat widget receives the event without any payload, it will:
286
+ 1. set the widget to closed state, the widget panel will be minimized. Post chat survey will not be displayed.
287
+ 2. trigger a sessionclose service network request to OmniChannel services.
288
+
289
+ If skipSessionCloseForPersistentChat is set to true. The session close network request will not be triggered, instead, if postChat survey is available, post chat survey will be displayed.
290
+
291
+ After successfully processed initiateEndChat event. The CloseChat event is broadcasted.
292
+ ```js
293
+ BroadcastService.getMessageByEventName("CloseChat").subscribe(async (msg) => {
294
+ console.log("close chat received: ", msg);
295
+ //more actions to unmount component and resources
296
+ })
297
+ ```
271
298
  ## See Also
272
299
 
273
300
  [Customizations Dev Guide](https://github.com/microsoft/omnichannel-chat-widget/blob/main/docs/customizations/getstarted.md)\
@@ -143,6 +143,7 @@ _defineProperty(Constants, "customEventName", "customEventName");
143
143
  _defineProperty(Constants, "customEventValue", "customEventValue");
144
144
  _defineProperty(Constants, "Hidden", "Hidden");
145
145
  _defineProperty(Constants, "EndConversationDueToOverflow", "endconversationduetooverflow");
146
+ _defineProperty(Constants, "SkipSessionCloseForPersistentChatFlag", "skipSessionCloseForPersistentChat");
146
147
  const Regex = (_class = /*#__PURE__*/_createClass(function Regex() {
147
148
  _classCallCheck(this, Regex);
148
149
  }), _defineProperty(_class, "EmailRegex", "^(?:[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+)*|\"[^\"\\\\]*(?:\\\\.[^\"\\\\]*)*\")@(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?(?:\\.[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?)*|\\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\])$"), _class);
@@ -378,6 +379,7 @@ _defineProperty(PrepareEndChatDescriptionConstants, "ConversationEndedBy", "Conv
378
379
  _defineProperty(PrepareEndChatDescriptionConstants, "PrepareEndChatError", "There's an error while preparing to end chat. Closing chat widget.");
379
380
  _defineProperty(PrepareEndChatDescriptionConstants, "WidgetLoadFailedAfterSessionInit", "SessionInit was successful, but widget load failed. Ending chat to avoid ghost chats in OC.");
380
381
  _defineProperty(PrepareEndChatDescriptionConstants, "InitiateEndChatReceived", "Received InitiateEndChat BroadcastEvent while conversation state is not Active. Ending chat.");
382
+ _defineProperty(PrepareEndChatDescriptionConstants, "InitiateEndChatReceivedActiveChat", "Received InitiateEndChat BroadcastEvent while conversation state is Active. Updating conversation states.");
381
383
  _defineProperty(PrepareEndChatDescriptionConstants, "EndChatReceivedFromOtherTabs", "Received EndChat BroadcastEvent from other tabs. Closing this chat.");
382
384
  _defineProperty(PrepareEndChatDescriptionConstants, "CustomerCloseChatOnFailureOrPostChat", "Customer is trying to close chat widget on start chat failure or post chat pane.");
383
385
  _defineProperty(PrepareEndChatDescriptionConstants, "CustomerCloseInactiveChat", "Chat was Inactive and customer is trying to close chat widget or refreshing the page.");
@@ -6,8 +6,11 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.AppInsightsEventMapping = void 0;
7
7
  const AppInsightsEventMapping = {
8
8
  "LCWChatButtonClicked": "LCWChatButtonActionStarted",
9
- "PrechatSubmitted": "PrechatSubmitCompleted",
10
- "StartChatEventRecevied": "StartChatEventReceivedCompleted",
9
+ "UXLCWChatButtonLoadingStart": "LiveChatWidgetChatButtonLoadingStarted",
10
+ "UXLCWChatButtonLoadingCompleted": "LiveChatWidgetChatButtonLoadingCompleted",
11
+ "UXPrechatPaneStart": "PrechatSurveyStarted",
12
+ "UXPrechatPaneCompleted": "PrechatSurveyCompleted",
13
+ "PrechatSubmitted": "PrechatSurveySubmitCompleted",
11
14
  "EndChatEventReceived": "EndChatEventReceivedCompleted",
12
15
  "EmailTranscriptSent": "EmailTranscriptActionCompleted",
13
16
  "EmailTranscriptFailed": "EmailTranscriptActionFailed",
@@ -15,8 +18,6 @@ const AppInsightsEventMapping = {
15
18
  "HeaderMinimizeButtonClicked": "MinimizeChatActionStarted",
16
19
  "DownloadTranscriptButtonClicked": "DownloadTranscriptActionStarted",
17
20
  "EmailTranscriptButtonClicked": "EmailTranscriptButtonActionStarted",
18
- "CustomerVoiceFormResponseSubmitted": "CustomerVoiceFormResponseSubmitCompleted",
19
- "StartProactiveChatEventReceived": "StartProactiveChatEventReceivedCompleted",
20
21
  "ProactiveChatRejected": "ProactiveChatTimeOutCompleted",
21
22
  "MessageSent": "MessageSentCompleted",
22
23
  "MessageReceived": "MessageReceivedCompleted",
@@ -25,6 +26,11 @@ const AppInsightsEventMapping = {
25
26
  "CustomContextReceived": "CustomContextReceivedCompleted",
26
27
  "NewTokenValidationStarted": "AuthTokenValidationStarted",
27
28
  "NewTokenValidationCompleted": "AuthTokenValidationCompleted",
28
- "NewTokenValidationFailed": "AuthTokenValidationFailed"
29
+ "NewTokenValidationFailed": "AuthTokenValidationFailed",
30
+ "UXPostChatPaneStarted": "PostChatSurveyStarted",
31
+ "UXPostChatPaneCompleted": "PostChatSurveyCompleted",
32
+ "WidgetLoadStarted": "ChatSessionInitializationStarted",
33
+ "WidgetLoadComplete": "ChatSessionInitializationCompleted",
34
+ "WidgetLoadFailed": "ChatSessionInitializationFailed"
29
35
  };
30
36
  exports.AppInsightsEventMapping = AppInsightsEventMapping;
@@ -306,6 +306,7 @@ exports.TelemetryEvent = TelemetryEvent;
306
306
  TelemetryEvent["LCWPersistentConversationHandlerInitialized"] = "LCWPersistentConversationHandlerInitialized";
307
307
  TelemetryEvent["LCWPersistentHistoryPullBlocked"] = "LCWPersistentHistoryPullBlocked";
308
308
  TelemetryEvent["LCWPersistentHistoryPullCompleted"] = "LCWPersistentHistoryPullCompleted";
309
+ TelemetryEvent["LCWPersistentHistoryReturnedNull"] = "LCWPersistentHistoryReturnedNull";
309
310
  TelemetryEvent["LCWLazyLoadInitializationStarted"] = "LCWLazyLoadInitializationStarted";
310
311
  TelemetryEvent["LCWLazyLoadContainerNotFound"] = "LCWLazyLoadContainerNotFound";
311
312
  TelemetryEvent["LCWLazyLoadInitializationCompleted"] = "LCWLazyLoadInitializationCompleted";
@@ -315,6 +316,7 @@ exports.TelemetryEvent = TelemetryEvent;
315
316
  TelemetryEvent["LCWLazyLoadActivityMounted"] = "LCWLazyLoadActivityMounted";
316
317
  TelemetryEvent["LCWLazyLoadReset"] = "LCWLazyLoadReset";
317
318
  TelemetryEvent["LCWLazyLoadNoMoreHistory"] = "LCWLazyLoadNoMoreHistory";
319
+ TelemetryEvent["LCWLazyLoadHistoryError"] = "LCWLazyLoadHistoryError";
318
320
  TelemetryEvent["LCWLazyLoadDestroyed"] = "LCWLazyLoadDestroyed";
319
321
  TelemetryEvent["SecureEventBusUnauthorizedDispatch"] = "SecureEventBusUnauthorizedDispatch";
320
322
  TelemetryEvent["SecureEventBusListenerError"] = "SecureEventBusListenerError";
@@ -50,7 +50,7 @@ const RegisterLoggers = () => {
50
50
  loggers.push((0, _consoleLogger.consoleLogger)());
51
51
  }
52
52
  if (((_TelemetryManager$Int9 = TelemetryManager.InternalTelemetryData) === null || _TelemetryManager$Int9 === void 0 ? void 0 : (_TelemetryManager$Int10 = _TelemetryManager$Int9.telemetryConfig) === null || _TelemetryManager$Int10 === void 0 ? void 0 : _TelemetryManager$Int10.telemetryDisabled) === false) {
53
- var _TelemetryManager$Int11, _TelemetryManager$Int20, _TelemetryManager$Int21, _TelemetryManager$Int22, _TelemetryManager$Int23;
53
+ var _TelemetryManager$Int11, _TelemetryManager$Int20, _TelemetryManager$Int21, _TelemetryManager$Int22, _TelemetryManager$Int23, _TelemetryManager$Int24, _TelemetryManager$Int25, _TelemetryManager$Int26;
54
54
  if ((_TelemetryManager$Int11 = TelemetryManager.InternalTelemetryData) !== null && _TelemetryManager$Int11 !== void 0 && _TelemetryManager$Int11.ariaConfig) {
55
55
  var _TelemetryManager$Int12, _TelemetryManager$Int13, _TelemetryManager$Int14, _TelemetryManager$Int15, _TelemetryManager$Int16, _TelemetryManager$Int17, _TelemetryManager$Int18, _TelemetryManager$Int19;
56
56
  loggers.push((0, _ariaTelemetryLogger.ariaTelemetryLogger)(((_TelemetryManager$Int12 = TelemetryManager.InternalTelemetryData) === null || _TelemetryManager$Int12 === void 0 ? void 0 : (_TelemetryManager$Int13 = _TelemetryManager$Int12.ariaConfig) === null || _TelemetryManager$Int13 === void 0 ? void 0 : _TelemetryManager$Int13.ariaTelemetryKey) ?? _defaultAriaConfig.defaultAriaConfig.ariaTelemetryKey, ((_TelemetryManager$Int14 = TelemetryManager.InternalTelemetryData) === null || _TelemetryManager$Int14 === void 0 ? void 0 : (_TelemetryManager$Int15 = _TelemetryManager$Int14.ariaConfig) === null || _TelemetryManager$Int15 === void 0 ? void 0 : _TelemetryManager$Int15.disableCookieUsage) ?? _defaultAriaConfig.defaultAriaConfig.disableCookieUsage, ((_TelemetryManager$Int16 = TelemetryManager.InternalTelemetryData) === null || _TelemetryManager$Int16 === void 0 ? void 0 : (_TelemetryManager$Int17 = _TelemetryManager$Int16.ariaConfig) === null || _TelemetryManager$Int17 === void 0 ? void 0 : _TelemetryManager$Int17.collectorUriForTelemetry) ?? _defaultAriaConfig.defaultAriaConfig.collectorUriForTelemetry, ((_TelemetryManager$Int18 = TelemetryManager.InternalTelemetryData) === null || _TelemetryManager$Int18 === void 0 ? void 0 : (_TelemetryManager$Int19 = _TelemetryManager$Int18.ariaConfig) === null || _TelemetryManager$Int19 === void 0 ? void 0 : _TelemetryManager$Int19.ariaTelemetryApplicationName) ?? _defaultAriaConfig.defaultAriaConfig.ariaTelemetryApplicationName));
@@ -61,12 +61,15 @@ const RegisterLoggers = () => {
61
61
  loggers.push(logger);
62
62
  });
63
63
  }
64
- if (((_TelemetryManager$Int22 = TelemetryManager.InternalTelemetryData) === null || _TelemetryManager$Int22 === void 0 ? void 0 : (_TelemetryManager$Int23 = _TelemetryManager$Int22.appInsightsConfig) === null || _TelemetryManager$Int23 === void 0 ? void 0 : _TelemetryManager$Int23.appInsightsDisabled) === false) {
65
- var _TelemetryManager$Int24;
66
- if ((_TelemetryManager$Int24 = TelemetryManager.InternalTelemetryData) !== null && _TelemetryManager$Int24 !== void 0 && _TelemetryManager$Int24.appInsightsConfig.appInsightsKey) {
67
- var _TelemetryManager$Int25;
68
- loggers.push((0, _appInsightsLogger.appInsightsLogger)((_TelemetryManager$Int25 = TelemetryManager.InternalTelemetryData) === null || _TelemetryManager$Int25 === void 0 ? void 0 : _TelemetryManager$Int25.appInsightsConfig.appInsightsKey));
69
- }
64
+ const chatConfigAppInsightsKey = (_TelemetryManager$Int22 = TelemetryManager.InternalTelemetryData) === null || _TelemetryManager$Int22 === void 0 ? void 0 : _TelemetryManager$Int22.chatConfigAppInsightsKey;
65
+ const appInsightsKeyFromUser = (_TelemetryManager$Int23 = TelemetryManager.InternalTelemetryData) === null || _TelemetryManager$Int23 === void 0 ? void 0 : (_TelemetryManager$Int24 = _TelemetryManager$Int23.appInsightsConfig) === null || _TelemetryManager$Int24 === void 0 ? void 0 : _TelemetryManager$Int24.appInsightsKey;
66
+ // when chatConfig has AppInsightsInstrumentationKey
67
+ if (chatConfigAppInsightsKey) {
68
+ loggers.push((0, _appInsightsLogger.appInsightsLogger)(chatConfigAppInsightsKey));
69
+ }
70
+ // when key set through appInsightsConfig
71
+ else if (appInsightsKeyFromUser && ((_TelemetryManager$Int25 = TelemetryManager.InternalTelemetryData) === null || _TelemetryManager$Int25 === void 0 ? void 0 : (_TelemetryManager$Int26 = _TelemetryManager$Int25.appInsightsConfig) === null || _TelemetryManager$Int26 === void 0 ? void 0 : _TelemetryManager$Int26.appInsightsDisabled) === false) {
72
+ loggers.push((0, _appInsightsLogger.appInsightsLogger)(appInsightsKeyFromUser));
70
73
  }
71
74
  }
72
75
  };
@@ -9,7 +9,7 @@ var ChatWidgetEvents;
9
9
  ChatWidgetEvents["ADD_ACTIVITY"] = "CHAT_WIDGET/ADD_ACTIVITY";
10
10
  ChatWidgetEvents["FETCH_PERSISTENT_CHAT_HISTORY"] = "CHAT_WIDGET/FETCH_PERSISTENT_CHAT_HISTORY";
11
11
  ChatWidgetEvents["NO_MORE_HISTORY_AVAILABLE"] = "CHAT_WIDGET/NO_MORE_HISTORY_AVAILABLE";
12
- ChatWidgetEvents["HIDE_LOADING_BANNER"] = "CHAT_WIDGET/HIDE_LOADING_BANNER";
12
+ ChatWidgetEvents["HISTORY_LOAD_ERROR"] = "CHAT_WIDGET/HISTORY_LOAD_ERROR";
13
13
  })(ChatWidgetEvents || (ChatWidgetEvents = {}));
14
14
  var _default = ChatWidgetEvents;
15
15
  exports.default = _default;
@@ -36,7 +36,7 @@ let PersistentConversationHandler = /*#__PURE__*/function () {
36
36
  _defineProperty(this, "facadeChatSDK", void 0);
37
37
  _defineProperty(this, "lastMessage", null);
38
38
  _defineProperty(this, "count", 0);
39
- _defineProperty(this, "pageSize", 4);
39
+ _defineProperty(this, "pageSize", _defaultPersistentChatHistoryProps.defaultPersistentChatHistoryProps.pageSize);
40
40
  _defineProperty(this, "isCurrentlyPulling", false);
41
41
  _defineProperty(this, "pageTokenInTransitSet", new Set());
42
42
  _defineProperty(this, "resetEventListener", _omnichannelChatComponents.BroadcastService.getMessageByEventName(_TelemetryConstants.BroadcastEvent.PersistentConversationReset).subscribe(() => {
@@ -48,7 +48,7 @@ let PersistentConversationHandler = /*#__PURE__*/function () {
48
48
  Event: _TelemetryConstants.TelemetryEvent.LCWPersistentConversationHandlerInitialized,
49
49
  Description: "PersistentConversationHandler initialized",
50
50
  CustomProperties: {
51
- pageSize: this.pageSize
51
+ pageSize: _defaultPersistentChatHistoryProps.defaultPersistentChatHistoryProps.pageSize
52
52
  }
53
53
  });
54
54
  }
@@ -61,8 +61,8 @@ let PersistentConversationHandler = /*#__PURE__*/function () {
61
61
  ...props
62
62
  };
63
63
 
64
- // if the props is not existent or is not anumber then default to 4
65
- this.pageSize = ((_this$appliedProps = this.appliedProps) === null || _this$appliedProps === void 0 ? void 0 : _this$appliedProps.pageSize) !== undefined && !isNaN(this.appliedProps.pageSize) ? this.appliedProps.pageSize : 4;
64
+ // if the props is not existent or is not a number then default to defaultPersistentChatHistoryProps.pageSize
65
+ this.pageSize = ((_this$appliedProps = this.appliedProps) === null || _this$appliedProps === void 0 ? void 0 : _this$appliedProps.pageSize) !== undefined && !isNaN(this.appliedProps.pageSize) ? this.appliedProps.pageSize : _defaultPersistentChatHistoryProps.defaultPersistentChatHistoryProps.pageSize;
66
66
  }
67
67
  }, {
68
68
  key: "reset",
@@ -107,12 +107,23 @@ let PersistentConversationHandler = /*#__PURE__*/function () {
107
107
  try {
108
108
  var _ref;
109
109
  const messages = await this.fetchHistoryMessages();
110
- if (messages === null || (messages === null || messages === void 0 ? void 0 : messages.length) === 0) {
110
+
111
+ // Handle error case - null indicates an error occurred
112
+ // Don't mark as last pull to allow retry on next attempt
113
+ if (messages == null) {
114
+ _TelemetryHelper.TelemetryHelper.logActionEvent(_TelemetryConstants.LogLevel.WARN, {
115
+ Event: _TelemetryConstants.TelemetryEvent.LCWPersistentHistoryReturnedNull,
116
+ Description: "History pull returned null - Possible error occurred, will retry on next scroll",
117
+ ElapsedTimeInMilliseconds: pullTimer.milliSecondsElapsed
118
+ });
119
+ return;
120
+ }
121
+
122
+ // Handle legitimate end of history - empty array
123
+ if (messages.length === 0) {
111
124
  this.isLastPull = true;
112
125
  // Dispatch event to notify UI that no more history is available
113
126
  (0, _dispatchCustomEvent.default)(_ChatWidgetEvents.default.NO_MORE_HISTORY_AVAILABLE);
114
- // Also hide the loading banner
115
- (0, _dispatchCustomEvent.default)(_ChatWidgetEvents.default.HIDE_LOADING_BANNER);
116
127
  _TelemetryHelper.TelemetryHelper.logActionEvent(_TelemetryConstants.LogLevel.INFO, {
117
128
  Event: _TelemetryConstants.TelemetryEvent.LCWPersistentHistoryPullCompleted,
118
129
  Description: "History pull completed - no more messages",
@@ -122,9 +133,6 @@ let PersistentConversationHandler = /*#__PURE__*/function () {
122
133
  }
123
134
  const messagesDescOrder = (_ref = [...messages]) === null || _ref === void 0 ? void 0 : _ref.reverse();
124
135
  this.processHistoryMessages(messagesDescOrder);
125
-
126
- // Dispatch event to hide the loading banner after messages are processed
127
- (0, _dispatchCustomEvent.default)(_ChatWidgetEvents.default.HIDE_LOADING_BANNER);
128
136
  _TelemetryHelper.TelemetryHelper.logActionEvent(_TelemetryConstants.LogLevel.INFO, {
129
137
  Event: _TelemetryConstants.TelemetryEvent.LCWPersistentHistoryPullCompleted,
130
138
  Description: "History pull completed successfully",
@@ -180,7 +188,6 @@ let PersistentConversationHandler = /*#__PURE__*/function () {
180
188
  if (!this.shouldPull()) {
181
189
  // Dispatch event to ensure banner is hidden when no more pulls are needed
182
190
  (0, _dispatchCustomEvent.default)(_ChatWidgetEvents.default.NO_MORE_HISTORY_AVAILABLE);
183
- (0, _dispatchCustomEvent.default)(_ChatWidgetEvents.default.HIDE_LOADING_BANNER);
184
191
  return [];
185
192
  }
186
193
  const options = {
@@ -206,24 +213,20 @@ let PersistentConversationHandler = /*#__PURE__*/function () {
206
213
  this.isLastPull = true;
207
214
  // Dispatch event when we reach the end of available history
208
215
  (0, _dispatchCustomEvent.default)(_ChatWidgetEvents.default.NO_MORE_HISTORY_AVAILABLE);
209
- // Also hide the loading banner
210
- (0, _dispatchCustomEvent.default)(_ChatWidgetEvents.default.HIDE_LOADING_BANNER);
211
216
  return [];
212
217
  }
213
- (0, _dispatchCustomEvent.default)(_ChatWidgetEvents.default.HIDE_LOADING_BANNER);
214
218
  return messages;
215
219
  } catch (error) {
216
220
  _TelemetryHelper.TelemetryHelper.logSDKEvent(_TelemetryConstants.LogLevel.ERROR, {
217
221
  Event: _TelemetryConstants.TelemetryEvent.FetchPersistentChatHistoryFailed,
218
222
  ExceptionDetails: error
219
223
  });
220
- this.isLastPull = true;
221
- this.pageToken = null;
222
- // Dispatch event when there's an error to stop loading banner
223
- (0, _dispatchCustomEvent.default)(_ChatWidgetEvents.default.NO_MORE_HISTORY_AVAILABLE);
224
- // Also hide the loading banner
225
- (0, _dispatchCustomEvent.default)(_ChatWidgetEvents.default.HIDE_LOADING_BANNER);
226
- return [];
224
+
225
+ // On error, dispatch HISTORY_LOAD_ERROR to hide loading banner without marking conversation as ended
226
+ // This allows recovery on the next attempt (e.g., transient network errors)
227
+ // Return null to distinguish error from legitimate empty history
228
+ (0, _dispatchCustomEvent.default)(_ChatWidgetEvents.default.HISTORY_LOAD_ERROR);
229
+ return null;
227
230
  }
228
231
  }
229
232
  }, {
@@ -5,8 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.defaultPersistentChatHistoryProps = void 0;
7
7
  const defaultPersistentChatHistoryProps = {
8
- persistentChatHistoryEnabled: true,
9
- pageSize: 4,
8
+ pageSize: 10,
10
9
  dividerActivityStyle: {
11
10
  border: "1px solid rgb(96, 94, 92, 0.5)",
12
11
  margin: "10px 20%"
@@ -201,6 +201,18 @@ const endChat = async (props, facadeChatSDK, state, dispatch, setAdapter, setWeb
201
201
  facadeChatSDK.destroy();
202
202
  }
203
203
  }
204
+
205
+ //moving logic below to before processing skipCloseChat logic to avoid race conditions of postMessage for endChatEvent for other tabs vs postMessage for CloseChat
206
+ //TODO: clarify if this postMessageToOtherTab actually works in production.
207
+ if (postMessageToOtherTab) {
208
+ const endChatEventName = await getEndChatEventName(facadeChatSDK, props);
209
+ _omnichannelChatComponents.BroadcastService.postMessage({
210
+ eventName: endChatEventName,
211
+ payload: {
212
+ runtimeId: _TelemetryManager.TelemetryManager.InternalTelemetryData.lcwRuntimeId
213
+ }
214
+ });
215
+ }
204
216
  if (!skipCloseChat) {
205
217
  try {
206
218
  var _props$webChatContain;
@@ -240,17 +252,17 @@ const endChat = async (props, facadeChatSDK, state, dispatch, setAdapter, setWeb
240
252
  });
241
253
  closeChatWidget(dispatch, setWebChatStyles, props);
242
254
  facadeChatSDK.destroy();
255
+
256
+ //always post the close chat event after chat closed and cleanup completed
257
+ _omnichannelChatComponents.BroadcastService.postMessage({
258
+ eventName: _TelemetryConstants.BroadcastEvent.CloseChat
259
+ });
260
+ _TelemetryHelper.TelemetryHelper.logActionEvent(_TelemetryConstants.LogLevel.INFO, {
261
+ Event: _TelemetryConstants.TelemetryEvent.CloseChatCall,
262
+ Description: "Broadcasted close chat event"
263
+ });
243
264
  }
244
265
  }
245
- if (postMessageToOtherTab) {
246
- const endChatEventName = await getEndChatEventName(facadeChatSDK, props);
247
- _omnichannelChatComponents.BroadcastService.postMessage({
248
- eventName: endChatEventName,
249
- payload: {
250
- runtimeId: _TelemetryManager.TelemetryManager.InternalTelemetryData.lcwRuntimeId
251
- }
252
- });
253
- }
254
266
  };
255
267
  exports.endChat = endChat;
256
268
  const callingStateCleanUp = dispatch => {
@@ -30,7 +30,10 @@ const registerTelemetryLoggers = (props, dispatch) => {
30
30
  appInsightsConfig: Object.assign({}, _defaultAppInsightsConfig.defaultAppInsightsConfig, props.appInsightsConfig)
31
31
  };
32
32
  if (props.chatConfig) {
33
+ var _props$chatConfig$Liv;
33
34
  telemetryData = _TelemetryHelper.TelemetryHelper.addChatConfigDataToTelemetry(props === null || props === void 0 ? void 0 : props.chatConfig, telemetryData);
35
+ //store AppInsights instrumentation key from chatConfig if present
36
+ telemetryData.chatConfigAppInsightsKey = (_props$chatConfig$Liv = props.chatConfig.LiveWSAndLiveChatEngJoin) === null || _props$chatConfig$Liv === void 0 ? void 0 : _props$chatConfig$Liv.AppInsightsInstrumentationKey;
34
37
  }
35
38
  if (!((_props$chatSDK = props.chatSDK) !== null && _props$chatSDK !== void 0 && (_props$chatSDK$omnich = _props$chatSDK.omnichannelConfig) !== null && _props$chatSDK$omnich !== void 0 && _props$chatSDK$omnich.orgId) || ((_props$chatSDK2 = props.chatSDK) === null || _props$chatSDK2 === void 0 ? void 0 : (_props$chatSDK2$omnic = _props$chatSDK2.omnichannelConfig) === null || _props$chatSDK2$omnic === void 0 ? void 0 : _props$chatSDK2$omnic.orgId.trim().length) === 0) {
36
39
  throw new Error("orgId is undefined in ChatSDK");
@@ -58,13 +58,14 @@ var _startProactiveChat = require("../common/startProactiveChat");
58
58
  var _useChatAdapterStore = _interopRequireDefault(require("../../../hooks/useChatAdapterStore"));
59
59
  var _useChatContextStore = _interopRequireDefault(require("../../../hooks/useChatContextStore"));
60
60
  var _useFacadeChatSDKStore = _interopRequireDefault(require("../../../hooks/useFacadeChatSDKStore"));
61
+ var _renderSurveyHelpers = require("../common/renderSurveyHelpers");
61
62
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
62
63
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
63
64
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
64
65
  function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
65
66
  let uiTimer;
66
67
  const LiveChatWidgetStateful = props => {
67
- var _props$webChatContain, _props$webChatContain2, _props$webChatContain3, _props$webChatContain4, _props$webChatContain5, _props$webChatContain6, _props$webChatContain7, _props$webChatContain8, _props$webChatContain9, _props$styleProps, _props$webChatContain10, _props$webChatContain11, _props$controlProps, _props$controlProps3, _state$appStates7, _props$webChatContain15, _state$appStates14, _props$webChatContain17, _props$webChatContain18, _props$controlProps12, _props$draggableChatW, _props$draggableChatW2, _props$draggableChatW3, _props$draggableChatW4, _props$draggableChatW5, _livechatProps$webCha, _livechatProps$styleP, _livechatProps$contro, _livechatProps$contro2, _livechatProps$compon, _livechatProps$contro3, _livechatProps$compon2, _livechatProps$contro4, _livechatProps$compon3, _livechatProps$contro5, _livechatProps$compon4, _livechatProps$contro6, _livechatProps$compon5, _livechatProps$contro7, _livechatProps$compon6, _livechatProps$contro8, _livechatProps$compon7, _livechatProps$contro9, _livechatProps$compon8, _livechatProps$contro10, _livechatProps$contro11, _livechatProps$compon9, _livechatProps$contro12, _livechatProps$compon10, _livechatProps$contro13, _livechatProps$compon11, _livechatProps$compon12, _livechatProps$compon13;
68
+ var _props$webChatContain, _props$webChatContain2, _props$webChatContain3, _props$webChatContain4, _props$webChatContain5, _props$webChatContain6, _props$webChatContain7, _props$webChatContain8, _props$webChatContain9, _props$styleProps, _props$webChatContain10, _props$webChatContain11, _props$controlProps, _props$controlProps3, _state$appStates7, _props$webChatContain15, _state$appStates8, _props$webChatContain17, _props$webChatContain18, _props$controlProps12, _props$draggableChatW, _props$draggableChatW2, _props$draggableChatW3, _props$draggableChatW4, _props$draggableChatW5, _livechatProps$webCha, _livechatProps$styleP, _livechatProps$contro, _livechatProps$contro2, _livechatProps$compon, _livechatProps$contro3, _livechatProps$compon2, _livechatProps$contro4, _livechatProps$compon3, _livechatProps$contro5, _livechatProps$compon4, _livechatProps$contro6, _livechatProps$compon5, _livechatProps$contro7, _livechatProps$compon6, _livechatProps$contro8, _livechatProps$compon7, _livechatProps$contro9, _livechatProps$compon8, _livechatProps$contro10, _livechatProps$contro11, _livechatProps$compon9, _livechatProps$contro12, _livechatProps$compon10, _livechatProps$contro13, _livechatProps$compon11, _livechatProps$compon12, _livechatProps$compon13;
68
69
  (0, _react2.useEffect)(() => {
69
70
  uiTimer = (0, _utils.createTimer)();
70
71
  _TelemetryHelper.TelemetryHelper.logLoadingEventToAllTelemetry(_TelemetryConstants.LogLevel.INFO, {
@@ -325,7 +326,7 @@ const LiveChatWidgetStateful = props => {
325
326
  });
326
327
  });
327
328
  _omnichannelChatComponents.BroadcastService.getMessageByEventName(_TelemetryConstants.BroadcastEvent.StartProactiveChat).subscribe(msg => {
328
- _TelemetryHelper.TelemetryHelper.logActionEventToAllTelemetry(_TelemetryConstants.LogLevel.INFO, {
329
+ _TelemetryHelper.TelemetryHelper.logActionEvent(_TelemetryConstants.LogLevel.INFO, {
329
330
  Event: _TelemetryConstants.TelemetryEvent.StartProactiveChatEventReceived,
330
331
  Description: "Start proactive chat event received."
331
332
  });
@@ -451,7 +452,7 @@ const LiveChatWidgetStateful = props => {
451
452
  payload: msg === null || msg === void 0 ? void 0 : (_msg$payload8 = msg.payload) === null || _msg$payload8 === void 0 ? void 0 : _msg$payload8.customContext
452
453
  });
453
454
  }
454
- _TelemetryHelper.TelemetryHelper.logActionEventToAllTelemetry(_TelemetryConstants.LogLevel.INFO, {
455
+ _TelemetryHelper.TelemetryHelper.logActionEvent(_TelemetryConstants.LogLevel.INFO, {
455
456
  Event: _TelemetryConstants.TelemetryEvent.StartChatEventReceived,
456
457
  Description: "Start chat event received."
457
458
  });
@@ -498,21 +499,91 @@ const LiveChatWidgetStateful = props => {
498
499
  return;
499
500
  }
500
501
  });
502
+ const handleInitiateEndChatForPersistentChat = async (msg, conversationDetails) => {
503
+ var _msg$payload10, _msg$payload11, _msg$payload12;
504
+ //If the payload does NOT include the skipSessionCloseForPersistentChat flag, default is false. Upon receiving the customer event, always ending session from C2.
505
+ const skipSessionCloseForPersistentChat = typeof (msg === null || msg === void 0 ? void 0 : (_msg$payload10 = msg.payload) === null || _msg$payload10 === void 0 ? void 0 : _msg$payload10[_Constants.Constants.SkipSessionCloseForPersistentChatFlag]) === _Constants.Constants.String && (msg === null || msg === void 0 ? void 0 : (_msg$payload11 = msg.payload) === null || _msg$payload11 === void 0 ? void 0 : _msg$payload11[_Constants.Constants.SkipSessionCloseForPersistentChatFlag]).toLowerCase() === _Constants.Constants.true || (msg === null || msg === void 0 ? void 0 : (_msg$payload12 = msg.payload) === null || _msg$payload12 === void 0 ? void 0 : _msg$payload12[_Constants.Constants.SkipSessionCloseForPersistentChatFlag]) === true;
506
+ _TelemetryHelper.TelemetryHelper.logSDKEventToAllTelemetry(_TelemetryConstants.LogLevel.INFO, {
507
+ Event: _TelemetryConstants.TelemetryEvent.EndChatEventReceived,
508
+ Description: "Processing initiateEndChat for persistent chat",
509
+ CustomProperties: {
510
+ conversationDetails
511
+ }
512
+ });
513
+ const conversationState = conversationDetails === null || conversationDetails === void 0 ? void 0 : conversationDetails.state;
514
+ if (conversationState !== _Constants.LiveWorkItemState.Closed && conversationState !== _Constants.LiveWorkItemState.WrapUp) {
515
+ if (skipSessionCloseForPersistentChat) {
516
+ var _conversationDetails$;
517
+ if (((_conversationDetails$ = conversationDetails.canRenderPostChat) === null || _conversationDetails$ === void 0 ? void 0 : _conversationDetails$.toLowerCase()) === "true") {
518
+ var _state$domainStates3;
519
+ _TelemetryHelper.TelemetryHelper.logSDKEventToAllTelemetry(_TelemetryConstants.LogLevel.INFO, {
520
+ Event: _TelemetryConstants.TelemetryEvent.EndChatEventReceived,
521
+ Description: "Processing initiateEndChat, fetching postChatContext"
522
+ });
523
+ const postchatContext = (await (0, _renderSurveyHelpers.getPostChatContext)(facadeChatSDK, state, dispatch)) ?? (state === null || state === void 0 ? void 0 : (_state$domainStates3 = state.domainStates) === null || _state$domainStates3 === void 0 ? void 0 : _state$domainStates3.postChatContext);
524
+ if (postchatContext) {
525
+ _TelemetryHelper.TelemetryHelper.logSDKEventToAllTelemetry(_TelemetryConstants.LogLevel.INFO, {
526
+ Event: _TelemetryConstants.TelemetryEvent.EndChatEventReceived,
527
+ Description: "Processing initiateEndChat, initiatePostChat",
528
+ CustomProperties: {
529
+ postchatContext
530
+ }
531
+ });
532
+ await (0, _renderSurveyHelpers.initiatePostChat)(props, conversationDetails, state, dispatch, postchatContext);
533
+ }
534
+ }
535
+ } else {
536
+ const skipEndChatSDK = false;
537
+ const skipCloseChat = false;
538
+ _TelemetryHelper.TelemetryHelper.logSDKEventToAllTelemetry(_TelemetryConstants.LogLevel.INFO, {
539
+ Event: _TelemetryConstants.TelemetryEvent.EndChatEventReceived,
540
+ Description: "Processing initiateEndChat, trigger endChat"
541
+ });
542
+ await (0, _endChat.endChat)(props, facadeChatSDK, state, dispatch, setAdapter, setWebChatStyles, adapter, skipEndChatSDK, skipCloseChat);
543
+ }
544
+ }
545
+ //if conversation already closed, it is safe to unmount it upon receiving the closeChat event
546
+ else {
547
+ _omnichannelChatComponents.BroadcastService.postMessage({
548
+ eventName: _TelemetryConstants.BroadcastEvent.CloseChat
549
+ });
550
+ }
551
+ };
501
552
 
502
553
  // End chat
503
- _omnichannelChatComponents.BroadcastService.getMessageByEventName(_TelemetryConstants.BroadcastEvent.InitiateEndChat).subscribe(async () => {
554
+ _omnichannelChatComponents.BroadcastService.getMessageByEventName(_TelemetryConstants.BroadcastEvent.InitiateEndChat).subscribe(async msg => {
504
555
  _TelemetryHelper.TelemetryHelper.logSDKEventToAllTelemetry(_TelemetryConstants.LogLevel.INFO, {
505
556
  Event: _TelemetryConstants.TelemetryEvent.EndChatEventReceived,
506
557
  Description: "Received InitiateEndChat BroadcastEvent.",
507
558
  CustomProperties: {
508
- ConversationStage: _TelemetryConstants.ConversationStage.ConversationEnd
559
+ ConversationStage: _TelemetryConstants.ConversationStage.ConversationEnd,
560
+ payload: msg === null || msg === void 0 ? void 0 : msg.payload
509
561
  }
510
562
  });
511
-
512
- // This is to ensure to get latest state from cache in multitab
563
+ const conversationDetails = await (0, _utils.getConversationDetailsCall)(facadeChatSDK);
564
+ const {
565
+ chatConfig
566
+ } = props;
567
+ const isPersistent = (0, _reconnectChatHelper.isPersistentEnabled)(chatConfig);
568
+ _TelemetryHelper.TelemetryHelper.logSDKEventToAllTelemetry(_TelemetryConstants.LogLevel.INFO, {
569
+ Event: _TelemetryConstants.TelemetryEvent.EndChatEventReceived,
570
+ Description: "Processing initiateEndChat, fetched conversation details",
571
+ CustomProperties: {
572
+ conversationDetails,
573
+ isPersistent
574
+ }
575
+ });
576
+ if (isPersistent && conversationDetails) {
577
+ await handleInitiateEndChatForPersistentChat(msg, conversationDetails);
578
+ return;
579
+ }
513
580
  const persistedState = (0, _utils.getStateFromCache)((0, _utils.getWidgetCacheIdfromProps)(props));
514
581
  if (persistedState && persistedState.appStates.conversationState === _ConversationState.ConversationState.Active) {
515
- // We need to simulate states for closing chat, in order to messup with close confirmation pane.
582
+ _TelemetryHelper.TelemetryHelper.logSDKEvent(_TelemetryConstants.LogLevel.INFO, {
583
+ Event: _TelemetryConstants.TelemetryEvent.PrepareEndChat,
584
+ Description: _Constants.PrepareEndChatDescriptionConstants.InitiateEndChatReceivedActiveChat
585
+ });
586
+ //We need to simulate states for closing chat, in order to messup with close confirmation pane.
516
587
  dispatch({
517
588
  type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONFIRMATION_STATE,
518
589
  payload: _Constants.ConfirmationState.Ok
@@ -532,11 +603,8 @@ const LiveChatWidgetStateful = props => {
532
603
  Event: _TelemetryConstants.TelemetryEvent.PrepareEndChat,
533
604
  Description: _Constants.PrepareEndChatDescriptionConstants.InitiateEndChatReceived
534
605
  });
535
- (0, _endChat.endChat)(props, facadeChatSDK, state, dispatch, setAdapter, setWebChatStyles, adapter, skipEndChatSDK, skipCloseChat);
606
+ await (0, _endChat.endChat)(props, facadeChatSDK, state, dispatch, setAdapter, setWebChatStyles, adapter, skipEndChatSDK, skipCloseChat);
536
607
  }
537
- _omnichannelChatComponents.BroadcastService.postMessage({
538
- eventName: _TelemetryConstants.BroadcastEvent.CloseChat
539
- });
540
608
  });
541
609
 
542
610
  // End chat on browser unload
@@ -547,8 +615,8 @@ const LiveChatWidgetStateful = props => {
547
615
  // Listen to end chat event from other tabs
548
616
  const endChatEventName = (0, _utils.getWidgetEndChatEventName)((_facadeChatSDK$getCha3 = facadeChatSDK.getChatSDK()) === null || _facadeChatSDK$getCha3 === void 0 ? void 0 : (_facadeChatSDK$getCha4 = _facadeChatSDK$getCha3.omnichannelConfig) === null || _facadeChatSDK$getCha4 === void 0 ? void 0 : _facadeChatSDK$getCha4.orgId, (_facadeChatSDK$getCha5 = facadeChatSDK.getChatSDK()) === null || _facadeChatSDK$getCha5 === void 0 ? void 0 : (_facadeChatSDK$getCha6 = _facadeChatSDK$getCha5.omnichannelConfig) === null || _facadeChatSDK$getCha6 === void 0 ? void 0 : _facadeChatSDK$getCha6.widgetId, ((_props$controlProps11 = props.controlProps) === null || _props$controlProps11 === void 0 ? void 0 : _props$controlProps11.widgetInstanceId) ?? "");
549
617
  _omnichannelChatComponents.BroadcastService.getMessageByEventName(endChatEventName).subscribe(msg => {
550
- var _msg$payload10;
551
- if ((msg === null || msg === void 0 ? void 0 : (_msg$payload10 = msg.payload) === null || _msg$payload10 === void 0 ? void 0 : _msg$payload10.runtimeId) !== _TelemetryManager.TelemetryManager.InternalTelemetryData.lcwRuntimeId) {
618
+ var _msg$payload13;
619
+ if ((msg === null || msg === void 0 ? void 0 : (_msg$payload13 = msg.payload) === null || _msg$payload13 === void 0 ? void 0 : _msg$payload13.runtimeId) !== _TelemetryManager.TelemetryManager.InternalTelemetryData.lcwRuntimeId) {
552
620
  _TelemetryHelper.TelemetryHelper.logSDKEvent(_TelemetryConstants.LogLevel.INFO, {
553
621
  Event: _TelemetryConstants.TelemetryEvent.PrepareEndChat,
554
622
  Description: "Received EndChat BroadcastEvent from other tabs. Closing this chat."
@@ -590,8 +658,8 @@ const LiveChatWidgetStateful = props => {
590
658
 
591
659
  // Retrieve convId
592
660
  _omnichannelChatComponents.BroadcastService.getMessageByEventName(_TelemetryConstants.BroadcastEvent.UpdateConversationDataForTelemetry).subscribe(msg => {
593
- var _msg$payload11, _msg$payload11$liveWo;
594
- if ((_msg$payload11 = msg.payload) !== null && _msg$payload11 !== void 0 && (_msg$payload11$liveWo = _msg$payload11.liveWorkItem) !== null && _msg$payload11$liveWo !== void 0 && _msg$payload11$liveWo.conversationId) {
661
+ var _msg$payload14, _msg$payload14$liveWo;
662
+ if ((_msg$payload14 = msg.payload) !== null && _msg$payload14 !== void 0 && (_msg$payload14$liveWo = _msg$payload14.liveWorkItem) !== null && _msg$payload14$liveWo !== void 0 && _msg$payload14$liveWo.conversationId) {
595
663
  setConversationId(msg.payload.liveWorkItem.conversationId);
596
664
  }
597
665
  });
@@ -709,14 +777,22 @@ const LiveChatWidgetStateful = props => {
709
777
  }
710
778
  }, [state.domainStates.confirmationState]);
711
779
  (0, _react2.useEffect)(() => {
712
- var _state$appStates8, _state$appStates9, _state$appStates10, _state$appStates11, _state$appStates12, _state$appStates13;
780
+ var _inMemoryState$appSta7, _inMemoryState$appSta8, _inMemoryState$appSta9, _inMemoryState$appSta10, _inMemoryState$appSta11, _inMemoryState$appSta12, _inMemoryState$appSta13;
781
+ const inMemoryState = (0, _createReducer.executeReducer)(state, {
782
+ type: _LiveChatWidgetActionType.LiveChatWidgetActionType.GET_IN_MEMORY_STATE,
783
+ payload: null
784
+ });
713
785
  // Do not process anything during initialization
714
- if ((state === null || state === void 0 ? void 0 : (_state$appStates8 = state.appStates) === null || _state$appStates8 === void 0 ? void 0 : _state$appStates8.conversationEndedBy) === _Constants.ConversationEndEntity.NotSet) {
786
+ if ((inMemoryState === null || inMemoryState === void 0 ? void 0 : (_inMemoryState$appSta7 = inMemoryState.appStates) === null || _inMemoryState$appSta7 === void 0 ? void 0 : _inMemoryState$appSta7.conversationEndedBy) === _Constants.ConversationEndEntity.NotSet) {
787
+ _TelemetryHelper.TelemetryHelper.logSDKEvent(_TelemetryConstants.LogLevel.INFO, {
788
+ Event: _TelemetryConstants.TelemetryEvent.PrepareEndChat,
789
+ Description: "conversationEndedBy is not set"
790
+ });
715
791
  return;
716
792
  }
717
793
 
718
794
  // If start chat failed, and C2 is trying to close chat widget
719
- if (state !== null && state !== void 0 && (_state$appStates9 = state.appStates) !== null && _state$appStates9 !== void 0 && _state$appStates9.startChatFailed || (state === null || state === void 0 ? void 0 : (_state$appStates10 = state.appStates) === null || _state$appStates10 === void 0 ? void 0 : _state$appStates10.conversationState) === _ConversationState.ConversationState.Postchat) {
795
+ if (inMemoryState !== null && inMemoryState !== void 0 && (_inMemoryState$appSta8 = inMemoryState.appStates) !== null && _inMemoryState$appSta8 !== void 0 && _inMemoryState$appSta8.startChatFailed || (inMemoryState === null || inMemoryState === void 0 ? void 0 : (_inMemoryState$appSta9 = inMemoryState.appStates) === null || _inMemoryState$appSta9 === void 0 ? void 0 : _inMemoryState$appSta9.conversationState) === _ConversationState.ConversationState.Postchat) {
720
796
  _TelemetryHelper.TelemetryHelper.logSDKEvent(_TelemetryConstants.LogLevel.INFO, {
721
797
  Event: _TelemetryConstants.TelemetryEvent.PrepareEndChat,
722
798
  Description: _Constants.PrepareEndChatDescriptionConstants.CustomerCloseChatOnFailureOrPostChat
@@ -726,7 +802,7 @@ const LiveChatWidgetStateful = props => {
726
802
  }
727
803
 
728
804
  // Scenario -> Chat was InActive and closing the chat (Refresh scenario on post chat)
729
- if ((state === null || state === void 0 ? void 0 : (_state$appStates11 = state.appStates) === null || _state$appStates11 === void 0 ? void 0 : _state$appStates11.conversationState) === _ConversationState.ConversationState.InActive) {
805
+ if ((inMemoryState === null || inMemoryState === void 0 ? void 0 : (_inMemoryState$appSta10 = inMemoryState.appStates) === null || _inMemoryState$appSta10 === void 0 ? void 0 : _inMemoryState$appSta10.conversationState) === _ConversationState.ConversationState.InActive) {
730
806
  _TelemetryHelper.TelemetryHelper.logSDKEvent(_TelemetryConstants.LogLevel.INFO, {
731
807
  Event: _TelemetryConstants.TelemetryEvent.PrepareEndChat,
732
808
  Description: _Constants.PrepareEndChatDescriptionConstants.CustomerCloseInactiveChat
@@ -734,11 +810,11 @@ const LiveChatWidgetStateful = props => {
734
810
  (0, _endChat.endChat)(props, facadeChatSDK, state, dispatch, setAdapter, setWebChatStyles, adapter, false, false, true);
735
811
  return;
736
812
  }
737
- const isConversationalSurveyEnabled = state.appStates.isConversationalSurveyEnabled;
813
+ const isConversationalSurveyEnabled = inMemoryState === null || inMemoryState === void 0 ? void 0 : (_inMemoryState$appSta11 = inMemoryState.appStates) === null || _inMemoryState$appSta11 === void 0 ? void 0 : _inMemoryState$appSta11.isConversationalSurveyEnabled;
738
814
 
739
815
  // In conversational survey, we need to check post chat survey logics before we set ConversationState to InActive
740
816
  // Hence setting ConversationState to InActive will be done later in the post chat flows
741
- if (!isConversationalSurveyEnabled && ((state === null || state === void 0 ? void 0 : (_state$appStates12 = state.appStates) === null || _state$appStates12 === void 0 ? void 0 : _state$appStates12.conversationEndedBy) === _Constants.ConversationEndEntity.Agent || (state === null || state === void 0 ? void 0 : (_state$appStates13 = state.appStates) === null || _state$appStates13 === void 0 ? void 0 : _state$appStates13.conversationEndedBy) === _Constants.ConversationEndEntity.Bot)) {
817
+ if (!isConversationalSurveyEnabled && (inMemoryState === null || inMemoryState === void 0 ? void 0 : (_inMemoryState$appSta12 = inMemoryState.appStates) === null || _inMemoryState$appSta12 === void 0 ? void 0 : _inMemoryState$appSta12.conversationEndedBy) === _Constants.ConversationEndEntity.Agent || (inMemoryState === null || inMemoryState === void 0 ? void 0 : (_inMemoryState$appSta13 = inMemoryState.appStates) === null || _inMemoryState$appSta13 === void 0 ? void 0 : _inMemoryState$appSta13.conversationEndedBy) === _Constants.ConversationEndEntity.Bot) {
742
818
  dispatch({
743
819
  type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_STATE,
744
820
  payload: _ConversationState.ConversationState.InActive
@@ -746,8 +822,8 @@ const LiveChatWidgetStateful = props => {
746
822
  }
747
823
 
748
824
  // All other cases
749
- (0, _endChat.prepareEndChat)(props, facadeChatSDK, state, dispatch, setAdapter, setWebChatStyles, adapter);
750
- }, [state === null || state === void 0 ? void 0 : (_state$appStates14 = state.appStates) === null || _state$appStates14 === void 0 ? void 0 : _state$appStates14.conversationEndedBy]);
825
+ (0, _endChat.prepareEndChat)(props, facadeChatSDK, inMemoryState, dispatch, setAdapter, setWebChatStyles, adapter);
826
+ }, [state === null || state === void 0 ? void 0 : (_state$appStates8 = state.appStates) === null || _state$appStates8 === void 0 ? void 0 : _state$appStates8.conversationEndedBy]);
751
827
 
752
828
  // Publish chat widget state
753
829
  (0, _react2.useEffect)(() => {
@@ -779,13 +855,13 @@ const LiveChatWidgetStateful = props => {
779
855
 
780
856
  // Handle Chat disconnect cases
781
857
  (0, _react2.useEffect)(() => {
782
- var _inMemoryState$appSta7;
858
+ var _inMemoryState$appSta14;
783
859
  const inMemoryState = (0, _createReducer.executeReducer)(state, {
784
860
  type: _LiveChatWidgetActionType.LiveChatWidgetActionType.GET_IN_MEMORY_STATE,
785
861
  payload: null
786
862
  });
787
863
  (0, _chatDisconnectHelper.handleChatDisconnect)(props, inMemoryState, setWebChatStyles);
788
- const chatDisconnectState = inMemoryState === null || inMemoryState === void 0 ? void 0 : (_inMemoryState$appSta7 = inMemoryState.appStates) === null || _inMemoryState$appSta7 === void 0 ? void 0 : _inMemoryState$appSta7.chatDisconnectEventReceived;
864
+ const chatDisconnectState = inMemoryState === null || inMemoryState === void 0 ? void 0 : (_inMemoryState$appSta14 = inMemoryState.appStates) === null || _inMemoryState$appSta14 === void 0 ? void 0 : _inMemoryState$appSta14.chatDisconnectEventReceived;
789
865
  if (chatDisconnectState && adapter) {
790
866
  try {
791
867
  adapter.end();
@@ -112,7 +112,7 @@ const PostChatSurveyPaneStateful = props => {
112
112
  Event: _TelemetryConstants.TelemetryEvent.CustomerVoiceResponsePageLoaded
113
113
  });
114
114
  } else if (data === _CustomerVoiceEvents.CustomerVoiceEvents.FormResponseSubmitted) {
115
- _TelemetryHelper.TelemetryHelper.logActionEventToAllTelemetry(_TelemetryConstants.LogLevel.INFO, {
115
+ _TelemetryHelper.TelemetryHelper.logActionEvent(_TelemetryConstants.LogLevel.INFO, {
116
116
  Event: _TelemetryConstants.TelemetryEvent.CustomerVoiceFormResponseSubmitted,
117
117
  Description: "Customer Voice form response submitted.",
118
118
  CustomProperties: {
@@ -120,7 +120,7 @@ const PostChatSurveyPaneStateful = props => {
120
120
  }
121
121
  });
122
122
  } else if (data === _CustomerVoiceEvents.CustomerVoiceEvents.FormResponseError) {
123
- _TelemetryHelper.TelemetryHelper.logActionEventToAllTelemetry(_TelemetryConstants.LogLevel.ERROR, {
123
+ _TelemetryHelper.TelemetryHelper.logActionEvent(_TelemetryConstants.LogLevel.ERROR, {
124
124
  Event: _TelemetryConstants.TelemetryEvent.CustomerVoiceFormResponseError,
125
125
  Description: "Customer Voice form response error.",
126
126
  ExceptionDetails: {