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.

How do you DM an arbitrary user?

See original GitHub issue

Hi. 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:open
  • Created 6 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

5reactions
jtatumcommented, Apr 24, 2017

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.

3reactions
twcurriecommented, Sep 19, 2017

This PR will allow you to directly message the sender of a message: https://github.com/lins05/slackbot/pull/161

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to direct message (DM) on Instagram - YouTube
In this video, you will learn, how to send a direct message to another Instagram user. Follow these steps as shown in this...
Read more >
How to Direct Message (DM) on Twitter - Twitter Help Center
Navigate to your Direct Message inbox. Swipe from left to right on the conversation you want to keep at the top of your...
Read more >
Use Slack Connect to start a DM with someone at another ...
Click Start a DM. Enter the email address for the person you'd like to invite. Click Send Invitation. ; Select DM someone from...
Read more >
Should You Send That DM? Well … - The New York Times
A direct message — DM — is a one-on-one conversation with another user hosted on a social media platform. Most of the places...
Read more >
Any way to send a personal message to another user?
Being able to answer closed questions would be ideal, but some way to direct message the user who asked the question would have...
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