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.