@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
package/README.md
CHANGED
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
1. [Installation](#installation)
|
|
14
14
|
1. [WebChat dependency constraint](#webchat-dependency-constraint)
|
|
15
15
|
1. [Example Usage](#example-usage)
|
|
16
|
+
1. [Bot authentication and the sign-in card](#bot-authentication-and-the-sign-in-card)
|
|
16
17
|
1. [Components](#components)
|
|
17
18
|
1. [See Also](#see-also)
|
|
18
19
|
|
|
@@ -53,10 +54,12 @@ This package requires Node.js `>=22.12.0` for consumer builds. Node 20 is not su
|
|
|
53
54
|
For a production application, pin the exact stable versions:
|
|
54
55
|
|
|
55
56
|
```bash
|
|
56
|
-
npm install --save-exact @microsoft/omnichannel-chat-widget@2.0.
|
|
57
|
+
npm install --save-exact @microsoft/omnichannel-chat-widget@2.0.1 @microsoft/omnichannel-chat-components@1.2.0 @microsoft/omnichannel-chat-sdk@2.0.1
|
|
57
58
|
```
|
|
58
59
|
|
|
59
|
-
`2.0.
|
|
60
|
+
`2.0.1` release date is 2026-10-05. Official support ends on 2027-10-05. See the [root support table](https://github.com/microsoft/omnichannel-chat-widget#chat-widget).
|
|
61
|
+
|
|
62
|
+
_**Known issue:**_ Chat SDK versions earlier than `1.11.6` can start duplicate conversations when `startChat()` is called again before the previous call is complete. Chat Widget `1.8.1` and earlier can use these versions. Upgrade the Chat SDK to `1.11.8` or later. See [Duplicate conversations with Chat SDK versions before 1.11.6](https://github.com/microsoft/omnichannel-chat-widget/blob/main/docs/KNOWN_ISSUE_CONCURRENT_STARTCHAT.md).
|
|
60
63
|
|
|
61
64
|
TypeScript consumers that imported the exported Web Chat middleware factories now receive Redux 5 `unknown` actions. Narrow with `isWebChatAction` before reading `type` or `payload`. Runtime behavior is unchanged.
|
|
62
65
|
|
|
@@ -79,6 +82,8 @@ This hotfix still declares these vulnerable transitive versions:
|
|
|
79
82
|
| `swiper` | `8.4.7` |
|
|
80
83
|
| `valibot` | `1.1.0` |
|
|
81
84
|
| `uuid` | `3.4.0`, `8.3.2`, and `9.0.1` |
|
|
85
|
+
| `deepmerge` (via `sanitize-html@2.14.0`) | `4.3.1` |
|
|
86
|
+
| `minimatch` (via the Speech SDK's `rimraf@3` → `glob@7`) | `3.1.5` |
|
|
82
87
|
|
|
83
88
|
The consumer audit permits only the reviewed advisories from this hotfix. It rejects each new advisory.
|
|
84
89
|
|
|
@@ -140,6 +145,60 @@ A typescript sample widget can be found [here](https://github.com/microsoft/omni
|
|
|
140
145
|
|
|
141
146
|
```react-scripts``` has deprecated to build the sample project, please refer to vite building instructions: [BuildingUsingVite.md](https://github.com/microsoft/omnichannel-chat-widget/blob/main/docs/BuildingUsingVite.md)
|
|
142
147
|
|
|
148
|
+
## Bot authentication and the sign-in card
|
|
149
|
+
|
|
150
|
+
A bot that uses single sign-on (SSO) can send a sign-in (OAuth) card. The host page decides whether the widget shows the card. It passes a callback to the Omnichannel SDK method [`setBotAuthTokenProvider`](https://learn.microsoft.com/dynamics365/customer-service/develop/reference/methods/setbotauthtokenprovider), and the callback calls `callback({show: false})` for a customer who is already signed in.
|
|
151
|
+
|
|
152
|
+
When a sign-in card arrives, the widget asks the host for this result. It tries `fetchBotAuthConfigRetries` times (default `3`), `fetchBotAuthConfigRetryInterval` milliseconds apart (default `1000`), so it waits about 2 seconds by default. If the host doesn't answer in that time, `fallbackShowSignInCard` decides what happens:
|
|
153
|
+
|
|
154
|
+
| `fallbackShowSignInCard` | Card when the host doesn't answer in time | Telemetry |
|
|
155
|
+
| --- | --- | --- |
|
|
156
|
+
| Not set (default) | Shown | `SetBotAuthProviderNotFound` (with the error) |
|
|
157
|
+
| `false` | Hidden | `SetBotAuthProviderNotFound` (with the fallback value), then `SetBotAuthProviderHideCard` |
|
|
158
|
+
| `true` | Shown | `SetBotAuthProviderNotFound` (with the fallback value), then `SetBotAuthProviderDisplayCard` |
|
|
159
|
+
|
|
160
|
+
Which value to use:
|
|
161
|
+
|
|
162
|
+
| Your setup | `fallbackShowSignInCard` |
|
|
163
|
+
| --- | --- |
|
|
164
|
+
| Your page signs the customer in, and your `setBotAuthTokenProvider` callback passes the token to the bot (bot SSO) | `false` |
|
|
165
|
+
| You want the card to show whenever the callback is late, and you want this logged as a decision | `true` |
|
|
166
|
+
| Customers sign in through the sign-in card itself | Leave it unset |
|
|
167
|
+
|
|
168
|
+
```js
|
|
169
|
+
const liveChatWidgetProps = {
|
|
170
|
+
chatSDK: chatSDK, // mandatory
|
|
171
|
+
chatConfig: chatConfig, // mandatory
|
|
172
|
+
webChatContainerProps: {
|
|
173
|
+
botAuthConfig: {
|
|
174
|
+
fallbackShowSignInCard: false // hide the card if the host doesn't answer in time
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
If you use the live chat widget 2.0 script instead of this package, the function that the script's `data-customization-callback` attribute references must return a root props object that contains the setting, for example `{ webChatContainerProps: { botAuthConfig: { fallbackShowSignInCard: false } } }`. See [Develop a custom live chat widget](https://learn.microsoft.com/dynamics365/customer-service/develop/develop-live-chat-widget).
|
|
181
|
+
|
|
182
|
+
What the customer sees:
|
|
183
|
+
|
|
184
|
+
| Situation | Card |
|
|
185
|
+
| --- | --- |
|
|
186
|
+
| The host answers `callback({show: false})` in time | Hidden (`SetBotAuthProviderHideCard`) |
|
|
187
|
+
| The host answers `callback({show: true})` in time | Shown (`SetBotAuthProviderDisplayCard`) |
|
|
188
|
+
| The host doesn't answer in time (slow request, error, or no `callback(...)` call) | Depends on `fallbackShowSignInCard` (see the previous table) |
|
|
189
|
+
| The widget can't extract a sign-in ID from the card, or can't get a token exchange URL (from the card or from the Bot Framework token service) | Shown. The widget doesn't ask the host. |
|
|
190
|
+
|
|
191
|
+
`fallbackShowSignInCard` changes only what happens when the host doesn't answer in time. It isn't a substitute for a working `setBotAuthTokenProvider` callback. If you set it to `false` and the callback fails for a customer who isn't signed in, that customer doesn't see the card and can't sign in.
|
|
192
|
+
|
|
193
|
+
**Troubleshooting: a signed-in customer sometimes sees the sign-in card.** The `setBotAuthTokenProvider` callback probably didn't answer in time. Look for `SetBotAuthProviderNotFound` in the widget telemetry. To fix it:
|
|
194
|
+
|
|
195
|
+
1. Call `callback(...)` on every code path of the function, including error paths. If the function throws before it calls `callback(...)`, the widget gets no answer.
|
|
196
|
+
1. Make the whole function finish quickly. With the live chat widget 2.0 script, the widget gets the `callback(...)` value only after the function finishes, so slow work after `callback(...)` still delays the answer. For a sign-in card that your page already completed, call `callback({show: false})` and return at once. Otherwise, complete the token exchange, then call `callback(...)` with its result.
|
|
197
|
+
1. If the function is correct but can't finish in about 2 seconds, increase `fetchBotAuthConfigRetries` or `fetchBotAuthConfigRetryInterval`.
|
|
198
|
+
1. If your function passes a token to the bot for every customer before the chat needs it (bot SSO works), set `fallbackShowSignInCard: false`. Signing the customer in to your page, or using authenticated chat, doesn't by itself sign the customer in to the bot.
|
|
199
|
+
|
|
200
|
+
For the host-side callback, see [Pass authentication token to bot during single sign-on in live chat](https://learn.microsoft.com/dynamics365/customer-service/develop/pass-auth-token-sso-live-chat).
|
|
201
|
+
|
|
143
202
|
## Components
|
|
144
203
|
|
|
145
204
|
For a detailed guide on how to customize each component with sample usages, please see our new [Developer Guide](https://github.com/microsoft/omnichannel-chat-widget/blob/main/docs/customizations/getstarted.md).
|
|
@@ -111,6 +111,7 @@ let TelemetryEvent = exports.TelemetryEvent = /*#__PURE__*/function (TelemetryEv
|
|
|
111
111
|
TelemetryEvent["MidConversationAuthSucceeded"] = "MidConversationAuthSucceeded";
|
|
112
112
|
TelemetryEvent["MidConversationAuthFailed"] = "MidConversationAuthFailed";
|
|
113
113
|
TelemetryEvent["MidConversationAuthReset"] = "MidConversationAuthReset";
|
|
114
|
+
TelemetryEvent["RecoveryEligibilityEvaluated"] = "RecoveryEligibilityEvaluated";
|
|
114
115
|
TelemetryEvent["GetConversationDetailsCallStarted"] = "GetConversationDetailsCallStarted";
|
|
115
116
|
TelemetryEvent["GetConversationDetailsCallFailed"] = "GetConversationDetailsCallFailed";
|
|
116
117
|
TelemetryEvent["EndChatSDKCallFailed"] = "EndChatSDKCallFailed";
|
|
@@ -142,6 +143,8 @@ let TelemetryEvent = exports.TelemetryEvent = /*#__PURE__*/function (TelemetryEv
|
|
|
142
143
|
TelemetryEvent["PrechatSubmitted"] = "PrechatSubmitted";
|
|
143
144
|
TelemetryEvent["StartChatSDKCall"] = "StartChatCall";
|
|
144
145
|
TelemetryEvent["StartChatEventReceived"] = "StartChatEventReceived";
|
|
146
|
+
TelemetryEvent["ConcurrentStartChatRejected"] = "ConcurrentStartChatRejected";
|
|
147
|
+
TelemetryEvent["ChatSDKStateCleanUpDisconnectFailed"] = "ChatSDKStateCleanUpDisconnectFailed";
|
|
145
148
|
TelemetryEvent["EndChatSDKCall"] = "EndChatSDKCall";
|
|
146
149
|
TelemetryEvent["PrepareEndChat"] = "PrepareEndChat";
|
|
147
150
|
TelemetryEvent["EndChatEventReceived"] = "EndChatEventReceived";
|
|
@@ -414,6 +417,9 @@ let TelemetryConstants = exports.TelemetryConstants = /*#__PURE__*/function () {
|
|
|
414
417
|
case TelemetryEvent.SecureEventBusDispatchError:
|
|
415
418
|
case TelemetryEvent.AgentJoinedConversation:
|
|
416
419
|
case TelemetryEvent.BrowserTabHidden:
|
|
420
|
+
case TelemetryEvent.ConcurrentStartChatRejected:
|
|
421
|
+
case TelemetryEvent.ChatSDKStateCleanUpDisconnectFailed:
|
|
422
|
+
case TelemetryEvent.RecoveryEligibilityEvaluated:
|
|
417
423
|
return ScenarioType.ACTIONS;
|
|
418
424
|
case TelemetryEvent.StartChatSDKCall:
|
|
419
425
|
case TelemetryEvent.StartChatEventReceived:
|
|
@@ -58,37 +58,54 @@ const ChatButtonStateful = props => {
|
|
|
58
58
|
const ref = (0, _react.useRef)(() => {
|
|
59
59
|
return;
|
|
60
60
|
});
|
|
61
|
+
// Optimistic guard against rapid double-clicks. `conversationState` only flips to
|
|
62
|
+
// `Loading` after React re-renders, so the button stays visible and clickable for the
|
|
63
|
+
// whole duration of the first click's async work. Without this ref two concurrent
|
|
64
|
+
// startChat() calls can create two conversations on the backend.
|
|
65
|
+
const startChatInProgressRef = (0, _react.useRef)(false);
|
|
61
66
|
ref.current = async () => {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
ConversationStage: _TelemetryConstants.ConversationStage.Initialization
|
|
67
|
-
}
|
|
68
|
-
});
|
|
69
|
-
if (state.appStates.isMinimized) {
|
|
70
|
-
dispatch({
|
|
71
|
-
type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_MINIMIZED,
|
|
72
|
-
payload: false
|
|
67
|
+
if (startChatInProgressRef.current) {
|
|
68
|
+
_TelemetryHelper.TelemetryHelper.logActionEvent(_TelemetryConstants.LogLevel.WARN, {
|
|
69
|
+
Event: _TelemetryConstants.TelemetryEvent.ConcurrentStartChatRejected,
|
|
70
|
+
Description: "Chat button click ignored, a start chat operation is already in progress."
|
|
73
71
|
});
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
startChatInProgressRef.current = true;
|
|
75
|
+
try {
|
|
76
|
+
_TelemetryHelper.TelemetryHelper.logActionEventToAllTelemetry(_TelemetryConstants.LogLevel.INFO, {
|
|
77
|
+
Event: _TelemetryConstants.TelemetryEvent.LCWChatButtonClicked,
|
|
78
|
+
Description: "Chat button click action started",
|
|
79
|
+
CustomProperties: {
|
|
80
|
+
ConversationStage: _TelemetryConstants.ConversationStage.Initialization
|
|
81
|
+
}
|
|
77
82
|
});
|
|
78
|
-
|
|
79
|
-
|
|
83
|
+
if (state.appStates.isMinimized) {
|
|
84
|
+
dispatch({
|
|
85
|
+
type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_MINIMIZED,
|
|
86
|
+
payload: false
|
|
87
|
+
});
|
|
88
|
+
dispatch({
|
|
89
|
+
type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_UNREAD_MESSAGE_COUNT,
|
|
90
|
+
payload: 0
|
|
91
|
+
});
|
|
92
|
+
// If chat is minimized and then unminimized, start a chat if convesation state is closed.
|
|
93
|
+
if (state.appStates.conversationState === _ConversationState.ConversationState.Closed) {
|
|
94
|
+
await startChat();
|
|
95
|
+
}
|
|
96
|
+
} else {
|
|
80
97
|
await startChat();
|
|
81
98
|
}
|
|
82
|
-
|
|
83
|
-
|
|
99
|
+
_TelemetryHelper.TelemetryHelper.logActionEventToAllTelemetry(_TelemetryConstants.LogLevel.INFO, {
|
|
100
|
+
Event: _TelemetryConstants.TelemetryEvent.LCWChatButtonActionCompleted,
|
|
101
|
+
Description: "Chat button action completed",
|
|
102
|
+
CustomProperties: {
|
|
103
|
+
ConversationStage: _TelemetryConstants.ConversationStage.Initialization
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
} finally {
|
|
107
|
+
startChatInProgressRef.current = false;
|
|
84
108
|
}
|
|
85
|
-
_TelemetryHelper.TelemetryHelper.logActionEventToAllTelemetry(_TelemetryConstants.LogLevel.INFO, {
|
|
86
|
-
Event: _TelemetryConstants.TelemetryEvent.LCWChatButtonActionCompleted,
|
|
87
|
-
Description: "Chat button action completed",
|
|
88
|
-
CustomProperties: {
|
|
89
|
-
ConversationStage: _TelemetryConstants.ConversationStage.Initialization
|
|
90
|
-
}
|
|
91
|
-
});
|
|
92
109
|
};
|
|
93
110
|
const outOfOfficeStyleProps = Object.assign({}, _defaultOutOfOfficeChatButtonStyleProps.defaultOutOfOfficeChatButtonStyleProps, outOfOfficeButtonProps === null || outOfOfficeButtonProps === void 0 ? void 0 : outOfOfficeButtonProps.styleProps);
|
|
94
111
|
const controlProps = {
|
|
@@ -360,13 +360,52 @@ const closeChatStateCleanUp = dispatch => {
|
|
|
360
360
|
|
|
361
361
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
362
362
|
exports.closeChatStateCleanUp = closeChatStateCleanUp;
|
|
363
|
+
const logCleanUpDisconnectFailure = error => {
|
|
364
|
+
_TelemetryHelper.TelemetryHelper.logActionEvent(_TelemetryConstants.LogLevel.WARN, {
|
|
365
|
+
Event: _TelemetryConstants.TelemetryEvent.ChatSDKStateCleanUpDisconnectFailed,
|
|
366
|
+
Description: "Failed to disconnect the previous conversation during chat SDK state clean up.",
|
|
367
|
+
ExceptionDetails: {
|
|
368
|
+
exception: (error === null || error === void 0 ? void 0 : error.message) ?? error
|
|
369
|
+
}
|
|
370
|
+
});
|
|
371
|
+
};
|
|
372
|
+
|
|
373
|
+
// Releases the previous session's conversation. Mirrors the cleanup OmnichannelChatSDK.endChat()
|
|
374
|
+
// runs in its finally block (disconnect, then drop the reference). Without it, a conversation
|
|
375
|
+
// left over from a failed or orphaned start chat, or from a chat ended in another tab (which
|
|
376
|
+
// skips the SDK endChat), keeps its messaging session open and leaks into the next chat.
|
|
377
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
378
|
+
const disconnectConversation = chatSDK => {
|
|
379
|
+
const conversation = chatSDK.conversation;
|
|
380
|
+
if (!conversation || typeof conversation.disconnect !== "function") {
|
|
381
|
+
return;
|
|
382
|
+
}
|
|
383
|
+
try {
|
|
384
|
+
// ACS conversations disconnect asynchronously; legacy IC3 conversations may not return a promise.
|
|
385
|
+
const result = conversation.disconnect();
|
|
386
|
+
if (result && typeof result.catch === "function") {
|
|
387
|
+
result.catch(logCleanUpDisconnectFailure);
|
|
388
|
+
}
|
|
389
|
+
} catch (error) {
|
|
390
|
+
logCleanUpDisconnectFailure(error);
|
|
391
|
+
}
|
|
392
|
+
};
|
|
393
|
+
|
|
394
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
363
395
|
const chatSDKStateCleanUp = chatSDK => {
|
|
396
|
+
if (!chatSDK) {
|
|
397
|
+
return;
|
|
398
|
+
}
|
|
399
|
+
|
|
364
400
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
365
401
|
chatSDK.requestId = (0, _omnichannelChatSdk.uuidv4)();
|
|
366
402
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
367
403
|
chatSDK.chatToken = {};
|
|
368
404
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
369
405
|
chatSDK.reconnectId = null;
|
|
406
|
+
disconnectConversation(chatSDK);
|
|
407
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
408
|
+
chatSDK.conversation = null;
|
|
370
409
|
};
|
|
371
410
|
|
|
372
411
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.initWebChatComposer = void 0;
|
|
6
|
+
exports.initWebChatComposer = exports.createScreenReaderMarkdownRenderer = void 0;
|
|
7
7
|
var _Constants = require("../../../common/Constants");
|
|
8
8
|
var _TelemetryConstants = require("../../../common/telemetry/TelemetryConstants");
|
|
9
9
|
var _utils = require("../../../common/utils");
|
|
@@ -20,6 +20,7 @@ var _attachmentSentAnnouncementMiddleware = _interopRequireDefault(require("../.
|
|
|
20
20
|
var _channelDataMiddleware = _interopRequireDefault(require("../../webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/channelDataMiddleware"));
|
|
21
21
|
var _activityMiddleware = require("../../webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityMiddleware");
|
|
22
22
|
var _activityStatusMiddleware = require("../../webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityStatusMiddleware");
|
|
23
|
+
var _attachmentForScreenReaderMiddleware = require("../../webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/attachmentForScreenReaderMiddleware");
|
|
23
24
|
var _attachmentMiddleware = require("../../webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/attachmentMiddleware");
|
|
24
25
|
var _attachmentUploadValidatorMiddleware = _interopRequireDefault(require("../../webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/attachmentUploadValidatorMiddleware"));
|
|
25
26
|
var _avatarMiddleware = require("../../webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/avatarMiddleware");
|
|
@@ -48,7 +49,34 @@ var _htmlTextMiddleware = _interopRequireDefault(require("../../webchatcontainer
|
|
|
48
49
|
var _preProcessingMiddleware = _interopRequireDefault(require("../../webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/preProcessingMiddleware"));
|
|
49
50
|
var _sanitizationMiddleware = _interopRequireDefault(require("../../webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/sanitizationMiddleware"));
|
|
50
51
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
52
|
+
const markdownSanitizeConfig = {
|
|
53
|
+
FORBID_TAGS: ["form", "button", "script", "div", "input"],
|
|
54
|
+
FORBID_ATTR: ["action"],
|
|
55
|
+
ADD_ATTR: ["target"]
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Renders Markdown for the screen reader text of Adaptive Cards, from the same pieces as the visible card:
|
|
60
|
+
* the host renderMarkdown when set, the hyperlink text override, and the same sanitization.
|
|
61
|
+
* Markdown is always formatted, also when the widget shows Markdown unformatted, so that screen readers do not read the syntax.
|
|
62
|
+
* Styles are removed with their content because the card does not show them.
|
|
63
|
+
*/
|
|
64
|
+
const createScreenReaderMarkdownRenderer = webChatContainerProps => {
|
|
65
|
+
var _webChatContainerProp;
|
|
66
|
+
const hostRenderMarkdown = webChatContainerProps === null || webChatContainerProps === void 0 || (_webChatContainerProp = webChatContainerProps.webChatProps) === null || _webChatContainerProp === void 0 ? void 0 : _webChatContainerProp.renderMarkdown;
|
|
67
|
+
const markdown = (0, _createMarkdown.createMarkdown)(false, (webChatContainerProps === null || webChatContainerProps === void 0 ? void 0 : webChatContainerProps.disableNewLineMarkdownSupport) ?? _defaultWebChatContainerStatefulProps.defaultWebChatContainerStatefulProps.disableNewLineMarkdownSupport, webChatContainerProps === null || webChatContainerProps === void 0 ? void 0 : webChatContainerProps.opensMarkdownLinksInSameTab);
|
|
68
|
+
const hyperlinkTextOverrideRenderer = new _HyperlinkTextOverrideRenderer.default((webChatContainerProps === null || webChatContainerProps === void 0 ? void 0 : webChatContainerProps.hyperlinkTextOverride) ?? _defaultWebChatContainerStatefulProps.defaultWebChatContainerStatefulProps.hyperlinkTextOverride);
|
|
69
|
+
return text => {
|
|
70
|
+
const html = hostRenderMarkdown ? hostRenderMarkdown(text) : markdown.render(text);
|
|
71
|
+
return _dompurify.default.sanitize(hyperlinkTextOverrideRenderer.render(html), {
|
|
72
|
+
...markdownSanitizeConfig,
|
|
73
|
+
FORBID_TAGS: [...markdownSanitizeConfig.FORBID_TAGS, "style"]
|
|
74
|
+
});
|
|
75
|
+
};
|
|
76
|
+
};
|
|
77
|
+
|
|
51
78
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
79
|
+
exports.createScreenReaderMarkdownRenderer = createScreenReaderMarkdownRenderer;
|
|
52
80
|
const initWebChatComposer = (props, state, dispatch, facadeChatSDK, endChat) => {
|
|
53
81
|
var _props$webChatContain, _props$webChatContain2, _props$webChatContain3, _props$webChatContain4, _props$webChatContain5, _props$webChatContain6, _state$domainStates$l4, _props$webChatContain0, _state$domainStates$r, _state$domainStates$r2, _props$webChatContain1, _state$domainStates$r3, _props$webChatContain10, _state$domainStates$l5, _props$webChatContain11, _props$webChatContain12, _state$domainStates$r4, _state$domainStates$r5, _props$webChatContain13, _defaultWebChatContai, _props$webChatContain14, _defaultWebChatContai2, _props$webChatContain15, _props$webChatContain16, _props$webChatContain17;
|
|
54
82
|
// Add a hook to make all links open a new window
|
|
@@ -67,7 +95,7 @@ const initWebChatComposer = (props, state, dispatch, facadeChatSDK, endChat) =>
|
|
|
67
95
|
// Initialize Web Chat's redux store
|
|
68
96
|
let webChatStore = _WebChatStoreLoader.WebChatStoreLoader.store;
|
|
69
97
|
if (!webChatStore) {
|
|
70
|
-
var _state$domainStates$l, _state$domainStates$l2, _state$domainStates$l3, _props$webChatContain7;
|
|
98
|
+
var _state$domainStates$l, _state$domainStates$l2, _props$controlProps, _state$domainStates$l3, _props$webChatContain7;
|
|
71
99
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
72
100
|
const addConversationalSurveyTagsCallback = action => {
|
|
73
101
|
var _inMemoryState$appSta;
|
|
@@ -126,7 +154,7 @@ const initWebChatComposer = (props, state, dispatch, facadeChatSDK, endChat) =>
|
|
|
126
154
|
};
|
|
127
155
|
webChatStore = (0, _botframeworkWebchat.createStore)({},
|
|
128
156
|
//initial state
|
|
129
|
-
_preProcessingMiddleware.default, _attachmentProcessingMiddleware.default, (0, _attachmentUploadValidatorMiddleware.default)((_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), _attachmentSentAnnouncementMiddleware.default, (0, _customEventMiddleware.default)(_omnichannelChatComponents.BroadcastService), (0, _queueOverflowHandlerMiddleware.createQueueOverflowMiddleware)(state, dispatch), (0, _channelDataMiddleware.default)(addConversationalSurveyTagsCallback), (0, _conversationEndMiddleware.default)(conversationEndCallback, startConversationalSurveyCallback, endConversationalSurveyCallback), (0, _dataMaskingMiddleware.default)((_state$domainStates$l3 = state.domainStates.liveChatConfig) === null || _state$domainStates$l3 === void 0 ? void 0 : _state$domainStates$l3.DataMaskingInfo), _messageTimestampMiddleware.createMessageTimeStampMiddleware, _messageSequenceIdOverrideMiddleware.createMessageSequenceIdOverrideMiddleware, (0, _citationsMiddleware.createCitationsMiddleware)(state, dispatch), _gifUploadMiddleware.default, _htmlPlayerMiddleware.default, (0, _htmlTextMiddleware.default)(honorsTargetInHTMLLinks), (0, _maxMessageSizeValidator.default)(localizedTexts), _sanitizationMiddleware.default, (0, _callActionMiddleware.default)(),
|
|
157
|
+
_preProcessingMiddleware.default, _attachmentProcessingMiddleware.default, (0, _attachmentUploadValidatorMiddleware.default)((_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), (0, _attachmentSentAnnouncementMiddleware.default)(localizedTexts, ((_props$controlProps = props.controlProps) === null || _props$controlProps === void 0 ? void 0 : _props$controlProps.id) || "oc-lcw"), (0, _customEventMiddleware.default)(_omnichannelChatComponents.BroadcastService), (0, _queueOverflowHandlerMiddleware.createQueueOverflowMiddleware)(state, dispatch), (0, _channelDataMiddleware.default)(addConversationalSurveyTagsCallback), (0, _conversationEndMiddleware.default)(conversationEndCallback, startConversationalSurveyCallback, endConversationalSurveyCallback), (0, _dataMaskingMiddleware.default)((_state$domainStates$l3 = state.domainStates.liveChatConfig) === null || _state$domainStates$l3 === void 0 ? void 0 : _state$domainStates$l3.DataMaskingInfo), _messageTimestampMiddleware.createMessageTimeStampMiddleware, _messageSequenceIdOverrideMiddleware.createMessageSequenceIdOverrideMiddleware, (0, _citationsMiddleware.createCitationsMiddleware)(state, dispatch), _gifUploadMiddleware.default, _htmlPlayerMiddleware.default, (0, _htmlTextMiddleware.default)(honorsTargetInHTMLLinks), (0, _maxMessageSizeValidator.default)(localizedTexts), _sanitizationMiddleware.default, (0, _callActionMiddleware.default)(),
|
|
130
158
|
// Pass a callback so middleware can push initials into React context for reactivity
|
|
131
159
|
(0, _localizedStringsBotInitialsMiddleware.localizedStringsBotInitialsMiddleware)(initials => {
|
|
132
160
|
dispatch({
|
|
@@ -154,12 +182,7 @@ const initWebChatComposer = (props, state, dispatch, facadeChatSDK, endChat) =>
|
|
|
154
182
|
});
|
|
155
183
|
|
|
156
184
|
// EXISTING sanitization (continues to work as before)
|
|
157
|
-
|
|
158
|
-
FORBID_TAGS: ["form", "button", "script", "div", "input"],
|
|
159
|
-
FORBID_ATTR: ["action"],
|
|
160
|
-
ADD_ATTR: ["target"]
|
|
161
|
-
};
|
|
162
|
-
text = _dompurify.default.sanitize(text, config);
|
|
185
|
+
text = _dompurify.default.sanitize(text, markdownSanitizeConfig);
|
|
163
186
|
|
|
164
187
|
// MONITOR-ONLY: Test what the stricter allowlist would remove (Phase 1)
|
|
165
188
|
// This does NOT modify the text, only logs telemetry
|
|
@@ -256,6 +279,12 @@ const initWebChatComposer = (props, state, dispatch, facadeChatSDK, endChat) =>
|
|
|
256
279
|
// Track what would be removed
|
|
257
280
|
const removedTags = [];
|
|
258
281
|
const removedAttributes = [];
|
|
282
|
+
const trackAttribute = name => {
|
|
283
|
+
const attrName = name.toLowerCase();
|
|
284
|
+
if (!strictConfig.ALLOWED_ATTR.includes(attrName) && attrName !== "class" && attrName !== "id") {
|
|
285
|
+
removedAttributes.push(attrName);
|
|
286
|
+
}
|
|
287
|
+
};
|
|
259
288
|
|
|
260
289
|
// Add hooks to the isolated monitoring instance
|
|
261
290
|
monitorDOMPurify.addHook("uponSanitizeElement", (node, data) => {
|
|
@@ -264,6 +293,8 @@ const initWebChatComposer = (props, state, dispatch, facadeChatSDK, endChat) =>
|
|
|
264
293
|
// Filter out "body" tag which is DOMPurify's internal wrapper
|
|
265
294
|
if (node.nodeType === 1 && !strictConfig.ALLOWED_TAGS.includes(tagName) && tagName !== "body") {
|
|
266
295
|
removedTags.push(tagName);
|
|
296
|
+
// DOMPurify 3.4.16+ skips uponSanitizeAttribute for removed elements
|
|
297
|
+
Array.from(node.attributes ?? []).forEach(attr => trackAttribute(attr.name));
|
|
267
298
|
}
|
|
268
299
|
} catch (hookError) {
|
|
269
300
|
// Silently ignore hook errors
|
|
@@ -271,10 +302,7 @@ const initWebChatComposer = (props, state, dispatch, facadeChatSDK, endChat) =>
|
|
|
271
302
|
});
|
|
272
303
|
monitorDOMPurify.addHook("uponSanitizeAttribute", (node, data) => {
|
|
273
304
|
try {
|
|
274
|
-
|
|
275
|
-
if (!strictConfig.ALLOWED_ATTR.includes(attrName) && attrName !== "class" && attrName !== "id") {
|
|
276
|
-
removedAttributes.push(attrName);
|
|
277
|
-
}
|
|
305
|
+
trackAttribute(data.attrName);
|
|
278
306
|
} catch (hookError) {
|
|
279
307
|
// Silently ignore hook errors
|
|
280
308
|
}
|
|
@@ -358,6 +386,7 @@ const initWebChatComposer = (props, state, dispatch, facadeChatSDK, endChat) =>
|
|
|
358
386
|
store: webChatStore,
|
|
359
387
|
activityMiddleware: (_props$webChatContain0 = props.webChatContainerProps) !== null && _props$webChatContain0 !== void 0 && (_props$webChatContain0 = _props$webChatContain0.renderingMiddlewareProps) !== null && _props$webChatContain0 !== void 0 && _props$webChatContain0.disableActivityMiddleware ? undefined : (0, _activityMiddleware.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),
|
|
360
388
|
attachmentMiddleware: (_props$webChatContain1 = props.webChatContainerProps) !== null && _props$webChatContain1 !== void 0 && (_props$webChatContain1 = _props$webChatContain1.renderingMiddlewareProps) !== null && _props$webChatContain1 !== void 0 && _props$webChatContain1.disableAttachmentMiddleware ? undefined : (0, _attachmentMiddleware.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.defaultAttachmentProps.enableInlinePlaying),
|
|
389
|
+
attachmentForScreenReaderMiddleware: (0, _attachmentForScreenReaderMiddleware.createAttachmentForScreenReaderMiddleware)(createScreenReaderMarkdownRenderer(props.webChatContainerProps)),
|
|
361
390
|
activityStatusMiddleware: (_props$webChatContain10 = props.webChatContainerProps) !== null && _props$webChatContain10 !== void 0 && (_props$webChatContain10 = _props$webChatContain10.renderingMiddlewareProps) !== null && _props$webChatContain10 !== void 0 && _props$webChatContain10.disableActivityStatusMiddleware ? undefined : (0, _activityStatusMiddleware.createActivityStatusMiddleware)((0, _omnichannelChatSdk.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)),
|
|
362
391
|
toastMiddleware: (_props$webChatContain11 = props.webChatContainerProps) !== null && _props$webChatContain11 !== void 0 && (_props$webChatContain11 = _props$webChatContain11.renderingMiddlewareProps) !== null && _props$webChatContain11 !== void 0 && _props$webChatContain11.disableToastMiddleware ? undefined : (0, _toastMiddleware.createToastMiddleware)(props.notificationPaneProps, endChat),
|
|
363
392
|
renderMarkdown,
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.logRecoveryEligibilityTelemetry = exports.getRecoveryEligibilityTelemetryProperties = exports.RecoveryEligibilityReason = void 0;
|
|
7
|
+
var _ConversationState = require("../../../contexts/common/ConversationState");
|
|
8
|
+
var _TelemetryConstants = require("../../../common/telemetry/TelemetryConstants");
|
|
9
|
+
var _TelemetryHelper = require("../../../common/telemetry/TelemetryHelper");
|
|
10
|
+
var _utils = require("../../../common/utils");
|
|
11
|
+
let RecoveryEligibilityReason = exports.RecoveryEligibilityReason = /*#__PURE__*/function (RecoveryEligibilityReason) {
|
|
12
|
+
RecoveryEligibilityReason["ReconnectIdPresent"] = "ReconnectIdPresent";
|
|
13
|
+
RecoveryEligibilityReason["ActiveContextPresent"] = "ActiveContextPresent";
|
|
14
|
+
RecoveryEligibilityReason["MissingContext"] = "MissingContext";
|
|
15
|
+
RecoveryEligibilityReason["CachedContextNonActive"] = "CachedContextNonActive";
|
|
16
|
+
return RecoveryEligibilityReason;
|
|
17
|
+
}({});
|
|
18
|
+
const getConversationStateName = conversationState => {
|
|
19
|
+
if (typeof conversationState !== "number") {
|
|
20
|
+
return "Unknown";
|
|
21
|
+
}
|
|
22
|
+
const stateName = _ConversationState.ConversationState[conversationState];
|
|
23
|
+
return typeof stateName === "string" ? stateName : "Unknown";
|
|
24
|
+
};
|
|
25
|
+
const getRecoveryEligibilityTelemetryProperties = (state, eligible) => {
|
|
26
|
+
var _state$appStates, _state$domainStates, _state$appStates2, _state$appStates3;
|
|
27
|
+
const reconnectId = (_state$appStates = state.appStates) === null || _state$appStates === void 0 ? void 0 : _state$appStates.reconnectId;
|
|
28
|
+
const liveChatContext = (_state$domainStates = state.domainStates) === null || _state$domainStates === void 0 ? void 0 : _state$domainStates.liveChatContext;
|
|
29
|
+
const hasReconnectId = !(0, _utils.isUndefinedOrEmpty)(reconnectId);
|
|
30
|
+
const hasLiveChatContext = !(0, _utils.isUndefinedOrEmpty)(liveChatContext);
|
|
31
|
+
const hasRequestId = !(0, _utils.isUndefinedOrEmpty)(liveChatContext === null || liveChatContext === void 0 ? void 0 : liveChatContext.requestId);
|
|
32
|
+
let reason = RecoveryEligibilityReason.ActiveContextPresent;
|
|
33
|
+
if (hasReconnectId) {
|
|
34
|
+
reason = RecoveryEligibilityReason.ReconnectIdPresent;
|
|
35
|
+
} else if (!hasLiveChatContext) {
|
|
36
|
+
reason = RecoveryEligibilityReason.MissingContext;
|
|
37
|
+
} else if (((_state$appStates2 = state.appStates) === null || _state$appStates2 === void 0 ? void 0 : _state$appStates2.conversationState) !== _ConversationState.ConversationState.Active) {
|
|
38
|
+
reason = RecoveryEligibilityReason.CachedContextNonActive;
|
|
39
|
+
}
|
|
40
|
+
return {
|
|
41
|
+
conversationState: getConversationStateName((_state$appStates3 = state.appStates) === null || _state$appStates3 === void 0 ? void 0 : _state$appStates3.conversationState),
|
|
42
|
+
hasReconnectId,
|
|
43
|
+
hasLiveChatContext,
|
|
44
|
+
hasRequestId,
|
|
45
|
+
eligible,
|
|
46
|
+
reason
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
exports.getRecoveryEligibilityTelemetryProperties = getRecoveryEligibilityTelemetryProperties;
|
|
50
|
+
const logRecoveryEligibilityTelemetry = (state, eligible) => {
|
|
51
|
+
try {
|
|
52
|
+
_TelemetryHelper.TelemetryHelper.logActionEvent(_TelemetryConstants.LogLevel.INFO, {
|
|
53
|
+
Event: _TelemetryConstants.TelemetryEvent.RecoveryEligibilityEvaluated,
|
|
54
|
+
CustomProperties: getRecoveryEligibilityTelemetryProperties(state, eligible)
|
|
55
|
+
});
|
|
56
|
+
} catch (error) {
|
|
57
|
+
console.warn(error);
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
exports.logRecoveryEligibilityTelemetry = logRecoveryEligibilityTelemetry;
|