Slack Cleaner2 is an improved slack cleaner version using a python first approach
Project description
slack_cleaner2
Bulk delete messages and files on Slack.
Install
Install from PyPi:
pip install slack-cleaner2
latest version
pip install -e git+https://github.com/sgratzl/slack_cleaner2.git
Usage
In contrast to the original version (https://github.com/kfei/slack-cleaner) this version is a focusing on pure python package that allows for easy scripting instead of a vast amount of different command line arguments.
basic usage
from slack_cleaner2 import *
s = SlackCleaner('SECRET TOKEN')
# list of users
s.users
# list of all kind of channels
s.conversations
# delete all messages in -bots channels
for msg in s.msgs(filter(match('.*-bots'), s.conversations)):
# delete messages, its files, and all its replies (thread)
msg.delete(replies=True, files=True)
# delete all general messages and also iterate over all replies
for msg in s.c.general.msgs(with_replies=True):
msg.delete()
Tokens
You will need to generate a Slack legacy user token to use slack-cleaner. You can generate a token here:
https://api.slack.com/custom-integrations/legacy-tokens.
The token should start with xoxp and not like bot tokens with xoxb.
Permission Scopes needed
The permissions to grant depend on what you are going to use the script for. Grant the permissions below depending on your use.
Beyond granting permissions, if you wish to use this script to delete messages or files posted by others, you will need to be an Owner or Admin of the workspace.
General channel and user detection
channels:read
users:read
users.profile:read
users:read.email
im:read
mpim:read
Deleting messages from public channels
channels:history
channels:read
chat:write:user
users:read
Deleting messages from private channels
groups:history
groups:read
chat:write:user
users:read
Deleting messages from 1:1 IMs
im:history
im:read
chat:write:user
users:read
Deleting messages from multi-person IMs
mpim:history
mpim:read
chat:write:user
users:read
Deleting files
files:read
files:write:user
users:read
Configuring app
The cleaner needs you to give Slack's API permission to let it run the operations it needs. You grant these by registering it as an app in the workspace you want to use it in.
You can grant these permissions to the app by:
- going to Your Apps
- select 'Create New App', fill out an App Name (eg 'Slack Cleaner') and select the Slack workspace you want to use it in
- select 'OAuth & Permissions' in the sidebar
- scroll down to Scopes and select all scopes you need
- select 'Save changes'
- select 'Install App to Workspace'
- review the permissions and press 'Authorize'
- copy the 'OAuth Access Token' shown, and use this token as the
--token
argument to the script
Credits
To all the people who can only afford a free plan. :cry:
Development
Release
python setup.py clean sdist bdist_wheel
twine upload dist/*
change version in slack_cleaner2/_info.py
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for slack_cleaner2-2.2.0-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1b3357cbca1ba7b5eff6e172d2672a7f67994cef2286986b61f1f54c4d60096f |
|
MD5 | e3323f9ce3377ffa9511f6024047578f |
|
BLAKE2b-256 | e32a2ff4f8d63624172e6f3078b15ae72bd4f223b23c79331a3b35b1aa3ac925 |