Slack bot permission to delete a message

10,124

In order to be able to delete message from other users by your bot you need the following:

  1. Your Slack app needs to be installed by an admin
  2. 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.

Share:
10,124
duality_
Author by

duality_

Updated on June 25, 2022

Comments

  • duality_
    duality_ almost 2 years

    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?

  • duality_
    duality_ over 6 years
    So I created a Slack App here: https://api.slack.com/apps/. I've added a bot here https://api.slack.com/apps/[app-id]/bots. Is this what I was supposed to do? When I go to my Apps here https://[company].slack.com/apps/manage, I don't see my app to be able to add it. What now?
  • Erik Kalkoken
    Erik Kalkoken over 6 years
    Technically this is a new question :-) But yes, first 2 steps are correct. Then you need to install it to your workspace. Adding from "Manage Apps" only works for public apps, but you can go to https://api.slack.com/apps/[app-id]/install-on-team to install your internal Slack app directly. See also documentation here