Using the slack-api gem to query Slack Channels and more

require "slack"
require "yaml"

#token = ENV["TOKEN"] || (print "Token: "; gets.strip)
token = "[your Slack token]"
client = Slack::Client.new token: token

# Get users list
puts "Get users list"
users = Hash[client.users_list["members"].map{|m| [m["id"], m["name"]]}]

puts YAML.dump users
puts
puts

# Get channels list
puts "Get channels list"
channels = client.channels_list["channels"]
puts YAML.dump channels
puts
puts

channels.each do |c|
  puts "- id: #{c["id"]}, name: #{c["name"]}"

  # Get channel histry
  messages = client.channels_history(channel: "#{c["id"]}")["messages"]
  messages.each do |message|
    user_name = users[message["user"]]
    text = message["text"].inspect
    puts "  - #{user_name}: #{text}"
  end
end

sleep 1

The above script worked for me, it not only retrieved the list of users in the team, it retrieved all previous messages (including who sent them) from each channel.

Resources