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

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 (132) hide show
  1. package/lib/cjs/common/Constants.js +5 -0
  2. package/lib/cjs/common/facades/FacadeChatSDK.js +6 -0
  3. package/lib/cjs/common/telemetry/AppInsightsEvents.js +4 -5
  4. package/lib/cjs/common/telemetry/TelemetryConstants.js +44 -2
  5. package/lib/cjs/common/telemetry/loggers/appInsightsLogger.js +26 -10
  6. package/lib/cjs/common/utils/SecureEventBus.js +307 -0
  7. package/lib/cjs/common/utils/dispatchCustomEvent.js +25 -0
  8. package/lib/cjs/components/chatbuttonstateful/ChatButtonStateful.js +16 -4
  9. package/lib/cjs/components/citationpanestateful/CitationPaneStateful.js +20 -1
  10. package/lib/cjs/components/headerstateful/HeaderStateful.js +8 -2
  11. package/lib/cjs/components/livechatwidget/common/ActivitySubscriber/AddActivitySubscriber.js +127 -0
  12. package/lib/cjs/components/livechatwidget/common/ChatWidgetEvents.js +15 -0
  13. package/lib/cjs/components/livechatwidget/common/PersistentConversationHandler.js +287 -0
  14. package/lib/cjs/components/livechatwidget/common/createAdapter.js +2 -0
  15. package/lib/cjs/components/livechatwidget/common/defaultProps/defaultPersistentChatHistoryProps.js +18 -0
  16. package/lib/cjs/components/livechatwidget/common/endChat.js +7 -1
  17. package/lib/cjs/components/livechatwidget/common/initWebChatComposer.js +16 -7
  18. package/lib/cjs/components/livechatwidget/common/renderSurveyHelpers.js +2 -2
  19. package/lib/cjs/components/livechatwidget/common/setPostChatContextAndLoadSurvey.js +3 -3
  20. package/lib/cjs/components/livechatwidget/common/startChat.js +5 -1
  21. package/lib/cjs/components/livechatwidget/common/startChatErrorHandler.js +24 -4
  22. package/lib/cjs/components/livechatwidget/interfaces/IPersistentChatHistoryProps.js +1 -0
  23. package/lib/cjs/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +22 -3
  24. package/lib/cjs/components/postchatsurveypanestateful/PostChatSurveyPaneStateful.js +29 -2
  25. package/lib/cjs/components/prechatsurveypanestateful/PreChatSurveyPaneStateful.js +12 -3
  26. package/lib/cjs/components/webchatcontainerstateful/WebChatContainerStateful.js +36 -5
  27. package/lib/cjs/components/webchatcontainerstateful/common/activities/botActivity.js +14 -0
  28. package/lib/cjs/components/webchatcontainerstateful/common/activities/conversationDividerActivity.js +17 -0
  29. package/lib/cjs/components/webchatcontainerstateful/common/activityConverters/convertPersistentChatHistoryMessageToActivity.js +97 -0
  30. package/lib/cjs/components/webchatcontainerstateful/common/defaultProps/defaultMiddlewareLocalizedTexts.js +3 -1
  31. package/lib/cjs/components/webchatcontainerstateful/common/defaultProps/defaultWebChatStatefulProps.js +1 -1
  32. package/lib/cjs/components/webchatcontainerstateful/hooks/usePersistentChatHistory.js +59 -0
  33. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/WebChatEventSubscribers.js +122 -0
  34. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activities/Constants.js +10 -0
  35. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activities/ConversationDividerActivity.js +47 -0
  36. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activities/LazyLoadActivity.js +1038 -0
  37. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activities/LoadInlineBannerActivity.js +34 -0
  38. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityMiddleware.js +50 -1
  39. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityStatusMiddleware.js +16 -2
  40. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/defaultStyles/defaultInLineBannerStyle.js +20 -0
  41. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/timestamps/DeliveredTimestamp.js +2 -2
  42. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/timestamps/HistoryMessageTimestamp.js +59 -0
  43. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/timestamps/NotDeliveredTimestamp.js +5 -3
  44. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/timestamps/SendingTimestamp.js +2 -2
  45. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/localizedStringsBotInitialsMiddleware.js +29 -7
  46. package/lib/cjs/contexts/common/LiveChatWidgetActionType.js +1 -0
  47. package/lib/cjs/contexts/common/LiveChatWidgetContextInitialState.js +7 -1
  48. package/lib/cjs/contexts/createReducer.js +15 -0
  49. package/lib/cjs/firstresponselatency/FirstMessageTrackerFromBot.js +3 -2
  50. package/lib/cjs/firstresponselatency/FirstResponseLatencyTracker.js +6 -2
  51. package/lib/cjs/plugins/newMessageEventHandler.js +4 -1
  52. package/lib/esm/common/Constants.js +5 -0
  53. package/lib/esm/common/facades/FacadeChatSDK.js +6 -0
  54. package/lib/esm/common/telemetry/AppInsightsEvents.js +4 -5
  55. package/lib/esm/common/telemetry/TelemetryConstants.js +42 -1
  56. package/lib/esm/common/telemetry/loggers/appInsightsLogger.js +27 -11
  57. package/lib/esm/common/utils/SecureEventBus.js +328 -0
  58. package/lib/esm/common/utils/dispatchCustomEvent.js +18 -0
  59. package/lib/esm/components/chatbuttonstateful/ChatButtonStateful.js +17 -5
  60. package/lib/esm/components/citationpanestateful/CitationPaneStateful.js +20 -1
  61. package/lib/esm/components/headerstateful/HeaderStateful.js +9 -3
  62. package/lib/esm/components/livechatwidget/common/ActivitySubscriber/AddActivitySubscriber.js +120 -0
  63. package/lib/esm/components/livechatwidget/common/ChatWidgetEvents.js +8 -0
  64. package/lib/esm/components/livechatwidget/common/PersistentConversationHandler.js +280 -0
  65. package/lib/esm/components/livechatwidget/common/createAdapter.js +2 -0
  66. package/lib/esm/components/livechatwidget/common/defaultProps/defaultPersistentChatHistoryProps.js +11 -0
  67. package/lib/esm/components/livechatwidget/common/endChat.js +7 -1
  68. package/lib/esm/components/livechatwidget/common/initWebChatComposer.js +16 -7
  69. package/lib/esm/components/livechatwidget/common/renderSurveyHelpers.js +2 -2
  70. package/lib/esm/components/livechatwidget/common/setPostChatContextAndLoadSurvey.js +3 -3
  71. package/lib/esm/components/livechatwidget/common/startChat.js +7 -3
  72. package/lib/esm/components/livechatwidget/common/startChatErrorHandler.js +23 -4
  73. package/lib/esm/components/livechatwidget/interfaces/IPersistentChatHistoryProps.js +1 -0
  74. package/lib/esm/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +23 -4
  75. package/lib/esm/components/postchatsurveypanestateful/PostChatSurveyPaneStateful.js +31 -4
  76. package/lib/esm/components/prechatsurveypanestateful/PreChatSurveyPaneStateful.js +13 -4
  77. package/lib/esm/components/webchatcontainerstateful/WebChatContainerStateful.js +39 -5
  78. package/lib/esm/components/webchatcontainerstateful/common/activities/botActivity.js +7 -0
  79. package/lib/esm/components/webchatcontainerstateful/common/activities/conversationDividerActivity.js +9 -0
  80. package/lib/esm/components/webchatcontainerstateful/common/activityConverters/convertPersistentChatHistoryMessageToActivity.js +90 -0
  81. package/lib/esm/components/webchatcontainerstateful/common/defaultProps/defaultMiddlewareLocalizedTexts.js +3 -1
  82. package/lib/esm/components/webchatcontainerstateful/common/defaultProps/defaultWebChatStatefulProps.js +2 -2
  83. package/lib/esm/components/webchatcontainerstateful/hooks/usePersistentChatHistory.js +51 -0
  84. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/WebChatEventSubscribers.js +115 -0
  85. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activities/Constants.js +3 -0
  86. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activities/ConversationDividerActivity.js +39 -0
  87. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activities/LazyLoadActivity.js +1060 -0
  88. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activities/LoadInlineBannerActivity.js +25 -0
  89. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityMiddleware.js +48 -1
  90. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityStatusMiddleware.js +13 -0
  91. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/defaultStyles/defaultInLineBannerStyle.js +13 -0
  92. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/timestamps/DeliveredTimestamp.js +1 -1
  93. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/timestamps/HistoryMessageTimestamp.js +52 -0
  94. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/timestamps/NotDeliveredTimestamp.js +3 -2
  95. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/timestamps/SendingTimestamp.js +1 -1
  96. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/localizedStringsBotInitialsMiddleware.js +29 -7
  97. package/lib/esm/contexts/common/LiveChatWidgetActionType.js +1 -0
  98. package/lib/esm/contexts/common/LiveChatWidgetContextInitialState.js +7 -1
  99. package/lib/esm/contexts/createReducer.js +15 -0
  100. package/lib/esm/firstresponselatency/FirstMessageTrackerFromBot.js +3 -2
  101. package/lib/esm/firstresponselatency/FirstResponseLatencyTracker.js +6 -2
  102. package/lib/esm/plugins/newMessageEventHandler.js +4 -1
  103. package/lib/types/common/Constants.d.ts +4 -0
  104. package/lib/types/common/facades/FacadeChatSDK.d.ts +3 -1
  105. package/lib/types/common/telemetry/TelemetryConstants.d.ts +39 -2
  106. package/lib/types/common/utils/SecureEventBus.d.ts +159 -0
  107. package/lib/types/common/utils/dispatchCustomEvent.d.ts +2 -0
  108. package/lib/types/components/livechatwidget/common/ActivitySubscriber/AddActivitySubscriber.d.ts +45 -0
  109. package/lib/types/components/livechatwidget/common/ChatWidgetEvents.d.ts +7 -0
  110. package/lib/types/components/livechatwidget/common/PersistentConversationHandler.d.ts +28 -0
  111. package/lib/types/components/livechatwidget/common/defaultProps/defaultPersistentChatHistoryProps.d.ts +2 -0
  112. package/lib/types/components/livechatwidget/common/startChatErrorHandler.d.ts +1 -0
  113. package/lib/types/components/livechatwidget/interfaces/ILiveChatWidgetProps.d.ts +2 -0
  114. package/lib/types/components/livechatwidget/interfaces/IPersistentChatHistoryProps.d.ts +12 -0
  115. package/lib/types/components/webchatcontainerstateful/common/activities/botActivity.d.ts +7 -0
  116. package/lib/types/components/webchatcontainerstateful/common/activities/conversationDividerActivity.d.ts +10 -0
  117. package/lib/types/components/webchatcontainerstateful/common/activityConverters/convertPersistentChatHistoryMessageToActivity.d.ts +2 -0
  118. package/lib/types/components/webchatcontainerstateful/hooks/usePersistentChatHistory.d.ts +4 -0
  119. package/lib/types/components/webchatcontainerstateful/webchatcontroller/WebChatEventSubscribers.d.ts +7 -0
  120. package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activities/Constants.d.ts +3 -0
  121. package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activities/ConversationDividerActivity.d.ts +4 -0
  122. package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activities/LazyLoadActivity.d.ts +326 -0
  123. package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activities/LoadInlineBannerActivity.d.ts +8 -0
  124. package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityMiddleware.d.ts +2 -1
  125. package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityStatusMiddleware.d.ts +1 -0
  126. package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/defaultStyles/defaultInLineBannerStyle.d.ts +2 -0
  127. package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/timestamps/HistoryMessageTimestamp.d.ts +2 -0
  128. package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/localizedStringsBotInitialsMiddleware.d.ts +1 -1
  129. package/lib/types/contexts/common/ILiveChatWidgetContext.d.ts +1 -0
  130. package/lib/types/contexts/common/ILiveChatWidgetLocalizedTexts.d.ts +6 -0
  131. package/lib/types/contexts/common/LiveChatWidgetActionType.d.ts +2 -1
  132. package/package.json +3 -3
