Skip to content

Instantly share code, notes, and snippets.

@ZenCocoon
Created January 28, 2017 01:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ZenCocoon/e7815604ef5e5732bc28601f6117cd15 to your computer and use it in GitHub Desktop.
Save ZenCocoon/e7815604ef5e5732bc28601f6117cd15 to your computer and use it in GitHub Desktop.
Invite a Slack user to every non archived channels and groups
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