@microsoft/omnichannel-chat-widget 2.0.1-main.a2ef2a3 → 2.0.1-main.a610fd8
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 +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 +33 -9
- package/lib/cjs/components/livechatwidget/common/reconnectChatHelper.js +29 -1
- package/lib/cjs/components/livechatwidget/common/startChat.js +118 -36
- package/lib/cjs/components/livechatwidget/common/updateSessionDataForTelemetry.js +34 -5
- package/lib/cjs/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +5 -17
- 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 +31 -9
- package/lib/esm/components/livechatwidget/common/reconnectChatHelper.js +28 -1
- package/lib/esm/components/livechatwidget/common/startChat.js +115 -34
- package/lib/esm/components/livechatwidget/common/updateSessionDataForTelemetry.js +34 -5
- package/lib/esm/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +6 -18
- 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/reconnectChatHelper.d.ts +6 -1
- package/lib/types/components/livechatwidget/common/startChat.d.ts +5 -1
- 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 +5 -6
|
@@ -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,
|
|
@@ -163,20 +163,6 @@ const LiveChatWidgetStateful = props => {
|
|
|
163
163
|
|
|
164
164
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
165
165
|
const startChat = async (props, localState) => {
|
|
166
|
-
const isReconnectTriggered = async () => {
|
|
167
|
-
if ((0, _reconnectChatHelper.isReconnectEnabled)(props.chatConfig) === true && !(0, _reconnectChatHelper.isPersistentEnabled)(props.chatConfig)) {
|
|
168
|
-
const noValidReconnectId = await (0, _reconnectChatHelper.handleChatReconnect)(facadeChatSDK, props, dispatch, setAdapter, _startChat.initStartChat, state);
|
|
169
|
-
const inMemoryState = (0, _createReducer.executeReducer)(state, {
|
|
170
|
-
type: _LiveChatWidgetActionType.LiveChatWidgetActionType.GET_IN_MEMORY_STATE,
|
|
171
|
-
payload: null
|
|
172
|
-
});
|
|
173
|
-
// If chat reconnect has kicked in chat state will become Active or Reconnect. So just exit, else go next
|
|
174
|
-
if (!noValidReconnectId && (inMemoryState.appStates.conversationState === _ConversationState.ConversationState.Active || inMemoryState.appStates.conversationState === _ConversationState.ConversationState.ReconnectChat)) {
|
|
175
|
-
return true;
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
return false;
|
|
179
|
-
};
|
|
180
166
|
let isChatValid = false;
|
|
181
167
|
//Start a chat from cache/reconnectid
|
|
182
168
|
if (activeCachedChatExist === true) {
|
|
@@ -188,7 +174,7 @@ const LiveChatWidgetStateful = props => {
|
|
|
188
174
|
//Check if conversation state is not in wrapup or closed state
|
|
189
175
|
isChatValid = await (0, _startChat.checkIfConversationStillValid)(facadeChatSDK, dispatch, state);
|
|
190
176
|
if (isChatValid === true) {
|
|
191
|
-
const reconnectTriggered = await isReconnectTriggered();
|
|
177
|
+
const reconnectTriggered = await (0, _reconnectChatHelper.isReconnectTriggered)(facadeChatSDK, props, dispatch, setAdapter, _startChat.initStartChat, state);
|
|
192
178
|
if (!reconnectTriggered) {
|
|
193
179
|
await (0, _startChat.initStartChat)(facadeChatSDK, dispatch, setAdapter, state, props, optionalParams);
|
|
194
180
|
}
|
|
@@ -204,7 +190,7 @@ const LiveChatWidgetStateful = props => {
|
|
|
204
190
|
if (isChatValid === false) {
|
|
205
191
|
if (localState) {
|
|
206
192
|
// adding the reconnect logic for the case when customer tries to reconnect from a new browser or InPrivate browser
|
|
207
|
-
const reconnectTriggered = await isReconnectTriggered();
|
|
193
|
+
const reconnectTriggered = await (0, _reconnectChatHelper.isReconnectTriggered)(facadeChatSDK, props, dispatch, setAdapter, _startChat.initStartChat, state);
|
|
208
194
|
if (!reconnectTriggered) {
|
|
209
195
|
const inMemoryState = (0, _createReducer.executeReducer)(state, {
|
|
210
196
|
type: _LiveChatWidgetActionType.LiveChatWidgetActionType.GET_IN_MEMORY_STATE,
|
|
@@ -1000,7 +986,9 @@ const LiveChatWidgetStateful = props => {
|
|
|
1000
986
|
const endChatRelay = (adapter, skipEndChatSDK, skipCloseChat, postMessageToOtherTab) => (0, _endChat.endChat)(props, facadeChatSDK, state, dispatch, setAdapter, setWebChatStyles, adapter, skipEndChatSDK, skipCloseChat, postMessageToOtherTab);
|
|
1001
987
|
const prepareStartChatRelay = () => (0, _startChat.prepareStartChat)(props, facadeChatSDK, state, dispatch, setAdapter);
|
|
1002
988
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1003
|
-
const initStartChatRelay = (optionalParams, persistedState) =>
|
|
989
|
+
const initStartChatRelay = async (optionalParams, persistedState) => {
|
|
990
|
+
await (0, _startChat.initStartChat)(facadeChatSDK, dispatch, setAdapter, state, props, optionalParams, persistedState);
|
|
991
|
+
};
|
|
1004
992
|
const confirmationPaneProps = (0, _initConfirmationPropsComposer.initConfirmationPropsComposer)(props);
|
|
1005
993
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1006
994
|
const prepareEndChatRelay = () => (0, _endChat.prepareEndChat)(props, facadeChatSDK, state, dispatch, setAdapter, setWebChatStyles, adapter);
|
|
@@ -537,9 +537,9 @@ const WebChatContainerStateful = props => {
|
|
|
537
537
|
|
|
538
538
|
/* Suggested actions carousel previous/next navigation focus */
|
|
539
539
|
.webchat__suggested-actions .webchat__suggested-actions__carousel .react-film__flipper:focus-visible .react-film__flipper__body {
|
|
540
|
-
outline: ${(webChatContainerProps === null || webChatContainerProps === void 0 || (_webChatContainerProp20 = webChatContainerProps.webChatStyles) === null || _webChatContainerProp20 === void 0 ? void 0 : _webChatContainerProp20.suggestedActionKeyboardFocusIndicatorBorderStyle) ?? "
|
|
540
|
+
outline: ${(webChatContainerProps === null || webChatContainerProps === void 0 || (_webChatContainerProp20 = webChatContainerProps.webChatStyles) === null || _webChatContainerProp20 === void 0 ? void 0 : _webChatContainerProp20.suggestedActionKeyboardFocusIndicatorBorderStyle) ?? "solid"} ${(webChatContainerProps === null || webChatContainerProps === void 0 || (_webChatContainerProp21 = webChatContainerProps.webChatStyles) === null || _webChatContainerProp21 === void 0 ? void 0 : _webChatContainerProp21.suggestedActionKeyboardFocusIndicatorBorderWidth) ?? "2px"} ${(webChatContainerProps === null || webChatContainerProps === void 0 || (_webChatContainerProp22 = webChatContainerProps.webChatStyles) === null || _webChatContainerProp22 === void 0 ? void 0 : _webChatContainerProp22.suggestedActionKeyboardFocusIndicatorBorderColor) ?? "#605E5C"} !important;
|
|
541
541
|
outline-offset: ${(webChatContainerProps === null || webChatContainerProps === void 0 || (_webChatContainerProp23 = webChatContainerProps.webChatStyles) === null || _webChatContainerProp23 === void 0 ? void 0 : _webChatContainerProp23.suggestedActionKeyboardFocusIndicatorInset) ?? "2px"} !important;
|
|
542
|
-
|
|
542
|
+
}
|
|
543
543
|
`), /*#__PURE__*/_react2.default.createElement(_react.Stack, {
|
|
544
544
|
styles: containerStyles,
|
|
545
545
|
className: "webchat__stacked-layout_container"
|
|
@@ -33,7 +33,8 @@ const defaultMiddlewareLocalizedTexts = exports.defaultMiddlewareLocalizedTexts
|
|
|
33
33
|
MIDDLEWARE_BANNER_CHAT_DISCONNECT: "Your conversation has been disconnected. For additional assistance, please start a new chat.",
|
|
34
34
|
THIRD_PARTY_COOKIES_BLOCKED_ALERT_MESSAGE: "Allow sites to save/read cookies in browser settings. Reloading page starts a new chat.",
|
|
35
35
|
MIDDLEWARE_BANNER_FILE_IS_MALICIOUS: "{0} has been blocked because the file may contain a malware.",
|
|
36
|
-
MIDDLEWARE_BANNER_FILE_SENT: "File sent
|
|
36
|
+
MIDDLEWARE_BANNER_FILE_SENT: "File {2} sent",
|
|
37
|
+
MIDDLEWARE_BANNER_FILES_SENT: "{0} files sent",
|
|
37
38
|
MIDDLEWARE_BANNER_FILE_EMAIL_ADDRESS_RECORDED_SUCCESS: "Email will be sent after chat ends!",
|
|
38
39
|
MIDDLEWARE_BANNER_FILE_EMAIL_ADDRESS_RECORDED_ERROR: "Email {0} could not be saved, try again later.",
|
|
39
40
|
MIDDLEWARE_SR_PREFIX_SUCCESS: "Success. ",
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getAdaptiveCardSpeak = exports.createAttachmentForScreenReaderMiddleware = void 0;
|
|
7
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
8
|
+
var _Constants = require("../../../../../common/Constants");
|
|
9
|
+
var _botframeworkWebchat = require("botframework-webchat");
|
|
10
|
+
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); }
|
|
11
|
+
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
|
|
12
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
13
|
+
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
14
|
+
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
15
|
+
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
16
|
+
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; } /* eslint-disable @typescript-eslint/no-explicit-any */ /******
|
|
17
|
+
* AttachmentForScreenReaderMiddleware
|
|
18
|
+
*
|
|
19
|
+
* Web Chat reads an Adaptive Card to screen readers only from the card's `speak` property.
|
|
20
|
+
* A card without `speak` is announced as "A card" with no content.
|
|
21
|
+
* This middleware sets `speak` from the visible text of the card, then lets Web Chat render it as usual.
|
|
22
|
+
******/
|
|
23
|
+
const useAdaptiveCardsPackage = _botframeworkWebchat.hooks.useAdaptiveCardsPackage,
|
|
24
|
+
useStyleOptions = _botframeworkWebchat.hooks.useStyleOptions;
|
|
25
|
+
const ADAPTIVE_CARD_CONTENT_TYPE = "application/vnd.microsoft.card.adaptive";
|
|
26
|
+
const HTML_BLOCK_END = /<\/(p|li|h[1-6]|div|tr|td|th|blockquote|pre)>|<br\s*\/?>/gi;
|
|
27
|
+
// The "opens in a new window" icon of each link is left out: it describes the link target, not the content of the message.
|
|
28
|
+
const htmlToText = html => {
|
|
29
|
+
const body = new DOMParser().parseFromString(html.replace(HTML_BLOCK_END, "$& "), "text/html").body;
|
|
30
|
+
body.querySelectorAll(`script, style, template, img.${_Constants.Constants.OpenLinkIconCssClass}`).forEach(element => element.remove());
|
|
31
|
+
body.querySelectorAll("img").forEach(image => image.replaceWith(` ${image.getAttribute("alt") ?? ""} `));
|
|
32
|
+
return (body.textContent ?? "").replace(/\s+/g, " ").trim();
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
// Renders the element as the visible card does: Adaptive Cards formats {{DATE()}} and {{TIME()}}, then the Markdown is rendered.
|
|
36
|
+
// Web Chat sets the static Markdown handler before each visible render, and this restores the previous handler after rendering.
|
|
37
|
+
const getRenderedText = (element, AdaptiveCard, renderMarkdownAsHTML) => {
|
|
38
|
+
const previousOnProcessMarkdown = AdaptiveCard.onProcessMarkdown;
|
|
39
|
+
try {
|
|
40
|
+
AdaptiveCard.onProcessMarkdown = (text, result) => {
|
|
41
|
+
result.outputHtml = renderMarkdownAsHTML(text);
|
|
42
|
+
result.didProcess = true;
|
|
43
|
+
};
|
|
44
|
+
const renderedElement = element.render();
|
|
45
|
+
return renderedElement ? htmlToText(renderedElement.outerHTML) : "";
|
|
46
|
+
} catch {
|
|
47
|
+
var _element$asString;
|
|
48
|
+
return ((_element$asString = element.asString) === null || _element$asString === void 0 ? void 0 : _element$asString.call(element)) ?? "";
|
|
49
|
+
} finally {
|
|
50
|
+
AdaptiveCard.onProcessMarkdown = previousOnProcessMarkdown;
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
// Collects the visible text of the card in document order, after the parser has applied element fallbacks.
|
|
55
|
+
// Inputs and actions are not collected because Web Chat already lists them after the card text.
|
|
56
|
+
const getAdaptiveCardSpeak = (content, adaptiveCardsPackage, renderMarkdownAsHTML, adaptiveCardsParserMaxVersion) => {
|
|
57
|
+
const AdaptiveCard = adaptiveCardsPackage.AdaptiveCard,
|
|
58
|
+
FactSet = adaptiveCardsPackage.FactSet,
|
|
59
|
+
Image = adaptiveCardsPackage.Image,
|
|
60
|
+
RichTextBlock = adaptiveCardsPackage.RichTextBlock,
|
|
61
|
+
SerializationContext = adaptiveCardsPackage.SerializationContext,
|
|
62
|
+
TextBlock = adaptiveCardsPackage.TextBlock,
|
|
63
|
+
Version = adaptiveCardsPackage.Version;
|
|
64
|
+
const maxVersion = adaptiveCardsParserMaxVersion ? Version.parse(adaptiveCardsParserMaxVersion, new SerializationContext()) : undefined;
|
|
65
|
+
const card = new AdaptiveCard();
|
|
66
|
+
const texts = [];
|
|
67
|
+
card.parse(content, new SerializationContext(maxVersion !== null && maxVersion !== void 0 && maxVersion.isValid ? maxVersion : undefined));
|
|
68
|
+
const getFactText = (factSet, text) => {
|
|
69
|
+
const textBlock = new TextBlock(text);
|
|
70
|
+
textBlock.setParent(factSet);
|
|
71
|
+
return getRenderedText(textBlock, AdaptiveCard, renderMarkdownAsHTML);
|
|
72
|
+
};
|
|
73
|
+
const walk = element => {
|
|
74
|
+
if (!(element !== null && element !== void 0 && element.isVisible)) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
if (element instanceof TextBlock || element instanceof RichTextBlock) {
|
|
78
|
+
texts.push(getRenderedText(element, AdaptiveCard, renderMarkdownAsHTML));
|
|
79
|
+
} else if (element instanceof FactSet) {
|
|
80
|
+
element.facts.forEach(_ref => {
|
|
81
|
+
let name = _ref.name,
|
|
82
|
+
value = _ref.value;
|
|
83
|
+
texts.push([name, value].map(text => text ? getFactText(element, text) : "").filter(Boolean).join(": "));
|
|
84
|
+
});
|
|
85
|
+
} else if (element instanceof Image) {
|
|
86
|
+
texts.push(element.altText);
|
|
87
|
+
}
|
|
88
|
+
if (element.getItemAt && element.getItemCount) {
|
|
89
|
+
for (let index = 0, count = element.getItemCount(); index < count; index++) {
|
|
90
|
+
walk(element.getItemAt(index));
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
walk(card);
|
|
95
|
+
return texts.filter(text => typeof text === "string" && text).join(" ").replace(/\s+/g, " ").trim();
|
|
96
|
+
};
|
|
97
|
+
exports.getAdaptiveCardSpeak = getAdaptiveCardSpeak;
|
|
98
|
+
const AdaptiveCardForScreenReader = _ref2 => {
|
|
99
|
+
let args = _ref2.args,
|
|
100
|
+
next = _ref2.next,
|
|
101
|
+
renderMarkdownAsHTML = _ref2.renderMarkdownAsHTML;
|
|
102
|
+
const _useAdaptiveCardsPack = useAdaptiveCardsPackage(),
|
|
103
|
+
_useAdaptiveCardsPack2 = _slicedToArray(_useAdaptiveCardsPack, 1),
|
|
104
|
+
adaptiveCardsPackage = _useAdaptiveCardsPack2[0];
|
|
105
|
+
const _useStyleOptions = useStyleOptions(),
|
|
106
|
+
_useStyleOptions2 = _slicedToArray(_useStyleOptions, 1),
|
|
107
|
+
adaptiveCardsParserMaxVersion = _useStyleOptions2[0].adaptiveCardsParserMaxVersion;
|
|
108
|
+
const _args = _slicedToArray(args, 1),
|
|
109
|
+
options = _args[0];
|
|
110
|
+
const attachment = options.attachment;
|
|
111
|
+
|
|
112
|
+
// The widget creates a new Markdown renderer on each render with the same settings, so the text is computed once for each attachment.
|
|
113
|
+
const contentWithSpeak = (0, _react.useMemo)(() => {
|
|
114
|
+
try {
|
|
115
|
+
const content = typeof attachment.content === "string" ? JSON.parse(attachment.content) : attachment.content;
|
|
116
|
+
if (!content || typeof content !== "object" || content.speak) {
|
|
117
|
+
return undefined;
|
|
118
|
+
}
|
|
119
|
+
const speak = getAdaptiveCardSpeak(content, adaptiveCardsPackage, renderMarkdownAsHTML, adaptiveCardsParserMaxVersion);
|
|
120
|
+
return speak ? {
|
|
121
|
+
...content,
|
|
122
|
+
speak
|
|
123
|
+
} : undefined;
|
|
124
|
+
} catch {
|
|
125
|
+
return undefined;
|
|
126
|
+
}
|
|
127
|
+
}, [adaptiveCardsPackage, adaptiveCardsParserMaxVersion, attachment]);
|
|
128
|
+
const render = contentWithSpeak ? next({
|
|
129
|
+
...options,
|
|
130
|
+
attachment: {
|
|
131
|
+
...attachment,
|
|
132
|
+
content: contentWithSpeak
|
|
133
|
+
}
|
|
134
|
+
}, ...args.slice(1)) : next(...args);
|
|
135
|
+
return typeof render === "function" ? render() : null;
|
|
136
|
+
};
|
|
137
|
+
const createAttachmentForScreenReaderMiddleware = renderMarkdownAsHTML => {
|
|
138
|
+
const attachmentForScreenReaderMiddleware = () => next => function () {
|
|
139
|
+
var _args$;
|
|
140
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
141
|
+
args[_key] = arguments[_key];
|
|
142
|
+
}
|
|
143
|
+
const attachment = (_args$ = args[0]) === null || _args$ === void 0 ? void 0 : _args$.attachment;
|
|
144
|
+
|
|
145
|
+
// Web Chat renders nothing for a card without content, so it is left to Web Chat.
|
|
146
|
+
if ((attachment === null || attachment === void 0 ? void 0 : attachment.contentType) !== ADAPTIVE_CARD_CONTENT_TYPE || !attachment.content) {
|
|
147
|
+
return next(...args);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// eslint-disable-next-line react/display-name
|
|
151
|
+
return () => /*#__PURE__*/_react.default.createElement(AdaptiveCardForScreenReader, {
|
|
152
|
+
args: args,
|
|
153
|
+
next: next,
|
|
154
|
+
renderMarkdownAsHTML: renderMarkdownAsHTML
|
|
155
|
+
});
|
|
156
|
+
};
|
|
157
|
+
return attachmentForScreenReaderMiddleware;
|
|
158
|
+
};
|
|
159
|
+
exports.createAttachmentForScreenReaderMiddleware = createAttachmentForScreenReaderMiddleware;
|
|
@@ -94,6 +94,19 @@ const AdaptiveCardAccessibilityWrapper = _ref => {
|
|
|
94
94
|
}
|
|
95
95
|
});
|
|
96
96
|
|
|
97
|
+
// action-button-double-read: the adaptivecards renderer writes the action
|
|
98
|
+
// title to the button text, aria-label AND title. The title becomes the
|
|
99
|
+
// accessible description, so TalkBack reads the label twice ("Submit,
|
|
100
|
+
// button, Submit"). Drop the title only when it repeats the button name;
|
|
101
|
+
// a distinct title (an action tooltip) adds information and is kept.
|
|
102
|
+
container.querySelectorAll("button[title]").forEach(btn => {
|
|
103
|
+
const title = (btn.getAttribute("title") || "").trim();
|
|
104
|
+
const name = (btn.getAttribute("aria-label") ?? btn.textContent ?? "").trim();
|
|
105
|
+
if (title && title === name) {
|
|
106
|
+
btn.removeAttribute("title");
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
|
|
97
110
|
// Find all radio inputs inside the adaptive card
|
|
98
111
|
const radios = container.querySelectorAll("input[type='radio']");
|
|
99
112
|
if (radios.length === 0) return;
|
|
@@ -175,7 +188,8 @@ const AdaptiveCardAccessibilityWrapper = _ref => {
|
|
|
175
188
|
|
|
176
189
|
// Use MutationObserver to patch after WebChat finishes rendering the card.
|
|
177
190
|
// Also watch attribute changes on aria-hidden so we can re-apply if React
|
|
178
|
-
// reconciliation removes it from labels
|
|
191
|
+
// reconciliation removes it from labels, and on title so a re-added
|
|
192
|
+
// duplicate button title is removed again.
|
|
179
193
|
const observer = new MutationObserver(() => {
|
|
180
194
|
patchRadioGroups();
|
|
181
195
|
});
|
|
@@ -183,7 +197,7 @@ const AdaptiveCardAccessibilityWrapper = _ref => {
|
|
|
183
197
|
childList: true,
|
|
184
198
|
subtree: true,
|
|
185
199
|
attributes: true,
|
|
186
|
-
attributeFilter: ["aria-hidden"]
|
|
200
|
+
attributeFilter: ["aria-hidden", "title"]
|
|
187
201
|
});
|
|
188
202
|
|
|
189
203
|
// Also run immediately in case the card is already rendered
|
|
@@ -3,31 +3,41 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.default = void 0;
|
|
6
|
+
exports.getFileSentMessage = exports.default = exports.createAttachmentSentAnnouncementMiddleware = exports.ATTACHMENT_ANNOUNCEMENT_REGION_ID = void 0;
|
|
7
7
|
var _IWebChatAction = require("../../../interfaces/IWebChatAction");
|
|
8
8
|
var _WebChatActionType = require("../../enums/WebChatActionType");
|
|
9
9
|
/******
|
|
10
10
|
* AttachmentSentAnnouncementMiddleware
|
|
11
11
|
*
|
|
12
12
|
* When a file attachment is successfully sent, announces the result to
|
|
13
|
-
* screen readers
|
|
14
|
-
*
|
|
13
|
+
* screen readers so that assistive technology users receive immediate
|
|
14
|
+
* feedback ("File report.pdf sent").
|
|
15
|
+
*
|
|
16
|
+
* The announcement region lives inside the chat dialog. While the dialog is
|
|
17
|
+
* open it is aria-modal and its host siblings are aria-hidden, so screen
|
|
18
|
+
* readers (TalkBack, VoiceOver) ignore live regions outside it.
|
|
15
19
|
******/
|
|
16
20
|
|
|
17
|
-
const
|
|
21
|
+
const ATTACHMENT_ANNOUNCEMENT_REGION_ID = exports.ATTACHMENT_ANNOUNCEMENT_REGION_ID = "oc-lcw-attachment-announcement";
|
|
22
|
+
const DEFAULT_FILE_SENT_TEXT = "File {2} sent";
|
|
23
|
+
const DEFAULT_FILES_SENT_TEXT = "{0} files sent";
|
|
24
|
+
|
|
25
|
+
// Let the send-box focus shift settle before speaking, then keep the node
|
|
26
|
+
// long enough for the screen reader to read it.
|
|
27
|
+
const ANNOUNCE_DELAY_MS = 100;
|
|
28
|
+
const ANNOUNCEMENT_LIFETIME_MS = 5000;
|
|
18
29
|
|
|
19
30
|
/**
|
|
20
|
-
* Ensures a visually-hidden aria-live region exists
|
|
21
|
-
* announcing attachment upload results to screen readers.
|
|
31
|
+
* Ensures a visually-hidden aria-live region exists inside the chat dialog
|
|
32
|
+
* for announcing attachment upload results to screen readers.
|
|
22
33
|
*/
|
|
23
|
-
const ensureAriaLiveRegion =
|
|
24
|
-
|
|
34
|
+
const ensureAriaLiveRegion = widgetElementId => {
|
|
35
|
+
const host = document.getElementById(widgetElementId) || document.body;
|
|
36
|
+
let region = document.getElementById(ATTACHMENT_ANNOUNCEMENT_REGION_ID);
|
|
25
37
|
if (!region) {
|
|
26
38
|
region = document.createElement("div");
|
|
27
|
-
region.id =
|
|
39
|
+
region.id = ATTACHMENT_ANNOUNCEMENT_REGION_ID;
|
|
28
40
|
region.setAttribute("aria-live", "polite");
|
|
29
|
-
region.setAttribute("role", "status");
|
|
30
|
-
region.setAttribute("aria-atomic", "true");
|
|
31
41
|
// Visually hidden but available to screen readers
|
|
32
42
|
Object.assign(region.style, {
|
|
33
43
|
position: "absolute",
|
|
@@ -40,44 +50,62 @@ const ensureAriaLiveRegion = () => {
|
|
|
40
50
|
whiteSpace: "nowrap",
|
|
41
51
|
border: "0"
|
|
42
52
|
});
|
|
43
|
-
|
|
44
|
-
|
|
53
|
+
}
|
|
54
|
+
if (region.parentElement !== host) {
|
|
55
|
+
host.appendChild(region);
|
|
45
56
|
}
|
|
46
57
|
return region;
|
|
47
58
|
};
|
|
48
59
|
|
|
49
60
|
/**
|
|
50
|
-
* Announces a message
|
|
51
|
-
*
|
|
61
|
+
* Announces a message by appending a fresh node to the live region.
|
|
62
|
+
* TalkBack reliably speaks newly added nodes but often misses text changes
|
|
63
|
+
* on an existing node, so each announcement gets its own element.
|
|
52
64
|
*/
|
|
53
|
-
const announce = message => {
|
|
54
|
-
const region = ensureAriaLiveRegion();
|
|
55
|
-
region.textContent = "";
|
|
56
|
-
// Small delay so the screen reader detects the content change
|
|
65
|
+
const announce = (message, widgetElementId) => {
|
|
66
|
+
const region = ensureAriaLiveRegion(widgetElementId);
|
|
57
67
|
setTimeout(() => {
|
|
58
|
-
|
|
59
|
-
|
|
68
|
+
const node = document.createElement("div");
|
|
69
|
+
node.textContent = message;
|
|
70
|
+
region.appendChild(node);
|
|
71
|
+
setTimeout(() => node.remove(), ANNOUNCEMENT_LIFETIME_MS);
|
|
72
|
+
}, ANNOUNCE_DELAY_MS);
|
|
60
73
|
};
|
|
61
74
|
|
|
62
|
-
// eslint-disable-next-line @typescript-eslint/no-
|
|
63
|
-
const
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
75
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
76
|
+
const getFileSentMessage = (attachments, localizedTexts) => {
|
|
77
|
+
var _attachments$;
|
|
78
|
+
if (attachments.length > 1) {
|
|
79
|
+
// Replacer callbacks insert values literally; a string would treat "$&" or "$$" as patterns.
|
|
80
|
+
return ((localizedTexts === null || localizedTexts === void 0 ? void 0 : localizedTexts.MIDDLEWARE_BANNER_FILES_SENT) || DEFAULT_FILES_SENT_TEXT).replace("{0}", () => String(attachments.length));
|
|
81
|
+
}
|
|
82
|
+
const name = typeof ((_attachments$ = attachments[0]) === null || _attachments$ === void 0 ? void 0 : _attachments$.name) === "string" ? attachments[0].name.trim() : "";
|
|
83
|
+
return ((localizedTexts === null || localizedTexts === void 0 ? void 0 : localizedTexts.MIDDLEWARE_BANNER_FILE_SENT) || DEFAULT_FILE_SENT_TEXT).replace("{2}", () => name).replace(/\s{2,}/g, " ").trim();
|
|
84
|
+
};
|
|
85
|
+
exports.getFileSentMessage = getFileSentMessage;
|
|
86
|
+
const createAttachmentSentAnnouncementMiddleware = function (localizedTexts) {
|
|
87
|
+
let widgetElementId = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "oc-lcw";
|
|
88
|
+
return (
|
|
89
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
90
|
+
_ref => {
|
|
91
|
+
let dispatch = _ref.dispatch;
|
|
92
|
+
return next => action => {
|
|
93
|
+
if (!(0, _IWebChatAction.isWebChatAction)(action)) {
|
|
94
|
+
return next(action);
|
|
95
|
+
}
|
|
69
96
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
97
|
+
// Intercept successfully posted activities that contain attachments
|
|
98
|
+
if (action.type === _WebChatActionType.WebChatActionType.DIRECT_LINE_POST_ACTIVITY_FULFILLED) {
|
|
99
|
+
var _action$payload;
|
|
100
|
+
const attachments = (_action$payload = action.payload) === null || _action$payload === void 0 || (_action$payload = _action$payload.activity) === null || _action$payload === void 0 ? void 0 : _action$payload.attachments;
|
|
101
|
+
if (attachments && attachments.length > 0) {
|
|
102
|
+
announce(getFileSentMessage(attachments, localizedTexts), widgetElementId);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
return next(action);
|
|
106
|
+
};
|
|
79
107
|
}
|
|
80
|
-
|
|
81
|
-
};
|
|
108
|
+
);
|
|
82
109
|
};
|
|
83
|
-
|
|
110
|
+
exports.createAttachmentSentAnnouncementMiddleware = createAttachmentSentAnnouncementMiddleware;
|
|
111
|
+
var _default = exports.default = createAttachmentSentAnnouncementMiddleware;
|
|
@@ -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
|
}
|
|
@@ -112,6 +112,7 @@ export let TelemetryEvent = /*#__PURE__*/function (TelemetryEvent) {
|
|
|
112
112
|
TelemetryEvent["RecoveryEligibilityEvaluated"] = "RecoveryEligibilityEvaluated";
|
|
113
113
|
TelemetryEvent["GetConversationDetailsCallStarted"] = "GetConversationDetailsCallStarted";
|
|
114
114
|
TelemetryEvent["GetConversationDetailsCallFailed"] = "GetConversationDetailsCallFailed";
|
|
115
|
+
TelemetryEvent["UpdateTelemetryDataFailed"] = "UpdateTelemetryDataFailed";
|
|
115
116
|
TelemetryEvent["EndChatSDKCallFailed"] = "EndChatSDKCallFailed";
|
|
116
117
|
TelemetryEvent["DisconnectEndChatSDKCallFailed"] = "DisconnectEndChatSDKCallFailed";
|
|
117
118
|
TelemetryEvent["GetChatReconnectContextSDKCallStarted"] = "GetChatReconnectContextSDKCallStarted";
|
|
@@ -141,6 +142,8 @@ export let TelemetryEvent = /*#__PURE__*/function (TelemetryEvent) {
|
|
|
141
142
|
TelemetryEvent["PrechatSubmitted"] = "PrechatSubmitted";
|
|
142
143
|
TelemetryEvent["StartChatSDKCall"] = "StartChatCall";
|
|
143
144
|
TelemetryEvent["StartChatEventReceived"] = "StartChatEventReceived";
|
|
145
|
+
TelemetryEvent["ConcurrentStartChatRejected"] = "ConcurrentStartChatRejected";
|
|
146
|
+
TelemetryEvent["ChatSDKStateCleanUpDisconnectFailed"] = "ChatSDKStateCleanUpDisconnectFailed";
|
|
144
147
|
TelemetryEvent["EndChatSDKCall"] = "EndChatSDKCall";
|
|
145
148
|
TelemetryEvent["PrepareEndChat"] = "PrepareEndChat";
|
|
146
149
|
TelemetryEvent["EndChatEventReceived"] = "EndChatEventReceived";
|
|
@@ -413,6 +416,8 @@ export let TelemetryConstants = /*#__PURE__*/function () {
|
|
|
413
416
|
case TelemetryEvent.SecureEventBusDispatchError:
|
|
414
417
|
case TelemetryEvent.AgentJoinedConversation:
|
|
415
418
|
case TelemetryEvent.BrowserTabHidden:
|
|
419
|
+
case TelemetryEvent.ConcurrentStartChatRejected:
|
|
420
|
+
case TelemetryEvent.ChatSDKStateCleanUpDisconnectFailed:
|
|
416
421
|
case TelemetryEvent.RecoveryEligibilityEvaluated:
|
|
417
422
|
return ScenarioType.ACTIONS;
|
|
418
423
|
case TelemetryEvent.StartChatSDKCall:
|
|
@@ -424,6 +429,7 @@ export let TelemetryConstants = /*#__PURE__*/function () {
|
|
|
424
429
|
case TelemetryEvent.OnNewMessageFailed:
|
|
425
430
|
case TelemetryEvent.OnNewMessageAudioNotificationFailed:
|
|
426
431
|
case TelemetryEvent.GetConversationDetailsCallFailed:
|
|
432
|
+
case TelemetryEvent.UpdateTelemetryDataFailed:
|
|
427
433
|
case TelemetryEvent.EndChatSDKCall:
|
|
428
434
|
case TelemetryEvent.EndChatEventReceived:
|
|
429
435
|
case TelemetryEvent.EndChatSDKCallFailed:
|
|
@@ -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 = {
|