I'm creating a Slack application where, in a workspace with thousands of users, I want to DM a subset of these (hundreds) who share no specific channel.
I don't see any "batch" method in the Web API, so I was wondering which would be the best approach to achieve this. Should I just loop over the recipients list and DM one by one? What would be the rate limiting implications?
thanks in advance!
There's no batch methods available - you'll have to send each individual user a DM. You may possibly run into a rate limit with chat.postMessage
, but it's pretty generous, according to the documentation: https://api.slack.com/methods/chat.postMessage#rate_limiting
Depending on your use case you have multiple options.
A. Sending same message to many users
If you want to send the same message to all user (like an announcement) the easiest is to send that message to a public channel and start your message with <!everyone>
.
Alternatively you can use <!subteam>
to send the same message to a user group (only on paid tier Slack).
Or make sure all users are in the same channel and then use `' to address all users in that channel.
B. Sending individual messages to many users
There is indeed no "batch" API method for sending messages to multiple users, so you have to create your own batch logic. The rate limit is 1 message per second per workspace (see here for reference).
Depending on the amount of users you want to make sure your batch can run for a longer period of time without running into any timeouts, e.g. by using a queue for storing the message and a worker process for sending them one by one.