@@ -0,0 +1,120 @@
1
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
2
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
3
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
4
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
5
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
6
+ function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
7
+ import { BroadcastEvent } from "../../../../common/telemetry/TelemetryConstants";
8
+ import { BroadcastService } from "@microsoft/omnichannel-chat-components";
9
+ import ChatWidgetEvents from "../ChatWidgetEvents";
10
+ import SecureEventBus from "../../../../common/utils/SecureEventBus";
11
+
12
+ /**
13
+ * The `AddActivitySubscriber` class is responsible for subscribing to the `ADD_ACTIVITY` event
14
+ * from the `ChatWidgetEvents` and notifying an observer when a new activity is added.
15
+ *
16
+ * This class implements the `IActivitySubscriber` interface and acts as a bridge between
17
+ * the event system and the observer pattern.
18
+ */
19
+ export let AddActivitySubscriber = /*#__PURE__*/function () {
20
+ /**
21
+ * The observer that will be notified when a new activity is added.
22
+ * This is expected to be an object with a `next` method, such as an RxJS `Observer`.
23
+ */
24
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
25
+
26
+ /**
27
+ * Set to track processed activity IDs to prevent duplicate processing.
28
+ */
29
+
30
+ /**
31
+ * Unsubscribe function for the secure event listener
32
+ */
33
+
34
+ /**
35
+ * Subscription for PersistentConversationReset event
36
+ */
37
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
38
+
39
+ /**
40
+ * Constructor initializes the `AddActivitySubscriber` and sets up a secure event listener
41
+ * for the `ChatWidgetEvents.ADD_ACTIVITY` event. When the event is triggered, it checks
42
+ * if the event payload contains an `activity` and notifies the observer.
43
+ */
44
+ function AddActivitySubscriber() {
45
+ _classCallCheck(this, AddActivitySubscriber);
46
+ _defineProperty(this, "observer", void 0);
47
+ _defineProperty(this, "processedActivityIds", new Set());
48
+ _defineProperty(this, "unsubscribeFromSecureEvent", null);
49
+ _defineProperty(this, "resetEventListener", void 0);
50
+ const eventBus = SecureEventBus.getInstance();
51
+
52
+ // Subscribe to the secure event bus instead of global window events
53
+ this.unsubscribeFromSecureEvent = eventBus.subscribe(ChatWidgetEvents.ADD_ACTIVITY, payload => {
54
+ if (payload !== null && payload !== void 0 && payload.activity) {
55
+ var _this$observer;
56
+ const activity = payload.activity;
57
+ const activityId = activity.id;
58
+ if (activity.identifier) {
59
+ if (this.processedActivityIds.has(activity === null || activity === void 0 ? void 0 : activity.identifier)) {
60
+ return; // Skip processing if already handled
61
+ }
62
+ // Add the activity ID to the processed set
63
+ this.processedActivityIds.add(activity === null || activity === void 0 ? void 0 : activity.identifier);
64
+ }
65
+
66
+ // Check if activity has an ID and if it has already been processed
67
+ if (activityId) {
68
+ if (this.processedActivityIds.has(activityId)) {
69
+ return; // Skip processing if already handled
70
+ }
71
+
72
+ // Add the activity ID to the processed set
73
+ this.processedActivityIds.add(activityId);
74
+ }
75
+
76
+ // Notify the observer with the new activity
77
+ (_this$observer = this.observer) === null || _this$observer === void 0 ? void 0 : _this$observer.next(activity);
78
+ }
79
+ });
80
+
81
+ // Subscribe to reset events for cleanup
82
+ this.resetEventListener = BroadcastService.getMessageByEventName(BroadcastEvent.PersistentConversationReset).subscribe(() => {
83
+ this.reset();
84
+ // Clean up the secure event listener when conversation resets
85
+ if (this.unsubscribeFromSecureEvent) {
86
+ this.unsubscribeFromSecureEvent();
87
+ this.unsubscribeFromSecureEvent = null;
88
+ }
89
+ // Unsubscribe from the reset event to prevent accumulation
90
+ if (this.resetEventListener) {
91
+ this.resetEventListener.unsubscribe();
92
+ }
93
+ });
94
+ }
95
+
96
+ /**
97
+ * The `next` method is a placeholder for processing the activity.
98
+ * This method can be overridden or extended as needed.
99
+ *
100
+ * @param activity - The activity object to process.
101
+ * @returns The activity object (asynchronously).
102
+ */
103
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
104
+ _createClass(AddActivitySubscriber, [{
105
+ key: "next",
106
+ value: async function next(activity) {
107
+ return activity;
108
+ }
109
+
110
+ /**
111
+ * Reset the processed activity IDs when a conversation resets
112
+ */
113
+ }, {
114
+ key: "reset",
115
+ value: function reset() {
116
+ this.processedActivityIds.clear();
117
+ }
118
+ }]);
119
+ return AddActivitySubscriber;
120
+ }();
@@ -0,0 +1,8 @@
1
+ var ChatWidgetEvents;
2
+ (function (ChatWidgetEvents) {
3
+ ChatWidgetEvents["ADD_ACTIVITY"] = "CHAT_WIDGET/ADD_ACTIVITY";
4
+ ChatWidgetEvents["FETCH_PERSISTENT_CHAT_HISTORY"] = "CHAT_WIDGET/FETCH_PERSISTENT_CHAT_HISTORY";
5
+ ChatWidgetEvents["NO_MORE_HISTORY_AVAILABLE"] = "CHAT_WIDGET/NO_MORE_HISTORY_AVAILABLE";
6
+ ChatWidgetEvents["HIDE_LOADING_BANNER"] = "CHAT_WIDGET/HIDE_LOADING_BANNER";
7
+ })(ChatWidgetEvents || (ChatWidgetEvents = {}));
8
+ export default ChatWidgetEvents;
@@ -0,0 +1,280 @@
1
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
2
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
3
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
4
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
5
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
6
+ function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
7
+ import { BroadcastEvent, LogLevel, TelemetryEvent } from "../../../common/telemetry/TelemetryConstants";
8
+ import { BroadcastService } from "@microsoft/omnichannel-chat-components";
9
+ import ChatWidgetEvents from "./ChatWidgetEvents";
10
+ import { TelemetryHelper } from "../../../common/telemetry/TelemetryHelper";
11
+ import conversationDividerActivity from "../../webchatcontainerstateful/common/activities/conversationDividerActivity";
12
+ import convertPersistentChatHistoryMessageToActivity from "../../webchatcontainerstateful/common/activityConverters/convertPersistentChatHistoryMessageToActivity";
13
+ import { createTimer } from "../../../common/utils";
14
+ import { defaultPersistentChatHistoryProps } from "./defaultProps/defaultPersistentChatHistoryProps";
15
+ import dispatchCustomEvent from "../../../common/utils/dispatchCustomEvent";
16
+
17
+ /**
18
+ * Class responsible for handling persistent conversation history
19
+ */
20
+ let PersistentConversationHandler = /*#__PURE__*/function () {
21
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
22
+
23
+ function PersistentConversationHandler(facadeChatSDK, props) {
24
+ _classCallCheck(this, PersistentConversationHandler);
25
+ _defineProperty(this, "appliedProps", {
26
+ ...defaultPersistentChatHistoryProps
27
+ });
28
+ _defineProperty(this, "isLastPull", false);
29
+ _defineProperty(this, "pageToken", null);
30
+ _defineProperty(this, "facadeChatSDK", void 0);
31
+ _defineProperty(this, "lastMessage", null);
32
+ _defineProperty(this, "count", 0);
33
+ _defineProperty(this, "pageSize", 4);
34
+ _defineProperty(this, "isCurrentlyPulling", false);
35
+ _defineProperty(this, "pageTokenInTransitSet", new Set());
36
+ _defineProperty(this, "resetEventListener", BroadcastService.getMessageByEventName(BroadcastEvent.PersistentConversationReset).subscribe(() => {
37
+ this.reset();
38
+ }));
39
+ this.facadeChatSDK = facadeChatSDK;
40
+ this.appliedPropsHandler(props);
41
+ TelemetryHelper.logActionEventToAllTelemetry(LogLevel.INFO, {
42
+ Event: TelemetryEvent.LCWPersistentConversationHandlerInitialized,
43
+ Description: "PersistentConversationHandler initialized",
44
+ CustomProperties: {
45
+ pageSize: this.pageSize
46
+ }
47
+ });
48
+ }
49
+ _createClass(PersistentConversationHandler, [{
50
+ key: "appliedPropsHandler",
51
+ value: function appliedPropsHandler(props) {
52
+ var _this$appliedProps;
53
+ this.appliedProps = {
54
+ ...defaultPersistentChatHistoryProps,
55
+ ...props
56
+ };
57
+
58
+ // if the props is not existent or is not anumber then default to 4
59
+ 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;
60
+ }
61
+ }, {
62
+ key: "reset",
63
+ value: function reset() {
64
+ this.isLastPull = false;
65
+ this.pageToken = null;
66
+ this.lastMessage = null;
67
+ this.count = 0;
68
+ this.isCurrentlyPulling = false;
69
+ this.pageTokenInTransitSet.clear();
70
+ }
71
+ }, {
72
+ key: "destroy",
73
+ value: function destroy() {
74
+ // Only unsubscribe when the handler is being destroyed completely
75
+ this.resetEventListener.unsubscribe();
76
+ }
77
+ }, {
78
+ key: "pullHistory",
79
+ value: async function pullHistory() {
80
+ const pullTimer = createTimer();
81
+
82
+ // Prevent concurrent pulls regardless of pageToken
83
+ if (this.isCurrentlyPulling) {
84
+ TelemetryHelper.logActionEvent(LogLevel.WARN, {
85
+ Event: TelemetryEvent.LCWPersistentHistoryPullBlocked,
86
+ Description: "History pull blocked - already in progress"
87
+ });
88
+ return;
89
+ }
90
+
91
+ // Additional check for specific pageToken duplicates
92
+ if (this.pageToken && this.pageTokenInTransitSet.has(this.pageToken)) {
93
+ return;
94
+ }
95
+
96
+ // Mark as currently pulling
97
+ this.isCurrentlyPulling = true;
98
+ if (this.pageToken) {
99
+ this.pageTokenInTransitSet.add(this.pageToken);
100
+ }
101
+ try {
102
+ var _ref;
103
+ const messages = await this.fetchHistoryMessages();
104
+ if (messages === null || (messages === null || messages === void 0 ? void 0 : messages.length) === 0) {
105
+ this.isLastPull = true;
106
+ // Dispatch event to notify UI that no more history is available
107
+ dispatchCustomEvent(ChatWidgetEvents.NO_MORE_HISTORY_AVAILABLE);
108
+ // Also hide the loading banner
109
+ dispatchCustomEvent(ChatWidgetEvents.HIDE_LOADING_BANNER);
110
+ TelemetryHelper.logActionEvent(LogLevel.INFO, {
111
+ Event: TelemetryEvent.LCWPersistentHistoryPullCompleted,
112
+ Description: "History pull completed - no more messages",
113
+ ElapsedTimeInMilliseconds: pullTimer.milliSecondsElapsed
114
+ });
115
+ return;
116
+ }
117
+ const messagesDescOrder = (_ref = [...messages]) === null || _ref === void 0 ? void 0 : _ref.reverse();
118
+ this.processHistoryMessages(messagesDescOrder);
119
+
120
+ // Dispatch event to hide the loading banner after messages are processed
121
+ dispatchCustomEvent(ChatWidgetEvents.HIDE_LOADING_BANNER);
122
+ TelemetryHelper.logActionEvent(LogLevel.INFO, {
123
+ Event: TelemetryEvent.LCWPersistentHistoryPullCompleted,
124
+ Description: "History pull completed successfully",
125
+ ElapsedTimeInMilliseconds: pullTimer.milliSecondsElapsed,
126
+ CustomProperties: {
127
+ messageCount: messages.length,
128
+ totalProcessed: this.count
129
+ }
130
+ });
131
+ } finally {
132
+ // Always clear the pulling flag when done
133
+ this.isCurrentlyPulling = false;
134
+
135
+ // Remove pageToken from transit set if it was added
136
+ if (this.pageToken) {
137
+ this.pageTokenInTransitSet.delete(this.pageToken);
138
+ }
139
+ }
140
+ }
141
+
142
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
143
+ }, {
144
+ key: "processHistoryMessages",
145
+ value: function processHistoryMessages(messagesDescOrder) {
146
+ for (const message of messagesDescOrder) {
147
+ try {
148
+ const activity = this.processMessageToActivity(message);
149
+ if (activity) {
150
+ dispatchCustomEvent(ChatWidgetEvents.ADD_ACTIVITY, {
151
+ activity
152
+ });
153
+ const dividerActivity = this.createDividerActivity(activity);
154
+ if (dividerActivity) {
155
+ dispatchCustomEvent(ChatWidgetEvents.ADD_ACTIVITY, {
156
+ activity: dividerActivity
157
+ });
158
+ }
159
+ this.lastMessage = activity;
160
+ }
161
+ } catch (error) {
162
+ TelemetryHelper.logActionEvent(LogLevel.ERROR, {
163
+ Event: TelemetryEvent.ConvertPersistentChatHistoryMessageToActivityFailed,
164
+ ExceptionDetails: error
165
+ });
166
+ }
167
+ }
168
+ }
169
+
170
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
171
+ }, {
172
+ key: "fetchHistoryMessages",
173
+ value: async function fetchHistoryMessages() {
174
+ if (!this.shouldPull()) {
175
+ // Dispatch event to ensure banner is hidden when no more pulls are needed
176
+ dispatchCustomEvent(ChatWidgetEvents.NO_MORE_HISTORY_AVAILABLE);
177
+ dispatchCustomEvent(ChatWidgetEvents.HIDE_LOADING_BANNER);
178
+ return [];
179
+ }
180
+ const options = {
181
+ pageSize: this.pageSize,
182
+ pageToken: this.pageToken || undefined
183
+ };
184
+ try {
185
+ var _this$facadeChatSDK;
186
+ const response = await ((_this$facadeChatSDK = this.facadeChatSDK) === null || _this$facadeChatSDK === void 0 ? void 0 : _this$facadeChatSDK.fetchPersistentConversationHistory(options));
187
+ const {
188
+ chatMessages: messages,
189
+ nextPageToken: pageToken
190
+ } = response;
191
+ this.pageToken = pageToken || null;
192
+ if (pageToken === null) {
193
+ this.isLastPull = true;
194
+ // Dispatch event when we reach the end of available history
195
+ dispatchCustomEvent(ChatWidgetEvents.NO_MORE_HISTORY_AVAILABLE);
196
+ }
197
+
198
+ // if chatMessages is null, return empty array
199
+ if (!messages) {
200
+ this.isLastPull = true;
201
+ // Dispatch event when we reach the end of available history
202
+ dispatchCustomEvent(ChatWidgetEvents.NO_MORE_HISTORY_AVAILABLE);
203
+ // Also hide the loading banner
204
+ dispatchCustomEvent(ChatWidgetEvents.HIDE_LOADING_BANNER);
205
+ return [];
206
+ }
207
+ dispatchCustomEvent(ChatWidgetEvents.HIDE_LOADING_BANNER);
208
+ return messages;
209
+ } catch (error) {
210
+ TelemetryHelper.logSDKEvent(LogLevel.ERROR, {
211
+ Event: TelemetryEvent.FetchPersistentChatHistoryFailed,
212
+ ExceptionDetails: error
213
+ });
214
+ this.isLastPull = true;
215
+ this.pageToken = null;
216
+ // Dispatch event when there's an error to stop loading banner
217
+ dispatchCustomEvent(ChatWidgetEvents.NO_MORE_HISTORY_AVAILABLE);
218
+ // Also hide the loading banner
219
+ dispatchCustomEvent(ChatWidgetEvents.HIDE_LOADING_BANNER);
220
+ return [];
221
+ }
222
+ }
223
+ }, {
224
+ key: "shouldPull",
225
+ value: function shouldPull() {
226
+ return !this.isLastPull;
227
+ }
228
+
229
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
230
+ }, {
231
+ key: "processMessageToActivity",
232
+ value: function processMessageToActivity(message) {
233
+ try {
234
+ const activity = convertPersistentChatHistoryMessageToActivity(message);
235
+ activity.id = activity.id || `activity-${this.count}`;
236
+ activity.channelData = {
237
+ ...activity.channelData,
238
+ metadata: {
239
+ count: this.count
240
+ }
241
+ };
242
+
243
+ // Increment the count after assigning it to the activity
244
+ this.count += 1;
245
+ return activity;
246
+ } catch (error) {
247
+ TelemetryHelper.logActionEvent(LogLevel.ERROR, {
248
+ Event: TelemetryEvent.ConvertPersistentChatHistoryMessageToActivityFailed,
249
+ ExceptionDetails: error
250
+ });
251
+ throw error;
252
+ }
253
+ }
254
+
255
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
256
+ }, {
257
+ key: "createDividerActivity",
258
+ value: function createDividerActivity(activity) {
259
+ var _this$lastMessage, _this$lastMessage$cha;
260
+ if (((_this$lastMessage = this.lastMessage) === null || _this$lastMessage === void 0 ? void 0 : (_this$lastMessage$cha = _this$lastMessage.channelData) === null || _this$lastMessage$cha === void 0 ? void 0 : _this$lastMessage$cha.conversationId) !== activity.channelData.conversationId) {
261
+ const rawSequenceId = activity.channelData["webchat:sequence-id"];
262
+ const sequenceId = typeof rawSequenceId === "number" && !isNaN(rawSequenceId) ? rawSequenceId + 1 : 1;
263
+ const timestamp = new Date(activity.timestamp).getTime() + 1;
264
+ return {
265
+ ...conversationDividerActivity,
266
+ channelData: {
267
+ ...conversationDividerActivity.channelData,
268
+ conversationId: activity.channelData.conversationId,
269
+ "webchat:sequence-id": sequenceId
270
+ },
271
+ timestamp: new Date(timestamp).toISOString(),
272
+ identifier: `divider-${activity.channelData.conversationId}`
273
+ };
274
+ }
275
+ return null;
276
+ }
277
+ }]);
278
+ return PersistentConversationHandler;
279
+ }();
280
+ export default PersistentConversationHandler;
@@ -1,3 +1,4 @@
1
+ import { AddActivitySubscriber } from "./ActivitySubscriber/AddActivitySubscriber";
1
2
  import { BotAuthActivitySubscriber } from "./ActivitySubscriber/BotAuthActivitySubscriber";
