Skip to content

Private channels not being listed in conversations_list client API call #1312

Closed

Description

@saurabh0719

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) -

    @classmethod
    def get_channels(cls):
        log = logger.bind(event="fetch_all_channels")
        client = WebClient(token=os.environ.get("SLACK_BOT_TOKEN"))
        try:
            response = client.conversations_list(
                types="public_channel,private_channel",
                exclude_archives=True,
                limit=250
            )
        except SlackApiError as e:
            log.error(status="failed_to_fetch_all_channels", exception=e.response["error"])
            return

Expected result:

I expect all public channels and private channels to show up, with the expected total channel count to be 243 in my case
public - 242 and private - 1 (since the bot has been added only to one private channel)

Actual result:

When I use just the public_channel value for types it works just fine. Returning 242 channels. Similarly, when I use private_channel , it works fine, returning 1 channel.

The problem is when I use both together, to list all channels. I've tried the following variations -

  • types="public_channel,private_channel"
  • types=["public_channel,private_channel"

In both cases, the API returns only the public channels, and I get a total of 242 channels only. The private channels that my bot is a part of are not returned in this case.

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

Activity

  1. changed the title [-](Set a clear title describing the issue)[/-] [+]Private channels not being listed in conversations_list client API call[/+] on Dec 9, 2022
  2. seratch commented on Dec 9, 2022

    @seratch
    Contributor

    Hi @saurabh0719, thanks for asking the question!

    Other private channels should be in the next page of the responses (we do understand returning less than 250 channels is a confusing behavior, but the API behaves in the way by design). To learn how to call pagination call using this SDK, please refer to #1159 (comment) for more details.

    I hope this helps.

  3. saurabh0719 commented on Dec 9, 2022

    @saurabh0719
    Author

    @seratch thanks for such a quick response!

    Indeed, it seems to be a pagination issue, and on calling the next_cursor variable, it seemed to give me the remaining channels, which included the private one.

    However, this seems inconsistent since I explicitly specified the limit parameter.

    To give you more context - I'm trying to build a simple search utility, where the bot can list all public channels and private channels it is a part of and allow the user to select the appropriate channel to set up a recurring notification.

    The admin.conversations:search scope is for enterprise customers only, hence I had to build a workaround by fetching the channels and manually searching.

    How do you propose I achieve this without having to repeatedly hit the conversations.list API until there is no more next_cursor? Or to be more specific, is there any consistency I can guarantee, where it will definitely stop at the next page (2nd page in this case, cuz a total of 243 channels were split over 2 pages with the 2nd page holding just 1).

  4. seratch commented on Dec 9, 2022

    @seratch
    Contributor

    @saurabh0719 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.

    If you don't have further to clarify on this topic, would you mind closing this now? It'd be appreciated if you could understand this.

  5. saurabh0719 commented on Dec 9, 2022

    @saurabh0719
    Author

    Thanks @seratch - seems like the only solution for my problem is for the end-user to actually copy the channel_id itself from Slack as there is no feasible/stable way to search for a channel unless you're an enterprise customer.

    Is there any community/mailing list I can follow to get updates as soon as this (Slack's API) is fixed or enhanced? Feel free to close this issue after you've replied to this. Thank you

  6. seratch commented on Dec 9, 2022

    @seratch
    Contributor

    You can subscribe Slack Platform's changelog RSS feed for it: https://api.slack.com/changelog.rss

    Thanks again for taking the time to write in here!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions