How do you DM an arbitrary user?
See original GitHub issueHi. I read all docs, all issues, and still have no luck. Something is still wrong.
I cannot post something direct to someone. This code:
def say_to_slack(channel, text, attachments=None):
url = u'https://hooks.slack.com/services/T4xxxx/B4xxx/duzzzzzz'
headers = {u'Content-type': u'application/json'}
data = {'text': text,
"channel": channel,
"link_names": 1,
"username": "bot_name",
"icon_url": "https://avata...ab_72.png",
"attachments": attachments
}
return requests.post(url, data=json.dumps(data), headers=headers)
Posts anything to a channel, but when I try to post to someone, it “sort of” works, but the message gets delivered through Slack’s Slackbot, not from my bot. So, looks odd from the receiver perspective.
I tryed too directly on CLI:
client.rtm_send_message(client.find_channel_by_name('channel_x'),'test')
It works for a channel.
client.rtm_send_message(client.find_user_by_name('user_x'),'test')
Nothing happens on Slack. And I got no error back. I dont even know if this is allowed.
Do I need to set up some missing permission for direct messages? Am I using the wrong code? Since the bot is running on a loop, I imagined just getting the running client (but there is client object to get on the default examples), and call a send method.
Any advice?
Issue Analytics
- State:
- Created 6 years ago
- Comments:6 (1 by maintainers)
Top GitHub Comments
Slack DMs are weird. Replying to a DM is simple, but starting a new DM is a pain. You have to establish a DM channel. See https://api.slack.com/methods/im.open.
Note that DM channels start with D and while they’re often similar to user IDs, that’s not guaranteed. Also, as mentioned, the DM has to be “open” before you can send to it. This is already the case if a user DMed a bot, but if a bot needs to DM a random user, it will need to use the im.open method.
This PR will allow you to directly message the sender of a message: https://github.com/lins05/slackbot/pull/161