@microsoft/omnichannel-chat-widget 2.0.0 → 2.0.1-main.38c3c85

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.
Files changed (40) hide show
  1. package/README.md +61 -2
  2. package/lib/cjs/common/telemetry/TelemetryConstants.js +8 -0
  3. package/lib/cjs/components/chatbuttonstateful/ChatButtonStateful.js +42 -25
  4. package/lib/cjs/components/livechatwidget/common/endChat.js +39 -0
  5. package/lib/cjs/components/livechatwidget/common/initWebChatComposer.js +42 -13
  6. package/lib/cjs/components/livechatwidget/common/reconnectChatHelper.js +29 -1
  7. package/lib/cjs/components/livechatwidget/common/recoveryEligibilityTelemetry.js +60 -0
  8. package/lib/cjs/components/livechatwidget/common/startChat.js +118 -36
  9. package/lib/cjs/components/livechatwidget/common/updateSessionDataForTelemetry.js +34 -5
  10. package/lib/cjs/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +13 -23
  11. package/lib/cjs/components/webchatcontainerstateful/WebChatContainerStateful.js +2 -2
  12. package/lib/cjs/components/webchatcontainerstateful/common/defaultProps/defaultMiddlewareLocalizedTexts.js +2 -1
  13. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/attachmentForScreenReaderMiddleware.js +159 -0
  14. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/attachments/AdaptiveCardAccessibilityWrapper.js +16 -2
  15. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/attachmentSentAnnouncementMiddleware.js +68 -40
  16. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/attachmentUploadValidatorMiddleware.js +0 -27
  17. package/lib/esm/common/telemetry/TelemetryConstants.js +8 -0
  18. package/lib/esm/components/chatbuttonstateful/ChatButtonStateful.js +42 -25
  19. package/lib/esm/components/livechatwidget/common/endChat.js +39 -0
  20. package/lib/esm/components/livechatwidget/common/initWebChatComposer.js +40 -13
  21. package/lib/esm/components/livechatwidget/common/reconnectChatHelper.js +28 -1
  22. package/lib/esm/components/livechatwidget/common/recoveryEligibilityTelemetry.js +52 -0
  23. package/lib/esm/components/livechatwidget/common/startChat.js +115 -34
  24. package/lib/esm/components/livechatwidget/common/updateSessionDataForTelemetry.js +34 -5
  25. package/lib/esm/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +14 -24
  26. package/lib/esm/components/webchatcontainerstateful/WebChatContainerStateful.js +2 -2
  27. package/lib/esm/components/webchatcontainerstateful/common/defaultProps/defaultMiddlewareLocalizedTexts.js +2 -1
  28. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/attachmentForScreenReaderMiddleware.js +153 -0
  29. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/attachments/AdaptiveCardAccessibilityWrapper.js +16 -2
  30. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/attachmentSentAnnouncementMiddleware.js +65 -39
  31. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/attachmentUploadValidatorMiddleware.js +0 -27
  32. package/lib/types/common/telemetry/TelemetryConstants.d.ts +4 -0
  33. package/lib/types/components/livechatwidget/common/initWebChatComposer.d.ts +8 -0
  34. package/lib/types/components/livechatwidget/common/reconnectChatHelper.d.ts +6 -1
  35. package/lib/types/components/livechatwidget/common/recoveryEligibilityTelemetry.d.ts +17 -0
  36. package/lib/types/components/livechatwidget/common/startChat.d.ts +5 -1
  37. package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/attachmentForScreenReaderMiddleware.d.ts +11 -0
  38. package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/attachmentSentAnnouncementMiddleware.d.ts +11 -4
  39. package/lib/types/contexts/common/ILiveChatWidgetLocalizedTexts.d.ts +9 -2
  40. package/package.json +7 -7
@@ -18,19 +18,86 @@ import { isMidAuthEnabled } from "./authHelper";
18
18
  import { setPostChatContextAndLoadSurvey } from "./setPostChatContextAndLoadSurvey";
19
19
  import { shouldSetPreChatIfPersistentChat } from "./persistentChatHelper";
20
20
  import { updateTelemetryData } from "./updateSessionDataForTelemetry";
21
+ /**
22
+ * Per widget instance mutexes for the two chat creation entry points.
23
+ *
24
+ * Every guard in the prepareStartChat -> setPreChatAndInitiateChat -> initStartChat chain
25
+ * checks `conversationState === Closed`, but React state is updated asynchronously. A second
26
+ * invocation fired within the same render cycle (for example a rapid double click on the chat
27
+ * button, or a chat button click racing a BroadcastEvent.StartChat) therefore still observes
28
+ * the stale `Closed` state, reaches `facadeChatSDK.startChat()` and creates a second
29
+ * conversation on the backend which is then orphaned and never ended.
30
+ *
31
+ * The locks are keyed by FacadeChatSDK instance rather than being module wide, because a host
32
+ * page can mount several independent widgets, each with its own widgetInstanceId and its own
33
+ * FacadeChatSDK (created once per widget in LiveChatWidget.tsx). A module wide lock would make
34
+ * widget A's start chat silently drop widget B's legitimate simultaneous start chat.
35
+ *
36
+ * The two maps are separate because prepareStartChat calls initStartChat; sharing a single lock
37
+ * would make the nested call see its own parent as in flight and drop it. prepareStartChat is
38
+ * additionally blocked by an in flight initStartChat (pre-chat submit, reconnect, or the
39
+ * hideStartChatButton bootstrap call initStartChat directly). Otherwise a later prepareStartChat
40
+ * would dispatch Loading and maximize the widget, and only then have its nested initStartChat
41
+ * dropped.
42
+ */
43
+ const prepareStartChatGuards = new WeakMap();
44
+ const initStartChatGuards = new WeakMap();
21
45
 