2
3
  import { ChatAdapterShim } from "./ChatAdapterShim";
3
4
  import { HiddenAdaptiveCardActivitySubscriber } from "./ActivitySubscriber/HiddenAdaptiveCardActivitySubscriber";
@@ -44,6 +45,7 @@ export const createAdapter = async (facadeChatSDK, props) => {
44
45
  fetchBotAuthConfigRetryInterval: (props === null || props === void 0 ? void 0 : (_props$webChatContain3 = props.webChatContainerProps) === null || _props$webChatContain3 === void 0 ? void 0 : (_props$webChatContain4 = _props$webChatContain3.botAuthConfig) === null || _props$webChatContain4 === void 0 ? void 0 : _props$webChatContain4.fetchBotAuthConfigRetryInterval) || defaultBotAuthConfig.fetchBotAuthConfigRetryInterval
45
46
  };
46
47
  adapter = new ChatAdapterShim(adapter);
48
+ adapter.addSubscriber(new AddActivitySubscriber());
47
49
  adapter.addSubscriber(new PauseActivitySubscriber());
48
50
  adapter.addSubscriber(new BotAuthActivitySubscriber(botAuthActivitySubscriberOptionalParams));
49
51
  // Remove this code after ICM ID:544623085 is fixed
@@ -0,0 +1,11 @@
1
+ export const defaultPersistentChatHistoryProps = {
2
+ persistentChatHistoryEnabled: true,
3
+ pageSize: 4,
4
+ dividerActivityStyle: {
5
+ border: "1px solid rgb(96, 94, 92, 0.5)",
6
+ margin: "10px 20%"
7
+ },
8
+ bannerStyle: {
9
+ margin: "10px auto"
10
+ }
11
+ };
@@ -4,6 +4,7 @@ import { getConversationDetailsCall, getWidgetEndChatEventName } from "../../../
4
4
  import { getPostChatContext, initiatePostChat } from "./renderSurveyHelpers";
