Private channels. slacker.Error: channel_not_found
korniichuk opened this issue · 4 comments
Hi all,
can I use slacker for msg sending to Slack private channel?
https://get.slack.help/hc/en-us/articles/201925108-Understanding-channels-and-DMs
I am use Bots.
My bot is currently in python
private group.
Code:
from slacker import Slacker
slack_token = "xxxx-xxxxxxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxx"
slack_channel = "#python"
slack_msg = "Hello, world!"
slack = Slacker(slack_token)
slack.chat.post_message(slack_channel, slack_msg)
Traceback:
Traceback (most recent call last):
File "./slack.py", line 11, in <module>
slack.chat.post_message(slack_channel, slack_msg)
File "/usr/local/lib/python2.7/dist-packages/slacker/__init__.py", line 287, in post_message
'icon_emoji': icon_emoji
File "/usr/local/lib/python2.7/dist-packages/slacker/__init__.py", line 71, in post
return self._request(requests.post, api, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/slacker/__init__.py", line 63, in _request
raise Error(response.error)
slacker.Error: channel_not_found
Also I tried slack_channel = "python"
.
The code works for public channels (for example: #general
channel).
https://api.slack.com/methods/chat.postMessage#channels
It is works with encoded ID:
slack_channel = "G1U6JA8M8"
This is still broken, and should work with channel name without # as per documentation:
As long as the authenticated user is a member of the private group, you can either pass the group's name (secret-group) or encoded ID (G012AC86C), and the message will be posted to that group. The private group's ID can be retrieved through the groups.list API method.
+1 for fix plz
Hi there. When I was developing Slacker the idea was to replicate Slack API by keeping the same method signature including method names and parameters, so it remains consistent with the Slack API. We just pass given parameters without too much modification. I think the safe bet is to pass channel IDs instead of names as channel name is not supported across all Slack API endpoints.