@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
@@ -24,18 +24,87 @@ var _authHelper = require("./authHelper");
24
24
  var _setPostChatContextAndLoadSurvey = require("./setPostChatContextAndLoadSurvey");
25
25
  var _persistentChatHelper = require("./persistentChatHelper");
26
26
  var _updateSessionDataForTelemetry = require("./updateSessionDataForTelemetry");
27
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
28
- let optionalParams = {};
29
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
30
- let widgetInstanceId;
31
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
32
- let popoutWidgetInstanceId;
27
+ /**
28
+ * Per widget instance mutexes for the two chat creation entry points.
29
+ *
30
+ * Every guard in the prepareStartChat -> setPreChatAndInitiateChat -> initStartChat chain
31
+ * checks `conversationState === Closed`, but React state is updated asynchronously. A second
32
+ * invocation fired within the same render cycle (for example a rapid double click on the chat
33
+ * button, or a chat button click racing a BroadcastEvent.StartChat) therefore still observes
34
+ * the stale `Closed` state, reaches `facadeChatSDK.startChat()` and creates a second
35
+ * conversation on the backend which is then orphaned and never ended.
36
+ *
37
+ * The locks are keyed by FacadeChatSDK instance rather than being module wide, because a host
38
+ * page can mount several independent widgets, each with its own widgetInstanceId and its own
39
+ * FacadeChatSDK (created once per widget in LiveChatWidget.tsx). A module wide lock would make
40
+ * widget A's start chat silently drop widget B's legitimate simultaneous start chat.
41
+ *
42
+ * The two maps are separate because prepareStartChat calls initStartChat; sharing a single lock
43
+ * would make the nested call see its own parent as in flight and drop it. prepareStartChat is
44
+ * additionally blocked by an in flight initStartChat (pre-chat submit, reconnect, or the
45
+ * hideStartChatButton bootstrap call initStartChat directly). Otherwise a later prepareStartChat
46
+ * would dispatch Loading and maximize the widget, and only then have its nested initStartChat
47
+ * dropped.
48
+ */
49
+ const prepareStartChatGuards = new WeakMap();
50
+ const initStartChatGuards = new WeakMap();
51
+
52
+ // Fallback owner used only when no FacadeChatSDK instance is available to key on, so the guard
53
+ // degrades to the module wide behaviour instead of disappearing altogether.
54
+ const unkeyedGuardOwner = {};
55
+ const getGuard = (guards, facadeChatSDK) => {
56
+ const owner = facadeChatSDK ?? unkeyedGuardOwner;
57
+ let guard = guards.get(owner);
58
+ if (!guard) {
59
+ guard = {
60
+ inFlight: false
61
+ };
62
+ guards.set(owner, guard);
63
+ }
64
+ return guard;
65
+ };
66
+
67
+ /**
68
+ * Runs `operation` only if no other invocation for the same widget instance is already in
69
+ * flight. Concurrent invocations are dropped (and reported through telemetry) rather than
70
+ * awaiting the in-flight promise, so a future re-entrant call can never deadlock on itself.
71
+ * A dropped invocation resolves to `undefined`.
72
+ *
73
+ * `blockedBy` lets an operation also yield to a different, already running operation for the
74
+ * same widget instance without claiming that operation's lock.
75
+ */
76
+ const runExclusively = async (guards, facadeChatSDK, description, operation, props, blockedBy) => {
77
+ const guard = getGuard(guards, facadeChatSDK);
78
+ const blockingGuard = blockedBy ? getGuard(blockedBy, facadeChatSDK) : undefined;
79
+ if (guard.inFlight || blockingGuard !== null && blockingGuard !== void 0 && blockingGuard.inFlight) {
80
+ _TelemetryHelper.TelemetryHelper.logActionEvent(_TelemetryConstants.LogLevel.WARN, {
81
+ Event: _TelemetryConstants.TelemetryEvent.ConcurrentStartChatRejected,
82
+ Description: description,
83
+ CustomProperties: {
84
+ WidgetCacheId: props ? (0, _utils.getWidgetCacheIdfromProps)(props) : undefined
85
+ }
86
+ });
87
+ return undefined;
88
+ }
89
+
90
+ // Claim the lock before invoking the operation, so a re-entrant call made from the
91
+ // operation's synchronous preamble (before its first await) cannot slip past the check above.
92
+ guard.inFlight = true;
93
+ try {
94
+ return await operation();
95
+ } finally {
96
+ guard.inFlight = false;
97
+ }
98
+ };
33
99
 
