@microsoft/omnichannel-chat-widget 1.8.3 → 1.8.4-main.7bdb634
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/lib/cjs/common/Constants.js +4 -0
- package/lib/cjs/common/facades/FacadeChatSDK.js +6 -0
- package/lib/cjs/common/telemetry/TelemetryConstants.js +31 -0
- package/lib/cjs/common/utils/SecureEventBus.js +307 -0
- package/lib/cjs/common/utils/dispatchCustomEvent.js +25 -0
- 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 +284 -0
- package/lib/cjs/components/livechatwidget/common/createAdapter.js +2 -0
- package/lib/cjs/components/livechatwidget/common/defaultProps/defaultPersistentChatHistoryProps.js +18 -0
- package/lib/cjs/components/livechatwidget/common/endChat.js +7 -1
- package/lib/cjs/components/livechatwidget/common/initWebChatComposer.js +7 -5
- package/lib/cjs/components/livechatwidget/interfaces/IPersistentChatHistoryProps.js +1 -0
- package/lib/cjs/components/webchatcontainerstateful/WebChatContainerStateful.js +31 -5
- 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 +97 -0
- package/lib/cjs/components/webchatcontainerstateful/common/defaultProps/defaultMiddlewareLocalizedTexts.js +2 -1
- package/lib/cjs/components/webchatcontainerstateful/common/defaultProps/defaultWebChatStatefulProps.js +1 -1
- package/lib/cjs/components/webchatcontainerstateful/hooks/usePersistentChatHistory.js +59 -0
- package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/WebChatEventSubscribers.js +122 -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 +18 -0
- package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activities/LazyLoadActivity.js +1038 -0
- package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activities/LoadInlineBannerActivity.js +34 -0
- package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityMiddleware.js +44 -0
- 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 +4 -3
- package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/timestamps/SendingTimestamp.js +2 -2
- package/lib/esm/common/Constants.js +4 -0
- package/lib/esm/common/facades/FacadeChatSDK.js +6 -0
- package/lib/esm/common/telemetry/TelemetryConstants.js +31 -0
- package/lib/esm/common/utils/SecureEventBus.js +328 -0
- package/lib/esm/common/utils/dispatchCustomEvent.js +18 -0
- 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 +277 -0
- package/lib/esm/components/livechatwidget/common/createAdapter.js +2 -0
- package/lib/esm/components/livechatwidget/common/defaultProps/defaultPersistentChatHistoryProps.js +11 -0
- package/lib/esm/components/livechatwidget/common/endChat.js +7 -1
- package/lib/esm/components/livechatwidget/common/initWebChatComposer.js +7 -5
- package/lib/esm/components/livechatwidget/interfaces/IPersistentChatHistoryProps.js +1 -0
- package/lib/esm/components/webchatcontainerstateful/WebChatContainerStateful.js +34 -5
- 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 +90 -0
- package/lib/esm/components/webchatcontainerstateful/common/defaultProps/defaultMiddlewareLocalizedTexts.js +2 -1
- package/lib/esm/components/webchatcontainerstateful/common/defaultProps/defaultWebChatStatefulProps.js +2 -2
- package/lib/esm/components/webchatcontainerstateful/hooks/usePersistentChatHistory.js +51 -0
- package/lib/esm/components/webchatcontainerstateful/webchatcontroller/WebChatEventSubscribers.js +115 -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 +10 -0
- package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activities/LazyLoadActivity.js +1060 -0
- package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activities/LoadInlineBannerActivity.js +25 -0
- package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityMiddleware.js +42 -0
- 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 +2 -2
- package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/timestamps/SendingTimestamp.js +1 -1
- package/lib/types/common/Constants.d.ts +3 -0
- package/lib/types/common/facades/FacadeChatSDK.d.ts +3 -1
- package/lib/types/common/telemetry/TelemetryConstants.d.ts +30 -2
- package/lib/types/common/utils/SecureEventBus.d.ts +159 -0
- package/lib/types/common/utils/dispatchCustomEvent.d.ts +2 -0
- 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/interfaces/ILiveChatWidgetProps.d.ts +2 -0
- package/lib/types/components/livechatwidget/interfaces/IPersistentChatHistoryProps.d.ts +7 -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/webchatcontroller/WebChatEventSubscribers.d.ts +7 -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/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/contexts/common/ILiveChatWidgetLocalizedTexts.d.ts +1 -0
- package/package.json +2 -2
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { LogLevel, TelemetryEvent } from "../../../common/telemetry/TelemetryConstants";
|
|
2
|
+
import { useEffect, useRef } from "react";
|
|
3
|
+
import ChatWidgetEvents from "../../livechatwidget/common/ChatWidgetEvents";
|
|
4
|
+
import PersistentConversationHandler from "../../livechatwidget/common/PersistentConversationHandler";
|
|
5
|
+
import { TelemetryHelper } from "../../../common/telemetry/TelemetryHelper";
|
|
6
|
+
import dispatchCustomEvent from "../../../common/utils/dispatchCustomEvent";
|
|
7
|
+
import SecureEventBus from "../../../common/utils/SecureEventBus";
|
|
8
|
+
const usePersistentChatHistory = (facadeChatSDK, props) => {
|
|
9
|
+
const handlerRef = useRef(null);
|
|
10
|
+
useEffect(() => {
|
|
11
|
+
if (!facadeChatSDK) {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
TelemetryHelper.logLoadingEventToAllTelemetry(LogLevel.INFO, {
|
|
15
|
+
Event: TelemetryEvent.UXLCWPersistentChatHistoryInitialized,
|
|
16
|
+
Description: "Persistent chat history hook initialized"
|
|
17
|
+
});
|
|
18
|
+
handlerRef.current = new PersistentConversationHandler(facadeChatSDK, props);
|
|
19
|
+
const handler = async () => {
|
|
20
|
+
TelemetryHelper.logActionEventToAllTelemetry(LogLevel.INFO, {
|
|
21
|
+
Event: TelemetryEvent.LCWPersistentChatHistoryFetchStarted,
|
|
22
|
+
Description: "Persistent chat history fetch started"
|
|
23
|
+
});
|
|
24
|
+
try {
|
|
25
|
+
var _handlerRef$current;
|
|
26
|
+
await ((_handlerRef$current = handlerRef.current) === null || _handlerRef$current === void 0 ? void 0 : _handlerRef$current.pullHistory());
|
|
27
|
+
dispatchCustomEvent(ChatWidgetEvents.HIDE_LOADING_BANNER);
|
|
28
|
+
TelemetryHelper.logActionEventToAllTelemetry(LogLevel.INFO, {
|
|
29
|
+
Event: TelemetryEvent.LCWPersistentChatHistoryFetchCompleted,
|
|
30
|
+
Description: "Persistent chat history fetch completed successfully"
|
|
31
|
+
});
|
|
32
|
+
} catch (error) {
|
|
33
|
+
TelemetryHelper.logActionEventToAllTelemetry(LogLevel.ERROR, {
|
|
34
|
+
Event: TelemetryEvent.LCWPersistentChatHistoryFetchFailed,
|
|
35
|
+
Description: "Persistent chat history fetch failed",
|
|
36
|
+
ExceptionDetails: error
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
// Subscribe to the secure event bus instead of global window events
|
|
42
|
+
const eventBus = SecureEventBus.getInstance();
|
|
43
|
+
const unsubscribe = eventBus.subscribe(ChatWidgetEvents.FETCH_PERSISTENT_CHAT_HISTORY, handler);
|
|
44
|
+
return () => {
|
|
45
|
+
var _handlerRef$current2;
|
|
46
|
+
unsubscribe();
|
|
47
|
+
(_handlerRef$current2 = handlerRef.current) === null || _handlerRef$current2 === void 0 ? void 0 : _handlerRef$current2.destroy(); // Call destroy instead of reset to properly clean up
|
|
48
|
+
};
|
|
49
|
+
}, [facadeChatSDK]);
|
|
50
|
+
};
|
|
51
|
+
export default usePersistentChatHistory;
|
package/lib/esm/components/webchatcontainerstateful/webchatcontroller/WebChatEventSubscribers.js
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { LogLevel, TelemetryEvent } from "../../../common/telemetry/TelemetryConstants";
|
|
2
|
+
import { useEffect, useState } from "react";
|
|
3
|
+
import ChatWidgetEvents from "../../livechatwidget/common/ChatWidgetEvents";
|
|
4
|
+
import { Constants } from "../../../common/Constants";
|
|
5
|
+
import { TelemetryHelper } from "../../../common/telemetry/TelemetryHelper";
|
|
6
|
+
import { WebChatStoreLoader } from "./WebChatStoreLoader";
|
|
7
|
+
import { createTimer } from "../../../common/utils";
|
|
8
|
+
import dispatchCustomEvent from "../../../common/utils/dispatchCustomEvent";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Component to handle persistent chat history events.
|
|
12
|
+
* Uses WebChatStoreLoader instead of hooks to avoid context issues.
|
|
13
|
+
*/
|
|
14
|
+
const WebChatEventSubscribers = props => {
|
|
15
|
+
const [isConnected, setIsConnected] = useState(false);
|
|
16
|
+
const [storeReady, setStoreReady] = useState(false);
|
|
17
|
+
const storeWaitTimer = createTimer();
|
|
18
|
+
useEffect(() => {
|
|
19
|
+
if (!props.persistentChatHistoryEnabled) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
TelemetryHelper.logActionEventToAllTelemetry(LogLevel.INFO, {
|
|
23
|
+
Event: TelemetryEvent.LCWWebChatStorePollingStarted,
|
|
24
|
+
Description: "WebChat store polling started"
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
// Wait for WebChat store to be available
|
|
28
|
+
const waitForStore = () => {
|
|
29
|
+
if (WebChatStoreLoader.store) {
|
|
30
|
+
setStoreReady(true);
|
|
31
|
+
TelemetryHelper.logActionEventToAllTelemetry(LogLevel.INFO, {
|
|
32
|
+
Event: TelemetryEvent.LCWWebChatStoreReady,
|
|
33
|
+
Description: "WebChat store ready",
|
|
34
|
+
ElapsedTimeInMilliseconds: storeWaitTimer.milliSecondsElapsed
|
|
35
|
+
});
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
38
|
+
return false;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
// Check if store is already available
|
|
42
|
+
if (!waitForStore()) {
|
|
43
|
+
// Poll for store availability
|
|
44
|
+
const storeCheckInterval = setInterval(() => {
|
|
45
|
+
if (waitForStore()) {
|
|
46
|
+
clearInterval(storeCheckInterval);
|
|
47
|
+
}
|
|
48
|
+
}, 100);
|
|
49
|
+
return () => {
|
|
50
|
+
clearInterval(storeCheckInterval);
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
}, [props.persistentChatHistoryEnabled]);
|
|
54
|
+
useEffect(() => {
|
|
55
|
+
if (!props.persistentChatHistoryEnabled || !storeReady) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
const checkConnectionStatus = () => {
|
|
59
|
+
try {
|
|
60
|
+
if (WebChatStoreLoader.store) {
|
|
61
|
+
const state = WebChatStoreLoader.store.getState();
|
|
62
|
+
const connectivityStatus = state === null || state === void 0 ? void 0 : state.connectivityStatus;
|
|
63
|
+
const newIsConnected = connectivityStatus === "connected";
|
|
64
|
+
if (newIsConnected && !isConnected) {
|
|
65
|
+
setIsConnected(true);
|
|
66
|
+
TelemetryHelper.logActionEventToAllTelemetry(LogLevel.INFO, {
|
|
67
|
+
Event: TelemetryEvent.LCWWebChatConnected,
|
|
68
|
+
Description: "WebChat connection established, dispatching events"
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
// Dispatch events when connection is established
|
|
72
|
+
setTimeout(() => {
|
|
73
|
+
dispatchCustomEvent(ChatWidgetEvents.FETCH_PERSISTENT_CHAT_HISTORY);
|
|
74
|
+
dispatchCustomEvent(ChatWidgetEvents.ADD_ACTIVITY, {
|
|
75
|
+
activity: {
|
|
76
|
+
from: {
|
|
77
|
+
role: "bot"
|
|
78
|
+
},
|
|
79
|
+
timestamp: 0,
|
|
80
|
+
type: "message",
|
|
81
|
+
channelData: {
|
|
82
|
+
tags: [Constants.persistentChatHistoryMessagePullTriggerTag]
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
}, 2000);
|
|
87
|
+
} else if (!newIsConnected && isConnected) {
|
|
88
|
+
setIsConnected(false);
|
|
89
|
+
TelemetryHelper.logActionEventToAllTelemetry(LogLevel.WARN, {
|
|
90
|
+
Event: TelemetryEvent.LCWWebChatDisconnected,
|
|
91
|
+
Description: "WebChat connection lost"
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
} catch (error) {
|
|
96
|
+
TelemetryHelper.logActionEventToAllTelemetry(LogLevel.ERROR, {
|
|
97
|
+
Event: TelemetryEvent.LCWWebChatConnectionCheckFailed,
|
|
98
|
+
Description: "WebChat connection status check failed",
|
|
99
|
+
ExceptionDetails: error
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
// Check immediately
|
|
105
|
+
checkConnectionStatus();
|
|
106
|
+
|
|
107
|
+
// Set up interval to check connection status
|
|
108
|
+
const interval = setInterval(checkConnectionStatus, 1000);
|
|
109
|
+
return () => {
|
|
110
|
+
clearInterval(interval);
|
|
111
|
+
};
|
|
112
|
+
}, [isConnected, props.persistentChatHistoryEnabled, storeReady]);
|
|
113
|
+
return null;
|
|
114
|
+
};
|
|
115
|
+
export default WebChatEventSubscribers;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { defaultPersistentChatHistoryProps } from "../../../../../livechatwidget/common/defaultProps/defaultPersistentChatHistoryProps";
|
|
3
|
+
import { mergeStyles } from "@fluentui/react";
|
|
4
|
+
const ConversationDividerActivity = props => {
|
|
5
|
+
const styleApplied = mergeStyles(defaultPersistentChatHistoryProps.dividerActivityStyle, props.dividerActivityStyle);
|
|
6
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
7
|
+
className: styleApplied
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
export default ConversationDividerActivity;
|