GitHub - tlloydukdev/slack-delete-channel-messages: Node script to delete all me...
source link: https://github.com/tlloydukdev/slack-delete-channel-messages
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Repository files navigation
Delete all messages from a Slack channel
A feature that isn't natively available in Slack (at the time of writing)
Use this script to delete all messages from any slack channel, including #general.
You will need to be a Slack Administrator.
Quick Start
- Clone the repository
- Install dependencies with
npm install
oryarn install
- Copy
.env.example
to.env
- Create a Slack App (see Guide below)
- Run the script and follow the prompts
node index.js
Slack App Setup
To use the script you must create a Slack app that has the required permissions to view and delete messages. The steps are described below.
- Log in to Slack App management
- Click Create New App
- Select From Scratch
- Enter an App Name e.g. Deletor
- Select the workspace to add the App to
- Click Create App
- On the left, click OAuth & Permissions
- Scroll down to Scopes
- Under Bot Token Scopes click Add an OAuth Scope and add
channels:history
,channels:read
andchat:write
in turn - Under User Token Scopes click Add an OAuth Scope and add
chat:write
- Scroll to the top and click Install to Workspace
- Copy the User OAuth Token into the
USER_TOKEN
property in.env
- Copy the Bot User OAuth Token into the
BOT_TOKEN
property in.env
- Go to your Slack client and
/invite @deletor
into the channel you want to remove messages from - Run the script and follow the prompts
node index.js
Rate Limiting
The script allows you to specify a custom rate limit if required. This is particularly useful on channels with a lot of messages. If you decide to use the Slack API defaults, then very quickly the delete attempts will be throttled until it's quite slow. By applying a custom rate limit, you can try and keep under the official rate limit radar. You can select which option to choose when running the script.
Troubleshooting
You're most likely to encounter errors relating to the tokens and scopes, for example cant_delete_message
- double check steps 8-10 in the Slack App Setup above and also make sure you have correctly created your .env
file, it should look like:
BOT_TOKEN=xoxb-222888608336-6599678687984-2Ufo177zpOIg06l1WVvyiiox
USER_TOKEN=xoxp-222888608336-223470001299-6589549747649-f9cb406156c663158de29d07566dfeb4
After Use
I highly recommend you remove the app from your channel and delete the App from the Slack control panel. At the very least, revoke the tokens!
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK