mishk0 / slack-bot-api

:rocket: Simple way to control your Slack Bot
MIT License
1.35k stars 176 forks source link

How to post a direct message from Bot to User based on UserID #87

Open sdbarrington opened 7 years ago

sdbarrington commented 7 years ago

Every time I post, they end up in the SlackBot channel... is there a para I'm missing?

ZeroDragon commented 7 years ago

you need to open (re-open) an im channel with the user

const postMessageToUserById = async (userID, message, opts={}) => {
  const { channel: { id: channelID } } = await bot.openIm(userID);
  bot.postMessage(channelID, message, opts)
}