@microsoft/omnichannel-chat-widget 2.0.0 → 2.0.1-main.2b5f4df
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 +61 -2
- package/lib/cjs/common/telemetry/TelemetryConstants.js +6 -0
- package/lib/cjs/components/chatbuttonstateful/ChatButtonStateful.js +42 -25
- package/lib/cjs/components/livechatwidget/common/endChat.js +39 -0
- package/lib/cjs/components/livechatwidget/common/initWebChatComposer.js +42 -13
- package/lib/cjs/components/livechatwidget/common/recoveryEligibilityTelemetry.js +60 -0
- package/lib/cjs/components/livechatwidget/common/startChat.js +107 -33
- package/lib/cjs/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +8 -6
- package/lib/cjs/components/webchatcontainerstateful/WebChatContainerStateful.js +2 -2
- package/lib/cjs/components/webchatcontainerstateful/common/defaultProps/defaultMiddlewareLocalizedTexts.js +2 -1
- package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/attachmentForScreenReaderMiddleware.js +159 -0
- package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/attachments/AdaptiveCardAccessibilityWrapper.js +16 -2
- package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/attachmentSentAnnouncementMiddleware.js +68 -40
- package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/attachmentUploadValidatorMiddleware.js +0 -27
- package/lib/esm/common/telemetry/TelemetryConstants.js +6 -0
- package/lib/esm/components/chatbuttonstateful/ChatButtonStateful.js +42 -25
- package/lib/esm/components/livechatwidget/common/endChat.js +39 -0
- package/lib/esm/components/livechatwidget/common/initWebChatComposer.js +40 -13
- package/lib/esm/components/livechatwidget/common/recoveryEligibilityTelemetry.js +52 -0
- package/lib/esm/components/livechatwidget/common/startChat.js +104 -31
- package/lib/esm/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +8 -6
- package/lib/esm/components/webchatcontainerstateful/WebChatContainerStateful.js +2 -2
- package/lib/esm/components/webchatcontainerstateful/common/defaultProps/defaultMiddlewareLocalizedTexts.js +2 -1
- package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/attachmentForScreenReaderMiddleware.js +153 -0
- package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/attachments/AdaptiveCardAccessibilityWrapper.js +16 -2
- package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/attachmentSentAnnouncementMiddleware.js +65 -39
- package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/attachmentUploadValidatorMiddleware.js +0 -27
- package/lib/types/common/telemetry/TelemetryConstants.d.ts +3 -0
- package/lib/types/components/livechatwidget/common/initWebChatComposer.d.ts +8 -0
- package/lib/types/components/livechatwidget/common/recoveryEligibilityTelemetry.d.ts +17 -0
- package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/attachmentForScreenReaderMiddleware.d.ts +11 -0
- package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/attachmentSentAnnouncementMiddleware.d.ts +11 -4
- package/lib/types/contexts/common/ILiveChatWidgetLocalizedTexts.d.ts +9 -2
- package/package.json +7 -7
|
@@ -18,27 +18,6 @@ var _WebChatActionType = require("../../enums/WebChatActionType");
|
|
|
18
18
|
******/
|
|
19
19
|
|
|
20
20
|
const MBtoBRatio = 1000000;
|
|
21
|
-
const announceFileSent = message => {
|
|
22
|
-
// TalkBack on Android WebView reliably announces newly *appended*
|
|
23
|
-
// role="alert" nodes but often misses text-content updates on existing
|
|
24
|
-
// nodes. Wait 500ms for the send-box focus shift to settle, then inject
|
|
25
|
-
// a fresh alert element appended to document.body and remove it after 3s.
|
|
26
|
-
setTimeout(() => {
|
|
27
|
-
const el = document.createElement("div");
|
|
28
|
-
el.setAttribute("role", "alert");
|
|
29
|
-
el.setAttribute("aria-live", "assertive");
|
|
30
|
-
el.setAttribute("aria-atomic", "true");
|
|
31
|
-
el.style.cssText = "position:absolute;left:-9999px;top:auto;width:1px;height:1px;overflow:hidden;";
|
|
32
|
-
el.textContent = message;
|
|
33
|
-
document.body.appendChild(el);
|
|
34
|
-
// Remove after TalkBack has had time to read it
|
|
35
|
-
setTimeout(() => {
|
|
36
|
-
if (el.parentNode) {
|
|
37
|
-
el.parentNode.removeChild(el);
|
|
38
|
-
}
|
|
39
|
-
}, 3000);
|
|
40
|
-
}, 500);
|
|
41
|
-
};
|
|
42
21
|
|
|
43
22
|
/*
|
|
44
23
|
* If an attachment is invalid, delete this attachment from the attachments list
|
|
@@ -227,13 +206,7 @@ const createAttachmentUploadValidatorMiddleware = (allowedFileExtensions, maxFil
|
|
|
227
206
|
var _payload$activity, _payload$activity2;
|
|
228
207
|
const payload = action.payload;
|
|
229
208
|
if (payload !== null && payload !== void 0 && payload.activity.attachments && payload.activity.attachments.length > 0 && (payload === null || payload === void 0 || (_payload$activity = payload.activity) === null || _payload$activity === void 0 || (_payload$activity = _payload$activity.attachments) === null || _payload$activity === void 0 ? void 0 : _payload$activity.length) === (payload === null || payload === void 0 || (_payload$activity2 = payload.activity) === null || _payload$activity2 === void 0 || (_payload$activity2 = _payload$activity2.channelData) === null || _payload$activity2 === void 0 || (_payload$activity2 = _payload$activity2.attachmentSizes) === null || _payload$activity2 === void 0 ? void 0 : _payload$activity2.length)) {
|
|
230
|
-
var _validatedAction$payl;
|
|
231
209
|
const validatedAction = validateAttachment(action, allowedFileExtensions, maxFileSizeSupportedByDynamics, localizedTexts);
|
|
232
|
-
|
|
233
|
-
// Announce to screen readers that the file was sent when validation passes
|
|
234
|
-
if (((_validatedAction$payl = validatedAction.payload) === null || _validatedAction$payl === void 0 || (_validatedAction$payl = _validatedAction$payl.activity) === null || _validatedAction$payl === void 0 || (_validatedAction$payl = _validatedAction$payl.attachments) === null || _validatedAction$payl === void 0 ? void 0 : _validatedAction$payl.length) > 0) {
|
|
235
|
-
announceFileSent(localizedTexts.MIDDLEWARE_BANNER_FILE_SENT ?? "File sent successfully.");
|
|
236
|
-
}
|
|
237
210
|
return next(validatedAction);
|
|
238
211
|
}
|
|
239
212
|
}
|
|
@@ -109,6 +109,7 @@ export let TelemetryEvent = /*#__PURE__*/function (TelemetryEvent) {
|
|
|
109
109
|
TelemetryEvent["MidConversationAuthSucceeded"] = "MidConversationAuthSucceeded";
|
|
110
110
|
TelemetryEvent["MidConversationAuthFailed"] = "MidConversationAuthFailed";
|
|
111
111
|
TelemetryEvent["MidConversationAuthReset"] = "MidConversationAuthReset";
|
|
112
|
+
TelemetryEvent["RecoveryEligibilityEvaluated"] = "RecoveryEligibilityEvaluated";
|
|
112
113
|
TelemetryEvent["GetConversationDetailsCallStarted"] = "GetConversationDetailsCallStarted";
|
|
113
114
|
TelemetryEvent["GetConversationDetailsCallFailed"] = "GetConversationDetailsCallFailed";
|
|
114
115
|
TelemetryEvent["EndChatSDKCallFailed"] = "EndChatSDKCallFailed";
|
|
@@ -140,6 +141,8 @@ export let TelemetryEvent = /*#__PURE__*/function (TelemetryEvent) {
|
|
|
140
141
|
TelemetryEvent["PrechatSubmitted"] = "PrechatSubmitted";
|
|
141
142
|
TelemetryEvent["StartChatSDKCall"] = "StartChatCall";
|
|
142
143
|
TelemetryEvent["StartChatEventReceived"] = "StartChatEventReceived";
|
|
144
|
+
TelemetryEvent["ConcurrentStartChatRejected"] = "ConcurrentStartChatRejected";
|
|
145
|
+
TelemetryEvent["ChatSDKStateCleanUpDisconnectFailed"] = "ChatSDKStateCleanUpDisconnectFailed";
|
|
143
146
|
TelemetryEvent["EndChatSDKCall"] = "EndChatSDKCall";
|
|
144
147
|
TelemetryEvent["PrepareEndChat"] = "PrepareEndChat";
|
|
145
148
|
TelemetryEvent["EndChatEventReceived"] = "EndChatEventReceived";
|
|
@@ -412,6 +415,9 @@ export let TelemetryConstants = /*#__PURE__*/function () {
|
|
|
412
415
|
case TelemetryEvent.SecureEventBusDispatchError:
|
|
413
416
|
case TelemetryEvent.AgentJoinedConversation:
|
|
414
417
|
case TelemetryEvent.BrowserTabHidden:
|
|
418
|
+
case TelemetryEvent.ConcurrentStartChatRejected:
|
|
419
|
+
case TelemetryEvent.ChatSDKStateCleanUpDisconnectFailed:
|
|
420
|
+
case TelemetryEvent.RecoveryEligibilityEvaluated:
|
|
415
421
|
return ScenarioType.ACTIONS;
|
|
416
422
|
case TelemetryEvent.StartChatSDKCall:
|
|
417
423
|
case TelemetryEvent.StartChatEventReceived:
|
|
@@ -50,37 +50,54 @@ export const ChatButtonStateful = props => {
|
|
|
50
50
|
const ref = useRef(() => {
|
|
51
51
|
return;
|
|
52
52
|
});
|
|
53
|
+
// Optimistic guard against rapid double-clicks. `conversationState` only flips to
|
|
54
|
+
// `Loading` after React re-renders, so the button stays visible and clickable for the
|
|
55
|
+
// whole duration of the first click's async work. Without this ref two concurrent
|
|
56
|
+
// startChat() calls can create two conversations on the backend.
|
|
57
|
+
const startChatInProgressRef = useRef(false);
|
|
53
58
|
ref.current = async () => {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
ConversationStage: ConversationStage.Initialization
|
|
59
|
-
}
|
|
60
|
-
});
|
|
61
|
-
if (state.appStates.isMinimized) {
|
|
62
|
-
dispatch({
|
|
63
|
-
type: LiveChatWidgetActionType.SET_MINIMIZED,
|
|
64
|
-
payload: false
|
|
59
|
+
if (startChatInProgressRef.current) {
|
|
60
|
+
TelemetryHelper.logActionEvent(LogLevel.WARN, {
|
|
61
|
+
Event: TelemetryEvent.ConcurrentStartChatRejected,
|
|
62
|
+
Description: "Chat button click ignored, a start chat operation is already in progress."
|
|
65
63
|
});
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
startChatInProgressRef.current = true;
|
|
67
|
+
try {
|
|
68
|
+
TelemetryHelper.logActionEventToAllTelemetry(LogLevel.INFO, {
|
|
69
|
+
Event: TelemetryEvent.LCWChatButtonClicked,
|
|
70
|
+
Description: "Chat button click action started",
|
|
71
|
+
CustomProperties: {
|
|
72
|
+
ConversationStage: ConversationStage.Initialization
|
|
73
|
+
}
|
|
69
74
|
});
|
|
70
|
-
|
|
71
|
-
|
|
75
|
+
if (state.appStates.isMinimized) {
|
|
76
|
+
dispatch({
|
|
77
|
+
type: LiveChatWidgetActionType.SET_MINIMIZED,
|
|
78
|
+
payload: false
|
|
79
|
+
});
|
|
80
|
+
dispatch({
|
|
81
|
+
type: LiveChatWidgetActionType.SET_UNREAD_MESSAGE_COUNT,
|
|
82
|
+
payload: 0
|
|
83
|
+
});
|
|
84
|
+
// If chat is minimized and then unminimized, start a chat if convesation state is closed.
|
|
85
|
+
if (state.appStates.conversationState === ConversationState.Closed) {
|
|
86
|
+
await startChat();
|
|
87
|
+
}
|
|
88
|
+
} else {
|
|
72
89
|
await startChat();
|
|
73
90
|
}
|
|
74
|
-
|
|
75
|
-
|
|
91
|
+
TelemetryHelper.logActionEventToAllTelemetry(LogLevel.INFO, {
|
|
92
|
+
Event: TelemetryEvent.LCWChatButtonActionCompleted,
|
|
93
|
+
Description: "Chat button action completed",
|
|
94
|
+
CustomProperties: {
|
|
95
|
+
ConversationStage: ConversationStage.Initialization
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
} finally {
|
|
99
|
+
startChatInProgressRef.current = false;
|
|
76
100
|
}
|
|
77
|
-
TelemetryHelper.logActionEventToAllTelemetry(LogLevel.INFO, {
|
|
78
|
-
Event: TelemetryEvent.LCWChatButtonActionCompleted,
|
|
79
|
-
Description: "Chat button action completed",
|
|
80
|
-
CustomProperties: {
|
|
81
|
-
ConversationStage: ConversationStage.Initialization
|
|
82
|
-
}
|
|
83
|
-
});
|
|
84
101
|
};
|
|
85
102
|
const outOfOfficeStyleProps = Object.assign({}, defaultOutOfOfficeChatButtonStyleProps, outOfOfficeButtonProps === null || outOfOfficeButtonProps === void 0 ? void 0 : outOfOfficeButtonProps.styleProps);
|
|
86
103
|
const controlProps = {
|
|
@@ -349,14 +349,53 @@ export const closeChatStateCleanUp = dispatch => {
|
|
|
349
349
|
});
|
|
350
350
|
};
|
|
351
351
|
|
|
352
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
353
|
+
const logCleanUpDisconnectFailure = error => {
|
|
354
|
+
TelemetryHelper.logActionEvent(LogLevel.WARN, {
|
|
355
|
+
Event: TelemetryEvent.ChatSDKStateCleanUpDisconnectFailed,
|
|
356
|
+
Description: "Failed to disconnect the previous conversation during chat SDK state clean up.",
|
|
357
|
+
ExceptionDetails: {
|
|
358
|
+
exception: (error === null || error === void 0 ? void 0 : error.message) ?? error
|
|
359
|
+
}
|
|
360
|
+
});
|
|
361
|
+
};
|
|
362
|
+
|
|
363
|
+
// Releases the previous session's conversation. Mirrors the cleanup OmnichannelChatSDK.endChat()
|
|
364
|
+
// runs in its finally block (disconnect, then drop the reference). Without it, a conversation
|
|
365
|
+
// left over from a failed or orphaned start chat, or from a chat ended in another tab (which
|
|
366
|
+
// skips the SDK endChat), keeps its messaging session open and leaks into the next chat.
|
|
367
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
368
|
+
const disconnectConversation = chatSDK => {
|
|
369
|
+
const conversation = chatSDK.conversation;
|
|
370
|
+
if (!conversation || typeof conversation.disconnect !== "function") {
|
|
371
|
+
return;
|
|
372
|
+
}
|
|
373
|
+
try {
|
|
374
|
+
// ACS conversations disconnect asynchronously; legacy IC3 conversations may not return a promise.
|
|
375
|
+
const result = conversation.disconnect();
|
|
376
|
+
if (result && typeof result.catch === "function") {
|
|
377
|
+
result.catch(logCleanUpDisconnectFailure);
|
|
378
|
+
}
|
|
379
|
+
} catch (error) {
|
|
380
|
+
logCleanUpDisconnectFailure(error);
|
|
381
|
+
}
|
|
382
|
+
};
|
|
383
|
+
|
|
352
384
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
353
385
|
export const chatSDKStateCleanUp = chatSDK => {
|
|
386
|
+
if (!chatSDK) {
|
|
387
|
+
return;
|
|
388
|
+
}
|
|
389
|
+
|
|
354
390
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
355
391
|
chatSDK.requestId = uuidv4();
|
|
356
392
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
357
393
|
chatSDK.chatToken = {};
|
|
358
394
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
359
395
|
chatSDK.reconnectId = null;
|
|
396
|
+
disconnectConversation(chatSDK);
|
|
397
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
398
|
+
chatSDK.conversation = null;
|
|
360
399
|
};
|
|
361
400
|
|
|
362
401
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -11,10 +11,11 @@ import { LiveChatWidgetActionType } from "../../../contexts/common/LiveChatWidge
|
|
|
11
11
|
import { TelemetryHelper } from "../../../common/telemetry/TelemetryHelper";
|
|
12
12
|
import { WebChatStoreLoader } from "../../webchatcontainerstateful/webchatcontroller/WebChatStoreLoader";
|
|
13
13
|
import attachmentProcessingMiddleware from "../../webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/attachmentProcessingMiddleware";
|
|
14
|
-
import
|
|
14
|
+
import createAttachmentSentAnnouncementMiddleware from "../../webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/attachmentSentAnnouncementMiddleware";
|
|
15
15
|
import channelDataMiddleware from "../../webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/channelDataMiddleware";
|
|
16
16
|
import { createActivityMiddleware } from "../../webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityMiddleware";
|
|
17
17
|
import { createActivityStatusMiddleware } from "../../webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityStatusMiddleware";
|
|
18
|
+
import { createAttachmentForScreenReaderMiddleware } from "../../webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/attachmentForScreenReaderMiddleware";
|
|
18
19
|
import { createAttachmentMiddleware } from "../../webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/attachmentMiddleware";
|
|
19
20
|
import createAttachmentUploadValidatorMiddleware from "../../webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/attachmentUploadValidatorMiddleware";
|
|
20
21
|
import { createAvatarMiddleware } from "../../webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/avatarMiddleware";
|
|
@@ -42,6 +43,31 @@ import htmlPlayerMiddleware from "../../webchatcontainerstateful/webchatcontroll
|
|
|
42
43
|
import htmlTextMiddleware from "../../webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/htmlTextMiddleware";
|
|
43
44
|
import preProcessingMiddleware from "../../webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/preProcessingMiddleware";
|
|
44
45
|
import sanitizationMiddleware from "../../webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/sanitizationMiddleware";
|
|
46
|
+
const markdownSanitizeConfig = {
|
|
47
|
+
FORBID_TAGS: ["form", "button", "script", "div", "input"],
|
|
48
|
+
FORBID_ATTR: ["action"],
|
|
49
|
+
ADD_ATTR: ["target"]
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Renders Markdown for the screen reader text of Adaptive Cards, from the same pieces as the visible card:
|
|
54
|
+
* the host renderMarkdown when set, the hyperlink text override, and the same sanitization.
|
|
55
|
+
* Markdown is always formatted, also when the widget shows Markdown unformatted, so that screen readers do not read the syntax.
|
|
56
|
+
* Styles are removed with their content because the card does not show them.
|
|
57
|
+
*/
|
|
58
|
+
export const createScreenReaderMarkdownRenderer = webChatContainerProps => {
|
|
59
|
+
var _webChatContainerProp;
|
|
60
|
+
const hostRenderMarkdown = webChatContainerProps === null || webChatContainerProps === void 0 || (_webChatContainerProp = webChatContainerProps.webChatProps) === null || _webChatContainerProp === void 0 ? void 0 : _webChatContainerProp.renderMarkdown;
|
|
61
|
+
const markdown = createMarkdown(false, (webChatContainerProps === null || webChatContainerProps === void 0 ? void 0 : webChatContainerProps.disableNewLineMarkdownSupport) ?? defaultWebChatContainerStatefulProps.disableNewLineMarkdownSupport, webChatContainerProps === null || webChatContainerProps === void 0 ? void 0 : webChatContainerProps.opensMarkdownLinksInSameTab);
|
|
62
|
+
const hyperlinkTextOverrideRenderer = new HyperlinkTextOverrideRenderer((webChatContainerProps === null || webChatContainerProps === void 0 ? void 0 : webChatContainerProps.hyperlinkTextOverride) ?? defaultWebChatContainerStatefulProps.hyperlinkTextOverride);
|
|
63
|
+
return text => {
|
|
64
|
+
const html = hostRenderMarkdown ? hostRenderMarkdown(text) : markdown.render(text);
|
|
65
|
+
return DOMPurify.sanitize(hyperlinkTextOverrideRenderer.render(html), {
|
|
66
|
+
...markdownSanitizeConfig,
|
|
67
|
+
FORBID_TAGS: [...markdownSanitizeConfig.FORBID_TAGS, "style"]
|
|
68
|
+
});
|
|
69
|
+
};
|
|
70
|
+
};
|
|
45
71
|
|
|
46
72
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
47
73
|
export const initWebChatComposer = (props, state, dispatch, facadeChatSDK, endChat) => {
|
|
@@ -62,7 +88,7 @@ export const initWebChatComposer = (props, state, dispatch, facadeChatSDK, endCh
|
|
|
62
88
|
// Initialize Web Chat's redux store
|
|
63
89
|
let webChatStore = WebChatStoreLoader.store;
|
|
64
90
|
if (!webChatStore) {
|
|
65
|
-
var _state$domainStates$l, _state$domainStates$l2, _state$domainStates$l3, _props$webChatContain7;
|
|
91
|
+
var _state$domainStates$l, _state$domainStates$l2, _props$controlProps, _state$domainStates$l3, _props$webChatContain7;
|
|
66
92
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
67
93
|
const addConversationalSurveyTagsCallback = action => {
|
|
68
94
|
var _inMemoryState$appSta;
|
|
@@ -121,7 +147,7 @@ export const initWebChatComposer = (props, state, dispatch, facadeChatSDK, endCh
|
|
|
121
147
|
};
|
|
122
148
|
webChatStore = createStore({},
|
|
123
149
|
//initial state
|
|
124
|
-
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),
|
|
150
|
+
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), createAttachmentSentAnnouncementMiddleware(localizedTexts, ((_props$controlProps = props.controlProps) === null || _props$controlProps === void 0 ? void 0 : _props$controlProps.id) || "oc-lcw"), 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(),
|
|
125
151
|
// Pass a callback so middleware can push initials into React context for reactivity
|
|
126
152
|
localizedStringsBotInitialsMiddleware(initials => {
|
|
127
153
|
dispatch({
|
|
@@ -149,12 +175,7 @@ export const initWebChatComposer = (props, state, dispatch, facadeChatSDK, endCh
|
|
|
149
175
|
});
|
|
150
176
|
|
|
151
177
|
// EXISTING sanitization (continues to work as before)
|
|
152
|
-
|
|
153
|
-
FORBID_TAGS: ["form", "button", "script", "div", "input"],
|
|
154
|
-
FORBID_ATTR: ["action"],
|
|
155
|
-
ADD_ATTR: ["target"]
|
|
156
|
-
};
|
|
157
|
-
text = DOMPurify.sanitize(text, config);
|
|
178
|
+
text = DOMPurify.sanitize(text, markdownSanitizeConfig);
|
|
158
179
|
|
|
159
180
|
// MONITOR-ONLY: Test what the stricter allowlist would remove (Phase 1)
|
|
160
181
|
// This does NOT modify the text, only logs telemetry
|
|
@@ -251,6 +272,12 @@ export const initWebChatComposer = (props, state, dispatch, facadeChatSDK, endCh
|
|
|
251
272
|
// Track what would be removed
|
|
252
273
|
const removedTags = [];
|
|
253
274
|
const removedAttributes = [];
|
|
275
|
+
const trackAttribute = name => {
|
|
276
|
+
const attrName = name.toLowerCase();
|
|
277
|
+
if (!strictConfig.ALLOWED_ATTR.includes(attrName) && attrName !== "class" && attrName !== "id") {
|
|
278
|
+
removedAttributes.push(attrName);
|
|
279
|
+
}
|
|
280
|
+
};
|
|
254
281
|
|
|
255
282
|
// Add hooks to the isolated monitoring instance
|
|
256
283
|
monitorDOMPurify.addHook("uponSanitizeElement", (node, data) => {
|
|
@@ -259,6 +286,8 @@ export const initWebChatComposer = (props, state, dispatch, facadeChatSDK, endCh
|
|
|
259
286
|
// Filter out "body" tag which is DOMPurify's internal wrapper
|
|
260
287
|
if (node.nodeType === 1 && !strictConfig.ALLOWED_TAGS.includes(tagName) && tagName !== "body") {
|
|
261
288
|
removedTags.push(tagName);
|
|
289
|
+
// DOMPurify 3.4.16+ skips uponSanitizeAttribute for removed elements
|
|
290
|
+
Array.from(node.attributes ?? []).forEach(attr => trackAttribute(attr.name));
|
|
262
291
|
}
|
|
263
292
|
} catch (hookError) {
|
|
264
293
|
// Silently ignore hook errors
|
|
@@ -266,10 +295,7 @@ export const initWebChatComposer = (props, state, dispatch, facadeChatSDK, endCh
|
|
|
266
295
|
});
|
|
267
296
|
monitorDOMPurify.addHook("uponSanitizeAttribute", (node, data) => {
|
|
268
297
|
try {
|
|
269
|
-
|
|
270
|
-
if (!strictConfig.ALLOWED_ATTR.includes(attrName) && attrName !== "class" && attrName !== "id") {
|
|
271
|
-
removedAttributes.push(attrName);
|
|
272
|
-
}
|
|
298
|
+
trackAttribute(data.attrName);
|
|
273
299
|
} catch (hookError) {
|
|
274
300
|
// Silently ignore hook errors
|
|
275
301
|
}
|
|
@@ -353,6 +379,7 @@ export const initWebChatComposer = (props, state, dispatch, facadeChatSDK, endCh
|
|
|
353
379
|
store: webChatStore,
|
|
354
380
|
activityMiddleware: (_props$webChatContain0 = props.webChatContainerProps) !== null && _props$webChatContain0 !== void 0 && (_props$webChatContain0 = _props$webChatContain0.renderingMiddlewareProps) !== null && _props$webChatContain0 !== void 0 && _props$webChatContain0.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),
|
|
355
381
|
attachmentMiddleware: (_props$webChatContain1 = props.webChatContainerProps) !== null && _props$webChatContain1 !== void 0 && (_props$webChatContain1 = _props$webChatContain1.renderingMiddlewareProps) !== null && _props$webChatContain1 !== void 0 && _props$webChatContain1.disableAttachmentMiddleware ? undefined : createAttachmentMiddleware(((_state$domainStates$r3 = state.domainStates.renderingMiddlewareProps) === null || _state$domainStates$r3 === void 0 || (_state$domainStates$r3 = _state$domainStates$r3.attachmentProps) === null || _state$domainStates$r3 === void 0 ? void 0 : _state$domainStates$r3.enableInlinePlaying) ?? defaultAttachmentProps.enableInlinePlaying),
|
|
382
|
+
attachmentForScreenReaderMiddleware: createAttachmentForScreenReaderMiddleware(createScreenReaderMarkdownRenderer(props.webChatContainerProps)),
|
|
356
383
|
activityStatusMiddleware: (_props$webChatContain10 = props.webChatContainerProps) !== null && _props$webChatContain10 !== void 0 && (_props$webChatContain10 = _props$webChatContain10.renderingMiddlewareProps) !== null && _props$webChatContain10 !== void 0 && _props$webChatContain10.disableActivityStatusMiddleware ? undefined : createActivityStatusMiddleware(getLocaleStringFromId((_state$domainStates$l5 = state.domainStates.liveChatConfig) === null || _state$domainStates$l5 === void 0 || (_state$domainStates$l5 = _state$domainStates$l5.ChatWidgetLanguage) === null || _state$domainStates$l5 === void 0 ? void 0 : _state$domainStates$l5.msdyn_localeid)),
|
|
357
384
|
toastMiddleware: (_props$webChatContain11 = props.webChatContainerProps) !== null && _props$webChatContain11 !== void 0 && (_props$webChatContain11 = _props$webChatContain11.renderingMiddlewareProps) !== null && _props$webChatContain11 !== void 0 && _props$webChatContain11.disableToastMiddleware ? undefined : createToastMiddleware(props.notificationPaneProps, endChat),
|
|
358
385
|
renderMarkdown,
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { ConversationState } from "../../../contexts/common/ConversationState";
|
|
2
|
+
import { LogLevel, TelemetryEvent } from "../../../common/telemetry/TelemetryConstants";
|
|
3
|
+
import { TelemetryHelper } from "../../../common/telemetry/TelemetryHelper";
|
|
4
|
+
import { isUndefinedOrEmpty } from "../../../common/utils";
|
|
5
|
+
export let RecoveryEligibilityReason = /*#__PURE__*/function (RecoveryEligibilityReason) {
|
|
6
|
+
RecoveryEligibilityReason["ReconnectIdPresent"] = "ReconnectIdPresent";
|
|
7
|
+
RecoveryEligibilityReason["ActiveContextPresent"] = "ActiveContextPresent";
|
|
8
|
+
RecoveryEligibilityReason["MissingContext"] = "MissingContext";
|
|
9
|
+
RecoveryEligibilityReason["CachedContextNonActive"] = "CachedContextNonActive";
|
|
10
|
+
return RecoveryEligibilityReason;
|
|
11
|
+
}({});
|
|
12
|
+
const getConversationStateName = conversationState => {
|
|
13
|
+
if (typeof conversationState !== "number") {
|
|
14
|
+
return "Unknown";
|
|
15
|
+
}
|
|
16
|
+
const stateName = ConversationState[conversationState];
|
|
17
|
+
return typeof stateName === "string" ? stateName : "Unknown";
|
|
18
|
+
};
|
|
19
|
+
export const getRecoveryEligibilityTelemetryProperties = (state, eligible) => {
|
|
20
|
+
var _state$appStates, _state$domainStates, _state$appStates2, _state$appStates3;
|
|
21
|
+
const reconnectId = (_state$appStates = state.appStates) === null || _state$appStates === void 0 ? void 0 : _state$appStates.reconnectId;
|
|
22
|
+
const liveChatContext = (_state$domainStates = state.domainStates) === null || _state$domainStates === void 0 ? void 0 : _state$domainStates.liveChatContext;
|
|
23
|
+
const hasReconnectId = !isUndefinedOrEmpty(reconnectId);
|
|
24
|
+
const hasLiveChatContext = !isUndefinedOrEmpty(liveChatContext);
|
|
25
|
+
const hasRequestId = !isUndefinedOrEmpty(liveChatContext === null || liveChatContext === void 0 ? void 0 : liveChatContext.requestId);
|
|
26
|
+
let reason = RecoveryEligibilityReason.ActiveContextPresent;
|
|
27
|
+
if (hasReconnectId) {
|
|
28
|
+
reason = RecoveryEligibilityReason.ReconnectIdPresent;
|
|
29
|
+
} else if (!hasLiveChatContext) {
|
|
30
|
+
reason = RecoveryEligibilityReason.MissingContext;
|
|
31
|
+
} else if (((_state$appStates2 = state.appStates) === null || _state$appStates2 === void 0 ? void 0 : _state$appStates2.conversationState) !== ConversationState.Active) {
|
|
32
|
+
reason = RecoveryEligibilityReason.CachedContextNonActive;
|
|
33
|
+
}
|
|
34
|
+
return {
|
|
35
|
+
conversationState: getConversationStateName((_state$appStates3 = state.appStates) === null || _state$appStates3 === void 0 ? void 0 : _state$appStates3.conversationState),
|
|
36
|
+
hasReconnectId,
|
|
37
|
+
hasLiveChatContext,
|
|
38
|
+
hasRequestId,
|
|
39
|
+
eligible,
|
|
40
|
+
reason
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
export const logRecoveryEligibilityTelemetry = (state, eligible) => {
|
|
44
|
+
try {
|
|
45
|
+
TelemetryHelper.logActionEvent(LogLevel.INFO, {
|
|
46
|
+
Event: TelemetryEvent.RecoveryEligibilityEvaluated,
|
|
47
|
+
CustomProperties: getRecoveryEligibilityTelemetryProperties(state, eligible)
|
|
48
|
+
});
|
|
49
|
+
} catch (error) {
|
|
50
|
+
console.warn(error);
|
|
51
|
+
}
|
|
52
|
+
};
|
|
@@ -18,19 +18,86 @@ import { isMidAuthEnabled } from "./authHelper";
|
|
|
18
18
|
import { setPostChatContextAndLoadSurvey } from "./setPostChatContextAndLoadSurvey";
|
|
19
19
|
import { shouldSetPreChatIfPersistentChat } from "./persistentChatHelper";
|
|
20
20
|
import { updateTelemetryData } from "./updateSessionDataForTelemetry";
|
|
21
|
+
/**
|
|
22
|
+
* Per widget instance mutexes for the two chat creation entry points.
|
|
23
|
+
*
|
|
24
|
+
* Every guard in the prepareStartChat -> setPreChatAndInitiateChat -> initStartChat chain
|
|
25
|
+
* checks `conversationState === Closed`, but React state is updated asynchronously. A second
|
|
26
|
+
* invocation fired within the same render cycle (for example a rapid double click on the chat
|
|
27
|
+
* button, or a chat button click racing a BroadcastEvent.StartChat) therefore still observes
|
|
28
|
+
* the stale `Closed` state, reaches `facadeChatSDK.startChat()` and creates a second
|
|
29
|
+
* conversation on the backend which is then orphaned and never ended.
|
|
30
|
+
*
|
|
31
|
+
* The locks are keyed by FacadeChatSDK instance rather than being module wide, because a host
|
|
32
|
+
* page can mount several independent widgets, each with its own widgetInstanceId and its own
|
|
33
|
+
* FacadeChatSDK (created once per widget in LiveChatWidget.tsx). A module wide lock would make
|
|
34
|
+
* widget A's start chat silently drop widget B's legitimate simultaneous start chat.
|
|
35
|
+
*
|
|
36
|
+
* The two maps are separate because prepareStartChat calls initStartChat; sharing a single lock
|
|
37
|
+
* would make the nested call see its own parent as in flight and drop it. prepareStartChat is
|
|
38
|
+
* additionally blocked by an in flight initStartChat (pre-chat submit, reconnect, or the
|
|
39
|
+
* hideStartChatButton bootstrap call initStartChat directly). Otherwise a later prepareStartChat
|
|
40
|
+
* would dispatch Loading and maximize the widget, and only then have its nested initStartChat
|
|
41
|
+
* dropped.
|
|
42
|
+
*/
|
|
43
|
+
const prepareStartChatGuards = new WeakMap();
|
|
44
|
+
const initStartChatGuards = new WeakMap();
|
|
21
45
|
|
|
22
|
-
//
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
let
|
|
46
|
+
// Fallback owner used only when no FacadeChatSDK instance is available to key on, so the guard
|
|
47
|
+
// degrades to the module wide behaviour instead of disappearing altogether.
|
|
48
|
+
const unkeyedGuardOwner = {};
|
|
49
|
+
const getGuard = (guards, facadeChatSDK) => {
|
|
50
|
+
const owner = facadeChatSDK ?? unkeyedGuardOwner;
|
|
51
|
+
let guard = guards.get(owner);
|
|
52
|
+
if (!guard) {
|
|
53
|
+
guard = {
|
|
54
|
+
inFlight: false
|
|
55
|
+
};
|
|
56
|
+
guards.set(owner, guard);
|
|
57
|
+
}
|
|
58
|
+
return guard;
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Runs `operation` only if no other invocation for the same widget instance is already in
|
|
63
|
+
* flight. Concurrent invocations are dropped (and reported through telemetry) rather than
|
|
64
|
+
* awaiting the in-flight promise, so a future re-entrant call can never deadlock on itself.
|
|
65
|
+
* No caller acts on the resolved value, so dropping is safe.
|
|
66
|
+
*
|
|
67
|
+
* `blockedBy` lets an operation also yield to a different, already running operation for the
|
|
68
|
+
* same widget instance without claiming that operation's lock.
|
|
69
|
+
*/
|
|
70
|
+
const runExclusively = async (guards, facadeChatSDK, description, operation, props, blockedBy) => {
|
|
71
|
+
const guard = getGuard(guards, facadeChatSDK);
|
|
72
|
+
const blockingGuard = blockedBy ? getGuard(blockedBy, facadeChatSDK) : undefined;
|
|
73
|
+
if (guard.inFlight || blockingGuard !== null && blockingGuard !== void 0 && blockingGuard.inFlight) {
|
|
74
|
+
TelemetryHelper.logActionEvent(LogLevel.WARN, {
|
|
75
|
+
Event: TelemetryEvent.ConcurrentStartChatRejected,
|
|
76
|
+
Description: description,
|
|
77
|
+
CustomProperties: {
|
|
78
|
+
WidgetCacheId: props ? getWidgetCacheIdfromProps(props) : undefined
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// Claim the lock before invoking the operation, so a re-entrant call made from the
|
|
85
|
+
// operation's synchronous preamble (before its first await) cannot slip past the check above.
|
|
86
|
+
guard.inFlight = true;
|
|
87
|
+
try {
|
|
88
|
+
await operation();
|
|
89
|
+
} finally {
|
|
90
|
+
guard.inFlight = false;
|
|
91
|
+
}
|
|
92
|
+
};
|
|
28
93
|
|
|
29
94
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
30
95
|
const prepareStartChat = async (props, facadeChatSDK, state, dispatch, setAdapter) => {
|
|
31
|
-
|
|
32
|
-
|
|
96
|
+
return runExclusively(prepareStartChatGuards, facadeChatSDK, "Concurrent prepareStartChat call ignored, a start chat operation is already in progress for this widget instance.", () => prepareStartChatInternal(props, facadeChatSDK, state, dispatch, setAdapter), props, initStartChatGuards);
|
|
97
|
+
};
|
|
33
98
|
|
|
99
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
100
|
+
const prepareStartChatInternal = async (props, facadeChatSDK, state, dispatch, setAdapter) => {
|
|
34
101
|
// reconnect > chat from cache
|
|
35
102
|
if (isReconnectEnabled(props.chatConfig) === true && !isPersistentEnabled(props.chatConfig)) {
|
|
36
103
|
const shouldStartChatNormally = await handleChatReconnect(facadeChatSDK, props, dispatch, setAdapter, initStartChat, state);
|
|
@@ -156,6 +223,11 @@ const setPreChatAndInitiateChat = async (facadeChatSDK, dispatch, setAdapter, is
|
|
|
156
223
|
|
|
157
224
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
158
225
|
const initStartChat = async (facadeChatSDK, dispatch, setAdapter, state, props, params, persistedState) => {
|
|
226
|
+
return runExclusively(initStartChatGuards, facadeChatSDK, "Concurrent initStartChat call ignored, a start chat operation is already in progress for this widget instance.", () => initStartChatInternal(facadeChatSDK, dispatch, setAdapter, state, props, params, persistedState), props);
|
|
227
|
+
};
|
|
228
|
+
|
|
229
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
230
|
+
const initStartChatInternal = async (facadeChatSDK, dispatch, setAdapter, state, props, params, persistedState) => {
|
|
159
231
|
var _state$domainStates7;
|
|
160
232
|
let isStartChatSuccessful = false;
|
|
161
233
|
const persistentChatEnabled = isPersistentChatEnabled(state === null || state === void 0 || (_state$domainStates7 = state.domainStates) === null || _state$domainStates7 === void 0 || (_state$domainStates7 = _state$domainStates7.liveChatConfig) === null || _state$domainStates7 === void 0 || (_state$domainStates7 = _state$domainStates7.LiveWSAndLiveChatEngJoin) === null || _state$domainStates7 === void 0 ? void 0 : _state$domainStates7.msdyn_conversationmode);
|
|
@@ -194,14 +266,15 @@ const initStartChat = async (facadeChatSDK, dispatch, setAdapter, state, props,
|
|
|
194
266
|
}
|
|
195
267
|
try {
|
|
196
268
|
var _window$Microsoft, _state$domainStates8;
|
|
197
|
-
// Set custom context params
|
|
198
|
-
|
|
269
|
+
// Set custom context params. Returned (not stored module-side) so that concurrent
|
|
270
|
+
// widget instances cannot overwrite each other's custom context.
|
|
271
|
+
const customContextParams = await setCustomContextParams(state, props);
|
|
199
272
|
const defaultOptionalParams = {
|
|
200
273
|
sendDefaultInitContext: true,
|
|
201
274
|
isProactiveChat: !!(params !== null && params !== void 0 && params.isProactiveChat),
|
|
202
275
|
portalContactId: (_window$Microsoft = window.Microsoft) === null || _window$Microsoft === void 0 || (_window$Microsoft = _window$Microsoft.Dynamic365) === null || _window$Microsoft === void 0 || (_window$Microsoft = _window$Microsoft.Portal) === null || _window$Microsoft === void 0 || (_window$Microsoft = _window$Microsoft.User) === null || _window$Microsoft === void 0 ? void 0 : _window$Microsoft.contactId
|
|
203
276
|
};
|
|
204
|
-
const startChatOptionalParams = Object.assign({}, params,
|
|
277
|
+
const startChatOptionalParams = Object.assign({}, params, customContextParams, defaultOptionalParams);
|
|
205
278
|
|
|
206
279
|
// MID-AUTH: Add wasAuthenticated flag for reconnect scenarios
|
|
207
280
|
// Tells FacadeChatSDK whether the previous session was authenticated
|
|
@@ -284,9 +357,6 @@ const initStartChat = async (facadeChatSDK, dispatch, setAdapter, state, props,
|
|
|
284
357
|
await updateTelemetryData(facadeChatSDK, dispatch);
|
|
285
358
|
} catch (ex) {
|
|
286
359
|
handleStartChatError(dispatch, facadeChatSDK, props, ex, isStartChatSuccessful);
|
|
287
|
-
} finally {
|
|
288
|
-
optionalParams = {};
|
|
289
|
-
widgetInstanceId = "";
|
|
290
360
|
}
|
|
291
361
|
};
|
|
292
362
|
|
|
@@ -330,19 +400,22 @@ const canConnectToExistingChat = async (props, facadeChatSDK, state, dispatch, s
|
|
|
330
400
|
return false;
|
|
331
401
|
};
|
|
332
402
|
|
|
333
|
-
|
|
403
|
+
/**
|
|
404
|
+
* Resolves the custom context to start the chat with.
|
|
405
|
+
*
|
|
406
|
+
* Returns the resolved params instead of mutating module-level state: a page can host several
|
|
407
|
+
* independent widgets, and once per-instance start-chat guards allow them to run concurrently,
|
|
408
|
+
* shared mutable state would let one widget overwrite another widget's custom context.
|
|
409
|
+
*/
|
|
334
410
|
const setCustomContextParams = async (state, props) => {
|
|
335
411
|
var _state$domainStates9, _persistedState$domai5;
|
|
336
412
|
if (state !== null && state !== void 0 && (_state$domainStates9 = state.domainStates) !== null && _state$domainStates9 !== void 0 && _state$domainStates9.customContext) {
|
|
337
413
|
var _state$domainStates0;
|
|
338
|
-
|
|
414
|
+
return {
|
|
339
415
|
customContext: JSON.parse(JSON.stringify(state === null || state === void 0 || (_state$domainStates0 = state.domainStates) === null || _state$domainStates0 === void 0 ? void 0 : _state$domainStates0.customContext))
|
|
340
|
-
}
|
|
341
|
-
return;
|
|
342
|
-
}
|
|
343
|
-
if (isNullOrEmptyString(widgetInstanceId)) {
|
|
344
|
-
widgetInstanceId = getWidgetCacheIdfromProps(props);
|
|
416
|
+
};
|
|
345
417
|
}
|
|
418
|
+
const widgetInstanceId = props ? getWidgetCacheIdfromProps(props) : "";
|
|
346
419
|
// Add custom context only for unauthenticated chat
|
|
347
420
|
const persistedState = getStateFromCache(widgetInstanceId);
|
|
348
421
|
const customContextLocal = (persistedState === null || persistedState === void 0 || (_persistedState$domai5 = persistedState.domainStates) === null || _persistedState$domai5 === void 0 ? void 0 : _persistedState$domai5.customContext) ?? (props === null || props === void 0 ? void 0 : props.initialCustomContext);
|
|
@@ -351,23 +424,23 @@ const setCustomContextParams = async (state, props) => {
|
|
|
351
424
|
Event: TelemetryEvent.SettingCustomContext,
|
|
352
425
|
Description: "Setting custom context for unauthenticated chat"
|
|
353
426
|
});
|
|
354
|
-
|
|
427
|
+
return {
|
|
355
428
|
customContext: JSON.parse(JSON.stringify(customContextLocal))
|
|
356
|
-
}
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
}
|
|
429
|
+
};
|
|
430
|
+
}
|
|
431
|
+
const customContextFromParent = await getInitContextParamsForPopout();
|
|
432
|
+
if (!isUndefinedOrEmpty(customContextFromParent === null || customContextFromParent === void 0 ? void 0 : customContextFromParent.contextVariables)) {
|
|
433
|
+
return {
|
|
434
|
+
customContext: JSON.parse(JSON.stringify(customContextFromParent.contextVariables))
|
|
435
|
+
};
|
|
364
436
|
}
|
|
437
|
+
return {};
|
|
365
438
|
};
|
|
366
439
|
const canStartPopoutChat = async props => {
|
|
367
440
|
if (props.allowSdkChatSupport === false) {
|
|
368
441
|
return false;
|
|
369
442
|
}
|
|
370
|
-
popoutWidgetInstanceId = getWidgetCacheIdfromProps(props, true);
|
|
443
|
+
const popoutWidgetInstanceId = getWidgetCacheIdfromProps(props, true);
|
|
371
444
|
if (!isNullOrEmptyString(popoutWidgetInstanceId)) {
|
|
372
445
|
var _persistedState$domai6, _persistedState$appSt3;
|
|
373
446
|
const persistedState = getStateFromCache(popoutWidgetInstanceId);
|
|
@@ -62,6 +62,7 @@ import useChatAdapterStore from "../../../hooks/useChatAdapterStore";
|
|
|
62
62
|
import useChatContextStore from "../../../hooks/useChatContextStore";
|
|
63
63
|
import useFacadeSDKStore from "../../../hooks/useFacadeChatSDKStore";
|
|
64
64
|
import { getPostChatContext, initiatePostChat } from "../common/renderSurveyHelpers";
|
|
65
|
+
import { logRecoveryEligibilityTelemetry } from "../common/recoveryEligibilityTelemetry";
|
|
65
66
|
let uiTimer;
|
|
66
67
|
export const LiveChatWidgetStateful = props => {
|
|
67
68
|
var _props$webChatContain, _props$webChatContain2, _props$webChatContain3, _props$webChatContain4, _props$webChatContain5, _props$styleProps, _props$webChatContain6, _props$controlProps, _props$controlProps3, _state$appStates7, _props$webChatContain9, _state$appStates8, _props$webChatContain1, _props$webChatContain10, _props$controlProps10, _props$draggableChatW, _props$draggableChatW2, _props$draggableChatW3, _props$draggableChatW4, _props$draggableChatW5, _livechatProps$webCha, _livechatProps$styleP, _props$headerProps, _livechatProps$contro, _livechatProps$contro2, _livechatProps$compon, _livechatProps$contro3, _livechatProps$compon2, _livechatProps$contro4, _livechatProps$compon3, _livechatProps$contro5, _livechatProps$compon4, _livechatProps$contro6, _livechatProps$compon5, _livechatProps$contro7, _livechatProps$compon6, _livechatProps$contro8, _livechatProps$compon7, _livechatProps$contro9, _livechatProps$compon8, _livechatProps$contro0, _livechatProps$contro1, _livechatProps$compon9, _livechatProps$contro10, _livechatProps$compon0, _livechatProps$contro11, _livechatProps$compon1, _livechatProps$compon10, _livechatProps$compon11;
|
|
@@ -150,6 +151,7 @@ export const LiveChatWidgetStateful = props => {
|
|
|
150
151
|
activeCachedChatExist = false;
|
|
151
152
|
optionalParams = {};
|
|
152
153
|
}
|
|
154
|
+
logRecoveryEligibilityTelemetry(state, activeCachedChatExist);
|
|
153
155
|
};
|
|
154
156
|
|
|
155
157
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -1165,18 +1167,18 @@ export const LiveChatWidgetStateful = props => {
|
|
|
1165
1167
|
.webchat__auto-resize-textarea.webchat__send-box-text-box__text-area {
|
|
1166
1168
|
min-height: ${sendBoxTextArea === null || sendBoxTextArea === void 0 ? void 0 : sendBoxTextArea.minHeight} !important;
|
|
1167
1169
|
}`}
|
|
1168
|
-
`), /*#__PURE__*/React.createElement(DraggableChatWidget, chatWidgetDraggableConfig, /*#__PURE__*/React.createElement(
|
|
1169
|
-
userID: userID,
|
|
1170
|
-
styleOptions: styleOptions,
|
|
1171
|
-
directLine: directLine
|
|
1172
|
-
}), /*#__PURE__*/React.createElement(Stack, {
|
|
1170
|
+
`), /*#__PURE__*/React.createElement(DraggableChatWidget, chatWidgetDraggableConfig, /*#__PURE__*/React.createElement(Stack, {
|
|
1173
1171
|
id: widgetElementId,
|
|
1174
1172
|
styles: generalStyles,
|
|
1175
1173
|
className: (_livechatProps$styleP = livechatProps.styleProps) === null || _livechatProps$styleP === void 0 ? void 0 : _livechatProps$styleP.className,
|
|
1176
1174
|
role: isWidgetOpen ? "dialog" : undefined,
|
|
1177
1175
|
"aria-modal": isWidgetOpen ? true : undefined,
|
|
1178
1176
|
"aria-label": isWidgetOpen ? ((_props$headerProps = props.headerProps) === null || _props$headerProps === void 0 || (_props$headerProps = _props$headerProps.controlProps) === null || _props$headerProps === void 0 || (_props$headerProps = _props$headerProps.headerTitleProps) === null || _props$headerProps === void 0 ? void 0 : _props$headerProps.text) ?? "Live Chat" : undefined
|
|
1179
|
-
},
|
|
1177
|
+
}, /*#__PURE__*/React.createElement(Composer, _extends({}, webChatProps, {
|
|
1178
|
+
userID: userID,
|
|
1179
|
+
styleOptions: styleOptions,
|
|
1180
|
+
directLine: directLine
|
|
1181
|
+
}), !((_livechatProps$contro = livechatProps.controlProps) !== null && _livechatProps$contro !== void 0 && _livechatProps$contro.hideChatButton) && !((_livechatProps$contro2 = livechatProps.controlProps) !== null && _livechatProps$contro2 !== void 0 && _livechatProps$contro2.hideStartChatButton) && shouldShowChatButton(state) && (decodeComponentString((_livechatProps$compon = livechatProps.componentOverrides) === null || _livechatProps$compon === void 0 ? void 0 : _livechatProps$compon.chatButton) || /*#__PURE__*/React.createElement(ChatButtonStateful, {
|
|
1180
1182
|
buttonProps: livechatProps.chatButtonProps,
|
|
1181
1183
|
outOfOfficeButtonProps: livechatProps.outOfOfficeChatButtonProps,
|
|
1182
1184
|
startChat: prepareStartChatRelay
|