Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

slack bot scope missing while making api request

I have made a slack app in which I have a bot. I have selected channels:history, channels:read, channels:write under my permission scope, and also I have passed scopes

"scope":"bot channel:history channel:read channel:write"

while doing my oauth2 verification (using python), and I got a response where the scope is

"scope":"identify,bot,channels:history,channels:read,channels:write"

along with client and bot access tokens.

Now when I do an api call to fetch history of a channel in which my bot is invited to, I get

{ 
  ok: false,
  error: 'missing_scope',
  needed: 'channels:history',
  provided: 'identify,bot:basic' 
}

Can someone please tell me where I am going wrong. How can I PROVIDE the channels:history scope in my api call. This is really driving me nuts. Should I be using the client access token, ie xoxp-xxxx, instead of bot token, ie xoxb-xxxx ?'

Thanks!

like image 806
saf1 Avatar asked May 18 '17 13:05

saf1


People also ask

How do I add a scope to Slack API?

You can select the scopes to add to your app by heading over to the OAuth & Permissions sidebar. Scroll down to the Scopes section and click to Add an OAuth Scope. For example, try adding the chat:write scope to your Bot Token. It'll allow your app to post messages!

What is the request scope for write access to the API while using OAuth?

OAuth 2.0 scopes provide a way to limit the amount of access that is granted to an access token. For example, an access token issued to a client app may be granted READ and WRITE access to protected resources, or just READ access. You can implement your APIs to enforce any scope or combination of scopes you wish.

How do I make a Slack API call?

There are two ways for your app to integrate with Slack so that users can initiate and deal with Calls within Slack. One way for a user to initiate your app is via a Slash command—for example, by typing /mycallapp into the message composer. The other way for a user to initiate your app is directly via the Call icon.

How do you get a Slack bot access token?

Visit the App Directory at my.slack.com/apps/manage on your desktop. Click Edit configuration next to the integration. On the configuration page, click Regenerate below the current token. This is the new token that you can use anywhere you need it.


2 Answers

For people having this problem in the future;

your integrated bot has full access to the slack api, whereas a bot in a slack app don't, as it will used publicly. When you successfully finish oauth2, you should get 2 tokens, user access token and bot token. The user token is used to read history from any channel/groups, and the bot access token is used to write to them. This means you constantly have to be switching from user token to bot access token in your app.

enter image description here

Also, remember that bot-user MUST be a member of a private channel which you want him to connect to.

Hope that helps.

Ps, if any found a better way going about this, feel free to answer below.

like image 163
saf1 Avatar answered Sep 29 '22 00:09

saf1


Since you did not mention it: You also need to specify all required scopes on the admin page for your Slack app under "Oauth & Permission Scopes".

like image 28
Erik Kalkoken Avatar answered Sep 28 '22 23:09

Erik Kalkoken