Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Slack DM to a user not in `im.list`

I'm implementing a slack ops bot that will notify users of job completion on a build server. It needs to be able to DM users on job completion.

I've setup a bot user as per the instructions @ https://api.slack.com/bot-users. To send a DM to a particular user, chat.postMessage takes the first argument (channel) as either a @username or a IM channel's ID as per the documentation @ https://api.slack.com/methods/chat.postMessage#channels . To get the IM channel ID of a user, im.list can be used. But im.list only gives the IM channel IDs of the users the bot has previously interacted with (or the user has pinged the bot or the bot and the user are part of any channel).

So it seems the bot cannot DM any user it hasn't previously interacted with. Is my understanding of the bot behavior correct ?

Is there any workaround for this use case ?

like image 559
Irshad Avatar asked Jun 02 '16 17:06

Irshad


1 Answers

I think you're looking for im.open. Pass in a user ID, and you'll get back a channel ID for the direct message conversation with that user.

like image 196
user94559 Avatar answered Oct 30 '22 03:10

user94559