@microsoft/omnichannel-chat-widget 1.8.3 → 1.8.4-main.21aec08
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +27 -0
- package/lib/cjs/common/Constants.js +7 -0
- package/lib/cjs/common/facades/FacadeChatSDK.js +6 -0
- package/lib/cjs/common/telemetry/AppInsightsEvents.js +14 -9
- package/lib/cjs/common/telemetry/TelemetryConstants.js +46 -2
- package/lib/cjs/common/telemetry/TelemetryManager.js +10 -7
- package/lib/cjs/common/telemetry/loggers/appInsightsLogger.js +29 -13
- package/lib/cjs/common/utils/SecureEventBus.js +307 -0
- package/lib/cjs/common/utils/dispatchCustomEvent.js +25 -0
- package/lib/cjs/common/utils.js +14 -1
- package/lib/cjs/components/chatbuttonstateful/ChatButtonStateful.js +16 -4
- package/lib/cjs/components/citationpanestateful/CitationPaneStateful.js +20 -1
- package/lib/cjs/components/headerstateful/HeaderStateful.js +8 -2
- package/lib/cjs/components/livechatwidget/common/ActivitySubscriber/AddActivitySubscriber.js +127 -0
- package/lib/cjs/components/livechatwidget/common/ChatWidgetEvents.js +15 -0
- package/lib/cjs/components/livechatwidget/common/PersistentConversationHandler.js +290 -0
- package/lib/cjs/components/livechatwidget/common/createAdapter.js +2 -0
- package/lib/cjs/components/livechatwidget/common/defaultProps/defaultPersistentChatHistoryProps.js +17 -0
- package/lib/cjs/components/livechatwidget/common/endChat.js +33 -10
- package/lib/cjs/components/livechatwidget/common/initWebChatComposer.js +16 -7
- package/lib/cjs/components/livechatwidget/common/liveChatConfigUtils.js +36 -4
- package/lib/cjs/components/livechatwidget/common/registerTelemetryLoggers.js +3 -0
- package/lib/cjs/components/livechatwidget/common/renderSurveyHelpers.js +2 -2
- package/lib/cjs/components/livechatwidget/common/setPostChatContextAndLoadSurvey.js +3 -3
- package/lib/cjs/components/livechatwidget/common/startChat.js +5 -1
- package/lib/cjs/components/livechatwidget/common/startChatErrorHandler.js +24 -4
- package/lib/cjs/components/livechatwidget/interfaces/IPersistentChatHistoryProps.js +1 -0
- package/lib/cjs/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +123 -28
- package/lib/cjs/components/postchatsurveypanestateful/PostChatSurveyPaneStateful.js +37 -8
- package/lib/cjs/components/prechatsurveypanestateful/PreChatSurveyPaneStateful.js +12 -3
- package/lib/cjs/components/webchatcontainerstateful/WebChatContainerStateful.js +46 -22
- package/lib/cjs/components/webchatcontainerstateful/common/activities/botActivity.js +14 -0
- package/lib/cjs/components/webchatcontainerstateful/common/activities/conversationDividerActivity.js +17 -0
- package/lib/cjs/components/webchatcontainerstateful/common/activityConverters/convertPersistentChatHistoryMessageToActivity.js +103 -0
- package/lib/cjs/components/webchatcontainerstateful/common/defaultProps/defaultMiddlewareLocalizedTexts.js +3 -1
- package/lib/cjs/components/webchatcontainerstateful/common/defaultProps/defaultWebChatStatefulProps.js +1 -1
- package/lib/cjs/components/webchatcontainerstateful/hooks/usePersistentChatHistory.js +57 -0
- package/lib/cjs/components/webchatcontainerstateful/interfaces/IExtendedChatConffig.js +1 -0
- package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/WebChatEventSubscribers.js +121 -0
- package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activities/Constants.js +10 -0
- package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activities/ConversationDividerActivity.js +47 -0
- package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activities/LazyLoadActivity.js +1058 -0
- package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activities/LoadInlineBannerActivity.js +34 -0
- package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityMiddleware.js +50 -1
- package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityStatusMiddleware.js +16 -2
- package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/defaultStyles/defaultInLineBannerStyle.js +20 -0
- package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/timestamps/DeliveredTimestamp.js +2 -2
- package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/timestamps/HistoryMessageTimestamp.js +59 -0
- package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/timestamps/NotDeliveredTimestamp.js +5 -3
- package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/timestamps/SendingTimestamp.js +2 -2
- package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/citationsMiddleware.js +6 -1
- package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/localizedStringsBotInitialsMiddleware.js +29 -7
- package/lib/cjs/contexts/common/LiveChatWidgetActionType.js +1 -0
- package/lib/cjs/contexts/common/LiveChatWidgetContextInitialState.js +7 -1
- package/lib/cjs/contexts/createReducer.js +15 -0
- package/lib/cjs/firstresponselatency/FirstMessageTrackerFromBot.js +3 -2
- package/lib/cjs/firstresponselatency/FirstResponseLatencyTracker.js +6 -2
- package/lib/cjs/plugins/newMessageEventHandler.js +4 -1
- package/lib/esm/common/Constants.js +7 -0
- package/lib/esm/common/facades/FacadeChatSDK.js +6 -0
- package/lib/esm/common/telemetry/AppInsightsEvents.js +14 -9
- package/lib/esm/common/telemetry/TelemetryConstants.js +44 -1
- package/lib/esm/common/telemetry/TelemetryManager.js +10 -7
- package/lib/esm/common/telemetry/loggers/appInsightsLogger.js +30 -14
- package/lib/esm/common/utils/SecureEventBus.js +328 -0
- package/lib/esm/common/utils/dispatchCustomEvent.js +18 -0
- package/lib/esm/common/utils.js +11 -0
- package/lib/esm/components/chatbuttonstateful/ChatButtonStateful.js +17 -5
- package/lib/esm/components/citationpanestateful/CitationPaneStateful.js +20 -1
- package/lib/esm/components/headerstateful/HeaderStateful.js +9 -3
- package/lib/esm/components/livechatwidget/common/ActivitySubscriber/AddActivitySubscriber.js +120 -0
- package/lib/esm/components/livechatwidget/common/ChatWidgetEvents.js +8 -0
- package/lib/esm/components/livechatwidget/common/PersistentConversationHandler.js +283 -0
- package/lib/esm/components/livechatwidget/common/createAdapter.js +2 -0
- package/lib/esm/components/livechatwidget/common/defaultProps/defaultPersistentChatHistoryProps.js +10 -0
- package/lib/esm/components/livechatwidget/common/endChat.js +33 -10
- package/lib/esm/components/livechatwidget/common/initWebChatComposer.js +16 -7
- package/lib/esm/components/livechatwidget/common/liveChatConfigUtils.js +33 -2
- package/lib/esm/components/livechatwidget/common/registerTelemetryLoggers.js +3 -0
- package/lib/esm/components/livechatwidget/common/renderSurveyHelpers.js +2 -2
- package/lib/esm/components/livechatwidget/common/setPostChatContextAndLoadSurvey.js +3 -3
- package/lib/esm/components/livechatwidget/common/startChat.js +7 -3
- package/lib/esm/components/livechatwidget/common/startChatErrorHandler.js +23 -4
- package/lib/esm/components/livechatwidget/interfaces/IPersistentChatHistoryProps.js +1 -0
- package/lib/esm/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +124 -29
- package/lib/esm/components/postchatsurveypanestateful/PostChatSurveyPaneStateful.js +39 -10
- package/lib/esm/components/prechatsurveypanestateful/PreChatSurveyPaneStateful.js +13 -4
- package/lib/esm/components/webchatcontainerstateful/WebChatContainerStateful.js +46 -22
- package/lib/esm/components/webchatcontainerstateful/common/activities/botActivity.js +7 -0
- package/lib/esm/components/webchatcontainerstateful/common/activities/conversationDividerActivity.js +9 -0
- package/lib/esm/components/webchatcontainerstateful/common/activityConverters/convertPersistentChatHistoryMessageToActivity.js +96 -0
- package/lib/esm/components/webchatcontainerstateful/common/defaultProps/defaultMiddlewareLocalizedTexts.js +3 -1
- package/lib/esm/components/webchatcontainerstateful/common/defaultProps/defaultWebChatStatefulProps.js +2 -2
- package/lib/esm/components/webchatcontainerstateful/hooks/usePersistentChatHistory.js +49 -0
- package/lib/esm/components/webchatcontainerstateful/interfaces/IExtendedChatConffig.js +1 -0
- package/lib/esm/components/webchatcontainerstateful/webchatcontroller/WebChatEventSubscribers.js +114 -0
- package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activities/Constants.js +3 -0
- package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activities/ConversationDividerActivity.js +39 -0
- package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activities/LazyLoadActivity.js +1080 -0
- package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activities/LoadInlineBannerActivity.js +25 -0
- package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityMiddleware.js +48 -1
- package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityStatusMiddleware.js +13 -0
- package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/defaultStyles/defaultInLineBannerStyle.js +13 -0
- package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/timestamps/DeliveredTimestamp.js +1 -1
- package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/timestamps/HistoryMessageTimestamp.js +52 -0
- package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/timestamps/NotDeliveredTimestamp.js +3 -2
- package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/timestamps/SendingTimestamp.js +1 -1
- package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/citationsMiddleware.js +6 -1
- package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/localizedStringsBotInitialsMiddleware.js +29 -7
- package/lib/esm/contexts/common/LiveChatWidgetActionType.js +1 -0
- package/lib/esm/contexts/common/LiveChatWidgetContextInitialState.js +7 -1
- package/lib/esm/contexts/createReducer.js +15 -0
- package/lib/esm/firstresponselatency/FirstMessageTrackerFromBot.js +3 -2
- package/lib/esm/firstresponselatency/FirstResponseLatencyTracker.js +6 -2
- package/lib/esm/plugins/newMessageEventHandler.js +4 -1
- package/lib/types/common/Constants.d.ts +6 -0
- package/lib/types/common/facades/FacadeChatSDK.d.ts +3 -1
- package/lib/types/common/telemetry/TelemetryConstants.d.ts +41 -2
- package/lib/types/common/telemetry/interfaces/IInternalTelemetryData.d.ts +1 -0
- package/lib/types/common/utils/SecureEventBus.d.ts +159 -0
- package/lib/types/common/utils/dispatchCustomEvent.d.ts +2 -0
- package/lib/types/common/utils.d.ts +9 -1
- package/lib/types/components/livechatwidget/common/ActivitySubscriber/AddActivitySubscriber.d.ts +45 -0
- package/lib/types/components/livechatwidget/common/ChatWidgetEvents.d.ts +7 -0
- package/lib/types/components/livechatwidget/common/PersistentConversationHandler.d.ts +28 -0
- package/lib/types/components/livechatwidget/common/defaultProps/defaultPersistentChatHistoryProps.d.ts +2 -0
- package/lib/types/components/livechatwidget/common/liveChatConfigUtils.d.ts +11 -0
- package/lib/types/components/livechatwidget/common/startChatErrorHandler.d.ts +1 -0
- package/lib/types/components/livechatwidget/interfaces/ILiveChatWidgetProps.d.ts +2 -0
- package/lib/types/components/livechatwidget/interfaces/IPersistentChatHistoryProps.d.ts +11 -0
- package/lib/types/components/webchatcontainerstateful/common/activities/botActivity.d.ts +7 -0
- package/lib/types/components/webchatcontainerstateful/common/activities/conversationDividerActivity.d.ts +10 -0
- package/lib/types/components/webchatcontainerstateful/common/activityConverters/convertPersistentChatHistoryMessageToActivity.d.ts +2 -0
- package/lib/types/components/webchatcontainerstateful/hooks/usePersistentChatHistory.d.ts +4 -0
- package/lib/types/components/webchatcontainerstateful/interfaces/IExtendedChatConffig.d.ts +15 -0
- package/lib/types/components/webchatcontainerstateful/webchatcontroller/WebChatEventSubscribers.d.ts +6 -0
- package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activities/Constants.d.ts +3 -0
- package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activities/ConversationDividerActivity.d.ts +4 -0
- package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activities/LazyLoadActivity.d.ts +326 -0
- package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activities/LoadInlineBannerActivity.d.ts +8 -0
- package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityMiddleware.d.ts +2 -1
- package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityStatusMiddleware.d.ts +1 -0
- package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/defaultStyles/defaultInLineBannerStyle.d.ts +2 -0
- package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/timestamps/HistoryMessageTimestamp.d.ts +2 -0
- package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/localizedStringsBotInitialsMiddleware.d.ts +1 -1
- package/lib/types/contexts/common/ILiveChatWidgetContext.d.ts +1 -0
- package/lib/types/contexts/common/ILiveChatWidgetLocalizedTexts.d.ts +6 -0
- package/lib/types/contexts/common/LiveChatWidgetActionType.d.ts +2 -1
- package/package.json +3 -3
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { LogLevel, TelemetryEvent } from "../../common/telemetry/TelemetryConstants";
|
|
1
|
+
import { ConversationStage, LogLevel, TelemetryEvent } from "../../common/telemetry/TelemetryConstants";
|
|
2
2
|
import React, { useEffect, useRef, useState } from "react";
|
|
3
3
|
import { ConfirmationState } from "../../common/Constants";
|
|
4
4
|
import { ConversationState } from "../../contexts/common/ConversationState";
|
|
@@ -61,7 +61,10 @@ export const HeaderStateful = props => {
|
|
|
61
61
|
var _props$headerProps, _props$headerProps$co, _props$headerProps$co2;
|
|
62
62
|
TelemetryHelper.logActionEventToAllTelemetry(LogLevel.INFO, {
|
|
63
63
|
Event: TelemetryEvent.HeaderCloseButtonClicked,
|
|
64
|
-
Description: "Header Close action started."
|
|
64
|
+
Description: "Header Close action started.",
|
|
65
|
+
CustomProperties: {
|
|
66
|
+
ConversationStage: ConversationStage.ConversationEnd
|
|
67
|
+
}
|
|
65
68
|
});
|
|
66
69
|
if (localConfirmationPaneState.current !== ConfirmationState.Ok) {
|
|
67
70
|
dispatch({
|
|
@@ -76,7 +79,10 @@ export const HeaderStateful = props => {
|
|
|
76
79
|
}
|
|
77
80
|
TelemetryHelper.logActionEventToAllTelemetry(LogLevel.INFO, {
|
|
78
81
|
Event: TelemetryEvent.CloseChatActionCompleted,
|
|
79
|
-
Description: "Header Close action completed."
|
|
82
|
+
Description: "Header Close action completed.",
|
|
83
|
+
CustomProperties: {
|
|
84
|
+
ConversationStage: ConversationStage.ConversationEnd
|
|
85
|
+
}
|
|
80
86
|
});
|
|
81
87
|
const closeButtonId = ((_props$headerProps = props.headerProps) === null || _props$headerProps === void 0 ? void 0 : (_props$headerProps$co = _props$headerProps.controlProps) === null || _props$headerProps$co === void 0 ? void 0 : (_props$headerProps$co2 = _props$headerProps$co.closeButtonProps) === null || _props$headerProps$co2 === void 0 ? void 0 : _props$headerProps$co2.id) ?? `${controlProps.id}-close-button`;
|
|
82
88
|
if (closeButtonId) {
|
|
@@ -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["HISTORY_LOAD_ERROR"] = "CHAT_WIDGET/HISTORY_LOAD_ERROR";
|
|
7
|
+
})(ChatWidgetEvents || (ChatWidgetEvents = {}));
|
|
8
|
+
export default ChatWidgetEvents;
|
|
@@ -0,0 +1,283 @@
|
|
|
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", defaultPersistentChatHistoryProps.pageSize);
|
|
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: defaultPersistentChatHistoryProps.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 a number then default to defaultPersistentChatHistoryProps.pageSize
|
|
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 : defaultPersistentChatHistoryProps.pageSize;
|
|
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
|
+
|
|
105
|
+
// Handle error case - null indicates an error occurred
|
|
106
|
+
// Don't mark as last pull to allow retry on next attempt
|
|
107
|
+
if (messages == null) {
|
|
108
|
+
TelemetryHelper.logActionEvent(LogLevel.WARN, {
|
|
109
|
+
Event: TelemetryEvent.LCWPersistentHistoryReturnedNull,
|
|
110
|
+
Description: "History pull returned null - Possible error occurred, will retry on next scroll",
|
|
111
|
+
ElapsedTimeInMilliseconds: pullTimer.milliSecondsElapsed
|
|
112
|
+
});
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// Handle legitimate end of history - empty array
|
|
117
|
+
if (messages.length === 0) {
|
|
118
|
+
this.isLastPull = true;
|
|
119
|
+
// Dispatch event to notify UI that no more history is available
|
|
120
|
+
dispatchCustomEvent(ChatWidgetEvents.NO_MORE_HISTORY_AVAILABLE);
|
|
121
|
+
TelemetryHelper.logActionEvent(LogLevel.INFO, {
|
|
122
|
+
Event: TelemetryEvent.LCWPersistentHistoryPullCompleted,
|
|
123
|
+
Description: "History pull completed - no more messages",
|
|
124
|
+
ElapsedTimeInMilliseconds: pullTimer.milliSecondsElapsed
|
|
125
|
+
});
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
const messagesDescOrder = (_ref = [...messages]) === null || _ref === void 0 ? void 0 : _ref.reverse();
|
|
129
|
+
this.processHistoryMessages(messagesDescOrder);
|
|
130
|
+
TelemetryHelper.logActionEvent(LogLevel.INFO, {
|
|
131
|
+
Event: TelemetryEvent.LCWPersistentHistoryPullCompleted,
|
|
132
|
+
Description: "History pull completed successfully",
|
|
133
|
+
ElapsedTimeInMilliseconds: pullTimer.milliSecondsElapsed,
|
|
134
|
+
CustomProperties: {
|
|
135
|
+
messageCount: messages.length,
|
|
136
|
+
totalProcessed: this.count
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
} finally {
|
|
140
|
+
// Always clear the pulling flag when done
|
|
141
|
+
this.isCurrentlyPulling = false;
|
|
142
|
+
|
|
143
|
+
// Remove pageToken from transit set if it was added
|
|
144
|
+
if (this.pageToken) {
|
|
145
|
+
this.pageTokenInTransitSet.delete(this.pageToken);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
151
|
+
}, {
|
|
152
|
+
key: "processHistoryMessages",
|
|
153
|
+
value: function processHistoryMessages(messagesDescOrder) {
|
|
154
|
+
for (const message of messagesDescOrder) {
|
|
155
|
+
try {
|
|
156
|
+
const activity = this.processMessageToActivity(message);
|
|
157
|
+
if (activity) {
|
|
158
|
+
dispatchCustomEvent(ChatWidgetEvents.ADD_ACTIVITY, {
|
|
159
|
+
activity
|
|
160
|
+
});
|
|
161
|
+
const dividerActivity = this.createDividerActivity(activity);
|
|
162
|
+
if (dividerActivity) {
|
|
163
|
+
dispatchCustomEvent(ChatWidgetEvents.ADD_ACTIVITY, {
|
|
164
|
+
activity: dividerActivity
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
this.lastMessage = activity;
|
|
168
|
+
}
|
|
169
|
+
} catch (error) {
|
|
170
|
+
TelemetryHelper.logActionEvent(LogLevel.ERROR, {
|
|
171
|
+
Event: TelemetryEvent.ConvertPersistentChatHistoryMessageToActivityFailed,
|
|
172
|
+
ExceptionDetails: error
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
179
|
+
}, {
|
|
180
|
+
key: "fetchHistoryMessages",
|
|
181
|
+
value: async function fetchHistoryMessages() {
|
|
182
|
+
if (!this.shouldPull()) {
|
|
183
|
+
// Dispatch event to ensure banner is hidden when no more pulls are needed
|
|
184
|
+
dispatchCustomEvent(ChatWidgetEvents.NO_MORE_HISTORY_AVAILABLE);
|
|
185
|
+
return [];
|
|
186
|
+
}
|
|
187
|
+
const options = {
|
|
188
|
+
pageSize: this.pageSize,
|
|
189
|
+
pageToken: this.pageToken || undefined
|
|
190
|
+
};
|
|
191
|
+
try {
|
|
192
|
+
var _this$facadeChatSDK;
|
|
193
|
+
const response = await ((_this$facadeChatSDK = this.facadeChatSDK) === null || _this$facadeChatSDK === void 0 ? void 0 : _this$facadeChatSDK.fetchPersistentConversationHistory(options));
|
|
194
|
+
const {
|
|
195
|
+
chatMessages: messages,
|
|
196
|
+
nextPageToken: pageToken
|
|
197
|
+
} = response;
|
|
198
|
+
this.pageToken = pageToken || null;
|
|
199
|
+
if (pageToken === null) {
|
|
200
|
+
this.isLastPull = true;
|
|
201
|
+
// Dispatch event when we reach the end of available history
|
|
202
|
+
dispatchCustomEvent(ChatWidgetEvents.NO_MORE_HISTORY_AVAILABLE);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
// if chatMessages is null, return empty array
|
|
206
|
+
if (!messages) {
|
|
207
|
+
this.isLastPull = true;
|
|
208
|
+
// Dispatch event when we reach the end of available history
|
|
209
|
+
dispatchCustomEvent(ChatWidgetEvents.NO_MORE_HISTORY_AVAILABLE);
|
|
210
|
+
return [];
|
|
211
|
+
}
|
|
212
|
+
return messages;
|
|
213
|
+
} catch (error) {
|
|
214
|
+
TelemetryHelper.logSDKEvent(LogLevel.ERROR, {
|
|
215
|
+
Event: TelemetryEvent.FetchPersistentChatHistoryFailed,
|
|
216
|
+
ExceptionDetails: error
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
// On error, dispatch HISTORY_LOAD_ERROR to hide loading banner without marking conversation as ended
|
|
220
|
+
// This allows recovery on the next attempt (e.g., transient network errors)
|
|
221
|
+
// Return null to distinguish error from legitimate empty history
|
|
222
|
+
dispatchCustomEvent(ChatWidgetEvents.HISTORY_LOAD_ERROR);
|
|
223
|
+
return null;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
}, {
|
|
227
|
+
key: "shouldPull",
|
|
228
|
+
value: function shouldPull() {
|
|
229
|
+
return !this.isLastPull;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
233
|
+
}, {
|
|
234
|
+
key: "processMessageToActivity",
|
|
235
|
+
value: function processMessageToActivity(message) {
|
|
236
|
+
try {
|
|
237
|
+
const activity = convertPersistentChatHistoryMessageToActivity(message);
|
|
238
|
+
activity.id = activity.id || `activity-${this.count}`;
|
|
239
|
+
activity.channelData = {
|
|
240
|
+
...activity.channelData,
|
|
241
|
+
metadata: {
|
|
242
|
+
count: this.count
|
|
243
|
+
}
|
|
244
|
+
};
|
|
245
|
+
|
|
246
|
+
// Increment the count after assigning it to the activity
|
|
247
|
+
this.count += 1;
|
|
248
|
+
return activity;
|
|
249
|
+
} catch (error) {
|
|
250
|
+
TelemetryHelper.logActionEvent(LogLevel.ERROR, {
|
|
251
|
+
Event: TelemetryEvent.ConvertPersistentChatHistoryMessageToActivityFailed,
|
|
252
|
+
ExceptionDetails: error
|
|
253
|
+
});
|
|
254
|
+
throw error;
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
259
|
+
}, {
|
|
260
|
+
key: "createDividerActivity",
|
|
261
|
+
value: function createDividerActivity(activity) {
|
|
262
|
+
var _this$lastMessage, _this$lastMessage$cha;
|
|
263
|
+
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) {
|
|
264
|
+
const rawSequenceId = activity.channelData["webchat:sequence-id"];
|
|
265
|
+
const sequenceId = typeof rawSequenceId === "number" && !isNaN(rawSequenceId) ? rawSequenceId + 1 : 1;
|
|
266
|
+
const timestamp = new Date(activity.timestamp).getTime() + 1;
|
|
267
|
+
return {
|
|
268
|
+
...conversationDividerActivity,
|
|
269
|
+
channelData: {
|
|
270
|
+
...conversationDividerActivity.channelData,
|
|
271
|
+
conversationId: activity.channelData.conversationId,
|
|
272
|
+
"webchat:sequence-id": sequenceId
|
|
273
|
+
},
|
|
274
|
+
timestamp: new Date(timestamp).toISOString(),
|
|
275
|
+
identifier: `divider-${activity.channelData.conversationId}`
|
|
276
|
+
};
|
|
277
|
+
}
|
|
278
|
+
return null;
|
|
279
|
+
}
|
|
280
|
+
}]);
|
|
281
|
+
return PersistentConversationHandler;
|
|
282
|
+
}();
|
|
283
|
+
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
|
|
@@ -4,7 +4,10 @@ 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";
|
|
9
|
+
import { NotificationHandler } from "../../webchatcontainerstateful/webchatcontroller/notification/NotificationHandler";
|
|
10
|
+
import { NotificationScenarios } from "../../webchatcontainerstateful/webchatcontroller/enums/NotificationScenarios";
|
|
8
11
|
import { TelemetryHelper } from "../../../common/telemetry/TelemetryHelper";
|
|
9
12
|
import { TelemetryManager } from "../../../common/telemetry/TelemetryManager";
|
|
10
13
|
import { WebChatStoreLoader } from "../../webchatcontainerstateful/webchatcontroller/WebChatStoreLoader";
|
|
@@ -194,6 +197,18 @@ const endChat = async (props, facadeChatSDK, state, dispatch, setAdapter, setWeb
|
|
|
194
197
|
facadeChatSDK.destroy();
|
|
195
198
|
}
|
|
196
199
|
}
|
|
200
|
+
|
|
201
|
+
//moving logic below to before processing skipCloseChat logic to avoid race conditions of postMessage for endChatEvent for other tabs vs postMessage for CloseChat
|
|
202
|
+
//TODO: clarify if this postMessageToOtherTab actually works in production.
|
|
203
|
+
if (postMessageToOtherTab) {
|
|
204
|
+
const endChatEventName = await getEndChatEventName(facadeChatSDK, props);
|
|
205
|
+
BroadcastService.postMessage({
|
|
206
|
+
eventName: endChatEventName,
|
|
207
|
+
payload: {
|
|
208
|
+
runtimeId: TelemetryManager.InternalTelemetryData.lcwRuntimeId
|
|
209
|
+
}
|
|
210
|
+
});
|
|
211
|
+
}
|
|
197
212
|
if (!skipCloseChat) {
|
|
198
213
|
try {
|
|
199
214
|
var _props$webChatContain;
|
|
@@ -225,20 +240,25 @@ const endChat = async (props, facadeChatSDK, state, dispatch, setAdapter, setWeb
|
|
|
225
240
|
type: LiveChatWidgetActionType.SET_POST_CHAT_CONTEXT,
|
|
226
241
|
payload: undefined
|
|
227
242
|
});
|
|
228
|
-
|
|
243
|
+
|
|
244
|
+
// Call direct reset to ensure LazyLoadHandler gets reset regardless of broadcast timing
|
|
245
|
+
LazyLoadHandler.directReset();
|
|
246
|
+
BroadcastService.postMessage({
|
|
247
|
+
eventName: BroadcastEvent.PersistentConversationReset
|
|
248
|
+
});
|
|
229
249
|
closeChatWidget(dispatch, setWebChatStyles, props);
|
|
230
250
|
facadeChatSDK.destroy();
|
|
251
|
+
|
|
252
|
+
//always post the close chat event after chat closed and cleanup completed
|
|
253
|
+
BroadcastService.postMessage({
|
|
254
|
+
eventName: BroadcastEvent.CloseChat
|
|
255
|
+
});
|
|
256
|
+
TelemetryHelper.logActionEvent(LogLevel.INFO, {
|
|
257
|
+
Event: TelemetryEvent.CloseChatCall,
|
|
258
|
+
Description: "Broadcasted close chat event"
|
|
259
|
+
});
|
|
231
260
|
}
|
|
232
261
|
}
|
|
233
|
-
if (postMessageToOtherTab) {
|
|
234
|
-
const endChatEventName = await getEndChatEventName(facadeChatSDK, props);
|
|
235
|
-
BroadcastService.postMessage({
|
|
236
|
-
eventName: endChatEventName,
|
|
237
|
-
payload: {
|
|
238
|
-
runtimeId: TelemetryManager.InternalTelemetryData.lcwRuntimeId
|
|
239
|
-
}
|
|
240
|
-
});
|
|
241
|
-
}
|
|
242
262
|
};
|
|
243
263
|
export const callingStateCleanUp = dispatch => {
|
|
244
264
|
dispatch({
|
|
@@ -316,6 +336,9 @@ export const closeChatStateCleanUp = dispatch => {
|
|
|
316
336
|
payload: {}
|
|
317
337
|
});
|
|
318
338
|
|
|
339
|
+
// Dismiss the chat disconnect notification banner if it was shown
|
|
340
|
+
NotificationHandler.dismissNotification(NotificationScenarios.ChatDisconnect);
|
|
341
|
+
|
|
319
342
|
// Clear live chat context only if chat widget is fully closed to support transcript calls after sessionclose is called
|
|
320
343
|
dispatch({
|
|
321
344
|
type: LiveChatWidgetActionType.SET_LIVE_CHAT_CONTEXT,
|
|
@@ -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,
|
|
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(),
|
|
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 : (
|
|
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 : (
|
|
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 : (
|
|
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,
|