Using Slack Cleaner to automatically erase messages within Slack

NOTE: In order to use Slack-Cleaner, you do need administrative privileges to your Slack group. Be aware – there’s a bit of coding involved, but nothing that I don’t explain in the instructions below.

You’re probably using the free version of Slack, and need to do some maintanence. Maybe there’s been a troublesome user who you need to remove all of their messages. Or maybe you went bot crazy, and there’s now too many bot messages spamming your channels.

For that, there is Slack Cleaner.

Within Slack Cleaner, the instructions aren’t super clear for a newbie. So the goal of this guide is to provide more details in the how-to,

I’m running Windows – So I’ll explain how to do it via a Windows computer (Windows 10 to be specific). If you’re a Mac, 90% of the content is the same – you’ll just need to find the Mac equivalent. (So instead of ‘How to install PIP for Windows’, Google ‘How to install Pip for Mac’.)

A Steep Learning Curve

If you are super new to this, it may feel completely over your head. But I assure you – once you set it up, you’ll feel like a bon-a-fide hacker. Let this be the first step to your journey to automating your life with scrips.

Additionally, the hurdle is just the set up! Once you are past that hurdle, everything is a lto easier.

Each step requires a separate tutorial, which I’ll link to. The tutorial links I discovered were written for novices, which is why I recommend them.

Getting Started:

The overall process is to install PIP, which allows you to install this Slack Cleaner script. Then, you’ll get your Slack legacy API keys, and run specific commands in CMD or PowerShell.

If that’s a bunch of buzz words – don’t worry. I’ll explain in detail what each bit is.


STEP 1: In order to install PIP, you’ll need to install Python.

Python is a scripting language, and PIP is a package manager. The analog would be if you hired movers, and the mover was German. So you need to learn German, to tell the mover where to put your stuff and set it up correctly.

How to install python 3.7 (Should take 10 minutes):

https://matthewhorne.me/how-to-install-python-and-pip-on-windows-10/


Step 2: After installing Python, your next step is to install PIP.

What is PIP?

PIP is a Package Manager for Python. If you write code using Python (which may contain a folder of a bunch of python code), you’ll want to ‘pack it up’. PIP makes it easier for Python developers.

Using our German metaphor, you now speak German! You want to explain to him how you prefer to unpack your things.

Installing PIP (like 2 minutes)

https://www.liquidweb.com/kb/install-pip-windows/


Step 2.5: Install git

In the comments, @Justin shares that he needed to install Git to get this working.

To install git (for windows) – download the 32-bit or 64-bit “.exe” file here: https://github.com/git-for-windows/git/releases/tag/v2.23.0.windows.1

Note – the screenshot may not match exactly what’s on the site. New versions of Git get released all the time. Just make sure you grab the latest .exe file.


Step 3: You’ve installed Python, as well as PIP. Now install the Slack-Cleaner script.

The readme: https://github.com/sgratzl/slack-cleaner

Open up CMD or PowerEditor (with Admin access).

(1 minute Youtube video: https://www.youtube.com/watch?v=EohzkYPV6nI)

I’ll be referring to the command line as CMD.

While in the CMD and with Admin access, and run this code.

pip install -e git+https://github.com/sgratzl/slack-cleaner.git#egg=slack-cleaner

That should start the installation.


Step 4: You’ve installed Python, PIP, and hopefully Slack-Cleaner.

Now to see if the installation worked!

In the CMD line, type: “slack-cleaner –help”

If you can run this, you’ve installed it correctly.

If it isn’t working… Make sure you followed step 1 correctly (by following that tutorial), and had Python in the environmental variables.


Step 5: If Slack-cleaner works, then it’s time to get your Slack Legacy API.

You can find your Slack Legacy API tokens here: https://api.slack.com/custom-integrations/legacy-tokens

It should look like this… here is mine:

(I’m okay sharing that, since you can only see 30% of the full api token. I challenge anyone to guess the other 70%.)


6) Now write up the command, and run it in your CMD

Running this code It will give you a SIMULATION of everything that will be erased. It won’t actually do it. We’ll do it for real in Step 7.

# Delete all messages from certain user

“slack-cleaner –token <TOKEN> –message –channel gossip –user johndoe”

Replace the <TOKEN> with your token, obviously.


7) Okay now to do it for real.

We’ll add two additional parameters to your line.

Add “–rate=1 –perform”

“rate=1”

means that it’ll take 1 second for each call. If you don’t add it, Slack cuts your access.

“–perform”

means to commit the actual change.

FROM: “slack-cleaner –token <TOKEN> –message –channel gossip –user johndoe”

TO: “slack-cleaner –token <TOKEN> –message –channel gossip –user johndoe –rate=1 –perform”


Alright, that should be the step by step! Leave a note in the comments if it worked, or if there’s a specific step that’s giving you issues. Cheers!

2 Comments

  1. Justin on August 27, 2019 at 5:36 pm

    Hey Rockykev, great tutorial! It really helped me administrating my slack-workspace!
    But in step 3 there is a little mistake: the command “pip install slack-cleaner” installs an older version by kfei (https://github.com/kfei/slack-cleaner) and not the newer version by sgratzl (https://github.com/sgratzl/slack-cleaner). The newer version brings some nice arguments like –info or –keeppinned. I also had to install Git – maybe add this to your manual 🙂

    • rkadmin on August 27, 2019 at 8:16 pm

      Ah good call! Thanks for this. Will update the post! 🙂

Leave a Comment