Python-slack-sdk: Post ephemeral results in channel_not_found in direct messages

Created on 25 Jun 2020  路  9Comments  路  Source: slackapi/python-slack-sdk

Description

Hello, this may be a very beginner question but I'm finding it quite confusing and the documentation is not helping out. Whenever my bot receives a slash command from a direct message channel I get a payload like this:

{
  "token": [
    "redacted"
  ],
  "team_id": [
    "redacted"
  ],
  "team_domain": [
    "redacted"
  ],
  "channel_id": [
    "DV0AAAAAA"
  ],
  "channel_name": [
    "directmessage"
  ],
  "user_id": [
    "UV0AAAAAA"
  ],
  "user_name": [
    "redacted"
  ],
  "command": [
    "/command"
  ],
  "text": [
    "help"
  ],
  "response_url": [
    "redacted"
  ],
  "trigger_id": [
    "redacted"
  ]
}

And if I try to use postEphemeral like the following:

slack_client.chat_postEphemeral(
        channel="DV0AAAAA",
        user="UV0AAAAA",
        ...
    )

I get a channel_not_found message, what am I missing here?

What type of issue is this? (place an x in one of the [ ])

  • [ ] bug
  • [ ] enhancement (feature request)
  • [x] question
  • [ ] documentation related
  • [ ] testing related
  • [ ] discussion

Requirements (place an x in each of the [ ])

  • [x] I've read and understood the Contributing guidelines and have done my best effort to follow them.
  • [x] I've read and agree to the Code of Conduct.
  • [x] I've searched for any related issues and avoided creating a duplicate issue.

Reproducible in:

slackclient version: 2.5.0

python version: 3.8.2

OS version(s): Ubuntu 18.04

Steps to reproduce:

As described above.

2x question web-client

All 9 comments

I do understand the error code channel_not_found is a bit developer-unfriendly. When you encounter the error, there are mainly two possibilities.

  • The channel ID is really invalid or deleted
  • The channel ID is correct but your app doesn't have the permission to access the conversation

I guess your situation is the second one. If an end-user invokes your slash command in a DM with someone (another user, another app's bot user) or a private channel, your bot user is unable to access the conversation. It's even unable to know whether the channel exists. That's why the error code is "not found".

A suggested way to respond to such command invocations is to utilize the response_url in a payload. With the webhook URL, you can post a reply without knowing anything about the conversation. Refer to https://api.slack.com/interactivity/handling#message_responses for details.

馃憢 Let me know if you need anything further here. Please allow me to close this issue after waiting for your response for a few weeks.

Thanks for your answer and sorry for not getting back earlier. I guess this point could be clarified in the documents if possible.

Is there something similar scheme for view submissions? For instance, if as a response to my command I post an ephemeral message with buttons, these buttons trigger modals and when the user completes the tasks on those modals I want to post another ephemeral message to confirm the actions. It seems that the payload from a view submission does not contain a response_url so does that mean I can't post to that channel?

@sennav Sorry for my late reply here. You can use the combination ofresponse_url_enabled and default_to_current_conversation in an input block for it. https://api.slack.com/surfaces/modals/using#modal_response_url

@sennav Let me know if you need anything further here. Please allow me to close this issue after waiting for your response for a few days.

@seratch I hit a similar issue today and because I am using the Sanic framework and I need to initialize a seperate asynchronous http client to send my block kit payload to the response_url.

Is it possible to make another method in the SDK to support the response urls?

We are a enterprise grid customer and this has been a pain point for us when developing slackbots.

@samhaque

Is it possible to make another method in the SDK to support the response urls?

You can use WebhookClient / AsyncWebhookClient in the latest version - 2.8.0. Please try AsyncWebhookClient out in your Sanic apps! As a response_url is a short-lived special webhook, you can use this utility for it. The following test code may be helpful for learning how to use it.
https://github.com/slackapi/python-slackclient/blob/v2.8.0/tests/webhook/test_async_webhook.py

@seratch looks good, but I was hoping for more of a reusable client that I can initialize in the Sanic 'before_server_start' listener and specify all of our company proxy and SSL certificates, and just share this asynchronous client instance passing it a different wehook url each time.

Let me know your thoughts.

That makes sense. But I'm not planning to add webhook supports to WebClient as it's a bit confusing. I'd like to explore ways to support your use cases by adding a "reusable" webhook client.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

avinassh picture avinassh  路  3Comments

tinoargentino picture tinoargentino  路  4Comments

kompotkot picture kompotkot  路  4Comments

divyatman picture divyatman  路  4Comments

vv-grinko picture vv-grinko  路  3Comments