5
5
  import { BroadcastService } from "@microsoft/omnichannel-chat-components";
6
6
  import { ConversationState } from "../../../contexts/common/ConversationState";
7
+ import { LazyLoadHandler } from "../../webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activities/LazyLoadActivity";
7
8
  import { LiveChatWidgetActionType } from "../../../contexts/common/LiveChatWidgetActionType";
8
9
  import { TelemetryHelper } from "../../../common/telemetry/TelemetryHelper";
9
10
  import { TelemetryManager } from "../../../common/telemetry/TelemetryManager";
@@ -225,7 +226,12 @@ const endChat = async (props, facadeChatSDK, state, dispatch, setAdapter, setWeb
225
226
  type: LiveChatWidgetActionType.SET_POST_CHAT_CONTEXT,
226
227
  payload: undefined
227
228
  });
228
- // Always allow to close the chat for embedded mode irrespective of end chat errors
229
+
230
+ // Call direct reset to ensure LazyLoadHandler gets reset regardless of broadcast timing
231
+ LazyLoadHandler.directReset();
232
+ BroadcastService.postMessage({
233
+ eventName: BroadcastEvent.PersistentConversationReset
234
+ });
229
235
  closeChatWidget(dispatch, setWebChatStyles, props);
230
236
  facadeChatSDK.destroy();
