-
Notifications
You must be signed in to change notification settings - Fork 833
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
Text not registering with event.get("text") on message sent via datadog app #1587
Comments
Hi @ebruodok, thanks for your question. I haven't checked how the Datadog app works, but one possible reason for your situation might be that the app does not set the top-level "text" property when sending a message via the chat.postMessage API. This means the app might only set "blocks" (the Block Kit message data representation) and skip the top-level "text." Although this request is accepted by the Slack server, we generally recommend including both text and blocks for a better user experience. In the channel UI, only the blocks data is used to display the message, but the text is used for mobile app notifications, accessibility features, and Slack's search engine index. On your end, a feasible workaround is to scan the "blocks" property data to find the text data you're looking for. I'm not sure if this will meet your needs, but I hope it was helpful to you. |
Thank you so much for responding! |
If that's the case, message "subtype" events might be causing the confusion you're experiencing. As shown here: https://api.slack.com/events/message#subtypes, there are several additional patterns of message events. Many of these do not have "text" data at the top level (e.g., message_changed, message_deleted). If your app aims to handle only newly posted messages, it's best to respond only to those patterns. You can check this code to learn how to filter subtype patterns: https://github.com/slackapi/bolt-python/blob/v1.21.2/slack_bolt/app/app.py#L885-L900 If this does not resolve your issue, I'd suggest adding debug logs to print the whole payload your app receives. Also, if the above suggestion resolves the issue, would you mind closing this issue? |
Unfortunately the app I am creating needs to be able to access the text that the Datadog bot is sending in new messages so it can regex match. |
I meant just printing the whole payload data this way: @app.event("message")
def handle_message(payload):
logging.info(payload) With this, you may be able to see variation of event data patterns. If the payload does not have "text" at top level, the payload pattern might be something different than you expect. If a message event really does not have "text" in it, at least "blocks" or "attachments" should exist. If that's the case, you may be able to use these data to respond to the bot message. That said, I still believe message event data usually has "text". Also, if your app does not need to handle subtype events, the following code could be simpler: @app.message("") # matches all newly posted messages
def handle_message(payload):
logging.info(payload) To further assist you on this, sharing the actual message event data (rather than just the existence of "text" / "subtype" property) with us would be appreciated. |
Hi team 👋
I created a slack app via the python sdk for tagging specific people in messages that the Datadog slack app sends to a channel. For context, we receive monitor alerts in a channel as messages sent by the Datadog app, and we have action items for on call engineers. The idea is that the slack app I created would be able to parse through the text of the message and tag people accordingly.
Unfortunately this isn't working, because seemingly there is no text from this message event.
How I attempt to get the text from the Datadog app's message:
Expected result:
I would expect to recognize the text of the message sent by the Datadog app. Logs should look something like this:
Actual result:
Logs show that the app I created is recognizing that an event is sent in a channel, and it correctly identifies the user ID and channel ID. However, it doesn't pick up any text. Logs:
Weirdly, if I copy and paste the same message and send it from my own user id, the app I created works as expected. It only fails on messages sent from the Datadog app agent. Is there a different way I should be getting the text from a message sent from a Slack app?
Requirements
For general questions/issues about Slack API platform or its server-side, could you submit questions at https://my.slack.com/help/requests/new instead. 🙇
Please read the Contributing guidelines and Code of Conduct before creating this issue or pull request. By submitting, you are agreeing to those rules.
The text was updated successfully, but these errors were encountered: