Search code examples
slack-apislack

How to initiate a Direct Message (Private IM) using the Slack API


Using the Slack API (webhooks, RTM, Web, doesn't matter) is it possible to initiate a DM/Private channel with a user where the private IM channel doesn't already exist?

I am aware of the API call https://api.slack.com/methods/im.list which will show me the private IM channels that are already open, however this is an empty list for the bot as no real user will have DM'd the bot.

Basically, we have a list of users who need to be notified of something privately by a bot, and those users will not likely have DM'd the bot before, so the private channel will not yet exist. How can we create that channel using the API?


Solution

  • Well, the fool that I am just needed to RTFM.

    https://api.slack.com/methods/im.open

    This method opens a direct message channel with another member of your Slack team.
    
    Arguments
    
    This method has the URL https://slack.com/api/im.open and follows the Slack Web API calling conventions.