Search code examples
javascriptnode.jsslackslack-api

Slack API not returning private channels


I'm trying to obtain a list of private channels in Slack (on a per-user basis is fine), but I'm having trouble seeing this information. I installed my application into the workspace in Slack originally and got an OAuth token in the form xoxp-4............

App OAuth token

When I try to use the slack API (node SDK) then I only get the publicly listed channels.

await new WebClient(`xoxp-4.....`)
    .conversations       
    .list({ exclude_archived: true })
).channels

I get the same if I try using the Slack API tester to grab a channel list.

User OAuth token
I've followed the OAuth 2.0 process to obtain a token for a given user (myself). I think I've done all this correctly (here's a response):

{
        ok: true,
        access_token: 'xoxp-4.........',
        scope: 'identify,bot,commands,channels:history,groups:history,im:history,mpim:history,channels:read,emoji:read,groups:read,im:read,search:read,team:read,users:read,users:read.email,usergroups:read,users.profile:read,chat:write:user,chat:write:bot,links:read',
        user_id: 'UD......',
        team_name: '............',
        team_id: '.......',
        scopes: ['identify',
            'bot',
            'commands',
            'channels:history',
            'groups:history',
            'im:history',
            'mpim:history',
            'channels:read',
            'emoji:read',
            'groups:read',
            'im:read',
            'search:read',
            'team:read',
            'users:read',
            'users:read.email',
            'usergroups:read',
            'users.profile:read',
            'chat:write:user',
            'chat:write:bot',
            'links:read'
        ]
    }

Interestingly I discovered this provides me with exactly the same OAuth token if I goto the application management (I assume because it was me who installed the app to the workspace).

Obviously, because it's the same token, I don't get permissions to see the private channels still, even though as far as I'm aware I should be able to do everything I can do as a user?

Can anyone point me to what I might be missing?


Solution

  • The reason why you do not get the private channels is that you are not requesting them.

    The conversations.list method will return public channels by default only. To also get private channels you need set the parameter types accordingly. e.g. types = public_channel,private_channel.

    Similar with calling channels.list. Channels.list will only return public channels. If you want to get the private channels you need to call groups.list. (note that private channels are called groups in the API for historical reasons).

    In general I would recommend using conversations.list, which is more powerful and the recommended approach to get all types of conversations.