slackapi/python-slack-sdk

All slack channels are not being returned in conversations.list, even after paginating

saurabh0719 opened this issue · 5 comments

The Slack SDK version

slack-sdk==3.19.5

Python runtime version

Python 3.8.13

OS info

Dell Inc. Latitude 5530 - Ubuntu 22.04 - 12th Gen Intel® Core™ i7-1255U × 12

Steps to reproduce:

Initialise Slack web client with the relevant bot token - bot token has access to the following scopes -
channels:join,channels:read,channels:manage,groups:read,chat:write,chat:write.public,chat:write.customize

I use the following code to list public channels and private channels (that the bot has been added to) -

    def get_list_of_channels(self, cursor=None):
        self.log.info(status="fetching_list_of_channels")
        channel_types = "public_channel,private_channel"
        try:
            if cursor:
                response = self.client.conversations_list(
                    cursor=cursor, types=channel_types, exclude_archives=True, limit=999)
            else:
                response = self.client.conversations_list(types=channel_types, exclude_archives=True, limit=999)
        except SlackApiError as e:
            self.log.error(status="failed_to_fetch_list_of_channels", exception=e.response["error"])
            return None
        return response

The above function is in turn wrapped around a recursive function that checks for the next_cursor variable to fetch ALL channels.

Expected result:

I expect all public channels and private channels to show up, with my customer claiming to have over 100+ channels, many of them public.

Actual result:

The API returns just 3 channels (2 of them being general and random if it helps). The next_cursor variable is empty as well, so it shouldn't be a pagination issue. This is weird, because my bot has fetched channels successfully for all other customers.

Looking for any pointers on where I might be going wrong, be it with my scopes or the API call.

Hi @saurabh0719, thanks for writing in.

Based on the information provided, it's challenging for me to pinpoint exactly why your code doesn't work for a specific workspace.

To ensure that you're using a valid OAuth token for your API call, how about doing further tests without the Python SDK? You can utilize the API tester for conversations.list for it. If you encounter the same results using this tester, it's possible that the token in use may lack the necessary permissions to retrieve the channel list. One potential scenario might be if the customer is on Slack's Enterprise Grid and unintentionally has installed your app in a workspace with only 3 active channels. If that's the case, you can ask the customer to install the app into the workspace they want to use your app.

I hope this helps you figure out the cause of your situation.

I think this is an api issue. It is seen here with an issue on scopes: slack-ruby/slack-ruby-client#397 and we are running into the same issues above in our node client just hitting the rest api directly. In our case, the api just completely omits channels, regardless of scope, whenever pagination is set to something that requires a cursor to appear. Setting to 9999 fixes the problem, but isn't ideal.

Hi @saurabh0719, our backend engineering team would like to know more about what's happening with your specific workspace. Since this is a public issue tracker, I am unable to ask you to provide your workspace information here. So, would you mind contacting our customer support team (via either /feedback in your workpace or https://my.slack.com/help/requests/new) to share your app ID (which starts with "A") and your workspace/organization ID (prefixed with "T" or "E")? Our backend engineers will dig deeper with that information.

@runfaj If your issue is exactly the same wih the one described here, could you contact our support team in the same way? If it's an issue specific to a workspace, our backend teams will check data and try to figure the cause out.

@seratch - This isn't an issue for us anymore - it was a customer of ours that was trying to connect their slack account to our product. Turns out they just connected the wrong workspace :) we asked them about this in the start itself, but it took them a while before they realised it was the wrong workspace.

@runfaj I think its an API design issue rather than something to do with scopes, I had a similar issue with the python client - #1312

TLDR; copying @seratch answer from the other thread -

Unfortunately, there is no work around for this as it's due to Slack API server-side behavior. The server-side fetches 250 first and then filters the item with the given filter conditions. Thus, limit=250 means that the endpoint may return 250 at maximum. We know that this is not a common behavior at all, and it can be a surprising behavior (even for me!). We've escalated this issue many times already. However, still there is no plans to change it.

We fixed it by iterating till the last page while syncing slack channels to our product. Hope this is relevant for you. @seratch feel free to close this ticket if there's nothing else.

Thanks for letting us know this, and I am glad to hear that everything is fine for you! Let me close this issue now.