22
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
23
- let optionalParams = {};
24
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
25
- let widgetInstanceId;
26
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
27
- let popoutWidgetInstanceId;
46
+ // Fallback owner used only when no FacadeChatSDK instance is available to key on, so the guard
47
+ // degrades to the module wide behaviour instead of disappearing altogether.
48
+ const unkeyedGuardOwner = {};
49
+ const getGuard = (guards, facadeChatSDK) => {
50
+ const owner = facadeChatSDK ?? unkeyedGuardOwner;
51
+ let guard = guards.get(owner);
52
+ if (!guard) {
53
+ guard = {
54
+ inFlight: false
55
+ };
56
+ guards.set(owner, guard);
57
+ }
58
+ return guard;
59
+ };
60
+
61
+ /**
62
+ * Runs `operation` only if no other invocation for the same widget instance is already in
63
+ * flight. Concurrent invocations are dropped (and reported through telemetry) rather than
64
+ * awaiting the in-flight promise, so a future re-entrant call can never deadlock on itself.
65
+ * A dropped invocation resolves to `undefined`.
66
+ *
67
+ * `blockedBy` lets an operation also yield to a different, already running operation for the
68
+ * same widget instance without claiming that operation's lock.
69
+ */
70
+ const runExclusively = async (guards, facadeChatSDK, description, operation, props, blockedBy) => {
71
+ const guard = getGuard(guards, facadeChatSDK);
72
+ const blockingGuard = blockedBy ? getGuard(blockedBy, facadeChatSDK) : undefined;
73
+ if (guard.inFlight || blockingGuard !== null && blockingGuard !== void 0 && blockingGuard.inFlight) {
74
+ TelemetryHelper.logActionEvent(LogLevel.WARN, {
75
+ Event: TelemetryEvent.ConcurrentStartChatRejected,
76
+ Description: description,
77
+ CustomProperties: {
78
+ WidgetCacheId: props ? getWidgetCacheIdfromProps(props) : undefined
79
+ }
80
+ });
81
+ return undefined;
82
+ }
83
+
84
+ // Claim the lock before invoking the operation, so a re-entrant call made from the
85
+ // operation's synchronous preamble (before its first await) cannot slip past the check above.
86
+ guard.inFlight = true;
87
+ try {
88
+ return await operation();
89
+ } finally {
90
+ guard.inFlight = false;
91
+ }
92
+ };
28
93
 
29
94
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
30
95
  const prepareStartChat = async (props, facadeChatSDK, state, dispatch, setAdapter) => {
31
- optionalParams = {}; //Resetting to ensure no stale values
32
- widgetInstanceId = getWidgetCacheIdfromProps(props);
96
+ return runExclusively(prepareStartChatGuards, facadeChatSDK, "Concurrent prepareStartChat call ignored, a start chat operation is already in progress for this widget instance.", () => prepareStartChatInternal(props, facadeChatSDK, state, dispatch, setAdapter), props, initStartChatGuards);
97
+ };
33
98
 