34
100
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
35
101
  const prepareStartChat = async (props, facadeChatSDK, state, dispatch, setAdapter) => {
36
- optionalParams = {}; //Resetting to ensure no stale values
37
- widgetInstanceId = (0, _utils.getWidgetCacheIdfromProps)(props);
102
+ 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);
103
+ };
38
104
 
105
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
106
+ exports.prepareStartChat = prepareStartChat;
107
+ const prepareStartChatInternal = async (props, facadeChatSDK, state, dispatch, setAdapter) => {
39
108
  // reconnect > chat from cache
40
109
  if ((0, _reconnectChatHelper.isReconnectEnabled)(props.chatConfig) === true && !(0, _reconnectChatHelper.isPersistentEnabled)(props.chatConfig)) {
41
110
  const shouldStartChatNormally = await (0, _reconnectChatHelper.handleChatReconnect)(facadeChatSDK, props, dispatch, setAdapter, initStartChat, state);
@@ -63,7 +132,6 @@ const prepareStartChat = async (props, facadeChatSDK, state, dispatch, setAdapte
63
132
  };
64
133
 
65
134
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
66
- exports.prepareStartChat = prepareStartChat;
67
135
  const setPreChatAndInitiateChat = async (facadeChatSDK, dispatch, setAdapter, isProactiveChat, proactiveChatEnablePrechatState, state, props) => {
68
136
  var _props$preChatSurveyP, _props$controlProps, _state$domainStates, _state$appStates2;
69
137
  // Reset before loading prechat to avoid starting chat with previous requestId
@@ -160,9 +228,20 @@ const setPreChatAndInitiateChat = async (facadeChatSDK, dispatch, setAdapter, is
160
228
  await initStartChat(facadeChatSDK, dispatch, setAdapter, state, props, optionalParams);
161
229
  };
162
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
+ */
163
235
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
164
236
  exports.setPreChatAndInitiateChat = setPreChatAndInitiateChat;
165
237
  const initStartChat = async (facadeChatSDK, dispatch, setAdapter, state, props, params, persistedState) => {
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;
240
+ };
241
+
242
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
243
+ exports.initStartChat = initStartChat;
244
+ const initStartChatInternal = async (facadeChatSDK, dispatch, setAdapter, state, props, params, persistedState) => {
166
245
  var _state$domainStates7;
167
246
  let isStartChatSuccessful = false;
168
247
  const persistentChatEnabled = (0, _liveChatConfigUtils.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);
@@ -201,14 +280,15 @@ const initStartChat = async (facadeChatSDK, dispatch, setAdapter, state, props,
201
280
  }
202
281
  try {
203
282
  var _window$Microsoft, _state$domainStates8;
204
- // Set custom context params
205
- await setCustomContextParams(state, props);
283
+ // Set custom context params. Returned (not stored module-side) so that concurrent
284
+ // widget instances cannot overwrite each other's custom context.
285
+ const customContextParams = await setCustomContextParams(state, props);
206
286
  const defaultOptionalParams = {
207
287
  sendDefaultInitContext: true,
208
288
  isProactiveChat: !!(params !== null && params !== void 0 && params.isProactiveChat),
209
289
  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
210
290
  };
211
- const startChatOptionalParams = Object.assign({}, params, optionalParams, defaultOptionalParams);
291
+ const startChatOptionalParams = Object.assign({}, params, customContextParams, defaultOptionalParams);
212
292
 
213
293
  // MID-AUTH: Add wasAuthenticated flag for reconnect scenarios
214
294
  // Tells FacadeChatSDK whether the previous session was authenticated
@@ -271,7 +351,7 @@ const initStartChat = async (facadeChatSDK, dispatch, setAdapter, state, props,
271
351
  (0, _startChatErrorHandler.logWidgetLoadComplete)(_Constants.WidgetLoadTelemetryMessage.PersistedStateRetrievedMessage);
272
352
  // Set post chat context in state, load in background to do not block the load
273
353
  (0, _setPostChatContextAndLoadSurvey.setPostChatContextAndLoadSurvey)(facadeChatSDK, dispatch, true);
274
- return;
354
+ return true;
275
355
  }
276
356
 
277
357
  // Persistent Chat relies on the `reconnectId` retrieved from reconnectablechats API to reconnect upon start chat and not `liveChatContext`
@@ -287,18 +367,17 @@ const initStartChat = async (facadeChatSDK, dispatch, setAdapter, state, props,
287
367
  (0, _startChatErrorHandler.logWidgetLoadComplete)();
288
368
  // Set post chat context in state, load in background to do not block the load
289
369
  (0, _setPostChatContextAndLoadSurvey.setPostChatContextAndLoadSurvey)(facadeChatSDK, dispatch);
290
- // Updating chat session detail for telemetry
291
- await (0, _updateSessionDataForTelemetry.updateTelemetryData)(facadeChatSDK, dispatch);
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;
292
374
  } catch (ex) {
293
375
  (0, _startChatErrorHandler.handleStartChatError)(dispatch, facadeChatSDK, props, ex, isStartChatSuccessful);
294
- } finally {
295
- optionalParams = {};
296
- widgetInstanceId = "";
376
+ return false;
297
377
  }
298
378
  };
299
379
 
300
380
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
301
- exports.initStartChat = initStartChat;
302
381
  const createAdapterAndSubscribe = async (facadeChatSDK, dispatch, setAdapter, startTime, props) => {
303
382
  // New adapter creation
304
383
  const newAdapter = await (0, _createAdapter.createAdapter)(facadeChatSDK, props);
@@ -338,19 +417,22 @@ const canConnectToExistingChat = async (props, facadeChatSDK, state, dispatch, s
338
417
  return false;
339
418
  };
340
419
 
341
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
420
+ /**
421
+ * Resolves the custom context to start the chat with.
422
+ *
423
+ * Returns the resolved params instead of mutating module-level state: a page can host several
424
+ * independent widgets, and once per-instance start-chat guards allow them to run concurrently,
425
+ * shared mutable state would let one widget overwrite another widget's custom context.
426
+ */
342
427
  const setCustomContextParams = async (state, props) => {
343
428
  var _state$domainStates9, _persistedState$domai5;
344
429
  if (state !== null && state !== void 0 && (_state$domainStates9 = state.domainStates) !== null && _state$domainStates9 !== void 0 && _state$domainStates9.customContext) {
345
430
  var _state$domainStates0;
346
- optionalParams = Object.assign({}, optionalParams, {
431
+ return {
347
432
  customContext: JSON.parse(JSON.stringify(state === null || state === void 0 || (_state$domainStates0 = state.domainStates) === null || _state$domainStates0 === void 0 ? void 0 : _state$domainStates0.customContext))
348
- });
349
- return;
350
- }
351
- if ((0, _utils.isNullOrEmptyString)(widgetInstanceId)) {
352
- widgetInstanceId = (0, _utils.getWidgetCacheIdfromProps)(props);
433
+ };
353
434
  }
435
+ const widgetInstanceId = props ? (0, _utils.getWidgetCacheIdfromProps)(props) : "";
354
436
  // Add custom context only for unauthenticated chat
355
437
  const persistedState = (0, _utils.getStateFromCache)(widgetInstanceId);
356
438
  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);
@@ -359,23 +441,23 @@ const setCustomContextParams = async (state, props) => {
359
441
  Event: _TelemetryConstants.TelemetryEvent.SettingCustomContext,
360
442
  Description: "Setting custom context for unauthenticated chat"
361
443
  });
362
- optionalParams = Object.assign({}, optionalParams, {
444
+ return {
363
445
  customContext: JSON.parse(JSON.stringify(customContextLocal))
364
- });
365
- } else {
366
- const customContextFromParent = await getInitContextParamsForPopout();
367
- if (!(0, _utils.isUndefinedOrEmpty)(customContextFromParent === null || customContextFromParent === void 0 ? void 0 : customContextFromParent.contextVariables)) {
368
- optionalParams = Object.assign({}, optionalParams, {
369
- customContext: JSON.parse(JSON.stringify(customContextFromParent.contextVariables))
370
- });
371
- }
446
+ };
447
+ }
448
+ const customContextFromParent = await getInitContextParamsForPopout();
449
+ if (!(0, _utils.isUndefinedOrEmpty)(customContextFromParent === null || customContextFromParent === void 0 ? void 0 : customContextFromParent.contextVariables)) {
450
+ return {
451
+ customContext: JSON.parse(JSON.stringify(customContextFromParent.contextVariables))
452
+ };
372
453
  }
454
+ return {};
373
455
  };
374
456
  const canStartPopoutChat = async props => {
375
457
  if (props.allowSdkChatSupport === false) {
376
458
  return false;
377
459
  }
378
- popoutWidgetInstanceId = (0, _utils.getWidgetCacheIdfromProps)(props, true);
460
+ const popoutWidgetInstanceId = (0, _utils.getWidgetCacheIdfromProps)(props, true);
379
461
  if (!(0, _utils.isNullOrEmptyString)(popoutWidgetInstanceId)) {
380
462
  var _persistedState$domai6, _persistedState$appSt3;
381
463
  const persistedState = (0, _utils.getStateFromCache)(popoutWidgetInstanceId);
@@ -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
- // load it concurrently, this will reduce the load time
16
- await Promise.all([updateSessionDataForTelemetry(facadeChatSDK, dispatch), updateConversationDataForTelemetry(facadeChatSDK, dispatch)]);
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
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
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 updateSessionDataForTelemetry = async (facadeChatSDK, dispatch) => {
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,
@@ -60,6 +60,7 @@ var _useChatAdapterStore3 = _interopRequireDefault(require("../../../hooks/useCh
60
60
  var _useChatContextStore3 = _interopRequireDefault(require("../../../hooks/useChatContextStore"));
61
61
  var _useFacadeChatSDKStore = _interopRequireDefault(require("../../../hooks/useFacadeChatSDKStore"));
62
62
  var _renderSurveyHelpers = require("../common/renderSurveyHelpers");
63
+ var _recoveryEligibilityTelemetry = require("../common/recoveryEligibilityTelemetry");
63
64
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
64
65
  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); }
65
66
  function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
@@ -157,24 +158,11 @@ const LiveChatWidgetStateful = props => {
157
158
  activeCachedChatExist = false;
158
159
  optionalParams = {};
159
160
  }
161
+ (0, _recoveryEligibilityTelemetry.logRecoveryEligibilityTelemetry)(state, activeCachedChatExist);
160
162
  };
161
163
 
162
164
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
163
165
  const startChat = async (props, localState) => {
164
- const isReconnectTriggered = async () => {
165
- if ((0, _reconnectChatHelper.isReconnectEnabled)(props.chatConfig) === true && !(0, _reconnectChatHelper.isPersistentEnabled)(props.chatConfig)) {
166
- const noValidReconnectId = await (0, _reconnectChatHelper.handleChatReconnect)(facadeChatSDK, props, dispatch, setAdapter, _startChat.initStartChat, state);
167
- const inMemoryState = (0, _createReducer.executeReducer)(state, {
168
- type: _LiveChatWidgetActionType.LiveChatWidgetActionType.GET_IN_MEMORY_STATE,
169
- payload: null
170
- });
171
- // If chat reconnect has kicked in chat state will become Active or Reconnect. So just exit, else go next
172
- if (!noValidReconnectId && (inMemoryState.appStates.conversationState === _ConversationState.ConversationState.Active || inMemoryState.appStates.conversationState === _ConversationState.ConversationState.ReconnectChat)) {
173
- return true;
174
- }
175
- }
176
- return false;
177
- };
178
166
  let isChatValid = false;
179
167
  //Start a chat from cache/reconnectid
180
168
  if (activeCachedChatExist === true) {
@@ -186,7 +174,7 @@ const LiveChatWidgetStateful = props => {
186
174
  //Check if conversation state is not in wrapup or closed state
187
175
  isChatValid = await (0, _startChat.checkIfConversationStillValid)(facadeChatSDK, dispatch, state);
188
176
  if (isChatValid === true) {
189
- const reconnectTriggered = await isReconnectTriggered();
177
+ const reconnectTriggered = await (0, _reconnectChatHelper.isReconnectTriggered)(facadeChatSDK, props, dispatch, setAdapter, _startChat.initStartChat, state);
190
178
  if (!reconnectTriggered) {
191
179
  await (0, _startChat.initStartChat)(facadeChatSDK, dispatch, setAdapter, state, props, optionalParams);
192
180
  }
@@ -202,7 +190,7 @@ const LiveChatWidgetStateful = props => {
202
190
  if (isChatValid === false) {
203
191
  if (localState) {
204
192
  // adding the reconnect logic for the case when customer tries to reconnect from a new browser or InPrivate browser
205
- const reconnectTriggered = await isReconnectTriggered();
193
+ const reconnectTriggered = await (0, _reconnectChatHelper.isReconnectTriggered)(facadeChatSDK, props, dispatch, setAdapter, _startChat.initStartChat, state);
206
194
  if (!reconnectTriggered) {
207
195
  const inMemoryState = (0, _createReducer.executeReducer)(state, {
208
196
  type: _LiveChatWidgetActionType.LiveChatWidgetActionType.GET_IN_MEMORY_STATE,
@@ -998,7 +986,9 @@ const LiveChatWidgetStateful = props => {
998
986
  const endChatRelay = (adapter, skipEndChatSDK, skipCloseChat, postMessageToOtherTab) => (0, _endChat.endChat)(props, facadeChatSDK, state, dispatch, setAdapter, setWebChatStyles, adapter, skipEndChatSDK, skipCloseChat, postMessageToOtherTab);
999
987
  const prepareStartChatRelay = () => (0, _startChat.prepareStartChat)(props, facadeChatSDK, state, dispatch, setAdapter);
1000
988
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
1001
- const initStartChatRelay = (optionalParams, persistedState) => (0, _startChat.initStartChat)(facadeChatSDK, dispatch, setAdapter, state, props, optionalParams, persistedState);
989
+ const initStartChatRelay = async (optionalParams, persistedState) => {
990
+ await (0, _startChat.initStartChat)(facadeChatSDK, dispatch, setAdapter, state, props, optionalParams, persistedState);
991
+ };
1002
992
  const confirmationPaneProps = (0, _initConfirmationPropsComposer.initConfirmationPropsComposer)(props);
1003
993
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
1004
994
  const prepareEndChatRelay = () => (0, _endChat.prepareEndChat)(props, facadeChatSDK, state, dispatch, setAdapter, setWebChatStyles, adapter);
@@ -1172,18 +1162,18 @@ const LiveChatWidgetStateful = props => {
1172
1162
  .webchat__auto-resize-textarea.webchat__send-box-text-box__text-area {
1173
1163
  min-height: ${sendBoxTextArea === null || sendBoxTextArea === void 0 ? void 0 : sendBoxTextArea.minHeight} !important;
1174
1164
  }`}
1175
- `), /*#__PURE__*/_react2.default.createElement(_DraggableChatWidget.default, chatWidgetDraggableConfig, /*#__PURE__*/_react2.default.createElement(Composer, _extends({}, webChatProps, {
1176
- userID: userID,
1177
- styleOptions: styleOptions,
1178
- directLine: directLine
1179
- }), /*#__PURE__*/_react2.default.createElement(_react.Stack, {
1165
+ `), /*#__PURE__*/_react2.default.createElement(_DraggableChatWidget.default, chatWidgetDraggableConfig, /*#__PURE__*/_react2.default.createElement(_react.Stack, {
1180
1166
  id: widgetElementId,
1181
1167
  styles: generalStyles,
1182
1168
  className: (_livechatProps$styleP = livechatProps.styleProps) === null || _livechatProps$styleP === void 0 ? void 0 : _livechatProps$styleP.className,
1183
1169
  role: isWidgetOpen ? "dialog" : undefined,
1184
1170
  "aria-modal": isWidgetOpen ? true : undefined,
1185
1171
  "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
1186
- }, !((_livechatProps$contro = livechatProps.controlProps) !== null && _livechatProps$contro !== void 0 && _livechatProps$contro.hideChatButton) && !((_livechatProps$contro2 = livechatProps.controlProps) !== null && _livechatProps$contro2 !== void 0 && _livechatProps$contro2.hideStartChatButton) && (0, _componentController.shouldShowChatButton)(state) && ((0, _omnichannelChatComponents.decodeComponentString)((_livechatProps$compon = livechatProps.componentOverrides) === null || _livechatProps$compon === void 0 ? void 0 : _livechatProps$compon.chatButton) || /*#__PURE__*/_react2.default.createElement(_ChatButtonStateful.default, {
1172
+ }, /*#__PURE__*/_react2.default.createElement(Composer, _extends({}, webChatProps, {
1173
+ userID: userID,
1174
+ styleOptions: styleOptions,
1175
+ directLine: directLine
1176
+ }), !((_livechatProps$contro = livechatProps.controlProps) !== null && _livechatProps$contro !== void 0 && _livechatProps$contro.hideChatButton) && !((_livechatProps$contro2 = livechatProps.controlProps) !== null && _livechatProps$contro2 !== void 0 && _livechatProps$contro2.hideStartChatButton) && (0, _componentController.shouldShowChatButton)(state) && ((0, _omnichannelChatComponents.decodeComponentString)((_livechatProps$compon = livechatProps.componentOverrides) === null || _livechatProps$compon === void 0 ? void 0 : _livechatProps$compon.chatButton) || /*#__PURE__*/_react2.default.createElement(_ChatButtonStateful.default, {
1187
1177
  buttonProps: livechatProps.chatButtonProps,
1188
1178
  outOfOfficeButtonProps: livechatProps.outOfOfficeChatButtonProps,
1189
1179
  startChat: prepareStartChatRelay
@@ -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) ?? "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;
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 successfully.",
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