@microsoft/omnichannel-chat-widget 2.0.1-main.38e7390 → 2.0.1-main.5b375de
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 +57 -0
- package/lib/cjs/common/telemetry/TelemetryConstants.js +10 -0
- package/lib/cjs/common/telemetry/TelemetryHelper.js +8 -0
- package/lib/cjs/components/livechatwidget/LiveChatWidget.js +2 -0
- package/lib/cjs/components/livechatwidget/common/initWebChatComposer.js +31 -7
- package/lib/cjs/components/livechatwidget/common/reconnectChatHelper.js +29 -1
- package/lib/cjs/components/livechatwidget/common/recoveryEligibilityTelemetry.js +11 -1
- package/lib/cjs/components/livechatwidget/common/startChat.js +15 -7
- package/lib/cjs/components/livechatwidget/common/updateSessionDataForTelemetry.js +34 -5
- package/lib/cjs/components/livechatwidget/common/useChatTokenRenewal.js +252 -0
- package/lib/cjs/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +5 -17
- package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/attachmentForScreenReaderMiddleware.js +159 -0
- package/lib/esm/common/telemetry/TelemetryConstants.js +10 -0
- package/lib/esm/common/telemetry/TelemetryHelper.js +8 -0
- package/lib/esm/components/livechatwidget/LiveChatWidget.js +3 -1
- package/lib/esm/components/livechatwidget/common/initWebChatComposer.js +28 -6
- package/lib/esm/components/livechatwidget/common/reconnectChatHelper.js +28 -1
- package/lib/esm/components/livechatwidget/common/recoveryEligibilityTelemetry.js +11 -1
- package/lib/esm/components/livechatwidget/common/startChat.js +15 -7
- package/lib/esm/components/livechatwidget/common/updateSessionDataForTelemetry.js +34 -5
- package/lib/esm/components/livechatwidget/common/useChatTokenRenewal.js +245 -0
- package/lib/esm/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +6 -18
- package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/attachmentForScreenReaderMiddleware.js +153 -0
- package/lib/types/common/telemetry/TelemetryConstants.d.ts +5 -0
- package/lib/types/common/telemetry/TelemetryHelper.d.ts +6 -0
- package/lib/types/common/telemetry/definitions/Contracts.d.ts +6 -0
- package/lib/types/common/telemetry/definitions/Payload.d.ts +6 -0
- package/lib/types/components/livechatwidget/common/initWebChatComposer.d.ts +8 -0
- package/lib/types/components/livechatwidget/common/reconnectChatHelper.d.ts +6 -1
- package/lib/types/components/livechatwidget/common/startChat.d.ts +5 -1
- package/lib/types/components/livechatwidget/common/useChatTokenRenewal.d.ts +5 -0
- package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/attachmentForScreenReaderMiddleware.d.ts +11 -0
- package/package.json +5 -6
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
|
|
|
@@ -81,6 +82,8 @@ This hotfix still declares these vulnerable transitive versions:
|
|
|
81
82
|
| `swiper` | `8.4.7` |
|
|
82
83
|
| `valibot` | `1.1.0` |
|
|
83
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` |
|
|
84
87
|
|
|
85
88
|
The consumer audit permits only the reviewed advisories from this hotfix. It rejects each new advisory.
|
|
86
89
|
|
|
@@ -142,6 +145,60 @@ A typescript sample widget can be found [here](https://github.com/microsoft/omni
|
|
|
142
145
|
|
|
143
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)
|
|
144
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
|
+
|
|
145
202
|
## Components
|
|
146
203
|
|
|
147
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).
|
|
@@ -114,6 +114,11 @@ let TelemetryEvent = exports.TelemetryEvent = /*#__PURE__*/function (TelemetryEv
|
|
|
114
114
|
TelemetryEvent["RecoveryEligibilityEvaluated"] = "RecoveryEligibilityEvaluated";
|
|
115
115
|
TelemetryEvent["GetConversationDetailsCallStarted"] = "GetConversationDetailsCallStarted";
|
|
116
116
|
TelemetryEvent["GetConversationDetailsCallFailed"] = "GetConversationDetailsCallFailed";
|
|
117
|
+
TelemetryEvent["UpdateTelemetryDataFailed"] = "UpdateTelemetryDataFailed";
|
|
118
|
+
TelemetryEvent["ChatTokenRenewalStateSyncFailed"] = "ChatTokenRenewalStateSyncFailed";
|
|
119
|
+
TelemetryEvent["ChatTokenRenewalStateSynced"] = "ChatTokenRenewalStateSynced";
|
|
120
|
+
TelemetryEvent["ChatTokenRenewalStateSyncSkipped"] = "ChatTokenRenewalStateSyncSkipped";
|
|
121
|
+
TelemetryEvent["ChatTokenRenewalStateSyncDeferred"] = "ChatTokenRenewalStateSyncDeferred";
|
|
117
122
|
TelemetryEvent["EndChatSDKCallFailed"] = "EndChatSDKCallFailed";
|
|
118
123
|
TelemetryEvent["DisconnectEndChatSDKCallFailed"] = "DisconnectEndChatSDKCallFailed";
|
|
119
124
|
TelemetryEvent["GetChatReconnectContextSDKCallStarted"] = "GetChatReconnectContextSDKCallStarted";
|
|
@@ -430,6 +435,11 @@ let TelemetryConstants = exports.TelemetryConstants = /*#__PURE__*/function () {
|
|
|
430
435
|
case TelemetryEvent.OnNewMessageFailed:
|
|
431
436
|
case TelemetryEvent.OnNewMessageAudioNotificationFailed:
|
|
432
437
|
case TelemetryEvent.GetConversationDetailsCallFailed:
|
|
438
|
+
case TelemetryEvent.UpdateTelemetryDataFailed:
|
|
439
|
+
case TelemetryEvent.ChatTokenRenewalStateSyncFailed:
|
|
440
|
+
case TelemetryEvent.ChatTokenRenewalStateSynced:
|
|
441
|
+
case TelemetryEvent.ChatTokenRenewalStateSyncSkipped:
|
|
442
|
+
case TelemetryEvent.ChatTokenRenewalStateSyncDeferred:
|
|
433
443
|
case TelemetryEvent.EndChatSDKCall:
|
|
434
444
|
case TelemetryEvent.EndChatEventReceived:
|
|
435
445
|
case TelemetryEvent.EndChatSDKCallFailed:
|
|
@@ -83,6 +83,14 @@ let TelemetryHelper = exports.TelemetryHelper = /*#__PURE__*/function () {
|
|
|
83
83
|
event.ExceptionDetails = JSON.stringify(payload.ExceptionDetails);
|
|
84
84
|
event.Description = payload.Description;
|
|
85
85
|
event.CustomProperties = JSON.stringify(payload.CustomProperties);
|
|
86
|
+
if (payload.Event === _TelemetryConstants.TelemetryEvent.RecoveryEligibilityEvaluated) {
|
|
87
|
+
event.conversationState = payload.conversationState;
|
|
88
|
+
event.hasReconnectId = payload.hasReconnectId;
|
|
89
|
+
event.hasLiveChatContext = payload.hasLiveChatContext;
|
|
90
|
+
event.hasRequestId = payload.hasRequestId;
|
|
91
|
+
event.eligible = payload.eligible;
|
|
92
|
+
event.reason = payload.reason;
|
|
93
|
+
}
|
|
86
94
|
});
|
|
87
95
|
}
|
|
88
96
|
}, {
|
|
@@ -18,6 +18,7 @@ var _utils = require("../../common/utils");
|
|
|
18
18
|
var _liveChatConfigUtils = require("./common/liveChatConfigUtils");
|
|
19
19
|
var _overridePropsOnMockIfApplicable = _interopRequireDefault(require("./common/overridePropsOnMockIfApplicable"));
|
|
20
20
|
var _registerTelemetryLoggers = require("./common/registerTelemetryLoggers");
|
|
21
|
+
var _useChatTokenRenewal = require("./common/useChatTokenRenewal");
|
|
21
22
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
22
23
|
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
23
24
|
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
|
|
@@ -73,6 +74,7 @@ const LiveChatWidget = props => {
|
|
|
73
74
|
(0, _react.useEffect)(() => {
|
|
74
75
|
(0, _registerTelemetryLoggers.registerTelemetryLoggers)(props, dispatch);
|
|
75
76
|
}, [dispatch]);
|
|
77
|
+
(0, _useChatTokenRenewal.useChatTokenRenewal)(facadeChatSDK, state, dispatch, (0, _utils.getWidgetCacheIdfromProps)(props));
|
|
76
78
|
return /*#__PURE__*/_react.default.createElement(_FacadeChatSDKStore.FacadeChatSDKStore.Provider, {
|
|
77
79
|
value: [facadeChatSDK, setFacadeChatSDK]
|
|
78
80
|
}, /*#__PURE__*/_react.default.createElement(_ChatSDKStore.ChatSDKStore.Provider, {
|
|
@@ -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
|
|
@@ -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
|
|
@@ -363,6 +386,7 @@ const initWebChatComposer = (props, state, dispatch, facadeChatSDK, endChat) =>
|
|
|
363
386
|
store: webChatStore,
|
|
364
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),
|
|
365
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)),
|
|
366
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)),
|
|
367
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),
|
|
368
392
|
renderMarkdown,
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.isReconnectEnabled = exports.isPersistentEnabled = exports.handleChatReconnect = exports.getChatReconnectContext = void 0;
|
|
6
|
+
exports.isReconnectTriggered = exports.isReconnectEnabled = exports.isPersistentEnabled = exports.handleChatReconnect = exports.getChatReconnectContext = void 0;
|
|
7
7
|
require("regenerator-runtime/runtime");
|
|
8
8
|
var _TelemetryConstants = require("../../../common/telemetry/TelemetryConstants");
|
|
9
9
|
var _Constants = require("../../../common/Constants");
|
|
@@ -13,6 +13,7 @@ var _omnichannelChatComponents = require("@microsoft/omnichannel-chat-components
|
|
|
13
13
|
var _ConversationState = require("../../../contexts/common/ConversationState");
|
|
14
14
|
var _LiveChatWidgetActionType = require("../../../contexts/common/LiveChatWidgetActionType");
|
|
15
15
|
var _TelemetryHelper = require("../../../common/telemetry/TelemetryHelper");
|
|
16
|
+
var _createReducer = require("../../../contexts/createReducer");
|
|
16
17
|
var _startChatErrorHandler = require("./startChatErrorHandler");
|
|
17
18
|
// Return value: should start normal chat flow when reconnect is enabled
|
|
18
19
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -55,8 +56,35 @@ const handleChatReconnect = async (facadeChatSDK, props, dispatch, setAdapter, i
|
|
|
55
56
|
return true;
|
|
56
57
|
};
|
|
57
58
|
|
|
59
|
+
/**
|
|
60
|
+
* Returns true when chat reconnect took over the start: it started the chat itself or showed the reconnect pane.
|
|
61
|
+
* In that case the caller must not start another chat.
|
|
62
|
+
*/
|
|
58
63
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
59
64
|
exports.handleChatReconnect = handleChatReconnect;
|
|
65
|
+
const isReconnectTriggered = async (facadeChatSDK, props, dispatch, setAdapter, initStartChat, state) => {
|
|
66
|
+
if (isReconnectEnabled(props.chatConfig) === true && !isPersistentEnabled(props.chatConfig)) {
|
|
67
|
+
let reconnectChatStarted = false;
|
|
68
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
69
|
+
const initStartChatAndTrack = async function () {
|
|
70
|
+
reconnectChatStarted = await initStartChat(...arguments);
|
|
71
|
+
};
|
|
72
|
+
const noValidReconnectId = await handleChatReconnect(facadeChatSDK, props, dispatch, setAdapter, initStartChatAndTrack, state);
|
|
73
|
+
// initStartChat resolves before React renders Active, so the in-memory state can still read Loading here.
|
|
74
|
+
// Its result tells whether reconnect started the chat; the in-memory state covers the reconnect pane.
|
|
75
|
+
const inMemoryState = (0, _createReducer.executeReducer)(state, {
|
|
76
|
+
type: _LiveChatWidgetActionType.LiveChatWidgetActionType.GET_IN_MEMORY_STATE,
|
|
77
|
+
payload: null
|
|
78
|
+
});
|
|
79
|
+
if (!noValidReconnectId && (reconnectChatStarted || inMemoryState.appStates.conversationState === _ConversationState.ConversationState.Active || inMemoryState.appStates.conversationState === _ConversationState.ConversationState.ReconnectChat)) {
|
|
80
|
+
return true;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return false;
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
87
|
+
exports.isReconnectTriggered = isReconnectTriggered;
|
|
60
88
|
const getChatReconnectContext = async (facadeChatSDK, chatConfig, props, isAuthenticatedChat, dispatch) => {
|
|
61
89
|
try {
|
|
62
90
|
var _props$reconnectChatP4;
|
|
@@ -47,11 +47,21 @@ const getRecoveryEligibilityTelemetryProperties = (state, eligible) => {
|
|
|
47
47
|
};
|
|
48
48
|
};
|
|
49
49
|
exports.getRecoveryEligibilityTelemetryProperties = getRecoveryEligibilityTelemetryProperties;
|
|
50
|
+
const getRecoveryEligibilityScalarTelemetryProperties = properties => ({
|
|
51
|
+
conversationState: properties.conversationState,
|
|
52
|
+
hasReconnectId: String(properties.hasReconnectId),
|
|
53
|
+
hasLiveChatContext: String(properties.hasLiveChatContext),
|
|
54
|
+
hasRequestId: String(properties.hasRequestId),
|
|
55
|
+
eligible: String(properties.eligible),
|
|
56
|
+
reason: properties.reason
|
|
57
|
+
});
|
|
50
58
|
const logRecoveryEligibilityTelemetry = (state, eligible) => {
|
|
51
59
|
try {
|
|
60
|
+
const properties = getRecoveryEligibilityTelemetryProperties(state, eligible);
|
|
52
61
|
_TelemetryHelper.TelemetryHelper.logActionEvent(_TelemetryConstants.LogLevel.INFO, {
|
|
53
62
|
Event: _TelemetryConstants.TelemetryEvent.RecoveryEligibilityEvaluated,
|
|
54
|
-
CustomProperties:
|
|
63
|
+
CustomProperties: properties,
|
|
64
|
+
...getRecoveryEligibilityScalarTelemetryProperties(properties)
|
|
55
65
|
});
|
|
56
66
|
} catch (error) {
|
|
57
67
|
console.warn(error);
|
|
@@ -68,7 +68,7 @@ const getGuard = (guards, facadeChatSDK) => {
|
|
|
68
68
|
* Runs `operation` only if no other invocation for the same widget instance is already in
|
|
69
69
|
* flight. Concurrent invocations are dropped (and reported through telemetry) rather than
|
|
70
70
|
* awaiting the in-flight promise, so a future re-entrant call can never deadlock on itself.
|
|
71
|
-
*
|
|
71
|
+
* A dropped invocation resolves to `undefined`.
|
|
72
72
|
*
|
|
73
73
|
* `blockedBy` lets an operation also yield to a different, already running operation for the
|
|
74
74
|
* same widget instance without claiming that operation's lock.
|
|
@@ -84,14 +84,14 @@ const runExclusively = async (guards, facadeChatSDK, description, operation, pro
|
|
|
84
84
|
WidgetCacheId: props ? (0, _utils.getWidgetCacheIdfromProps)(props) : undefined
|
|
85
85
|
}
|
|
86
86
|
});
|
|
87
|
-
return;
|
|
87
|
+
return undefined;
|
|
88
88
|
}
|
|
89
89
|
|
|
90
90
|
// Claim the lock before invoking the operation, so a re-entrant call made from the
|
|
91
91
|
// operation's synchronous preamble (before its first await) cannot slip past the check above.
|
|
92
92
|
guard.inFlight = true;
|
|
93
93
|
try {
|
|
94
|
-
await operation();
|
|
94
|
+
return await operation();
|
|
95
95
|
} finally {
|
|
96
96
|
guard.inFlight = false;
|
|
97
97
|
}
|
|
@@ -228,10 +228,15 @@ const setPreChatAndInitiateChat = async (facadeChatSDK, dispatch, setAdapter, is
|
|
|
228
228
|
await initStartChat(facadeChatSDK, dispatch, setAdapter, state, props, optionalParams);
|
|
229
229
|
};
|
|
230
230
|
|
|
231
|
+
/**
|
|
232
|
+
* Resolves to `true` when the chat reached Active, and `false` when it failed or the call was dropped.
|
|
233
|
+
* It resolves before React renders Active, so callers must use this value rather than reading the conversation state.
|
|
234
|
+
*/
|
|
231
235
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
232
236
|
exports.setPreChatAndInitiateChat = setPreChatAndInitiateChat;
|
|
233
237
|
const initStartChat = async (facadeChatSDK, dispatch, setAdapter, state, props, params, persistedState) => {
|
|
234
|
-
|
|
238
|
+
const chatStarted = await 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);
|
|
239
|
+
return chatStarted === true;
|
|
235
240
|
};
|
|
236
241
|
|
|
237
242
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -346,7 +351,7 @@ const initStartChatInternal = async (facadeChatSDK, dispatch, setAdapter, state,
|
|
|
346
351
|
(0, _startChatErrorHandler.logWidgetLoadComplete)(_Constants.WidgetLoadTelemetryMessage.PersistedStateRetrievedMessage);
|
|
347
352
|
// Set post chat context in state, load in background to do not block the load
|
|
348
353
|
(0, _setPostChatContextAndLoadSurvey.setPostChatContextAndLoadSurvey)(facadeChatSDK, dispatch, true);
|
|
349
|
-
return;
|
|
354
|
+
return true;
|
|
350
355
|
}
|
|
351
356
|
|
|
352
357
|
// Persistent Chat relies on the `reconnectId` retrieved from reconnectablechats API to reconnect upon start chat and not `liveChatContext`
|
|
@@ -362,10 +367,13 @@ const initStartChatInternal = async (facadeChatSDK, dispatch, setAdapter, state,
|
|
|
362
367
|
(0, _startChatErrorHandler.logWidgetLoadComplete)();
|
|
363
368
|
// Set post chat context in state, load in background to do not block the load
|
|
364
369
|
(0, _setPostChatContextAndLoadSurvey.setPostChatContextAndLoadSurvey)(facadeChatSDK, dispatch);
|
|
365
|
-
// Updating chat session detail for telemetry
|
|
366
|
-
|
|
370
|
+
// Updating chat session detail for telemetry, in background: getConversationDetails retries until the
|
|
371
|
+
// live work item exists (several seconds), and awaiting it would hold the start chat locks and drop the next start chat
|
|
372
|
+
(0, _updateSessionDataForTelemetry.updateTelemetryData)(facadeChatSDK, dispatch);
|
|
373
|
+
return true;
|
|
367
374
|
} catch (ex) {
|
|
368
375
|
(0, _startChatErrorHandler.handleStartChatError)(dispatch, facadeChatSDK, props, ex, isStartChatSuccessful);
|
|
376
|
+
return false;
|
|
369
377
|
}
|
|
370
378
|
};
|
|
371
379
|
|
|
@@ -12,16 +12,42 @@ var _TelemetryManager = require("../../../common/telemetry/TelemetryManager");
|
|
|
12
12
|
var _utils = require("../../../common/utils");
|
|
13
13
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
14
14
|
const updateTelemetryData = async (facadeChatSDK, dispatch) => {
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
var _facadeChatSDK$getCha;
|
|
16
|
+
// startChat no longer waits for this, so the next chat can start (chatSDKStateCleanUp assigns a new requestId)
|
|
17
|
+
// before these calls resolve. Results for an earlier chat must not overwrite the current chat's data.
|
|
18
|
+
// endChat also assigns a new requestId, so the chat that just ended still applies its own results.
|
|
19
|
+
const requestId = facadeChatSDK === null || facadeChatSDK === void 0 || (_facadeChatSDK$getCha = facadeChatSDK.getChatSDK()) === null || _facadeChatSDK$getCha === void 0 ? void 0 : _facadeChatSDK$getCha.requestId;
|
|
20
|
+
try {
|
|
21
|
+
// load it concurrently, this will reduce the load time
|
|
22
|
+
await Promise.all([updateSessionDataForTelemetry(facadeChatSDK, dispatch, requestId), updateConversationDataForTelemetry(facadeChatSDK, dispatch, requestId)]);
|
|
23
|
+
} catch (error) {
|
|
24
|
+
_TelemetryHelper.TelemetryHelper.logSDKEvent(_TelemetryConstants.LogLevel.ERROR, {
|
|
25
|
+
Event: _TelemetryConstants.TelemetryEvent.UpdateTelemetryDataFailed,
|
|
26
|
+
ExceptionDetails: {
|
|
27
|
+
exception: `Update telemetry data failed: ${error}`
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
}
|
|
17
31
|
};
|
|
18
32
|
|
|
19
|
-
//
|
|
33
|
+
// The requestId alone isn't enough: endChat also replaces it. Only the next chat's startChat gets a new chat token
|
|
34
|
+
// (endChat and chatSDKStateCleanUp clear it), so drop the result only when the SDK holds that next chat.
|
|
20
35
|
exports.updateTelemetryData = updateTelemetryData;
|
|
21
|
-
const
|
|
36
|
+
const isFromEarlierChat = (facadeChatSDK, requestId) => {
|
|
37
|
+
var _chatSDK$chatToken;
|
|
38
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
39
|
+
const chatSDK = facadeChatSDK.getChatSDK();
|
|
40
|
+
return (chatSDK === null || chatSDK === void 0 ? void 0 : chatSDK.requestId) !== requestId && !!(chatSDK !== null && chatSDK !== void 0 && (_chatSDK$chatToken = chatSDK.chatToken) !== null && _chatSDK$chatToken !== void 0 && _chatSDK$chatToken.chatId);
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
44
|
+
const updateSessionDataForTelemetry = async (facadeChatSDK, dispatch, requestId) => {
|
|
22
45
|
if (facadeChatSDK && facadeChatSDK.getChatSDK()) {
|
|
23
46
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
24
47
|
const chatSession = await facadeChatSDK.getCurrentLiveChatContext();
|
|
48
|
+
if (isFromEarlierChat(facadeChatSDK, requestId)) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
25
51
|
const telemetryData = _TelemetryHelper.TelemetryHelper.addSessionDataToTelemetry(chatSession, _TelemetryManager.TelemetryManager.InternalTelemetryData);
|
|
26
52
|
dispatch({
|
|
27
53
|
type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_TELEMETRY_DATA,
|
|
@@ -37,10 +63,13 @@ const updateSessionDataForTelemetry = async (facadeChatSDK, dispatch) => {
|
|
|
37
63
|
};
|
|
38
64
|
|
|
39
65
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
40
|
-
const updateConversationDataForTelemetry = async (facadeChatSDK, dispatch) => {
|
|
66
|
+
const updateConversationDataForTelemetry = async (facadeChatSDK, dispatch, requestId) => {
|
|
41
67
|
if (facadeChatSDK && facadeChatSDK.getChatSDK()) {
|
|
42
68
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
43
69
|
const liveWorkItem = await (0, _utils.getConversationDetailsCall)(facadeChatSDK);
|
|
70
|
+
if (isFromEarlierChat(facadeChatSDK, requestId)) {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
44
73
|
const telemetryData = _TelemetryHelper.TelemetryHelper.addConversationDataToTelemetry(liveWorkItem, _TelemetryManager.TelemetryManager.InternalTelemetryData);
|
|
45
74
|
dispatch({
|
|
46
75
|
type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_TELEMETRY_DATA,
|