Using the Slack API, how can I direct message all users at the same time?

巧了我就是萌 提交于 2019-12-24 01:17:05

问题


On Slack, I'm aware that using chat.postMessage allows me to message each user individually, but how would I go about direct messaging the entire team (400 members) at once?


回答1:


Hello For that you need a channel with all 400 of them in it, cause currently you cannot send to 400 individual users. For sending message to a channel, you just need to add channel argument for postMessage method.

Check this :: https://api.slack.com/methods/chat.postMessage




回答2:


There is no "bulk" variant of chat.postMessage. So you basically need to build your own bulk message sender, which you can easily do by iterating through the list of users and sending each of them a message.

You can get the list of all users with users.list. You then have two option for sending direct messages:

  1. Slackbot channel: Send each of them a message with chat.postMessage using the ID of each user as channel.
  2. App channel: Get the IM channel ID with im.open for each user and then use that as channel for chat.postMessage. This only works though if you have a bot user and send the message from the bot user.

Keep in mind though, that there is a request limit of 1 message per second.

There also is a 3 seconds request time-out for many requests between Slack and your app. (e.g. for direct response to slash commands). So if your bot needs to send many messages you want to use an approach that allows you to send them asynchronously.

One solution to this problem that works very well for me is to use a messaging queue for all Slack messages sent from my bots.



来源:https://stackoverflow.com/questions/47917744/using-the-slack-api-how-can-i-direct-message-all-users-at-the-same-time

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!