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

后端 未结 2 1923
臣服心动
臣服心动 2020-12-21 08:48

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 mem

相关标签:
2条回答
  • 2020-12-21 09:29

    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.

    0 讨论(0)
  • 2020-12-21 09:40

    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

    0 讨论(0)
提交回复
热议问题