-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Expand file tree
/
Copy pathisPresentational.ts
More file actions
31 lines (26 loc) · 1.12 KB
/
isPresentational.ts
File metadata and controls
31 lines (26 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import type { WebChatActivity } from '../types/WebChatActivity';
/**
* Determines if the rendering activity is presentational or not.
* Returns `true` if the activity is presentational and should not be read by screen reader, otherwise, `false`.
*
* @returns {boolean} `true` if the activity is presentational and should not be read by screen reader, otherwise, `false`.
*/
export default function isPresentational(activity: WebChatActivity): boolean {
if (activity.type !== 'message') {
return true;
}
const { channelData } = activity;
// "Fallback text" includes both message text and narratives for attachments.
// Emptying out "fallback text" essentially mute for both message and attachments.
const fallbackText = channelData?.['webchat:fallback-text'];
if (typeof fallbackText === 'string') {
return !fallbackText;
}
// If there are "displayText" (MessageBack), "text", any attachments, or suggested actions, there are something to narrate.
return !(
channelData?.messageBack?.displayText ||
activity.text ||
activity.attachments?.length ||
activity.suggestedActions?.actions?.length
);
}