99
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
100
+ const prepareStartChatInternal = async (props, facadeChatSDK, state, dispatch, setAdapter) => {
34
101
  // reconnect > chat from cache
35
102
  if (isReconnectEnabled(props.chatConfig) === true && !isPersistentEnabled(props.chatConfig)) {
36
103
  const shouldStartChatNormally = await handleChatReconnect(facadeChatSDK, props, dispatch, setAdapter, initStartChat, state);
@@ -154,8 +221,18 @@ const setPreChatAndInitiateChat = async (facadeChatSDK, dispatch, setAdapter, is
154
221
  await initStartChat(facadeChatSDK, dispatch, setAdapter, state, props, optionalParams);
155
222
  };
156
223
 
224
+ /**
225
+ * Resolves to `true` when the chat reached Active, and `false` when it failed or the call was dropped.
226
+ * It resolves before React renders Active, so callers must use this value rather than reading the conversation state.
227
+ */
157
228
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
158
229
  const initStartChat = async (facadeChatSDK, dispatch, setAdapter, state, props, params, persistedState) => {
230
+ 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);
231
+ return chatStarted === true;
232
+ };
233
+
234
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
235
+ const initStartChatInternal = async (facadeChatSDK, dispatch, setAdapter, state, props, params, persistedState) => {
159
236
  var _state$domainStates7;
160
237
  let isStartChatSuccessful = false;
161
238
  const persistentChatEnabled = isPersistentChatEnabled(state === null || state === void 0 || (_state$domainStates7 = state.domainStates) === null || _state$domainStates7 === void 0 || (_state$domainStates7 = _state$domainStates7.liveChatConfig) === null || _state$domainStates7 === void 0 || (_state$domainStates7 = _state$domainStates7.LiveWSAndLiveChatEngJoin) === null || _state$domainStates7 === void 0 ? void 0 : _state$domainStates7.msdyn_conversationmode);
@@ -194,14 +271,15 @@ const initStartChat = async (facadeChatSDK, dispatch, setAdapter, state, props,
194
271
  }
195
272
  try {
196
273
  var _window$Microsoft, _state$domainStates8;
197
- // Set custom context params
198
- await setCustomContextParams(state, props);
274
+ // Set custom context params. Returned (not stored module-side) so that concurrent
275
+ // widget instances cannot overwrite each other's custom context.
276
+ const customContextParams = await setCustomContextParams(state, props);
199
277
  const defaultOptionalParams = {
200
278
  sendDefaultInitContext: true,
201
279
  isProactiveChat: !!(params !== null && params !== void 0 && params.isProactiveChat),
202
280
  portalContactId: (_window$Microsoft = window.Microsoft) === null || _window$Microsoft === void 0 || (_window$Microsoft = _window$Microsoft.Dynamic365) === null || _window$Microsoft === void 0 || (_window$Microsoft = _window$Microsoft.Portal) === null || _window$Microsoft === void 0 || (_window$Microsoft = _window$Microsoft.User) === null || _window$Microsoft === void 0 ? void 0 : _window$Microsoft.contactId
203
281
  };
204
- const startChatOptionalParams = Object.assign({}, params, optionalParams, defaultOptionalParams);
282
+ const startChatOptionalParams = Object.assign({}, params, customContextParams, defaultOptionalParams);
205
283
 
206
284
  // MID-AUTH: Add wasAuthenticated flag for reconnect scenarios
207
285
  // Tells FacadeChatSDK whether the previous session was authenticated
@@ -264,7 +342,7 @@ const initStartChat = async (facadeChatSDK, dispatch, setAdapter, state, props,
264
342
  logWidgetLoadComplete(WidgetLoadTelemetryMessage.PersistedStateRetrievedMessage);
265
343
  // Set post chat context in state, load in background to do not block the load
266
344
  setPostChatContextAndLoadSurvey(facadeChatSDK, dispatch, true);
267
- return;
345
+ return true;
268
346
  }
269
347
 
270
348
  // Persistent Chat relies on the `reconnectId` retrieved from reconnectablechats API to reconnect upon start chat and not `liveChatContext`
@@ -280,13 +358,13 @@ const initStartChat = async (facadeChatSDK, dispatch, setAdapter, state, props,
280
358
  logWidgetLoadComplete();
281
359
  // Set post chat context in state, load in background to do not block the load
282
360
  setPostChatContextAndLoadSurvey(facadeChatSDK, dispatch);
283
- // Updating chat session detail for telemetry
284
- await updateTelemetryData(facadeChatSDK, dispatch);
361
+ // Updating chat session detail for telemetry, in background: getConversationDetails retries until the
362
+ // live work item exists (several seconds), and awaiting it would hold the start chat locks and drop the next start chat
363
+ updateTelemetryData(facadeChatSDK, dispatch);
364
+ return true;
285
365
  } catch (ex) {
286
366
  handleStartChatError(dispatch, facadeChatSDK, props, ex, isStartChatSuccessful);
287
- } finally {
288
- optionalParams = {};
289
- widgetInstanceId = "";
367
+ return false;
290
368
  }
291
369
  };
292
370
 
@@ -330,19 +408,22 @@ const canConnectToExistingChat = async (props, facadeChatSDK, state, dispatch, s
330
408
  return false;
331
409
  };
332
410
 
333
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
411
+ /**
412
+ * Resolves the custom context to start the chat with.
413
+ *
414
+ * Returns the resolved params instead of mutating module-level state: a page can host several
415
+ * independent widgets, and once per-instance start-chat guards allow them to run concurrently,
416
+ * shared mutable state would let one widget overwrite another widget's custom context.
417
+ */
334
418
  const setCustomContextParams = async (state, props) => {
335
419
  var _state$domainStates9, _persistedState$domai5;
336
420
  if (state !== null && state !== void 0 && (_state$domainStates9 = state.domainStates) !== null && _state$domainStates9 !== void 0 && _state$domainStates9.customContext) {
337
421
  var _state$domainStates0;
338
- optionalParams = Object.assign({}, optionalParams, {
422
+ return {
339
423
  customContext: JSON.parse(JSON.stringify(state === null || state === void 0 || (_state$domainStates0 = state.domainStates) === null || _state$domainStates0 === void 0 ? void 0 : _state$domainStates0.customContext))
340
- });
341
- return;
342
- }
343
- if (isNullOrEmptyString(widgetInstanceId)) {
344
- widgetInstanceId = getWidgetCacheIdfromProps(props);
424
+ };
345
425
  }
426
+ const widgetInstanceId = props ? getWidgetCacheIdfromProps(props) : "";
346
427
  // Add custom context only for unauthenticated chat
347
428
  const persistedState = getStateFromCache(widgetInstanceId);
348
429
  const customContextLocal = (persistedState === null || persistedState === void 0 || (_persistedState$domai5 = persistedState.domainStates) === null || _persistedState$domai5 === void 0 ? void 0 : _persistedState$domai5.customContext) ?? (props === null || props === void 0 ? void 0 : props.initialCustomContext);
@@ -351,23 +432,23 @@ const setCustomContextParams = async (state, props) => {
351
432
  Event: TelemetryEvent.SettingCustomContext,
352
433
  Description: "Setting custom context for unauthenticated chat"
353
434
  });
354
- optionalParams = Object.assign({}, optionalParams, {
435
+ return {
355
436
  customContext: JSON.parse(JSON.stringify(customContextLocal))
356
- });
357
- } else {
358
- const customContextFromParent = await getInitContextParamsForPopout();
359
- if (!isUndefinedOrEmpty(customContextFromParent === null || customContextFromParent === void 0 ? void 0 : customContextFromParent.contextVariables)) {
360
- optionalParams = Object.assign({}, optionalParams, {
361
- customContext: JSON.parse(JSON.stringify(customContextFromParent.contextVariables))
362
- });
363
- }
437
+ };
438
+ }
439
+ const customContextFromParent = await getInitContextParamsForPopout();
440
+ if (!isUndefinedOrEmpty(customContextFromParent === null || customContextFromParent === void 0 ? void 0 : customContextFromParent.contextVariables)) {
441
+ return {
442
+ customContext: JSON.parse(JSON.stringify(customContextFromParent.contextVariables))
443
+ };
364
444
  }
445
+ return {};
365
446
  };