231
237
  }
@@ -1,6 +1,7 @@
1
1
  import { ConversationEndEntity, ParticipantType } from "../../../common/Constants";
2
2
  import { LogLevel, TelemetryEvent } from "../../../common/telemetry/TelemetryConstants";
3
3
  import { changeLanguageCodeFormatForWebChat, getConversationDetailsCall } from "../../../common/utils";
4
+ import { getOverriddenLocalizedStrings, localizedStringsBotInitialsMiddleware } from "../../webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/localizedStringsBotInitialsMiddleware";
4
5
  import { BroadcastService } from "@microsoft/omnichannel-chat-components";
5
6
  import { Constants } from "../../../common/Constants";
6
7
  import { ConversationState } from "../../../contexts/common/ConversationState";
@@ -12,6 +13,7 @@ import { WebChatStoreLoader } from "../../webchatcontainerstateful/webchatcontro
12
13
  import attachmentProcessingMiddleware from "../../webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/attachmentProcessingMiddleware";
13
14
  import channelDataMiddleware from "../../webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/channelDataMiddleware";
14
15
  import { createActivityMiddleware } from "../../webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityMiddleware";
16
+ import { createActivityStatusMiddleware } from "../../webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityStatusMiddleware";
15
17
  import { createAttachmentMiddleware } from "../../webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/attachmentMiddleware";
