Have you ever googled "slack invite user to multiple channels"
? Yeah, me too. I do this every time a new engineer joins my team, and I inevitably end up inviting said engineer to each Slack channel manually. I got tired of this, so I rolled up my sleeves and whipped up this script.
I assume Slack will eventually add this ability. Until then, hopefully you can save some time by using this.
Enjoy!
channels:write
):
users:read
users:read.email
channels:read
channels:write
groups:read
(only if inviting to private channels)groups:write
(only if inviting to private channels)go install github.com/jamietsao/slack-multi-channel-invite@latest
slack-multi-channel-invite -api_token=<user-oauth-token> -emails=steph@warriors.com,klay@warriors.com -channels=dubnation,splashbrothers,thetown -private=<true|false>
The users with emails steph@warriors.com
and klay@warriors.com
should be invited to channels dubnation
, splashbrothers
, and thetown
!
* Set private
flag to true
if you want to invite users to private channels. As noted above, this will require the additional permission scopes of groups:read
and groups:write
Simply set the optional action
flag to remove
(add
is the default):
slack-multi-channel-invite -api_token=<user-oauth-token> -action=remove -emails=kd@warriors.com -channels=dubnation,warriors -private=<true|false>
Initially, I figured this script would be a simple loop that invoked some API to invite users to a channel. It turns out this API endpoint (conversations.invite
) expects the user ID (instead of username) and channel ID (instead of channel name). Problem is, it's not very straightforward to get user and channel IDs. There isn't a way to lookup a user by username (only by email). And there's no way to look up a single channel, unless you have the channel ID already (chicken and egg).
For these reasons, I wrote the script like so: