问题
I'm writing a bot that will make some channels read-only for most users except for a group of admins. This means the bot needs permission to delete users' messages. When I try to delete a message with the bot, I get a cant_delete_message
back. I understand that I need another token, one that starts with xoxp for that (I already have xoxb).
I've read a bunch of tutorials and docs on this topic, but I think they mostly don't go well with my use-case: I would not like to create and register an app with Slack as this will only be used internally.
How can I get this master token?
回答1:
In order to be able to delete message from other users by your bot you need the following:
- Your Slack app needs to be installed by an admin
- You need to use the user token, not the bot token to call chat.delete
You get the user token during the installing process for your Slack App where you will always receive two tokens: a user token (which is called access token) and a bot token.
Note that you will need a Slack app (that includes a bot user) - it will not work with a custom bot user.
Example from the offical documentation on bot users:
{
"access_token": "xoxp-XXXXXXXX-XXXXXXXX-XXXXX",
"scope": "incoming-webhook,commands,bot",
"team_name": "Team Installing Your Hook",
"team_id": "XXXXXXXXXX",
"incoming_webhook": {
"url": "https://hooks.slack.com/TXXXXX/BXXXXX/XXXXXXXXXX",
"channel": "#channel-it-will-post-to",
"configuration_url": "https://teamname.slack.com/services/BXXXXX"
},
"bot":{
"bot_user_id":"UTTTTTTTTTTR",
"bot_access_token":"xoxb-XXXXXXXXXXXX-TTTTTTTTTTTTTT"
}
}
To verify here is what the official documentation says on the topic:
When used with a typical user token, may only delete messages posted by that user.
When used with an admin user's user token, may delete most messages posted in a workspace.
When used with a bot user's token, may delete only messages posted by that bot user.
来源:https://stackoverflow.com/questions/48370501/slack-bot-permission-to-delete-a-message