slack-ruby / slack-ruby-client

A Ruby and command-line client for the Slack Web, Real Time Messaging and Event APIs.
MIT License
1.19k stars 214 forks source link

Broken behavior in `RealTime::Client#users` in 2.0.0 #460

Closed DannyBen closed 1 year ago

DannyBen commented 1 year ago

I am trying to find out what is the new way of doing things that used to work in 1.1.0 but not working in 2.x.

These methods:

no longer work for me in 2.0. I am guessing it has something to do with Slack::RealTime::Client#start_async?

Reproduction:

require 'bundler/inline'

gemfile do
  # gem 'slack-ruby-client', '1.1.0'  # WORKS
  gem 'slack-ruby-client', '2.0.0'  # BREAKS
  gem 'async-websocket', '~> 0.8.0'
end

token = ENV['SLACK_API_TOKEN']
raise 'Please set SLACK_API_TOKEN' unless token

Slack.configure { |c| c.token = token }

client = Slack::RealTime::Client.new
client.start_async # in order to have channels and users list
p client.users
dblock commented 1 year ago

I think you're looking for https://github.com/slack-ruby/slack-ruby-client/blob/master/UPGRADING.md#realtime-stores. Swap the store for https://github.com/slack-ruby/slack-ruby-client#slackrealtimestoresstore, do you get everything you need back?

DannyBen commented 1 year ago

do you get everything you need back?

Yes! (probably...)

Adding this helped:

Slack::RealTime::Client.configure do |config|
  config.store_class = Slack::RealTime::Stores::Store
  config.store_options = { caches: :all }
end

I am still getting empty hashes for bots, private_channels and public_channels - but this is probably a visibility issue for my token. Users list returns properly.

Thank you.

dblock commented 1 year ago

@DannyBen beware of how long these APIs take to return. If you have a large team this may be problematic. Curious how you use this?

DannyBen commented 1 year ago

Thanks for engaging.

I am using it in my slacktail gem - which just shows every message posted in the terminal.

I will probably also add this extension, to bring back channels:

class Slack::RealTime::Client
  def channels
    @channels ||= public_channels.merge(private_channels)
  end
end