@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,277 @@
|
|
|
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
|
+
this.appliedProps = {
|
|
53
|
+
...defaultPersistentChatHistoryProps,
|
|
54
|
+
...props
|
|
55
|
+
};
|
|
56
|
+
this.pageSize = this.appliedProps.pageSize || 4;
|
|
57
|
+
}
|
|
58
|
+
}, {
|
|
59
|
+
key: "reset",
|
|
60
|
+
value: function reset() {
|
|
61
|
+
this.isLastPull = false;
|
|
62
|
+
this.pageToken = null;
|
|
63
|
+
this.lastMessage = null;
|
|
64
|
+
this.count = 0;
|
|
65
|
+
this.isCurrentlyPulling = false;
|
|
66
|
+
this.pageTokenInTransitSet.clear();
|
|
67
|
+
}
|
|
68
|
+
}, {
|
|
69
|
+
key: "destroy",
|
|
70
|
+
value: function destroy() {
|
|
71
|
+
// Only unsubscribe when the handler is being destroyed completely
|
|
72
|
+
this.resetEventListener.unsubscribe();
|
|
73
|
+
}
|
|
74
|
+
}, {
|
|
75
|
+
key: "pullHistory",
|
|
76
|
+
value: async function pullHistory() {
|
|
77
|
+
const pullTimer = createTimer();
|
|
78
|
+
|
|
79
|
+
// Prevent concurrent pulls regardless of pageToken
|
|
80
|
+
if (this.isCurrentlyPulling) {
|
|
81
|
+
TelemetryHelper.logActionEvent(LogLevel.WARN, {
|
|
82
|
+
Event: TelemetryEvent.LCWPersistentHistoryPullBlocked,
|
|
83
|
+
Description: "History pull blocked - already in progress"
|
|
84
|
+
});
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// Additional check for specific pageToken duplicates
|
|
89
|
+
if (this.pageToken && this.pageTokenInTransitSet.has(this.pageToken)) {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// Mark as currently pulling
|
|
94
|
+
this.isCurrentlyPulling = true;
|
|
95
|
+
if (this.pageToken) {
|
|
96
|
+
this.pageTokenInTransitSet.add(this.pageToken);
|
|
97
|
+
}
|
|
98
|
+
try {
|
|
99
|
+
var _ref;
|
|
100
|
+
const messages = await this.fetchHistoryMessages();
|
|
101
|
+
if (messages === null || (messages === null || messages === void 0 ? void 0 : messages.length) === 0) {
|
|
102
|
+
this.isLastPull = true;
|
|
103
|
+
// Dispatch event to notify UI that no more history is available
|
|
104
|
+
dispatchCustomEvent(ChatWidgetEvents.NO_MORE_HISTORY_AVAILABLE);
|
|
105
|
+
// Also hide the loading banner
|
|
106
|
+
dispatchCustomEvent(ChatWidgetEvents.HIDE_LOADING_BANNER);
|
|
107
|
+
TelemetryHelper.logActionEvent(LogLevel.INFO, {
|
|
108
|
+
Event: TelemetryEvent.LCWPersistentHistoryPullCompleted,
|
|
109
|
+
Description: "History pull completed - no more messages",
|
|
110
|
+
ElapsedTimeInMilliseconds: pullTimer.milliSecondsElapsed
|
|
111
|
+
});
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
const messagesDescOrder = (_ref = [...messages]) === null || _ref === void 0 ? void 0 : _ref.reverse();
|
|
115
|
+
this.processHistoryMessages(messagesDescOrder);
|
|
116
|
+
|
|
117
|
+
// Dispatch event to hide the loading banner after messages are processed
|
|
118
|
+
dispatchCustomEvent(ChatWidgetEvents.HIDE_LOADING_BANNER);
|
|
119
|
+
TelemetryHelper.logActionEvent(LogLevel.INFO, {
|
|
120
|
+
Event: TelemetryEvent.LCWPersistentHistoryPullCompleted,
|
|
121
|
+
Description: "History pull completed successfully",
|
|
122
|
+
ElapsedTimeInMilliseconds: pullTimer.milliSecondsElapsed,
|
|
123
|
+
CustomProperties: {
|
|
124
|
+
messageCount: messages.length,
|
|
125
|
+
totalProcessed: this.count
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
} finally {
|
|
129
|
+
// Always clear the pulling flag when done
|
|
130
|
+
this.isCurrentlyPulling = false;
|
|
131
|
+
|
|
132
|
+
// Remove pageToken from transit set if it was added
|
|
133
|
+
if (this.pageToken) {
|
|
134
|
+
this.pageTokenInTransitSet.delete(this.pageToken);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
140
|
+
}, {
|
|
141
|
+
key: "processHistoryMessages",
|
|
142
|
+
value: function processHistoryMessages(messagesDescOrder) {
|
|
143
|
+
for (const message of messagesDescOrder) {
|
|
144
|
+
try {
|
|
145
|
+
const activity = this.processMessageToActivity(message);
|
|
146
|
+
if (activity) {
|
|
147
|
+
dispatchCustomEvent(ChatWidgetEvents.ADD_ACTIVITY, {
|
|
148
|
+
activity
|
|
149
|
+
});
|
|
150
|
+
const dividerActivity = this.createDividerActivity(activity);
|
|
151
|
+
if (dividerActivity) {
|
|
152
|
+
dispatchCustomEvent(ChatWidgetEvents.ADD_ACTIVITY, {
|
|
153
|
+
activity: dividerActivity
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
this.lastMessage = activity;
|
|
157
|
+
}
|
|
158
|
+
} catch (error) {
|
|
159
|
+
TelemetryHelper.logActionEvent(LogLevel.ERROR, {
|
|
160
|
+
Event: TelemetryEvent.ConvertPersistentChatHistoryMessageToActivityFailed,
|
|
161
|
+
ExceptionDetails: error
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
168
|
+
}, {
|
|
169
|
+
key: "fetchHistoryMessages",
|
|
170
|
+
value: async function fetchHistoryMessages() {
|
|
171
|
+
if (!this.shouldPull()) {
|
|
172
|
+
// Dispatch event to ensure banner is hidden when no more pulls are needed
|
|
173
|
+
dispatchCustomEvent(ChatWidgetEvents.NO_MORE_HISTORY_AVAILABLE);
|
|
174
|
+
dispatchCustomEvent(ChatWidgetEvents.HIDE_LOADING_BANNER);
|
|
175
|
+
return [];
|
|
176
|
+
}
|
|
177
|
+
const options = {
|
|
178
|
+
pageSize: this.pageSize,
|
|
179
|
+
pageToken: this.pageToken || undefined
|
|
180
|
+
};
|
|
181
|
+
try {
|
|
182
|
+
var _this$facadeChatSDK;
|
|
183
|
+
const response = await ((_this$facadeChatSDK = this.facadeChatSDK) === null || _this$facadeChatSDK === void 0 ? void 0 : _this$facadeChatSDK.fetchPersistentConversationHistory(options));
|
|
184
|
+
const {
|
|
185
|
+
chatMessages: messages,
|
|
186
|
+
nextPageToken: pageToken
|
|
187
|
+
} = response;
|
|
188
|
+
this.pageToken = pageToken || null;
|
|
189
|
+
if (pageToken === null) {
|
|
190
|
+
this.isLastPull = true;
|
|
191
|
+
// Dispatch event when we reach the end of available history
|
|
192
|
+
dispatchCustomEvent(ChatWidgetEvents.NO_MORE_HISTORY_AVAILABLE);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
// if chatMessages is null, return empty array
|
|
196
|
+
if (!messages) {
|
|
197
|
+
this.isLastPull = true;
|
|
198
|
+
// Dispatch event when we reach the end of available history
|
|
199
|
+
dispatchCustomEvent(ChatWidgetEvents.NO_MORE_HISTORY_AVAILABLE);
|
|
200
|
+
// Also hide the loading banner
|
|
201
|
+
dispatchCustomEvent(ChatWidgetEvents.HIDE_LOADING_BANNER);
|
|
202
|
+
return [];
|
|
203
|
+
}
|
|
204
|
+
dispatchCustomEvent(ChatWidgetEvents.HIDE_LOADING_BANNER);
|
|
205
|
+
return messages;
|
|
206
|
+
} catch (error) {
|
|
207
|
+
TelemetryHelper.logSDKEvent(LogLevel.ERROR, {
|
|
208
|
+
Event: TelemetryEvent.FetchPersistentChatHistoryFailed,
|
|
209
|
+
ExceptionDetails: error
|
|
210
|
+
});
|
|
211
|
+
this.isLastPull = true;
|
|
212
|
+
this.pageToken = null;
|
|
213
|
+
// Dispatch event when there's an error to stop loading banner
|
|
214
|
+
dispatchCustomEvent(ChatWidgetEvents.NO_MORE_HISTORY_AVAILABLE);
|
|
215
|
+
// Also hide the loading banner
|
|
216
|
+
dispatchCustomEvent(ChatWidgetEvents.HIDE_LOADING_BANNER);
|
|
217
|
+
return [];
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
}, {
|
|
221
|
+
key: "shouldPull",
|
|
222
|
+
value: function shouldPull() {
|
|
223
|
+
return !this.isLastPull;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
227
|
+
}, {
|
|
228
|
+
key: "processMessageToActivity",
|
|
229
|
+
value: function processMessageToActivity(message) {
|
|
230
|
+
try {
|
|
231
|
+
const activity = convertPersistentChatHistoryMessageToActivity(message);
|
|
232
|
+
activity.id = activity.id || `activity-${this.count}`;
|
|
233
|
+
activity.channelData = {
|
|
234
|
+
...activity.channelData,
|
|
235
|
+
metadata: {
|
|
236
|
+
count: this.count
|
|
237
|
+
}
|
|
238
|
+
};
|
|
239
|
+
|
|
240
|
+
// Increment the count after assigning it to the activity
|
|
241
|
+
this.count += 1;
|
|
242
|
+
return activity;
|
|
243
|
+
} catch (error) {
|
|
244
|
+
TelemetryHelper.logActionEvent(LogLevel.ERROR, {
|
|
245
|
+
Event: TelemetryEvent.ConvertPersistentChatHistoryMessageToActivityFailed,
|
|
246
|
+
ExceptionDetails: error
|
|
247
|
+
});
|
|
248
|
+
throw error;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
253
|
+
}, {
|
|
254
|
+
key: "createDividerActivity",
|
|
255
|
+
value: function createDividerActivity(activity) {
|
|
256
|
+
var _this$lastMessage, _this$lastMessage$cha;
|
|
257
|
+
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) {
|
|
258
|
+
const rawSequenceId = activity.channelData["webchat:sequence-id"];
|
|
259
|
+
const sequenceId = typeof rawSequenceId === "number" && !isNaN(rawSequenceId) ? rawSequenceId + 1 : 1;
|
|
260
|
+
const timestamp = new Date(activity.timestamp).getTime() + 1;
|
|
261
|
+
return {
|
|
262
|
+
...conversationDividerActivity,
|
|
263
|
+
channelData: {
|
|
264
|
+
...conversationDividerActivity.channelData,
|
|
265
|
+
conversationId: activity.channelData.conversationId,
|
|
266
|
+
"webchat:sequence-id": sequenceId
|
|
267
|
+
},
|
|
268
|
+
timestamp: new Date(timestamp).toISOString(),
|
|
269
|
+
identifier: `divider-${activity.channelData.conversationId}`
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
return null;
|
|
273
|
+
}
|
|
274
|
+
}]);
|
|
275
|
+
return PersistentConversationHandler;
|
|
276
|
+
}();
|
|
277
|
+
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,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
|
-
|
|
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,
|
|
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, {
|
|
@@ -163,12 +165,12 @@ export const initWebChatComposer = (props, state, dispatch, facadeChatSDK, endCh
|
|
|
163
165
|
store: webChatStore,
|
|
164
166
|
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),
|
|
165
167
|
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 : (
|
|
168
|
+
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
169
|
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
170
|
renderMarkdown,
|
|
169
171
|
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 : (
|
|
172
|
+
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,
|
|
173
|
+
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
174
|
onTelemetry: createWebChatTelemetry(),
|
|
173
175
|
cardActionMiddleware: createCardActionMiddleware(((_props$webChatContain25 = props.webChatContainerProps) === null || _props$webChatContain25 === void 0 ? void 0 : _props$webChatContain25.botMagicCode) || undefined),
|
|
174
176
|
sendTypingIndicator: true,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -11,6 +11,7 @@ import { NotificationHandler } from "./webchatcontroller/notification/Notificati
|
|
|
11
11
|
import { NotificationScenarios } from "./webchatcontroller/enums/NotificationScenarios";
|
|
12
12
|
import { TelemetryHelper } from "../../common/telemetry/TelemetryHelper";
|
|
13
13
|
import { WebChatActionType } from "./webchatcontroller/enums/WebChatActionType";
|
|
14
|
+
import WebChatEventSubscribers from "./webchatcontroller/WebChatEventSubscribers";
|
|
14
15
|
import { WebChatStoreLoader } from "./webchatcontroller/WebChatStoreLoader";
|
|
15
16
|
import { createIOSOptimizedEmojiFont } from "./common/utils/fontUtils";
|
|
16
17
|
import { defaultAdaptiveCardStyles } from "./common/defaultStyles/defaultAdaptiveCardStyles";
|
|
@@ -20,7 +21,13 @@ import { defaultSentMessageAnchorStyles } from "./webchatcontroller/middlewares/
|
|
|
20
21
|
import { defaultSystemMessageBoxStyles } from "./webchatcontroller/middlewares/renderingmiddlewares/defaultStyles/defaultSystemMessageBoxStyles";
|
|
21
22
|
import { defaultUserMessageBoxStyles } from "./webchatcontroller/middlewares/renderingmiddlewares/defaultStyles/defaultUserMessageBoxStyles";
|
|
22
23
|
import { defaultWebChatContainerStatefulProps } from "./common/defaultProps/defaultWebChatContainerStatefulProps";
|
|
24
|
+
import { isPersistentChatEnabled } from "../livechatwidget/common/liveChatConfigUtils";
|
|
23
25
|
import { useChatContextStore } from "../..";
|
|
26
|
+
import useFacadeSDKStore from "../../hooks/useFacadeChatSDKStore";
|
|
27
|
+
import usePersistentChatHistory from "./hooks/usePersistentChatHistory";
|
|
28
|
+
|
|
29
|
+
// Types for better type safety
|
|
30
|
+
|
|
24
31
|
let uiTimer;
|
|
25
32
|
const broadcastChannelMessageEvent = "message";
|
|
26
33
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -49,7 +56,9 @@ const createMagicCodeSuccessResponse = signin => {
|
|
|
49
56
|
};
|
|
50
57
|
};
|
|
51
58
|
export const WebChatContainerStateful = props => {
|
|
52
|
-
var _props$webChatContain, _defaultWebChatContai, _webChatContainerProp, _webChatContainerProp2, _webChatContainerProp3, _webChatContainerProp4, _webChatContainerProp5, _webChatContainerProp6, _webChatContainerProp7, _webChatContainerProp8, _props$webChatContain6, _props$webChatContain7, _defaultWebChatContai2, _props$webChatContain8, _props$webChatContain9, _defaultWebChatContai3, _webChatContainerProp9, _webChatContainerProp10, _webChatContainerProp11, _webChatContainerProp12, _webChatContainerProp13, _webChatContainerProp14, _webChatContainerProp15, _webChatContainerProp16, _webChatContainerProp17, _webChatContainerProp18, _webChatContainerProp19, _webChatContainerProp20, _webChatContainerProp21, _webChatContainerProp22, _webChatContainerProp23, _props$webChatContain10, _props$webChatContain11, _webChatContainerProp24, _webChatContainerProp25, _webChatContainerProp26, _webChatContainerProp27, _props$citationPanePr, _props$citationPanePr2, _props$citationPanePr3, _props$citationPanePr4, _props$citationPanePr5;
|
|
59
|
+
var _props$webChatContain, _defaultWebChatContai, _extendedChatConfig$L, _props$persistentChat, _extendedChatConfig$L2, _extendedChatConfig$L3, _webChatContainerProp, _webChatContainerProp2, _webChatContainerProp3, _webChatContainerProp4, _webChatContainerProp5, _webChatContainerProp6, _webChatContainerProp7, _webChatContainerProp8, _props$webChatContain6, _props$webChatContain7, _defaultWebChatContai2, _props$webChatContain8, _props$webChatContain9, _defaultWebChatContai3, _webChatContainerProp9, _webChatContainerProp10, _webChatContainerProp11, _webChatContainerProp12, _webChatContainerProp13, _webChatContainerProp14, _webChatContainerProp15, _webChatContainerProp16, _webChatContainerProp17, _webChatContainerProp18, _webChatContainerProp19, _webChatContainerProp20, _webChatContainerProp21, _webChatContainerProp22, _webChatContainerProp23, _props$webChatContain10, _props$webChatContain11, _webChatContainerProp24, _webChatContainerProp25, _webChatContainerProp26, _webChatContainerProp27, _props$persistentChat2, _props$citationPanePr, _props$citationPanePr2, _props$citationPanePr3, _props$citationPanePr4, _props$citationPanePr5;
|
|
60
|
+
const [facadeChatSDK] = useFacadeSDKStore();
|
|
61
|
+
|
|
53
62
|
// Create a font family that includes emoji support, based on the primary font or default
|
|
54
63
|
const webChatStyles = ((_props$webChatContain = props.webChatContainerProps) === null || _props$webChatContain === void 0 ? void 0 : _props$webChatContain.webChatStyles) ?? defaultWebChatContainerStatefulProps.webChatStyles;
|
|
55
64
|
const primaryFont = (webChatStyles === null || webChatStyles === void 0 ? void 0 : webChatStyles.primaryFont) ?? ((_defaultWebChatContai = defaultWebChatContainerStatefulProps.webChatStyles) === null || _defaultWebChatContai === void 0 ? void 0 : _defaultWebChatContai.primaryFont);
|
|
@@ -70,9 +79,6 @@ export const WebChatContainerStateful = props => {
|
|
|
70
79
|
// Guard to prevent handling multiple rapid clicks which could cause
|
|
71
80
|
// the dim layer and pane to re-render out of sync and create a flicker.
|
|
72
81
|
const citationOpeningRef = useRef(false);
|
|
73
|
-
|
|
74
|
-
// ...existing code...
|
|
75
|
-
|
|
76
82
|
const {
|
|
77
83
|
BasicWebChat
|
|
78
84
|
} = Components;
|
|
@@ -82,6 +88,21 @@ export const WebChatContainerStateful = props => {
|
|
|
82
88
|
contextDataStore
|
|
83
89
|
} = props;
|
|
84
90
|
|
|
91
|
+
// Type the chatConfig properly to avoid 'any' usage
|
|
92
|
+
const extendedChatConfig = props.chatConfig;
|
|
93
|
+
const isHistoryEnabledInConfig = extendedChatConfig === null || extendedChatConfig === void 0 ? void 0 : (_extendedChatConfig$L = extendedChatConfig.LcwFcbConfiguration) === null || _extendedChatConfig$L === void 0 ? void 0 : _extendedChatConfig$L.lcwPersistentChatHistoryEnabled;
|
|
94
|
+
const isHistoryEnabledViaProps = props === null || props === void 0 ? void 0 : (_props$persistentChat = props.persistentChatHistoryProps) === null || _props$persistentChat === void 0 ? void 0 : _props$persistentChat.persistentChatHistoryEnabled;
|
|
95
|
+
const isPersistentChatEnabledForWidget = !!(extendedChatConfig !== null && extendedChatConfig !== void 0 && (_extendedChatConfig$L2 = extendedChatConfig.LiveChatConfigAuthSettings) !== null && _extendedChatConfig$L2 !== void 0 && _extendedChatConfig$L2.msdyn_javascriptclientfunction) || isPersistentChatEnabled(extendedChatConfig === null || extendedChatConfig === void 0 ? void 0 : (_extendedChatConfig$L3 = extendedChatConfig.LiveWSAndLiveChatEngJoin) === null || _extendedChatConfig$L3 === void 0 ? void 0 : _extendedChatConfig$L3.msdyn_conversationmode);
|
|
96
|
+
|
|
97
|
+
// Persistent chat history is enabled if explicitly set via props, or if enabled in config
|
|
98
|
+
// Props take precedence over config settings
|
|
99
|
+
const isPersistentHistoryEnabled = isHistoryEnabledViaProps || isHistoryEnabledInConfig;
|
|
100
|
+
|
|
101
|
+
// Check if both persistent chat and widget support are enabled
|
|
102
|
+
const shouldLoadPersistentHistoryMessages = isPersistentHistoryEnabled && isPersistentChatEnabledForWidget;
|
|
103
|
+
if (shouldLoadPersistentHistoryMessages) {
|
|
104
|
+
usePersistentChatHistory(facadeChatSDK, (props === null || props === void 0 ? void 0 : props.persistentChatHistoryProps) ?? {});
|
|
105
|
+
}
|
|
85
106
|
// Delegated click handler for citation anchors. Placed after state is
|
|
86
107
|
// available so we can prefer reading citations from app state and fall
|
|
87
108
|
// back to the legacy window map for backward-compatibility in tests.
|
|
@@ -383,7 +404,15 @@ export const WebChatContainerStateful = props => {
|
|
|
383
404
|
`), /*#__PURE__*/React.createElement(Stack, {
|
|
384
405
|
styles: containerStyles,
|
|
385
406
|
className: "webchat__stacked-layout_container"
|
|
386
|
-
}, /*#__PURE__*/React.createElement(
|
|
407
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
408
|
+
id: "ms_lcw_webchat_root",
|
|
409
|
+
style: {
|
|
410
|
+
height: "100%",
|
|
411
|
+
width: "100%"
|
|
412
|
+
}
|
|
413
|
+
}, shouldLoadPersistentHistoryMessages && /*#__PURE__*/React.createElement(WebChatEventSubscribers, {
|
|
414
|
+
persistentChatHistoryEnabled: props === null || props === void 0 ? void 0 : (_props$persistentChat2 = props.persistentChatHistoryProps) === null || _props$persistentChat2 === void 0 ? void 0 : _props$persistentChat2.persistentChatHistoryEnabled
|
|
415
|
+
}), /*#__PURE__*/React.createElement(BasicWebChat, null))), citationPaneOpen && /*#__PURE__*/React.createElement(CitationPaneStateful, {
|
|
387
416
|
id: ((_props$citationPanePr = props.citationPaneProps) === null || _props$citationPanePr === void 0 ? void 0 : _props$citationPanePr.id) || HtmlAttributeNames.ocwCitationPaneClassName,
|
|
388
417
|
title: ((_props$citationPanePr2 = props.citationPaneProps) === null || _props$citationPanePr2 === void 0 ? void 0 : _props$citationPanePr2.title) || HtmlAttributeNames.ocwCitationPaneTitle,
|
|
389
418
|
contentHtml: citationPaneText,
|
package/lib/esm/components/webchatcontainerstateful/common/activities/conversationDividerActivity.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Constants } from "../../../../common/Constants";
|
|
2
|
+
import botActivity from "./botActivity";
|
|
3
|
+
const conversationDividerActivity = {
|
|
4
|
+
...botActivity,
|
|
5
|
+
channelData: {
|
|
6
|
+
tags: [Constants.conversationDividerTag]
|
|
7
|
+
}
|
|
8
|
+
};
|
|
9
|
+
export default conversationDividerActivity;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { Constants } from "../../../../common/Constants";
|
|
2
|
+
import botActivity from "../activities/botActivity";
|
|
3
|
+
|
|
4
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
5
|
+
const convertStringValueToInt = value => {
|
|
6
|
+
if (typeof value !== "string" || value === "") {
|
|
7
|
+
return undefined;
|
|
8
|
+
}
|
|
9
|
+
let result;
|
|
10
|
+
try {
|
|
11
|
+
result = parseInt(value);
|
|
12
|
+
} catch (e) {
|
|
13
|
+
return undefined;
|
|
14
|
+
}
|
|
15
|
+
return isNaN(result) ? undefined : result;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
19
|
+
const convertPersistentChatHistoryMessageToActivity = message => {
|
|
20
|
+
var _from$user, _from$application;
|
|
21
|
+
const {
|
|
22
|
+
additionalData,
|
|
23
|
+
attachments,
|
|
24
|
+
content,
|
|
25
|
+
created,
|
|
26
|
+
from,
|
|
27
|
+
transcriptOriginalMessageId
|
|
28
|
+
} = message;
|
|
29
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
30
|
+
const activity = {
|
|
31
|
+
...botActivity,
|
|
32
|
+
channelData: {
|
|
33
|
+
tags: [Constants.persistentChatHistoryMessageTag]
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
let webchatSequenceId;
|
|
37
|
+
let timestamp;
|
|
38
|
+
if (transcriptOriginalMessageId) {
|
|
39
|
+
const id = convertStringValueToInt(transcriptOriginalMessageId); // Id used to determine the sequence of messages which is the same as the 'live' messages
|
|
40
|
+
if (id) {
|
|
41
|
+
webchatSequenceId = id;
|
|
42
|
+
timestamp = new Date(id) || created;
|
|
43
|
+
activity.channelData = {
|
|
44
|
+
...activity.channelData,
|
|
45
|
+
"webchat:sequence-id": webchatSequenceId
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
if (additionalData !== null && additionalData !== void 0 && additionalData.tags) {
|
|
50
|
+
const {
|
|
51
|
+
tags,
|
|
52
|
+
ConversationId
|
|
53
|
+
} = additionalData;
|
|
54
|
+
if (ConversationId) {
|
|
55
|
+
activity.channelData.conversationId = ConversationId;
|
|
56
|
+
}
|
|
57
|
+
if (tags) {
|
|
58
|
+
const formattedTags = additionalData.tags.split(",");
|
|
59
|
+
activity.channelData.tags = [...activity.channelData.tags, ...formattedTags];
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
if (from !== null && from !== void 0 && (_from$user = from.user) !== null && _from$user !== void 0 && _from$user.displayName) {
|
|
63
|
+
activity.from.name = from.user.displayName;
|
|
64
|
+
}
|
|
65
|
+
if ((from === null || from === void 0 ? void 0 : (_from$application = from.application) === null || _from$application === void 0 ? void 0 : _from$application.displayName) === "Customer") {
|
|
66
|
+
activity.from = {
|
|
67
|
+
role: "user",
|
|
68
|
+
name: from.application.displayName
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
if (content) {
|
|
72
|
+
return {
|
|
73
|
+
...activity,
|
|
74
|
+
text: content,
|
|
75
|
+
timestamp
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
if (attachments && attachments.length > 0) {
|
|
79
|
+
const fileName = attachments[0].name || "Unknown";
|
|
80
|
+
const text = `The following attachment was uploaded during the conversation: ${fileName}`;
|
|
81
|
+
return {
|
|
82
|
+
...activity,
|
|
83
|
+
text,
|
|
84
|
+
timestamp
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
// If neither content nor attachments are present, return null to indicate no activity could be created.
|
|
88
|
+
return null;
|
|
89
|
+
};
|
|
90
|
+
export default convertPersistentChatHistoryMessageToActivity;
|
|
@@ -28,5 +28,6 @@ export const defaultMiddlewareLocalizedTexts = {
|
|
|
28
28
|
THIRD_PARTY_COOKIES_BLOCKED_ALERT_MESSAGE: "Allow sites to save/read cookies in browser settings. Reloading page starts a new chat.",
|
|
29
29
|
MIDDLEWARE_BANNER_FILE_IS_MALICIOUS: "{0} has been blocked because the file may contain a malware.",
|
|
30
30
|
MIDDLEWARE_BANNER_FILE_EMAIL_ADDRESS_RECORDED_SUCCESS: "Email will be sent after chat ends!",
|
|
31
|
-
MIDDLEWARE_BANNER_FILE_EMAIL_ADDRESS_RECORDED_ERROR: "Email {0} could not be saved, try again later."
|
|
31
|
+
MIDDLEWARE_BANNER_FILE_EMAIL_ADDRESS_RECORDED_ERROR: "Email {0} could not be saved, try again later.",
|
|
32
|
+
PREVIOUS_MESSAGES_LOADING: "Loading previous messages..."
|
|
32
33
|
};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createActivityStatusMiddleware } from "../../webchatcontroller/middlewares/renderingmiddlewares/activityStatusMiddleware";
|
|
2
2
|
import { groupActivitiesMiddleware } from "../../webchatcontroller/middlewares/renderingmiddlewares/groupActivitiesMiddleware";
|
|
3
3
|
import { typingIndicatorMiddleware } from "../../webchatcontroller/middlewares/renderingmiddlewares/typingIndicatorMiddleware";
|
|
4
4
|
export const defaultWebChatStatefulProps = {
|
|
5
5
|
// activityMiddleware: activityMiddleware, - this is implemented elsewhere and can be customized
|
|
6
|
-
activityStatusMiddleware:
|
|
6
|
+
activityStatusMiddleware: createActivityStatusMiddleware(),
|
|
7
7
|
// avatarMiddleware: avatarMiddleware, - this is implemented elsewhere and can be customized
|
|
8
8
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
9
9
|
groupActivitiesMiddleware: groupActivitiesMiddleware,
|