Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Ruby script to check slack reaction counts
require 'slack-ruby-client'
require 'date'
token = [YOUR TOKEN HERE]
Slack.configure do |config|
config.token = token
end
client = Slack::Web::Client.new
messages = []
while messages.empty? || DateTime.strptime(messages.last.ts,'%s') > Date.parse('2017-01-01') do
messages += messages.any? ?
client.channels_history(channel: '#general', count: 500, latest: messages.last.ts).messages :
client.channels_history(channel: '#general', count: 500).messages
puts messages.count
end
reactions = Hash.new(0)
messages.select { |mess| mess.reactions.present? }.each{ |mess| mess.reactions.each { |reaction| reactions[reaction[:name].split('::').first] += reaction[:count] } }
puts reactions.sort { |a, b| b[1] <=> a[1] }.inspect
puts "The End"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.