366
447
  const canStartPopoutChat = async props => {
367
448
  if (props.allowSdkChatSupport === false) {
368
449
  return false;
369
450
  }
370
- popoutWidgetInstanceId = getWidgetCacheIdfromProps(props, true);
451
+ const popoutWidgetInstanceId = getWidgetCacheIdfromProps(props, true);
371
452
  if (!isNullOrEmptyString(popoutWidgetInstanceId)) {
372
453
  var _persistedState$domai6, _persistedState$appSt3;
373
454
  const persistedState = getStateFromCache(popoutWidgetInstanceId);
@@ -1,4 +1,4 @@
1
- import { BroadcastEvent } from "../../../common/telemetry/TelemetryConstants";
1
+ import { BroadcastEvent, LogLevel, TelemetryEvent } from "../../../common/telemetry/TelemetryConstants";
2
2
  import { BroadcastService } from "@microsoft/omnichannel-chat-components";
3
3
  import { LiveChatWidgetActionType } from "../../../contexts/common/LiveChatWidgetActionType";
4
4
  import { TelemetryHelper } from "../../../common/telemetry/TelemetryHelper";
@@ -7,15 +7,41 @@ import { getConversationDetailsCall } from "../../../common/utils";
7
7
 
8
8
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
9
9
  export const updateTelemetryData = async (facadeChatSDK, dispatch) => {
10
- // load it concurrently, this will reduce the load time
11
- await Promise.all([updateSessionDataForTelemetry(facadeChatSDK, dispatch), updateConversationDataForTelemetry(facadeChatSDK, dispatch)]);
10
+ var _facadeChatSDK$getCha;
11
+ // startChat no longer waits for this, so the next chat can start (chatSDKStateCleanUp assigns a new requestId)
12
+ // before these calls resolve. Results for an earlier chat must not overwrite the current chat's data.
13
+ // endChat also assigns a new requestId, so the chat that just ended still applies its own results.
14
+ const requestId = facadeChatSDK === null || facadeChatSDK === void 0 || (_facadeChatSDK$getCha = facadeChatSDK.getChatSDK()) === null || _facadeChatSDK$getCha === void 0 ? void 0 : _facadeChatSDK$getCha.requestId;
15
+ try {
16
+ // load it concurrently, this will reduce the load time
17
+ await Promise.all([updateSessionDataForTelemetry(facadeChatSDK, dispatch, requestId), updateConversationDataForTelemetry(facadeChatSDK, dispatch, requestId)]);
18
+ } catch (error) {
19
+ TelemetryHelper.logSDKEvent(LogLevel.ERROR, {
20
+ Event: TelemetryEvent.UpdateTelemetryDataFailed,
21
+ ExceptionDetails: {
22
+ exception: `Update telemetry data failed: ${error}`
23
+ }
24
+ });
25
+ }
26
+ };
27
+
28
+ // The requestId alone isn't enough: endChat also replaces it. Only the next chat's startChat gets a new chat token
29
+ // (endChat and chatSDKStateCleanUp clear it), so drop the result only when the SDK holds that next chat.
30
+ const isFromEarlierChat = (facadeChatSDK, requestId) => {
31
+ var _chatSDK$chatToken;
32
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
33
+ const chatSDK = facadeChatSDK.getChatSDK();
34
+ 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);
12
35
  };
13
36
 
14
37
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
15
- const updateSessionDataForTelemetry = async (facadeChatSDK, dispatch) => {
38
+ const updateSessionDataForTelemetry = async (facadeChatSDK, dispatch, requestId) => {
16
39
  if (facadeChatSDK && facadeChatSDK.getChatSDK()) {
17
40
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
18
41
  const chatSession = await facadeChatSDK.getCurrentLiveChatContext();
42
+ if (isFromEarlierChat(facadeChatSDK, requestId)) {
43
+ return;
44
+ }
19
45
  const telemetryData = TelemetryHelper.addSessionDataToTelemetry(chatSession, TelemetryManager.InternalTelemetryData);
20
46
  dispatch({
21
47
  type: LiveChatWidgetActionType.SET_TELEMETRY_DATA,
@@ -31,10 +57,13 @@ const updateSessionDataForTelemetry = async (facadeChatSDK, dispatch) => {
31
57
  };
32
58
 
33
59
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
34
- const updateConversationDataForTelemetry = async (facadeChatSDK, dispatch) => {
60
+ const updateConversationDataForTelemetry = async (facadeChatSDK, dispatch, requestId) => {
35
61
  if (facadeChatSDK && facadeChatSDK.getChatSDK()) {
36
62
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
37
63
  const liveWorkItem = await getConversationDetailsCall(facadeChatSDK);
64
+ if (isFromEarlierChat(facadeChatSDK, requestId)) {
65
+ return;
66
+ }
38
67
  const telemetryData = TelemetryHelper.addConversationDataToTelemetry(liveWorkItem, TelemetryManager.InternalTelemetryData);
39
68
  dispatch({
40
69
  type: LiveChatWidgetActionType.SET_TELEMETRY_DATA,
@@ -17,7 +17,7 @@ import { checkIfConversationStillValid, initStartChat, prepareStartChat, setPreC
17
17
  import { createTimer, getBroadcastChannelName, getConversationDetailsCall, getLocaleDirection, getStateFromCache, getWidgetCacheIdfromProps, getWidgetEndChatEventName, isNullOrEmptyString, isNullOrUndefined, isThisSessionPopout, isUndefinedOrEmpty, setAriaHiddenForSiblings, setOcUserAgent } from "../../../common/utils";
18
18
  import { customEventCallback, subscribeToSendCustomEvent } from "../common/customEventHandler";
19
19
  import { defaultClientDataStoreProvider, isCookieAllowed } from "../../../common/storage/default/defaultClientDataStoreProvider";
20
- import { handleChatReconnect, isPersistentEnabled, isReconnectEnabled } from "../common/reconnectChatHelper";
20
+ import { isPersistentEnabled, isReconnectTriggered } from "../common/reconnectChatHelper";
21
21
  import { shouldShowCallingContainer, shouldShowChatButton, shouldShowConfirmationPane, shouldShowEmailTranscriptPane, shouldShowHeader, shouldShowLoadingPane, shouldShowOutOfOfficeHoursPane, shouldShowPostChatLoadingPane, shouldShowPostChatSurveyPane, shouldShowPreChatSurveyPane, shouldShowProactiveChatPane, shouldShowReconnectChatPane, shouldShowStartChatErrorPane, shouldShowWebChatContainer } from "../../../controller/componentController";
22
22
  import { ActivityStreamHandler } from "../common/ActivityStreamHandler";
23
23
  import CallingContainerStateful from "../../callingcontainerstateful/CallingContainerStateful";
@@ -62,6 +62,7 @@ import useChatAdapterStore from "../../../hooks/useChatAdapterStore";
62
62
  import useChatContextStore from "../../../hooks/useChatContextStore";
63
63
  import useFacadeSDKStore from "../../../hooks/useFacadeChatSDKStore";
64
64
  import { getPostChatContext, initiatePostChat } from "../common/renderSurveyHelpers";
65
+ import { logRecoveryEligibilityTelemetry } from "../common/recoveryEligibilityTelemetry";
65
66
  let uiTimer;
66
67
  export const LiveChatWidgetStateful = props => {
67
68
  var _props$webChatContain, _props$webChatContain2, _props$webChatContain3, _props$webChatContain4, _props$webChatContain5, _props$styleProps, _props$webChatContain6, _props$controlProps, _props$controlProps3, _state$appStates7, _props$webChatContain9, _state$appStates8, _props$webChatContain1, _props$webChatContain10, _props$controlProps10, _props$draggableChatW, _props$draggableChatW2, _props$draggableChatW3, _props$draggableChatW4, _props$draggableChatW5, _livechatProps$webCha, _livechatProps$styleP, _props$headerProps, _livechatProps$contro, _livechatProps$contro2, _livechatProps$compon, _livechatProps$contro3, _livechatProps$compon2, _livechatProps$contro4, _livechatProps$compon3, _livechatProps$contro5, _livechatProps$compon4, _livechatProps$contro6, _livechatProps$compon5, _livechatProps$contro7, _livechatProps$compon6, _livechatProps$contro8, _livechatProps$compon7, _livechatProps$contro9, _livechatProps$compon8, _livechatProps$contro0, _livechatProps$contro1, _livechatProps$compon9, _livechatProps$contro10, _livechatProps$compon0, _livechatProps$contro11, _livechatProps$compon1, _livechatProps$compon10, _livechatProps$compon11;
@@ -150,24 +151,11 @@ export const LiveChatWidgetStateful = props => {
150
151
  activeCachedChatExist = false;
151
152
  optionalParams = {};
152
153
  }
154
+ logRecoveryEligibilityTelemetry(state, activeCachedChatExist);
153
155
  };
154
156
 
155
157
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
156
158
  const startChat = async (props, localState) => {
157
- const isReconnectTriggered = async () => {
158
- if (isReconnectEnabled(props.chatConfig) === true && !isPersistentEnabled(props.chatConfig)) {
159
- const noValidReconnectId = await handleChatReconnect(facadeChatSDK, props, dispatch, setAdapter, initStartChat, state);
160
- const inMemoryState = executeReducer(state, {
161
- type: LiveChatWidgetActionType.GET_IN_MEMORY_STATE,
162
- payload: null
163
- });
164
- // If chat reconnect has kicked in chat state will become Active or Reconnect. So just exit, else go next
165
- if (!noValidReconnectId && (inMemoryState.appStates.conversationState === ConversationState.Active || inMemoryState.appStates.conversationState === ConversationState.ReconnectChat)) {
166
- return true;
167
- }
168
- }
169
- return false;
170
- };
171
159
  let isChatValid = false;
172
160
  //Start a chat from cache/reconnectid
173
161
  if (activeCachedChatExist === true) {
@@ -179,7 +167,7 @@ export const LiveChatWidgetStateful = props => {
179
167
  //Check if conversation state is not in wrapup or closed state
180
168
  isChatValid = await checkIfConversationStillValid(facadeChatSDK, dispatch, state);
181
169
  if (isChatValid === true) {
182
- const reconnectTriggered = await isReconnectTriggered();
170
+ const reconnectTriggered = await isReconnectTriggered(facadeChatSDK, props, dispatch, setAdapter, initStartChat, state);
183
171
  if (!reconnectTriggered) {
184
172
  await initStartChat(facadeChatSDK, dispatch, setAdapter, state, props, optionalParams);
185
173
  }
@@ -195,7 +183,7 @@ export const LiveChatWidgetStateful = props => {
195
183
  if (isChatValid === false) {
196
184
  if (localState) {
197
185
  // adding the reconnect logic for the case when customer tries to reconnect from a new browser or InPrivate browser
198
- const reconnectTriggered = await isReconnectTriggered();
186
+ const reconnectTriggered = await isReconnectTriggered(facadeChatSDK, props, dispatch, setAdapter, initStartChat, state);
199
187
  if (!reconnectTriggered) {
200
188
  const inMemoryState = executeReducer(state, {
201
189
  type: LiveChatWidgetActionType.GET_IN_MEMORY_STATE,
@@ -991,7 +979,9 @@ export const LiveChatWidgetStateful = props => {
991
979
  const endChatRelay = (adapter, skipEndChatSDK, skipCloseChat, postMessageToOtherTab) => endChat(props, facadeChatSDK, state, dispatch, setAdapter, setWebChatStyles, adapter, skipEndChatSDK, skipCloseChat, postMessageToOtherTab);
992
980
  const prepareStartChatRelay = () => prepareStartChat(props, facadeChatSDK, state, dispatch, setAdapter);
993
981
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
994
- const initStartChatRelay = (optionalParams, persistedState) => initStartChat(facadeChatSDK, dispatch, setAdapter, state, props, optionalParams, persistedState);
982
+ const initStartChatRelay = async (optionalParams, persistedState) => {
983
+ await initStartChat(facadeChatSDK, dispatch, setAdapter, state, props, optionalParams, persistedState);
984
+ };
995
985
  const confirmationPaneProps = initConfirmationPropsComposer(props);
996
986
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
997
987
  const prepareEndChatRelay = () => prepareEndChat(props, facadeChatSDK, state, dispatch, setAdapter, setWebChatStyles, adapter);
@@ -1165,18 +1155,18 @@ export const LiveChatWidgetStateful = props => {
1165
1155
  .webchat__auto-resize-textarea.webchat__send-box-text-box__text-area {
1166
1156
  min-height: ${sendBoxTextArea === null || sendBoxTextArea === void 0 ? void 0 : sendBoxTextArea.minHeight} !important;
1167
1157
  }`}
1168
- `), /*#__PURE__*/React.createElement(DraggableChatWidget, chatWidgetDraggableConfig, /*#__PURE__*/React.createElement(Composer, _extends({}, webChatProps, {
1169
- userID: userID,
1170
- styleOptions: styleOptions,
1171
- directLine: directLine
1172
- }), /*#__PURE__*/React.createElement(Stack, {
1158
+ `), /*#__PURE__*/React.createElement(DraggableChatWidget, chatWidgetDraggableConfig, /*#__PURE__*/React.createElement(Stack, {
1173
1159
  id: widgetElementId,
1174
1160
  styles: generalStyles,
1175
1161
  className: (_livechatProps$styleP = livechatProps.styleProps) === null || _livechatProps$styleP === void 0 ? void 0 : _livechatProps$styleP.className,
1176
1162
  role: isWidgetOpen ? "dialog" : undefined,
1177
1163
  "aria-modal": isWidgetOpen ? true : undefined,
1178
1164
  "aria-label": isWidgetOpen ? ((_props$headerProps = props.headerProps) === null || _props$headerProps === void 0 || (_props$headerProps = _props$headerProps.controlProps) === null || _props$headerProps === void 0 || (_props$headerProps = _props$headerProps.headerTitleProps) === null || _props$headerProps === void 0 ? void 0 : _props$headerProps.text) ?? "Live Chat" : undefined
1179
- }, !((_livechatProps$contro = livechatProps.controlProps) !== null && _livechatProps$contro !== void 0 && _livechatProps$contro.hideChatButton) && !((_livechatProps$contro2 = livechatProps.controlProps) !== null && _livechatProps$contro2 !== void 0 && _livechatProps$contro2.hideStartChatButton) && shouldShowChatButton(state) && (decodeComponentString((_livechatProps$compon = livechatProps.componentOverrides) === null || _livechatProps$compon === void 0 ? void 0 : _livechatProps$compon.chatButton) || /*#__PURE__*/React.createElement(ChatButtonStateful, {
1165
+ }, /*#__PURE__*/React.createElement(Composer, _extends({}, webChatProps, {
1166
+ userID: userID,
1167
+ styleOptions: styleOptions,
1168
+ directLine: directLine
1169
+ }), !((_livechatProps$contro = livechatProps.controlProps) !== null && _livechatProps$contro !== void 0 && _livechatProps$contro.hideChatButton) && !((_livechatProps$contro2 = livechatProps.controlProps) !== null && _livechatProps$contro2 !== void 0 && _livechatProps$contro2.hideStartChatButton) && shouldShowChatButton(state) && (decodeComponentString((_livechatProps$compon = livechatProps.componentOverrides) === null || _livechatProps$compon === void 0 ? void 0 : _livechatProps$compon.chatButton) || /*#__PURE__*/React.createElement(ChatButtonStateful, {
1180
1170
  buttonProps: livechatProps.chatButtonProps,
1181
1171
  outOfOfficeButtonProps: livechatProps.outOfOfficeChatButtonProps,
1182
1172
  startChat: prepareStartChatRelay
@@ -529,9 +529,9 @@ export const WebChatContainerStateful = props => {
529
529
 
530
530
  /* Suggested actions carousel previous/next navigation focus */
531
531
  .webchat__suggested-actions .webchat__suggested-actions__carousel .react-film__flipper:focus-visible .react-film__flipper__body {
532
- outline: ${(webChatContainerProps === null || webChatContainerProps === void 0 || (_webChatContainerProp20 = webChatContainerProps.webChatStyles) === null || _webChatContainerProp20 === void 0 ? void 0 : _webChatContainerProp20.suggestedActionKeyboardFocusIndicatorBorderStyle) ?? "dashed"} ${(webChatContainerProps === null || webChatContainerProps === void 0 || (_webChatContainerProp21 = webChatContainerProps.webChatStyles) === null || _webChatContainerProp21 === void 0 ? void 0 : _webChatContainerProp21.suggestedActionKeyboardFocusIndicatorBorderWidth) ?? "1px"} ${(webChatContainerProps === null || webChatContainerProps === void 0 || (_webChatContainerProp22 = webChatContainerProps.webChatStyles) === null || _webChatContainerProp22 === void 0 ? void 0 : _webChatContainerProp22.suggestedActionKeyboardFocusIndicatorBorderColor) ?? "#605E5C"} !important;
532
+ 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;
533
533
  outline-offset: ${(webChatContainerProps === null || webChatContainerProps === void 0 || (_webChatContainerProp23 = webChatContainerProps.webChatStyles) === null || _webChatContainerProp23 === void 0 ? void 0 : _webChatContainerProp23.suggestedActionKeyboardFocusIndicatorInset) ?? "2px"} !important;
534
-
534
+ }
535
535
  `), /*#__PURE__*/React.createElement(Stack, {
536
536
  styles: containerStyles,
537
537
  className: "webchat__stacked-layout_container"
@@ -27,7 +27,8 @@ export const defaultMiddlewareLocalizedTexts = {
27
27
  MIDDLEWARE_BANNER_CHAT_DISCONNECT: "Your conversation has been disconnected. For additional assistance, please start a new chat.",
28
28
  THIRD_PARTY_COOKIES_BLOCKED_ALERT_MESSAGE: "Allow sites to save/read cookies in browser settings. Reloading page starts a new chat.",
29
29
  MIDDLEWARE_BANNER_FILE_IS_MALICIOUS: "{0} has been blocked because the file may contain a malware.",
30
- MIDDLEWARE_BANNER_FILE_SENT: "File sent successfully.",
30
+ MIDDLEWARE_BANNER_FILE_SENT: "File {2} sent",
31
+ MIDDLEWARE_BANNER_FILES_SENT: "{0} files sent",
31
32
  MIDDLEWARE_BANNER_FILE_EMAIL_ADDRESS_RECORDED_SUCCESS: "Email will be sent after chat ends!",
32
33
  MIDDLEWARE_BANNER_FILE_EMAIL_ADDRESS_RECORDED_ERROR: "Email {0} could not be saved, try again later.",
33
34
  MIDDLEWARE_SR_PREFIX_SUCCESS: "Success. ",
@@ -0,0 +1,153 @@
1
+ function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
2
+ 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."); }
3
+ 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; } }
4
+ 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; }
5
+ 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; } }
6
+ function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
7
+ /* eslint-disable @typescript-eslint/no-explicit-any */
8
+ /******
9
+ * AttachmentForScreenReaderMiddleware
10
+ *
11
+ * Web Chat reads an Adaptive Card to screen readers only from the card's `speak` property.
12
+ * A card without `speak` is announced as "A card" with no content.
13
+ * This middleware sets `speak` from the visible text of the card, then lets Web Chat render it as usual.
14
+ ******/
15
+
16
+ import React, { useMemo } from "react";
17
+ import { Constants } from "../../../../../common/Constants";
18
+ import { hooks } from "botframework-webchat";
19
+ const useAdaptiveCardsPackage = hooks.useAdaptiveCardsPackage,
20
+ useStyleOptions = hooks.useStyleOptions;
21
+ const ADAPTIVE_CARD_CONTENT_TYPE = "application/vnd.microsoft.card.adaptive";
22
+ const HTML_BLOCK_END = /<\/(p|li|h[1-6]|div|tr|td|th|blockquote|pre)>|<br\s*\/?>/gi;
23
+ // The "opens in a new window" icon of each link is left out: it describes the link target, not the content of the message.
24
+ const htmlToText = html => {
25
+ const body = new DOMParser().parseFromString(html.replace(HTML_BLOCK_END, "$& "), "text/html").body;
26
+ body.querySelectorAll(`script, style, template, img.${Constants.OpenLinkIconCssClass}`).forEach(element => element.remove());
27
+ body.querySelectorAll("img").forEach(image => image.replaceWith(` ${image.getAttribute("alt") ?? ""} `));
28
+ return (body.textContent ?? "").replace(/\s+/g, " ").trim();
29
+ };
30
+
31
+ // Renders the element as the visible card does: Adaptive Cards formats {{DATE()}} and {{TIME()}}, then the Markdown is rendered.
32
+ // Web Chat sets the static Markdown handler before each visible render, and this restores the previous handler after rendering.
33
+ const getRenderedText = (element, AdaptiveCard, renderMarkdownAsHTML) => {
34
+ const previousOnProcessMarkdown = AdaptiveCard.onProcessMarkdown;
35
+ try {
36
+ AdaptiveCard.onProcessMarkdown = (text, result) => {
37
+ result.outputHtml = renderMarkdownAsHTML(text);
38
+ result.didProcess = true;
39
+ };
40
+ const renderedElement = element.render();
41
+ return renderedElement ? htmlToText(renderedElement.outerHTML) : "";
42
+ } catch {
43
+ var _element$asString;
44
+ return ((_element$asString = element.asString) === null || _element$asString === void 0 ? void 0 : _element$asString.call(element)) ?? "";
45
+ } finally {
46
+ AdaptiveCard.onProcessMarkdown = previousOnProcessMarkdown;
47
+ }
48
+ };
49
+
50
+ // Collects the visible text of the card in document order, after the parser has applied element fallbacks.
51
+ // Inputs and actions are not collected because Web Chat already lists them after the card text.
52
+ export const getAdaptiveCardSpeak = (content, adaptiveCardsPackage, renderMarkdownAsHTML, adaptiveCardsParserMaxVersion) => {
53
+ const AdaptiveCard = adaptiveCardsPackage.AdaptiveCard,
54
+ FactSet = adaptiveCardsPackage.FactSet,
55
+ Image = adaptiveCardsPackage.Image,
56
+ RichTextBlock = adaptiveCardsPackage.RichTextBlock,
57
+ SerializationContext = adaptiveCardsPackage.SerializationContext,
58
+ TextBlock = adaptiveCardsPackage.TextBlock,
59
+ Version = adaptiveCardsPackage.Version;
60
+ const maxVersion = adaptiveCardsParserMaxVersion ? Version.parse(adaptiveCardsParserMaxVersion, new SerializationContext()) : undefined;
61
+ const card = new AdaptiveCard();
62
+ const texts = [];
63
+ card.parse(content, new SerializationContext(maxVersion !== null && maxVersion !== void 0 && maxVersion.isValid ? maxVersion : undefined));
64
+ const getFactText = (factSet, text) => {
65
+ const textBlock = new TextBlock(text);
66
+ textBlock.setParent(factSet);
67
+ return getRenderedText(textBlock, AdaptiveCard, renderMarkdownAsHTML);
68
+ };
69
+ const walk = element => {
70
+ if (!(element !== null && element !== void 0 && element.isVisible)) {
71
+ return;
72
+ }
73
+ if (element instanceof TextBlock || element instanceof RichTextBlock) {
74
+ texts.push(getRenderedText(element, AdaptiveCard, renderMarkdownAsHTML));
75
+ } else if (element instanceof FactSet) {
76
+ element.facts.forEach(_ref => {
77
+ let name = _ref.name,
78
+ value = _ref.value;
79
+ texts.push([name, value].map(text => text ? getFactText(element, text) : "").filter(Boolean).join(": "));
80
+ });
81
+ } else if (element instanceof Image) {
82
+ texts.push(element.altText);
83
+ }
84
+ if (element.getItemAt && element.getItemCount) {
85
+ for (let index = 0, count = element.getItemCount(); index < count; index++) {
86
+ walk(element.getItemAt(index));
87
+ }
88
+ }
89
+ };
90
+ walk(card);
91
+ return texts.filter(text => typeof text === "string" && text).join(" ").replace(/\s+/g, " ").trim();
92
+ };
93
+ const AdaptiveCardForScreenReader = _ref2 => {
94
+ let args = _ref2.args,
95
+ next = _ref2.next,
96
+ renderMarkdownAsHTML = _ref2.renderMarkdownAsHTML;
97
+ const _useAdaptiveCardsPack = useAdaptiveCardsPackage(),
98
+ _useAdaptiveCardsPack2 = _slicedToArray(_useAdaptiveCardsPack, 1),
99
+ adaptiveCardsPackage = _useAdaptiveCardsPack2[0];
100
+ const _useStyleOptions = useStyleOptions(),
101
+ _useStyleOptions2 = _slicedToArray(_useStyleOptions, 1),
102
+ adaptiveCardsParserMaxVersion = _useStyleOptions2[0].adaptiveCardsParserMaxVersion;
103
+ const _args = _slicedToArray(args, 1),
104
+ options = _args[0];
105
+ const attachment = options.attachment;
106
+
107
+ // The widget creates a new Markdown renderer on each render with the same settings, so the text is computed once for each attachment.
108
+ const contentWithSpeak = useMemo(() => {
109
+ try {
110
+ const content = typeof attachment.content === "string" ? JSON.parse(attachment.content) : attachment.content;
111
+ if (!content || typeof content !== "object" || content.speak) {
112
+ return undefined;
113
+ }
114
+ const speak = getAdaptiveCardSpeak(content, adaptiveCardsPackage, renderMarkdownAsHTML, adaptiveCardsParserMaxVersion);
115
+ return speak ? {
116
+ ...content,
117
+ speak
118
+ } : undefined;
119
+ } catch {
120
+ return undefined;
121
+ }
122
+ }, [adaptiveCardsPackage, adaptiveCardsParserMaxVersion, attachment]);
123
+ const render = contentWithSpeak ? next({
124
+ ...options,
125
+ attachment: {
126
+ ...attachment,
127
+ content: contentWithSpeak
128
+ }
129
+ }, ...args.slice(1)) : next(...args);
130
+ return typeof render === "function" ? render() : null;
131
+ };
132
+ export const createAttachmentForScreenReaderMiddleware = renderMarkdownAsHTML => {
133
+ const attachmentForScreenReaderMiddleware = () => next => function () {
134
+ var _args$;
135
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
136
+ args[_key] = arguments[_key];
137
+ }
138
+ const attachment = (_args$ = args[0]) === null || _args$ === void 0 ? void 0 : _args$.attachment;
139
+
140
+ // Web Chat renders nothing for a card without content, so it is left to Web Chat.
141
+ if ((attachment === null || attachment === void 0 ? void 0 : attachment.contentType) !== ADAPTIVE_CARD_CONTENT_TYPE || !attachment.content) {
142
+ return next(...args);
143
+ }
144
+
145
+ // eslint-disable-next-line react/display-name
146
+ return () => /*#__PURE__*/React.createElement(AdaptiveCardForScreenReader, {
147
+ args: args,
148
+ next: next,
149
+ renderMarkdownAsHTML: renderMarkdownAsHTML
150
+ });
151
+ };
152
+ return attachmentForScreenReaderMiddleware;
153
+ };
@@ -88,6 +88,19 @@ const AdaptiveCardAccessibilityWrapper = _ref => {
88
88
  }
89
89
  });
90
90
 
91
+ // action-button-double-read: the adaptivecards renderer writes the action
92
+ // title to the button text, aria-label AND title. The title becomes the
93
+ // accessible description, so TalkBack reads the label twice ("Submit,
94
+ // button, Submit"). Drop the title only when it repeats the button name;
95
+ // a distinct title (an action tooltip) adds information and is kept.
96
+ container.querySelectorAll("button[title]").forEach(btn => {
97
+ const title = (btn.getAttribute("title") || "").trim();
98
+ const name = (btn.getAttribute("aria-label") ?? btn.textContent ?? "").trim();
99
+ if (title && title === name) {
100
+ btn.removeAttribute("title");
101
+ }
102
+ });
103
+
91
104
  // Find all radio inputs inside the adaptive card
92
105
  const radios = container.querySelectorAll("input[type='radio']");
93
106
  if (radios.length === 0) return;
@@ -169,7 +182,8 @@ const AdaptiveCardAccessibilityWrapper = _ref => {
169
182
 
170
183
  // Use MutationObserver to patch after WebChat finishes rendering the card.
171
184
  // Also watch attribute changes on aria-hidden so we can re-apply if React
172
- // reconciliation removes it from labels.
185
+ // reconciliation removes it from labels, and on title so a re-added
186
+ // duplicate button title is removed again.
173
187
  const observer = new MutationObserver(() => {
174
188
  patchRadioGroups();
175
189
  });
@@ -177,7 +191,7 @@ const AdaptiveCardAccessibilityWrapper = _ref => {
177
191
  childList: true,
178
192
  subtree: true,
179
193
  attributes: true,
180
- attributeFilter: ["aria-hidden"]
194
+ attributeFilter: ["aria-hidden", "title"]
181
195
  });
182
196
 
183
197
  // Also run immediately in case the card is already rendered