slack-ruby / slack-ruby-client

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

Method Deprecated error when using conversations_history #328

Closed skeletonlander closed 4 years ago

skeletonlander commented 4 years ago

Run this simple program:

# frozen_string_literal: true
require 'slack-ruby-client'

Slack.configure do |config|
  config.token = ENV['SLACK_API_TOKEN']
  raise 'Missing ENV[SLACK_API_TOKEN]!' unless config.token
end

client = Slack::Web::Client.new
client.auth_test

client.conversations_history(channel: '#somechannel')

And it will produce this error:

/usr/bin/bundle exec /usr/bin/ruby /Users/lorenanderson/ruby_slack/test_slack.rb
Traceback (most recent call last):
    17: from /Users/foobar/ruby_slack/test_slack.rb:12:in `<main>'
    16: from /Library/Ruby/Gems/2.6.0/gems/slack-ruby-client-0.14.6/lib/slack/web/api/endpoints/conversations.rb:70:in `conversations_history'
    15: from /Library/Ruby/Gems/2.6.0/gems/slack-ruby-client-0.14.6/lib/slack/web/api/mixins/channels.id.rb:19:in `channels_id'
    14: from /Library/Ruby/Gems/2.6.0/gems/slack-ruby-client-0.14.6/lib/slack/web/api/mixins/ids.id.rb:12:in `id_for'
    13: from /Library/Ruby/Gems/2.6.0/gems/slack-ruby-client-0.14.6/lib/slack/web/api/mixins/channels.id.rb:20:in `block in channels_id'
    12: from /Library/Ruby/Gems/2.6.0/gems/slack-ruby-client-0.14.6/lib/slack/web/api/endpoints/channels.rb:165:in `channels_list'
    11: from /Library/Ruby/Gems/2.6.0/gems/slack-ruby-client-0.14.6/lib/slack/web/faraday/request.rb:11:in `post'
    10: from /Library/Ruby/Gems/2.6.0/gems/slack-ruby-client-0.14.6/lib/slack/web/faraday/request.rb:26:in `request'
     9: from /Library/Ruby/Gems/2.6.0/gems/faraday-1.0.1/lib/faraday/connection.rb:279:in `post'
     8: from /Library/Ruby/Gems/2.6.0/gems/faraday-1.0.1/lib/faraday/connection.rb:492:in `run_request'
     7: from /Library/Ruby/Gems/2.6.0/gems/faraday-1.0.1/lib/faraday/rack_builder.rb:153:in `build_response'
     6: from /Library/Ruby/Gems/2.6.0/gems/faraday-1.0.1/lib/faraday/request/multipart.rb:25:in `call'
     5: from /Library/Ruby/Gems/2.6.0/gems/faraday-1.0.1/lib/faraday/request/url_encoded.rb:25:in `call'
     4: from /Library/Ruby/Gems/2.6.0/gems/faraday-1.0.1/lib/faraday/response.rb:11:in `call'
     3: from /Library/Ruby/Gems/2.6.0/gems/faraday-1.0.1/lib/faraday/response.rb:11:in `call'
     2: from /Library/Ruby/Gems/2.6.0/gems/faraday-1.0.1/lib/faraday/response.rb:65:in `on_complete'
     1: from /Library/Ruby/Gems/2.6.0/gems/faraday-1.0.1/lib/faraday/response.rb:12:in `block in call'
/Library/Ruby/Gems/2.6.0/gems/slack-ruby-client-0.14.6/lib/slack/web/faraday/response/raise_error.rb:16:in `on_complete': method_deprecated (Slack::Web::Api::Errors::SlackError)

The error is being produced by this API helper class:

# frozen_string_literal: true
require_relative 'ids.id'

module Slack
  module Web
    module Api
      module Mixins
        module Channels
          include Ids
          #
          # This method returns a channel ID given a channel name.
          #
          # @option options [channel] :channel
          #   Channel to get ID for, prefixed with #.
          def channels_id(options = {})
            name = options[:channel]
            throw ArgumentError.new('Required arguments :channel missing') if name.nil?

            id_for(:channel, name, '#', :channels, 'channel_not_found') do
              channels_list
            end
          end
        end
      end
    end
  end
end

It appears that the use of channels_list, which is deprecated, causes this failure.

dblock commented 4 years ago

You're right, this needs to be reimplemented using a newer method that replaced it.

dblock commented 4 years ago

Note that this is a client-side facility to resolve names to IDs, the underlying APIs don't support #channel. If you specify actual channel IDs here it won't try to call the deprecated method.

imarquezc commented 4 years ago

@dblock Hi, I'm having the same issue using client.conversations_info(channel: '#general')

client.conversations_info(channel: '#general')
*** Slack::Web::Api::Errors::SlackError Exception: method_deprecated
dblock commented 4 years ago

Someone please PR a fix.