Chat-integration plugin "Error: unable to fetch users from Slack" when running /post in large (17,000+) slack instance

CaseyG
Wed, 11 Oct 2023 12:11:12 +0000
Bug

Slack threads and chat integration plugin transcripts

I’m getting the error: “Error: unable to fetch users from Slack”

I’m also getting this error! No success in a private or public channel, both of which have the bot added.

Did you ever figure this out?

For what it’s worth, my Slack instance has 17,000+ users, so I am wondering if something is going wrong with the users.list endpoint? I am able to successfully return a very long users.list response via Slack’s API tester, using the same token provided in Discours settings. users.list method | Slack

One theory on what might be going wrong: it looks like Discourse is paginating 200 users at a time, which would require 85+ API calls.

Users.list is a Tier 2 rate limited endpoint:

Web API Tier 2
20+ per minute
Most methods allow at least 20 requests per minute, while allowing for occasional bursts of more requests.

Is it possible that this is a rate limit issue?

github.com/discourse/discourse-chat-integration

lib/discourse_chat_integration/provider/slack/slack_transcript.rb

4f9ccb58c

267. http = ::DiscourseChatIntegration::Provider::SlackProvider.slack_api_http





269. cursor = nil


270. req = Net::HTTP::Post.new(URI("https://slack.com/api/users.list"))





272. users = {}


273. loop do


274.   break if cursor == ""


275.   req.set_form_data(


276.     token: SiteSetting.chat_integration_slack_access_token,


277.     limit: 200,


278.     cursor: cursor,


279.   )


280.   response = http.request(req)


281.   raise UserFetchError.new unless response.kind_of? Net::HTTPSuccess


282.   json = JSON.parse(response.body)


283.   raise UserFetchError.new unless json["ok"]


284.   cursor = json["response_metadata"]["next_cursor"]


285.   json["members"].each do |user|


286.     # Slack uses display_name and falls back to real_name if it is not set


287.     if user["profile"]["display_name"].blank?

I also can’t seem to access any more detailed log info on this, on my discourse hosted instance. But happy to help debug if useful!

2 messaggi - 2 partecipanti