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

fix(1528): better warnings about webclient fallbacks #1529

Merged
merged 2 commits into from
Oct 28, 2022

Conversation

edwmurph
Copy link
Contributor

@edwmurph edwmurph commented Sep 2, 2022

Summary

fixes #1528

this PR updates the warning logic for the conversation api to better match this logic:

If the top-level text does not exist and any of its attachments does not have fallback property, we still should warn it (we can say "You should have either top-level text or fallback in all the attachments" if we want to make it more accurate). If all the attachments have the fallback property, no warnings should be printed.

Requirements

@CLAassistant
Copy link

CLAassistant commented Sep 2, 2022

CLA assistant check
All committers have signed the CLA.

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.

Thanks for taking the time to send this PR! Can you check my comments?

@@ -278,7 +278,7 @@ describe('WebClient', function () {
.map((v) => ({ method, args: Object.assign({}, v, args) }))
return acc.concat(textPatterns)
}, []).forEach(({ method, args }) => {
it(`should send both text and fallback-argument-specific warning to logs when client executes ${method} without text argument(${args.text === "" ? "empty" : args.text}) nor without attachment-level fallback argument (${args.attachments[0].fallback === " " ? "empty" : args.attachments[0].fallback})`, function () {
Copy link
Member

Choose a reason for hiding this comment

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

All the existing tests should behave the same. My intention here is that we should change the behavior only for the pattern with no text + valid fallbacks for all attachments, which is your situation. Can you add a new test pattern to cover your situation?

@@ -714,9 +714,10 @@ function warnIfFallbackIsMissing(method: string, logger: Logger, options?: WebAP
'Alternatively, you can provide an attachment-level `fallback` argument, though this is now considered a legacy field (see https://api.slack.com/reference/messaging/attachments#legacy_fields for more details).';
if (isTargetMethod && typeof options === 'object') {
if (isEmptyText(options)) {
Copy link
Member

Choose a reason for hiding this comment

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

My intention of the new requirement is something like this:

if (missingAttachmentFallbackDetected(options)) {
  if (isEmptyText(options)) {
    logger.warn(buildMissingTextWarning());
  }
  logger.warn(buildMissingFallbackWarning());
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i couldn't use that snippet ^ exactly because i think it broke existing functionality but i just pushed a commit that i think matches your original intention. could you give this another look when you get a chance?

@seratch seratch added enhancement M-T: A feature request for new functionality pkg:web-api applies to `@slack/web-api` labels Sep 5, 2022
@seratch seratch added this to the web-api@6.8.0 milestone Sep 5, 2022
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.

Sorry for my belated response here. Looks great to me 👍

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 always renders even if attachments are included
3 participants