Correct approach to DM many users using Web API

风格不统一 提交于 2019-12-10 22:17:18

问题


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!


回答1:


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




回答2:


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.



来源:https://stackoverflow.com/questions/50354288/correct-approach-to-dm-many-users-using-web-api

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