Skip to content

Tweaking logic for warning when using conversation APIs that are missing accessibility parameters#1479

Merged
srajiang merged 1 commit intomainfrom
fallback-args-warn
May 5, 2022
Merged

Tweaking logic for warning when using conversation APIs that are missing accessibility parameters#1479
srajiang merged 1 commit intomainfrom
fallback-args-warn

Conversation

@filmaj
Copy link
Copy Markdown
Contributor

@filmaj filmaj commented May 4, 2022

It is recommended to always provide a top-level text parameter for use in screen readers, etc. There is also a legacy fallback field at the attachment level.

This PR tweaks the logic slightly when displaying warnings to the user related to requests missing these fields. It also makes clear that text is the recommended field to always use.

This PR fixes #1476.

…ing accessibility parameters like `text` or `fallback`, updating the warnings posted to make clear `text` is recommended and `fallback` is legacy. Fixes #1476
@filmaj filmaj added enhancement M-T: A feature request for new functionality pkg:web-api applies to `@slack/web-api` labels May 4, 2022
@filmaj filmaj added this to the web-api@6.7.2 milestone May 4, 2022
@filmaj filmaj requested review from seratch and srajiang May 4, 2022 16:35
@filmaj filmaj self-assigned this May 4, 2022

const missingAttachmentFallbackDetected = (args: WebAPICallOptions) => Array.isArray(args.attachments) &&
args.attachments.some((attachment) => !attachment.fallback || attachment.fallback.trim() === 0);
args.attachments.some((attachment) => !attachment.fallback || attachment.fallback.trim() === '');
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

trim() returns the new string contents, and JS is funky and weird so actually '' == 0 is true but '' === 0 is false. So we can either turn the strict equality operator into just a regular equality operator and this would work - but I feel like that operation does not clearly convey what we are testing, so I opted for this slight change.

logger.warn(buildWarningMessage('fallback'));
} else {
logger.warn(buildWarningMessage('text'));
const buildMissingFallbackWarning = () => `Additionally, the attachment-level \`fallback\` argument is missing in the request payload for a ${method} call - ` +
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could just as easily turn these two build*Warning methods into a simple string - if a reviewer has a preference, let me know, happy to change it.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having these two warning messages look better than the current one to me 👍

@filmaj
Copy link
Copy Markdown
Contributor Author

filmaj commented May 4, 2022

To other reviewers: let me know what you think of this approach. If approved, I will copy the same approach over to the python and java SDKs.

Copy link
Copy Markdown
Contributor

@seratch seratch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@filmaj If you have the bandwidth, can you apply the same (or similar) changes to Python and Java SDKs?

logger.warn(buildWarningMessage('fallback'));
} else {
logger.warn(buildWarningMessage('text'));
const buildMissingFallbackWarning = () => `Additionally, the attachment-level \`fallback\` argument is missing in the request payload for a ${method} call - ` +
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having these two warning messages look better than the current one to me 👍

@seratch
Copy link
Copy Markdown
Contributor

seratch commented May 5, 2022

@srajiang If you don't have any concerns on this PR, approve and merge this PR in your business hours tomorrow.

@srajiang srajiang merged commit e2585a8 into main May 5, 2022
@filmaj
Copy link
Copy Markdown
Contributor Author

filmaj commented May 5, 2022

@seratch yes, will work on this now!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement M-T: A feature request for new functionality pkg:web-api applies to `@slack/web-api`

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fallback argument missing: confusing error text

3 participants