Created
January 28, 2017 01:47
-
-
Save ZenCocoon/e7815604ef5e5732bc28601f6117cd15 to your computer and use it in GitHub Desktop.
Invite a Slack user to every non archived channels and groups
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "slack-ruby-client" | |
token = ... | |
user_name = ... | |
Slack.configure do |config| | |
config.token = token | |
end | |
client = Slack::Web::Client.new | |
client.auth_test | |
user_id = client.users_list.members.find { |m| m.name == user_name }.id | |
channels = client.channels_list(exclude_archived: true).channels | |
channels_without_user = channels.select { |c| !c.members.include?(user_id) } | |
channels_without_user.each do |c| | |
client.channels_invite({ channel: c.id, user: user_id }) | |
end | |
groups = client.groups_list(exclude_archived: true).groups | |
groups = groups.select{|g| g.is_mpim == false } | |
groups_without_user = groups.select { |g| !g.members.include?(user_id) } | |
groups_without_user.each do |g| | |
client.groups_invite({ channel: g.id, user: user_id }) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment