You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The user with email `steph@curry.com` should be invited to channels `foo`, `bar`, and `baz`!
24
26
27
+
_* 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`_
28
+
25
29
## Implementation
26
30
Initially, I figured this script would be a simple loop that invoked some API to invite a user to a channel. It turns out this API endpoint ([`conversations.invite`](https://api.slack.com/methods/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).
27
31
28
32
For these reasons, I wrote the script like so:
29
33
1.[Look up](https://api.slack.com/methods/users.lookupByEmail) the Slack user ID by email.
30
-
2.[Query](https://api.slack.com/methods/conversations.list) all public channels in the workspace and create a name -> ID mapping.
34
+
2.[Query](https://api.slack.com/methods/conversations.list) all public (or private) channels in the workspace and create a name -> ID mapping.
31
35
3. For each of the given channels, [invite](https://api.slack.com/methods/conversations.invite) the user to the channel using the user ID and channel ID from steps 1 & 2.
0 commit comments