• Stars
    star
    224
  • Rank 172,068 (Top 4 %)
  • Language
    Python
  • License
    MIT License
  • Created over 4 years ago
  • Updated 7 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

📝 Python3 module for deleting Slack messages and files using the Slack REST API

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 <[email protected]>"

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. 😢

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

More Repositories

1

slack-cleaner

delete slack messages and files. An improved version is at:
Python
365
star
2

chartjs-chart-geo

Chart.js Choropleth and Bubble Maps
TypeScript
319
star
3

d3tutorial

📊📈 A D3 v7 tutorial - interactive bar chart and multiple coordinated views (MCV)
HTML
246
star
4

chartjs-chart-graph

Chart.js Graph-like Charts (tree, force directed)
TypeScript
156
star
5

chartjs-chart-boxplot

Chart.js Box Plots and Violin Plot Charts
TypeScript
94
star
6

chartjs-chart-wordcloud

Chart.js Word Clouds
TypeScript
91
star
7

cytoscape.js-layers

Cytoscape.js plugin for simplified layers (svg, canvas, html)
TypeScript
52
star
8

chartjs-plugin-hierarchical

Chart.js scale for hierarchical tree-like data structure
TypeScript
47
star
9

chartjs-chart-error-bars

Chart.js Plugin for showing error bars for various chart types
TypeScript
39
star
10

chartjs-chart-pcp

Chart.js Parallel Coordinates Plot
TypeScript
20
star
11

lineup-lite

LineUp-lite is an extension of the excellent react-table library for rendering beautiful interactive table visualizations based on the LineUp ranking visualization technique.
TypeScript
15
star
12

cytoscape.js-overlays

Cytoscape.js plugin for rendering node overlays
TypeScript
15
star
13

chartjs-chart-funnel

Chart.js Funnel chart
TypeScript
9
star
14

developer_webhook_bot

Telegram Bot Experiment for forwarding Webhooks
TypeScript
5
star
15

d3boilerplate

JavaScript
3
star
16

chartjs-chart-graph-dot-parser

Graphviz DOT parser for chartjs-chart-graph
JavaScript
3
star
17

yet_another_rss_bot

Yet Another RSS Bot for Telegram
TypeScript
3
star
18

chartjs-chart-graph-dagre

Chart.js Graph extension using the Dagre layouting library
TypeScript
3
star
19

covid19_demos

Demos repository how @lineupjs and @upsetjs can be used to explore Covid 19 data
Jupyter Notebook
2
star
20

boxplots

A simple boxplot Javascript library with various quantiles options (like R)
TypeScript
2
star
21

vue-chartjs-boxplot

Vue.js Boxplot Chart.js example
Vue
2
star
22

lineup_if_fi

Exploring Items and Features with IF, FI-Tables
JavaScript
2
star
23

ts-library-template

Template Repo based on rollup for yarn 2
JavaScript
2
star
24

ipython-tutorial-VA2015

IPython tutorial given as part of Visual Analytics winter term 2015/2016 at Johannes Kepler University
2
star
25

lineup_remote

LineUp remote data test
JavaScript
1
star
26

yacobo

Yet another COVID-19 Board
TypeScript
1
star
27

oogl

C++
1
star
28

covidcast-env

Jupyter Notebook
1
star
29

dash-tree-checklist

Tree Checklist component for Plotly Dash
TypeScript
1
star
30

chartjs-esm-facade

OUTDATED with beta version of chart.js 3
JavaScript
1
star
31

lineup_propsperity

JavaScript
1
star
32

vega-lite-examples

Advanced Vega Lite Examples
HTML
1
star