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 215 forks source link

Rate limiting on chat_update method #376

Closed rohitbordia closed 3 years ago

rohitbordia commented 3 years ago

Hello, We recently upgraded to started using the 0.16.0 version and we are being rate limited when using the chat_update method. Further investigating with the Slack support team we found that even though we are calling the chat_update API method it internally calls the conversations.list method which is throwing HTTPTooManyRequest errors. We contacted the Slack support team and found we made ~150 requests on chat_update method.

Stack trace: /usr/local/bundle/gems/resque-2.0.0/lib/resque/worker.rb:412:in block in unregister_signal_handlers' /usr/local/bundle/gems/slack-ruby-client-0.16.0/lib/slack/web/pagination/cursor.rb:35:insleep' /usr/local/bundle/gems/slack-ruby-client-0.16.0/lib/slack/web/pagination/cursor.rb:35:in rescue in block in each' /usr/local/bundle/gems/slack-ruby-client-0.16.0/lib/slack/web/pagination/cursor.rb:28:inblock in each' /usr/local/bundle/gems/slack-ruby-client-0.16.0/lib/slack/web/pagination/cursor.rb:26:in loop' /usr/local/bundle/gems/slack-ruby-client-0.16.0/lib/slack/web/pagination/cursor.rb:26:ineach' /usr/local/bundle/gems/slack-ruby-client-0.16.0/lib/slack/web/api/endpoints/conversations.rb:173:in conversations_list' /usr/local/bundle/gems/slack-ruby-client-0.16.0/lib/slack/web/api/mixins/ids.id.rb:12:inpublic_send' /usr/local/bundle/gems/slack-ruby-client-0.16.0/lib/slack/web/api/mixins/ids.id.rb:12:in id_for' /usr/local/bundle/gems/slack-ruby-client-0.16.0/lib/slack/web/api/mixins/conversations.id.rb:19:inconversations_id' /usr/local/bundle/gems/slack-ruby-client-0.16.0/lib/slack/web/api/endpoints/chat.rb:282:in `chat_update'

Usage:

slack_client.chat_update( channel: "channel-name", text: "test", ts: "1620689145.394500", attachments: nil, as_user: true )

dblock commented 3 years ago

Slack API doesn't actually support channel-name, so this happens because the client tries to resolve channel-name for you, see https://github.com/slack-ruby/slack-ruby-client#get-channel-info. Replace the channel name with a channel ID to fix this.

dblock commented 3 years ago

The implementation is https://github.com/slack-ruby/slack-ruby-client/blob/master/lib/slack/web/api/mixins/ids.id.rb FYI.