Using an App to Invite a User to a Private Slack Group Through the API

This is a smaller piece of a larger program, but to zero in on this specific issue, I've been having quite a bit of trouble recently setting up a program in python using the slackclient module that can invite a user to a private channel (called groups in the API). The program has 2 tokens, one for the bot and one for the actual app.

My issue is that while I can invite the bot to the private channel it should be inviting people to, bots can't have the required scopes to do so. If I switch over to the app token which does have those scopes, it can't complete the operation because apps can't be invited to a channel.

The documentations for this API Call can be found here.

This is the invite command I'm using:

SlackClient(slack_token).api_call("groups.invite", channel='GXXXXXXXX', user='UXXXXXXXX')

While the bot can access the channel information, attempting to invite someone with the bot returns this error:

'error': 'missing_scope', 'provided': 'identify,bot:basic', 'ok': False, 'needed': 'groups:write'

Switching to the app token returns this error:

'error': 'channel_not_found', 'ok': False

Am I missing something here? Or is it intentional that apps not be allowed to invite users to private channels at all?

1 answer

  • answered 2018-03-13 22:14 Erik Kalkoken

    The reason this does not work is as follows:

    • Using the bot token you get your first error. groups.invite does not work with the bot token in general. so you need to use the user token for this API method.
    • When using the user token you get the 2nd error, because the user that installed your Slack app is apparently not a member of that private group. So he can not invite another user to it