Skip to main content

Slack Cleaner2 is an improved slack cleaner version using a python first approach

Project description

slack_cleaner2

License: MIT Github Actions PyPi Read the Docs

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#egg=slack_cleaner2

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()

Migration Guides form slack-cleaner contains a series of common pattern in slack cleaner and their counterpart in Slack Cleaner2

Token

The slack 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:

  1. going to Your Apps
  2. select 'Create New App', fill out an App Name (eg 'Slack Cleaner') and select the Slack workspace you want to use it in
  3. select 'OAuth & Permissions' in the sidebar
  4. scroll down to User Token Scope and select all scopes you need according to list below
  5. select 'Save changes'
  6. select 'Install App to Workspace'
  7. review the permissions and press 'Authorize'
  8. copy the 'OAuth Access Token' shown, and use as the first argument to SlackCleaner

The token should start with xoxp and not like bot tokens with xoxb.

Beyond granting permissions, if you wish to use this library to delete messages or files posted by others, you will need to be an Owner or Admin of the workspace.

User Token Scopes by Use Case

General channel and user detection

  • users:read
  • channels:read
  • groups:read
  • im:read
  • mpim:read

Deleting messages from public channels

  • users:read
  • channels:read
  • channels:history
  • chat:write

Deleting messages from private channels

  • users:read
  • groups:read
  • groups:history
  • chat:write

Deleting messages from 1:1 IMs

Note: You can only delete your own messages, not the ones of others. This is due to a restriction in the Slack API and there is nothing one can do about it.

  • im:read
  • im:history
  • users:read
  • chat:write

Deleting messages from multi-person IMs

  • mpim:read
  • mpim:history
  • users:read
  • chat:write

Deleting files

  • files:read
  • users:read
  • files:write

All User Token scopes

user token scopes

Docker

There is no direct docker file available, however since it is a python module one can easily create one:

FROM python:3.9-alpine

LABEL maintainer="Samuel Gratzl <sam@sgratzl.com>"

VOLUME "/backup"
WORKDIR /backup

RUN pip --no-cache-dir install slack-cleaner2

CMD ["python", "-"]

An Docker image named slack_cleaner2 with this Dockerfile would be used like

cat myscript.py | docker run -i slack_cleaner2

The myscript.py file is a python script using the slack_cleaner2 module.

Credits

To all the people who can only afford a free plan. :cry:

Development

Release

bumpversion patch
git commit -am 'release vX.X.X'
git tag vX.X.X
invoke release
git push
git push --tags

change version in slack_cleaner2/_info.py

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

slack_cleaner2-3.2.7.tar.gz (24.3 kB view details)

Uploaded Source

Built Distribution

slack_cleaner2-3.2.7-py2.py3-none-any.whl (19.8 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file slack_cleaner2-3.2.7.tar.gz.

File metadata

  • Download URL: slack_cleaner2-3.2.7.tar.gz
  • Upload date:
  • Size: 24.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.7

File hashes

Hashes for slack_cleaner2-3.2.7.tar.gz
Algorithm Hash digest
SHA256 3c84312a12ab36ff2f7beeebeafeb5250973d2f89b93edf120cfe4d79a79a55f
MD5 3deaf50b5c8b6c8fbb96af42a8c5368d
BLAKE2b-256 3d52b6e241fe93d4c0389ef342a55f4108d149b0890e0c16c2d06214b40e8787

See more details on using hashes here.

File details

Details for the file slack_cleaner2-3.2.7-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for slack_cleaner2-3.2.7-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 23684909208454eb5731af1d46c3b335e5de45cb5c5e7e86826c26e030168cd5
MD5 d2802123519b7bc48516544eb95a38dc
BLAKE2b-256 0f90ac6f4d2339962a16568532099eac94ce7c92207b45953615e65c262082bd

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page