16
18
  import createAttachmentUploadValidatorMiddleware from "../../webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/attachmentUploadValidatorMiddleware";
17
19
  import { createAvatarMiddleware } from "../../webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/avatarMiddleware";
@@ -39,11 +41,10 @@ import htmlPlayerMiddleware from "../../webchatcontainerstateful/webchatcontroll
39
41
  import htmlTextMiddleware from "../../webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/htmlTextMiddleware";
40
42
  import preProcessingMiddleware from "../../webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/preProcessingMiddleware";
41
43
  import sanitizationMiddleware from "../../webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/sanitizationMiddleware";
42
- import { localizedStringsBotInitialsMiddleware, getOverriddenLocalizedStrings } from "../../webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/localizedStringsBotInitialsMiddleware";
43
44
 
44
45
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
45
46
  export const initWebChatComposer = (props, state, dispatch, facadeChatSDK, endChat) => {
46
- var _props$webChatContain, _props$webChatContain2, _props$webChatContain3, _props$webChatContain4, _props$webChatContain5, _props$webChatContain6, _state$domainStates$l4, _state$domainStates$l5, _props$webChatContain11, _props$webChatContain12, _state$domainStates$r, _state$domainStates$r2, _props$webChatContain13, _props$webChatContain14, _state$domainStates$r3, _state$domainStates$r4, _props$webChatContain15, _props$webChatContain16, _defaultWebChatContai, _props$webChatContain17, _props$webChatContain18, _props$webChatContain19, _props$webChatContain20, _state$domainStates$r5, _state$domainStates$r6, _props$webChatContain21, _props$webChatContain22, _defaultWebChatContai2, _props$webChatContain23, _props$webChatContain24, _defaultWebChatContai3, _props$webChatContain25, _props$webChatContain26, _props$webChatContain27, _props$webChatContain28;
47
+ var _props$webChatContain, _props$webChatContain2, _props$webChatContain3, _props$webChatContain4, _props$webChatContain5, _props$webChatContain6, _state$domainStates$l4, _state$domainStates$l5, _props$webChatContain11, _props$webChatContain12, _state$domainStates$r, _state$domainStates$r2, _props$webChatContain13, _props$webChatContain14, _state$domainStates$r3, _state$domainStates$r4, _props$webChatContain15, _props$webChatContain16, _state$domainStates$l6, _state$domainStates$l7, _props$webChatContain17, _props$webChatContain18, _props$webChatContain19, _props$webChatContain20, _state$domainStates$r5, _state$domainStates$r6, _props$webChatContain21, _props$webChatContain22, _defaultWebChatContai, _props$webChatContain23, _props$webChatContain24, _defaultWebChatContai2, _props$webChatContain25, _props$webChatContain26, _props$webChatContain27, _props$webChatContain28;
47
48
  // Add a hook to make all links open a new window
48
49
  postDomPurifyActivities();
49
50
  const localizedTexts = {
@@ -61,6 +62,7 @@ export const initWebChatComposer = (props, state, dispatch, facadeChatSDK, endCh
61
62
  let webChatStore = WebChatStoreLoader.store;
62
63
  if (!webChatStore) {
63
64
  var _state$domainStates$l, _state$domainStates$l2, _state$domainStates$l3, _props$webChatContain7;
65
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
64
66
  const addConversationalSurveyTagsCallback = action => {
65
67
  var _inMemoryState$appSta;
66
68
  const inMemoryState = executeReducer(state, {
@@ -118,7 +120,14 @@ export const initWebChatComposer = (props, state, dispatch, facadeChatSDK, endCh
118
120
  };
119
121
  webChatStore = createStore({},
120
122
  //initial state
121
- preProcessingMiddleware, attachmentProcessingMiddleware, createAttachmentUploadValidatorMiddleware((_state$domainStates$l = state.domainStates.liveChatConfig) === null || _state$domainStates$l === void 0 ? void 0 : _state$domainStates$l.allowedFileExtensions, (_state$domainStates$l2 = state.domainStates.liveChatConfig) === null || _state$domainStates$l2 === void 0 ? void 0 : _state$domainStates$l2.maxUploadFileSize, localizedTexts), createCustomEventMiddleware(BroadcastService), createQueueOverflowMiddleware(state, dispatch), channelDataMiddleware(addConversationalSurveyTagsCallback), createConversationEndMiddleware(conversationEndCallback, startConversationalSurveyCallback, endConversationalSurveyCallback), createDataMaskingMiddleware((_state$domainStates$l3 = state.domainStates.liveChatConfig) === null || _state$domainStates$l3 === void 0 ? void 0 : _state$domainStates$l3.DataMaskingInfo), createMessageTimeStampMiddleware, createMessageSequenceIdOverrideMiddleware, createCitationsMiddleware(state, dispatch), gifUploadMiddleware, htmlPlayerMiddleware, htmlTextMiddleware(honorsTargetInHTMLLinks), createMaxMessageSizeValidator(localizedTexts), sanitizationMiddleware, createCallActionMiddleware(), localizedStringsBotInitialsMiddleware(),
123
+ preProcessingMiddleware, attachmentProcessingMiddleware, createAttachmentUploadValidatorMiddleware((_state$domainStates$l = state.domainStates.liveChatConfig) === null || _state$domainStates$l === void 0 ? void 0 : _state$domainStates$l.allowedFileExtensions, (_state$domainStates$l2 = state.domainStates.liveChatConfig) === null || _state$domainStates$l2 === void 0 ? void 0 : _state$domainStates$l2.maxUploadFileSize, localizedTexts), createCustomEventMiddleware(BroadcastService), createQueueOverflowMiddleware(state, dispatch), channelDataMiddleware(addConversationalSurveyTagsCallback), createConversationEndMiddleware(conversationEndCallback, startConversationalSurveyCallback, endConversationalSurveyCallback), createDataMaskingMiddleware((_state$domainStates$l3 = state.domainStates.liveChatConfig) === null || _state$domainStates$l3 === void 0 ? void 0 : _state$domainStates$l3.DataMaskingInfo), createMessageTimeStampMiddleware, createMessageSequenceIdOverrideMiddleware, createCitationsMiddleware(state, dispatch), gifUploadMiddleware, htmlPlayerMiddleware, htmlTextMiddleware(honorsTargetInHTMLLinks), createMaxMessageSizeValidator(localizedTexts), sanitizationMiddleware, createCallActionMiddleware(),
124
+ // Pass a callback so middleware can push initials into React context for reactivity
125
+ localizedStringsBotInitialsMiddleware(initials => {
126
+ dispatch({
127
+ type: LiveChatWidgetActionType.SET_BOT_AVATAR_INITIALS,
128
+ payload: initials
129
+ });
130
+ }),
122
131
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
123
132
  ...(((_props$webChatContain7 = props.webChatContainerProps) === null || _props$webChatContain7 === void 0 ? void 0 : _props$webChatContain7.storeMiddlewares) ?? []));
124
133
  WebChatStoreLoader.store = webChatStore;
@@ -161,14 +170,14 @@ export const initWebChatComposer = (props, state, dispatch, facadeChatSDK, endCh
161
170
  dir: state.domainStates.globalDir,
162
171
  locale: changeLanguageCodeFormatForWebChat(getLocaleStringFromId((_state$domainStates$l4 = state.domainStates.liveChatConfig) === null || _state$domainStates$l4 === void 0 ? void 0 : (_state$domainStates$l5 = _state$domainStates$l4.ChatWidgetLanguage) === null || _state$domainStates$l5 === void 0 ? void 0 : _state$domainStates$l5.msdyn_localeid)),
163
172
  store: webChatStore,
164
- activityMiddleware: (_props$webChatContain11 = props.webChatContainerProps) !== null && _props$webChatContain11 !== void 0 && (_props$webChatContain12 = _props$webChatContain11.renderingMiddlewareProps) !== null && _props$webChatContain12 !== void 0 && _props$webChatContain12.disableActivityMiddleware ? undefined : createActivityMiddleware(renderMarkdown, (_state$domainStates$r = state.domainStates.renderingMiddlewareProps) === null || _state$domainStates$r === void 0 ? void 0 : _state$domainStates$r.systemMessageStyleProps, (_state$domainStates$r2 = state.domainStates.renderingMiddlewareProps) === null || _state$domainStates$r2 === void 0 ? void 0 : _state$domainStates$r2.userMessageStyleProps),
173
+ activityMiddleware: (_props$webChatContain11 = props.webChatContainerProps) !== null && _props$webChatContain11 !== void 0 && (_props$webChatContain12 = _props$webChatContain11.renderingMiddlewareProps) !== null && _props$webChatContain12 !== void 0 && _props$webChatContain12.disableActivityMiddleware ? undefined : createActivityMiddleware(renderMarkdown, (_state$domainStates$r = state.domainStates.renderingMiddlewareProps) === null || _state$domainStates$r === void 0 ? void 0 : _state$domainStates$r.systemMessageStyleProps, (_state$domainStates$r2 = state.domainStates.renderingMiddlewareProps) === null || _state$domainStates$r2 === void 0 ? void 0 : _state$domainStates$r2.userMessageStyleProps, localizedTexts),
165
174
  attachmentMiddleware: (_props$webChatContain13 = props.webChatContainerProps) !== null && _props$webChatContain13 !== void 0 && (_props$webChatContain14 = _props$webChatContain13.renderingMiddlewareProps) !== null && _props$webChatContain14 !== void 0 && _props$webChatContain14.disableAttachmentMiddleware ? undefined : createAttachmentMiddleware(((_state$domainStates$r3 = state.domainStates.renderingMiddlewareProps) === null || _state$domainStates$r3 === void 0 ? void 0 : (_state$domainStates$r4 = _state$domainStates$r3.attachmentProps) === null || _state$domainStates$r4 === void 0 ? void 0 : _state$domainStates$r4.enableInlinePlaying) ?? defaultAttachmentProps.enableInlinePlaying),
166
- activityStatusMiddleware: (_props$webChatContain15 = props.webChatContainerProps) !== null && _props$webChatContain15 !== void 0 && (_props$webChatContain16 = _props$webChatContain15.renderingMiddlewareProps) !== null && _props$webChatContain16 !== void 0 && _props$webChatContain16.disableActivityStatusMiddleware ? undefined : (_defaultWebChatContai = defaultWebChatContainerStatefulProps.webChatProps) === null || _defaultWebChatContai === void 0 ? void 0 : _defaultWebChatContai.activityStatusMiddleware,
175
+ activityStatusMiddleware: (_props$webChatContain15 = props.webChatContainerProps) !== null && _props$webChatContain15 !== void 0 && (_props$webChatContain16 = _props$webChatContain15.renderingMiddlewareProps) !== null && _props$webChatContain16 !== void 0 && _props$webChatContain16.disableActivityStatusMiddleware ? undefined : createActivityStatusMiddleware(getLocaleStringFromId((_state$domainStates$l6 = state.domainStates.liveChatConfig) === null || _state$domainStates$l6 === void 0 ? void 0 : (_state$domainStates$l7 = _state$domainStates$l6.ChatWidgetLanguage) === null || _state$domainStates$l7 === void 0 ? void 0 : _state$domainStates$l7.msdyn_localeid)),
167
176
  toastMiddleware: (_props$webChatContain17 = props.webChatContainerProps) !== null && _props$webChatContain17 !== void 0 && (_props$webChatContain18 = _props$webChatContain17.renderingMiddlewareProps) !== null && _props$webChatContain18 !== void 0 && _props$webChatContain18.disableToastMiddleware ? undefined : createToastMiddleware(props.notificationPaneProps, endChat),
168
177
  renderMarkdown,
169
178
  avatarMiddleware: (_props$webChatContain19 = props.webChatContainerProps) !== null && _props$webChatContain19 !== void 0 && (_props$webChatContain20 = _props$webChatContain19.renderingMiddlewareProps) !== null && _props$webChatContain20 !== void 0 && _props$webChatContain20.disableAvatarMiddleware ? undefined : createAvatarMiddleware((_state$domainStates$r5 = state.domainStates.renderingMiddlewareProps) === null || _state$domainStates$r5 === void 0 ? void 0 : _state$domainStates$r5.avatarStyleProps, (_state$domainStates$r6 = state.domainStates.renderingMiddlewareProps) === null || _state$domainStates$r6 === void 0 ? void 0 : _state$domainStates$r6.avatarTextStyleProps),
170
- groupActivitiesMiddleware: (_props$webChatContain21 = props.webChatContainerProps) !== null && _props$webChatContain21 !== void 0 && (_props$webChatContain22 = _props$webChatContain21.renderingMiddlewareProps) !== null && _props$webChatContain22 !== void 0 && _props$webChatContain22.disableGroupActivitiesMiddleware ? undefined : (_defaultWebChatContai2 = defaultWebChatContainerStatefulProps.webChatProps) === null || _defaultWebChatContai2 === void 0 ? void 0 : _defaultWebChatContai2.groupActivitiesMiddleware,
171
- typingIndicatorMiddleware: (_props$webChatContain23 = props.webChatContainerProps) !== null && _props$webChatContain23 !== void 0 && (_props$webChatContain24 = _props$webChatContain23.renderingMiddlewareProps) !== null && _props$webChatContain24 !== void 0 && _props$webChatContain24.disableTypingIndicatorMiddleware ? undefined : (_defaultWebChatContai3 = defaultWebChatContainerStatefulProps.webChatProps) === null || _defaultWebChatContai3 === void 0 ? void 0 : _defaultWebChatContai3.typingIndicatorMiddleware,
179
+ groupActivitiesMiddleware: (_props$webChatContain21 = props.webChatContainerProps) !== null && _props$webChatContain21 !== void 0 && (_props$webChatContain22 = _props$webChatContain21.renderingMiddlewareProps) !== null && _props$webChatContain22 !== void 0 && _props$webChatContain22.disableGroupActivitiesMiddleware ? undefined : (_defaultWebChatContai = defaultWebChatContainerStatefulProps.webChatProps) === null || _defaultWebChatContai === void 0 ? void 0 : _defaultWebChatContai.groupActivitiesMiddleware,
180
+ typingIndicatorMiddleware: (_props$webChatContain23 = props.webChatContainerProps) !== null && _props$webChatContain23 !== void 0 && (_props$webChatContain24 = _props$webChatContain23.renderingMiddlewareProps) !== null && _props$webChatContain24 !== void 0 && _props$webChatContain24.disableTypingIndicatorMiddleware ? undefined : (_defaultWebChatContai2 = defaultWebChatContainerStatefulProps.webChatProps) === null || _defaultWebChatContai2 === void 0 ? void 0 : _defaultWebChatContai2.typingIndicatorMiddleware,
172
181
  onTelemetry: createWebChatTelemetry(),
173
182
  cardActionMiddleware: createCardActionMiddleware(((_props$webChatContain25 = props.webChatContainerProps) === null || _props$webChatContain25 === void 0 ? void 0 : _props$webChatContain25.botMagicCode) || undefined),
174
183
  sendTypingIndicator: true,
@@ -149,7 +149,7 @@ const getPostChatContext = async (facadeChatSDK, state, dispatch) => {
149
149
  if ((state === null || state === void 0 ? void 0 : (_state$domainStates2 = state.domainStates) === null || _state$domainStates2 === void 0 ? void 0 : _state$domainStates2.postChatContext) === undefined) {
150
150
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
151
151
  const context = await facadeChatSDK.getPostChatSurveyContext();
152
- TelemetryHelper.logSDKEventToAllTelemetry(LogLevel.INFO, {
152
+ TelemetryHelper.logSDKEvent(LogLevel.INFO, {
153
153
  Event: TelemetryEvent.PostChatContextCallSucceed,
154
154
  Description: PostChatSurveyTelemetryMessage.PostChatContextCallSucceed
155
155
  });
@@ -167,7 +167,7 @@ const getPostChatContext = async (facadeChatSDK, state, dispatch) => {
167
167
  }
168
168
  }
169
169
  } catch (error) {
170
- TelemetryHelper.logSDKEventToAllTelemetry(LogLevel.ERROR, {
170
+ TelemetryHelper.logSDKEvent(LogLevel.ERROR, {
171
171
  Event: TelemetryEvent.PostChatContextCallFailed,
172
172
  Description: PostChatSurveyTelemetryMessage.PostChatContextCallFailed,
173
173
  ExceptionDetails: {
@@ -19,13 +19,13 @@ export const setPostChatContextAndLoadSurvey = async (facadeChatSDK, dispatch, p
19
19
  const postChatEnabled = postChatConfig.postChatEnabled;
20
20
  if (postChatEnabled) {
21
21
  if (!persistedChat) {
22
- TelemetryHelper.logSDKEventToAllTelemetry(LogLevel.INFO, {
22
+ TelemetryHelper.logSDKEvent(LogLevel.INFO, {
23
23
  Event: TelemetryEvent.PostChatContextCallStarted,
24
24
  Description: PostChatSurveyTelemetryMessage.PostChatContextCallStarted
25
25
  });
26
26
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
27
27
  const context = await facadeChatSDK.getPostChatSurveyContext();
28
- TelemetryHelper.logSDKEventToAllTelemetry(LogLevel.INFO, {
28
+ TelemetryHelper.logSDKEvent(LogLevel.INFO, {
29
29
  Event: TelemetryEvent.PostChatContextCallSucceed,
30
30
  Description: PostChatSurveyTelemetryMessage.PostChatContextCallSucceed
31
31
  });
@@ -42,7 +42,7 @@ export const setPostChatContextAndLoadSurvey = async (facadeChatSDK, dispatch, p
42
42
  }
43
43
  }
44
44
  } catch (ex) {
45
- TelemetryHelper.logSDKEventToAllTelemetry(LogLevel.ERROR, {
45
+ TelemetryHelper.logSDKEvent(LogLevel.ERROR, {
46
46
  Event: TelemetryEvent.PostChatContextCallFailed,
47
47
  Description: PostChatSurveyTelemetryMessage.PostChatContextCallFailed,
48
48
  ExceptionDetails: {
@@ -1,9 +1,9 @@
1
- import { BroadcastEvent, LogLevel, TelemetryEvent } from "../../../common/telemetry/TelemetryConstants";
1
+ import { BroadcastEvent, ConversationStage, LogLevel, TelemetryEvent } from "../../../common/telemetry/TelemetryConstants";
2
2
  import { Constants, LiveWorkItemState, WidgetLoadTelemetryMessage } from "../../../common/Constants";
3
3
  import { TelemetryManager, TelemetryTimers } from "../../../common/telemetry/TelemetryManager";
4
4
  import { checkContactIdError, createTimer, getConversationDetailsCall, getStateFromCache, getWidgetCacheIdfromProps, isNullOrEmptyString, isNullOrUndefined, isUndefinedOrEmpty } from "../../../common/utils";
5
5
  import { handleChatReconnect, isPersistentEnabled, isReconnectEnabled } from "./reconnectChatHelper";
6
- import { handleStartChatError, logWidgetLoadComplete } from "./startChatErrorHandler";
6
+ import { handleStartChatError, logStartChatComplete, logWidgetLoadComplete } from "./startChatErrorHandler";
7
7
  import { ActivityStreamHandler } from "./ActivityStreamHandler";
8
8
  import { BroadcastService } from "@microsoft/omnichannel-chat-components";
9
9
  import { ConversationState } from "../../../contexts/common/ConversationState";
@@ -174,7 +174,10 @@ const initStartChat = async (facadeChatSDK, dispatch, setAdapter, state, props,
174
174
  TelemetryTimers.WidgetLoadTimer = createTimer();
175
175
  TelemetryHelper.logLoadingEventToAllTelemetry(LogLevel.INFO, {
176
176
  Event: TelemetryEvent.WidgetLoadStarted,
177
- Description: "Widget start chat started."
177
+ Description: "Widget start chat started.",
178
+ CustomProperties: {
179
+ ConversationStage: ConversationStage.Initialization
180
+ }
178
181
  });
179
182
 
180
183
  //Check if chat retrieved from cache
@@ -202,6 +205,7 @@ const initStartChat = async (facadeChatSDK, dispatch, setAdapter, state, props,
202
205
  const startTime = new Date().getTime();
203
206
  createTrackingForFirstMessage();
204
207
  await facadeChatSDK.startChat(startChatOptionalParams);
208
+ logStartChatComplete();
205
209
  isStartChatSuccessful = true;
206
210
  await createAdapterAndSubscribe(facadeChatSDK, dispatch, setAdapter, startTime, props);
207
211
  } catch (error) {