question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

The implementation of #1208 is different from the node-slack-sdk version

See original GitHub issue

Original specification in node-slack-sdk https://github.com/slackapi/node-slack-sdk/issues/1476#issuecomment-1116654526

The implementation of the pull request created with reference to the above was different. https://github.com/slackapi/python-slack-sdk/pull/1208

The following condition in node-slack-sdk is different. Even if there is no top-level text, the warning is not displayed if there is a fallback in all attachments. https://github.com/slackapi/node-slack-sdk/blob/bcbe7cc8753a134d73daf88ac66eec0f359c2df7/packages/web-api/src/WebClient.ts#L868

Reproducible in:

The Slack SDK version

slack-sdk==3.19.2

Python runtime version

Python 3.11.0

OS info

ProductName: macOS ProductVersion: 12.6 BuildVersion: 21G115 Darwin Kernel Version 21.6.0: Mon Aug 22 20:17:10 PDT 2022; root:xnu-8020.140.49~2/RELEASE_X86_64

Steps to reproduce:

For example…

from slack_sdk import WebClient
import os

slack_token = os.environ["SLACK_BOT_TOKEN"]
client = WebClient(token=slack_token)

attachments = [
    {
        'fallback': 'title-message-fallback',
        'color': 'red',
        'fields': [
            {
                'title': 'title',
                'value': 'message',
            }]
    }
]

result = client.chat_postMessage(
    channel="C0XXXXXX",
    attachments=attachments,
    as_user=True)

Expected result:

No warnings are displayed.

Actual result:

The following warning is displayed.

UserWarning: The top-level `text` argument is missing in the request payload for a chat.postMessage call - It’s a best practice to always provide a `text` argument when posting a message. The `text` argument is used in places where content cannot be rendered such as: system push notifications, assistive technology such as screen readers, etc.
  warnings.warn(message, UserWarning)

maybe…

the following implementation?

    # if text argument is missing, Warn the user about this.
    # However, do not warn if a fallback field exists for all attachments, since this can be substituted.
    missing_text_message  = (
        f"The top-level `text` argument is missing in the request payload for a {endpoint} call - "
        f"It's a best practice to always provide a `text` argument when posting a message. "
        f"The `text` argument is used in places where content cannot be rendered such as: "
        "system push notifications, assistive technology such as screen readers, etc."
    )

    # https://api.slack.com/reference/messaging/attachments
    # Check if the fallback field exists for all the attachments
    # Not all attachments have a fallback property; warn about this too!
    missing_fallback_message = (
        f"Additionally, the attachment-level `fallback` argument is missing in the request payload for a {endpoint} call"
        f" - To avoid this warning, it is recommended to always provide a top-level `text` argument when posting a"
        f" message. Alternatively you can provide an attachment-level `fallback` argument, though this is now considered"
        f" a legacy field (see https://api.slack.com/reference/messaging/attachments#legacy_fields for more details)."
    )

    # Additionally, specifically for attachments, there is a legacy field available at the attachment level called `fallback`
    # Even with a missing text, one can provide a `fallback` per attachment.
    # More details here: https://api.slack.com/reference/messaging/attachments#legacy_fields
    attachments = kwargs.get("attachments")
    # Note that this method does not verify attachments
    # if the value is already serialized as a single str value.
    if (
        attachments is not None
        and isinstance(attachments, list)
    ):
        if (not all(
                [isinstance(attachment, dict)
                and len(attachment.get("fallback", "").strip()) > 0 for attachment in attachments]
            )
        ):
            warnings.warn(missing_text_message, UserWarning)
            warnings.warn(missing_fallback_message, UserWarning)
    else:
        warnings.warn(missing_text_message, UserWarning)

Issue Analytics

  • State:closed
  • Created 10 months ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
seratchcommented, Nov 18, 2022

@mar3mar3 Thanks for flagging this! The initial implementation across three bolt frameworks were consistent but recently Node SDK code has been improved by https://github.com/slackapi/node-slack-sdk/pull/1529. However, we haven’t updated Python and Java SDKs. If you are fine to use your time more on this, your pull request would be greatly appreciated. Otherwise, I will resolve it quickly later on.

1reaction
e-zimcommented, Nov 17, 2022

Hi @mar3mar3! Thank you for writing this in and sharing your implementation for a fix! This is definitely something we’ll want to patch in a future release. If you’d want to make a PR with your changes, that’d be welcomed! Otherwise, we’ll work on fixing this soon!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Fallback argument missing: confusing error text #1476 - GitHub
Opening a new issue after reading slackapi/bolt-js#1249 which is closed ... The implementation of #1208 is different from the node-slack-sdk ...
Read more >
Changelog - Slack Platform Developer Tools
This SDK is a collection of single-purpose packages. The packages are aimed at making building Slack apps easy, performant, secure, and scalable.
Read more >
Tools built by Slack - Slack API
Slack Developer Tools. Install this application to your workspace to quickly look up documentation, investigate the structure of messages, and more. Slack.
Read more >
Zowe Documentation - Zowe Docs
Onboarding a Node.js based REST API service on page 348 ... The following diagram depicts the difference in locations of Zowe ... combination...
Read more >
Build a Slackbot in Node.js with Slack's Bolt API
You can skip the last step where Slack prompts you to add other team members. Create a new Slack application. Now, we'll create...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found