Search code examples
node.jspokerslack-api

Private message Slack user via RTM


Has anyone figured out how to private message a user via Slack RTM? I'm trying to create a game and would like to PM a user in Slack to provide updates and such.

You can see how far I am via the coffee script in src/poker.coffee in https://github.com/robksawyer/hubot-poker.

Feel free to fork and finish. ;)

And please let me know if I'm way off track and if this isn't possible at all.


Solution

  • From the docs

    You can send a message to a private group or direct message channel in the same way, but using a Group ID (C024BE91L) or DM channel ID (D024BE91L).

    So you just need to specify the recipient @username or id of the DM D1234BLah as the value for channel when sending the message to the RTM API e.g.

    {
        "id": 1,
        "type": "message",
        "channel": "@jeff",
        "text": "hello jeff"
    }
    

    Full RTM docs here: https://api.slack.com/rtm