Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
May 5, 2022

Conversation

filmaj
Copy link
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
@@ -645,20 +645,24 @@ function warnIfFallbackIsMissing(method: string, logger: Logger, options?: WebAP
const isTargetMethod = targetMethods.includes(method);

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
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
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
Member

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
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
Member

@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
Member

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
Member

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
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