Git Product home page Git Product logo

slack-cleaner's Introduction

slack-cleaner

Bulk delete messages and files on Slack.

Install

Install from Pip:

pip install slack-cleaner

If you prefer Docker, there is a pre-built Docker image as well:

docker pull kfei/slack-cleaner

Usage

# Delete all messages from a channel
slack-cleaner --token <TOKEN> --message --channel general --user "*"

# Delete all messages from a private group
slack-cleaner --token <TOKEN> --message --group hr --user "*"

# Delete all messages from a direct message channel
slack-cleaner --token <TOKEN> --message --direct sherry --user johndoe

# Delete all messages from a multiparty direct message channel. Note that the
# list of usernames must contains yourself
slack-cleaner --token <TOKEN> --message --mpdirect sherry,james,johndoe --user "*" 

# Delete all messages from certain user
slack-cleaner --token <TOKEN> --message --channel gossip --user johndoe

# Delete all messages from bots (especially flooding CI updates)
slack-cleaner --token <TOKEN> --message --channel auto-build --bot

# Delete all messages older than 2015/09/19
slack-cleaner --token <TOKEN> --message --channel general --user "*" --before 20150919

# Delete all files
slack-cleaner --token <TOKEN> --file --user "*"

# Delete all files from certain user
slack-cleaner --token <TOKEN> --file --user johndoe

# Delete all snippets and images
slack-cleaner --token <TOKEN> --file --types snippets,images

# Always have a look at help message
slack-cleaner --help

Tips

After the task, a backup file slack-cleaner.<timestamp>.log will be created in current directory if --log is supplied.

If any API problem occurred, try --rate=<delay-in-seconds> to reduce the API call rate (which by default is unlimited).

If you see the following warning from urllib3, consider to install missing packages: pip install --upgrade requests[security] or just upgrade your Python to 2.7.9.

InsecurePlatformWarning: A true SSLContext object is not available.
          This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail.
          For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.

Credits

To all the people who can only afford a free plan. ๐Ÿ˜ข

slack-cleaner's People

Contributors

grantholly avatar jamessa avatar jomasti avatar kfei avatar renshuki avatar thebestmensch avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

slack-cleaner's Issues

Always show 0 messages to delete or can't find.

I'm trying "slack-cleaner --token "xoxp-XXX" --message --channel "geraldotest"" and it's only listing 0 messages, no matter what....

Also tryed:
slack-cleaner --token "xoxp-XXX" --message --direct user1--user me_user2
I get:
Running slack-cleaner v0.3.0
Channel, direct message or private group not found

Any hint on what might be happening? Any way that I can see debugging info?
Thank you.

Docker example?

Could you add an example of how to clean messages with the docker container?

Direct messages not properly listed

Using this command:
slack-cleaner --token <TOKEN> --message --direct sherry --user johndoe

Only 6 messages were listed for deletion. This DM channel however contains 10 visible DMs when viewed in Slack. Using --perform only deleted the 6 listed messages and left the 4 remaining others.

The deleted messages were neither the most recent nor the oldest, they were in the middle.

Re-runing the same command still leaves the 4 remaining messages intact, with output 0 message(s) will be cleaned..

windows user

Hi, how can use this tool on windows 10 ? Thanks

slacker.Error message

Installed slack-cleaner via pip without an issue. Goal is to remove all files in the account, however when running the command I get the following feedback:

$ sudo slack-cleaner --token SECRET --file --user "*" --rate=1
Running slack-cleaner v0.3.0
Traceback (most recent call last):
  File "/usr/local/bin/slack-cleaner", line 7, in <module>
    from slack_cleaner.cli import main
  File "/Library/Python/2.7/site-packages/slack_cleaner/cli.py", line 61, in <module>
    init_user_dict()
  File "/Library/Python/2.7/site-packages/slack_cleaner/cli.py", line 52, in init_user_dict
    res = slack.users.list().body
  File "/Library/Python/2.7/site-packages/slacker/__init__.py", line 164, in list
    return self.get('users.list', params={'presence': int(presence)})
  File "/Library/Python/2.7/site-packages/slacker/__init__.py", line 90, in get
    api, **kwargs
  File "/Library/Python/2.7/site-packages/slacker/__init__.py", line 72, in _request
    raise Error(response.error)
slacker.Error: invalid_auth

failed to delete

The cleaner works fine for a while but after about 50 messages I'm getting a "failed to delete" error:

[93m Failed to delete -> [0m]

followed by information on the message but not the issue. It happens with all the commands, and I've tried tried uninstalling and re-installing older versions, I can't see what the issue is. I even got a colleague to install and try it on their machine from fresh but the same error is occurring, can anyone help?

Getting "Failed to delete ->" on a lot of images...

Getting this on A LOT of files.... I ran the following:

slack-cleaner --token xxxxxxxxxxxxxxx --file --types snippets,images

Failed to delete ->
{   'channels': ['CAEABN55M'],
    'comments_count': 0,
    'created': 1529417675,
    'display_as_bot': False,
    'editable': False,
    'external_type': '',
    'filetype': 'jpg',
    'groups': [],
    'id': 'FB9JWMTL1',
    'image_exif_rotation': 1,
    'ims': [],
    'is_external': False,
    'is_public': True,
    'mimetype': 'image/jpeg',
    'mode': 'hosted',
    'name': 'Image uploaded from iOS.jpg',
    'original_h': 5079,
    'original_w': 3726,
    'permalink': 'https://dfspowerhour.slack.com/files/U7Y8BL5G9/FB9JWMTL1/image_uploaded_from_ios.jpg',
    'permalink_public': 'https://slack-files.com/T50LX5FEF-FB9JWMTL1-082e15034f',
    'pretty_type': 'JPEG',
    'public_url_shared': False,
    'size': 672210,
    'thumb_1024': 'https://files.slack.com/files-tmb/T50LX5FEF-FB9JWMTL1-f94c9acfef/image_uploaded_from_ios_1024.jpg',
    'thumb_1024_h': 1024,
    'thumb_1024_w': 751,
    'thumb_160': 'https://files.slack.com/files-tmb/T50LX5FEF-FB9JWMTL1-f94c9acfef/image_uploaded_from_ios_160.jpg',
    'thumb_360': 'https://files.slack.com/files-tmb/T50LX5FEF-FB9JWMTL1-f94c9acfef/image_uploaded_from_ios_360.jpg',
    'thumb_360_h': 360,
    'thumb_360_w': 264,
    'thumb_480': 'https://files.slack.com/files-tmb/T50LX5FEF-FB9JWMTL1-f94c9acfef/image_uploaded_from_ios_480.jpg',
    'thumb_480_h': 480,
    'thumb_480_w': 352,
    'thumb_64': 'https://files.slack.com/files-tmb/T50LX5FEF-FB9JWMTL1-f94c9acfef/image_uploaded_from_ios_64.jpg',
    'thumb_720': 'https://files.slack.com/files-tmb/T50LX5FEF-FB9JWMTL1-f94c9acfef/image_uploaded_from_ios_720.jpg',
    'thumb_720_h': 720,
    'thumb_720_w': 528,
    'thumb_80': 'https://files.slack.com/files-tmb/T50LX5FEF-FB9JWMTL1-f94c9acfef/image_uploaded_from_ios_80.jpg',
    'thumb_800': 'https://files.slack.com/files-tmb/T50LX5FEF-FB9JWMTL1-f94c9acfef/image_uploaded_from_ios_800.jpg',
    'thumb_800_h': 1090,
    'thumb_800_w': 800,
    'thumb_960': 'https://files.slack.com/files-tmb/T50LX5FEF-FB9JWMTL1-f94c9acfef/image_uploaded_from_ios_960.jpg',
    'thumb_960_h': 960,
    'thumb_960_w': 704,
    'timestamp': 1529417675,
    'title': 'Slack for iOS Upload',
    'url_private': 'https://files.slack.com/files-pri/T50LX5FEF-FB9JWMTL1/image_uploaded_from_ios.jpg',
    'url_private_download': 'https://files.slack.com/files-pri/T50LX5FEF-FB9JWMTL1/download/image_uploaded_from_ios.jpg',
    'user': 'U7Y8BL5G9',
    'username': ''}

No More Messages SyntaxError?

I'm trying to clean up our general channel and I'm always receiving a syntax error. I'm running Python 3.4 on Windows.

File "C:\Python34\lib\site-packages\slack_cleaner\cli.py", line 92
print 'No more messsages'
^
SyntaxError: Missing parentheses in call to 'print'

How to get slack to allow authorization?

New to Slack apps. Created an app on slack to get a token. Turned on assorted permissions but when I run the slack-cleaner I ultimately get a stack trace and 'slacker.Error: invalid_auth'.

It would be helpful if the readme had a short description of what to do on the Slack side of config.

slack-cleaner not recognizing older messages that Slack has hidden

On the mobile app, I see more messages that weren't deleted, those that are filtered on desktop, with the note "There's more to this conversation. to see and search this conversation's full history, upgrade to one of our paid plans." A bulk of our messages are in this section that Slack is trying to hide to incentivize us to pay. Is there a way to pull these via API? Does this have to do with the permission scope?

Question about Token

Hi there, what type of token should I use for the app? Under custom integrations I see Bots, but that doesn't seem to work. Is there another way of getting a token?

Request: Delete messages older than X

I'm sure there is a way to do this with a variable...but I am too dumb. Would be a great feature to have built in!

Example: Delete messages older than one week, 3 days etc.

Cleaning with --bot argument is deleting posts by users

Thanks for this very useful program, it was an extremely pleasing experience watching all of slackbots old reminder messages disappear!

I've encountered an issue trying to clean up bot posts in public channels, the syntax:
slack-cleaner --token TOKEN --channel test --message --bot --perform
cleans posts by users as well as bots (almost as if I hadn't used the --bot argument).

For example, in an empty test channel I posted two "asdasd" messages and ran the cleaner using the aforementioned synatx and got the following result:
22-03-2016 1-46-12 pm

Both my messages get deleted and I'm pretty sure I'm not a bot. Any ideas as to what I'm doing wrong?

list of required scopes?

Can someone let me know what scopes are required to delete a message from a #general channel? I keep getting slacker.Error: missing_scope messages. Kinda strange this isn't in the README.

Can't delete private messages sent by bot

Hi kfei!

Many thanks for your program, it's really useful, great work ;)

I'm trying to delete all the direct messages that my bot has sent to me (the messages appear in my slackbot's direct messages field), but I can't make it work. This are list of commands that I have tried:

With my personal token:

  • slack-cleaner --token= --message --channel auto-build --bot
  • slack-cleaner --token= --message --direct

With the bot's personal token:

  • slack-cleaner --token= --message --channel auto-build --bot
  • slack-cleaner --token= --message --direct
  • slack-cleaner --token= --message --direct slackbot

Do you know what command should I use? I'm a little bit lost...

Many thanks for your help! Best regards,

Aitor

Failed to delete

I have a slack channel populated by and incoming webhook bot. I want to clear the channel, I have paid account maybe I can do this within admin? I use this command and just get loads of failed to delete messages, any help would be great!

This is the command I use
slack-cleaner --token=###mytoken --message --channel my-channel --bot --perform --log --rate 1

Change rate arg type from int to float

Changing to float will allow 0.25 / 0.5 / etc. to be specified, which can help prevent the rate limiting errors, but also still perform more operations.

p.s. Thanks for the tool. Very helpful!

How can i clean the deactivated user's msg ?

Dear

I found some deactivated user and want to delete the msg from this user.
after ai execute
slack-cleaner --token --message --direct deactivateduser --user "*" --perform
i can only delete my msg
and shows

Failed to delete ->
{ u'text': u'\u4e5f\u53ea\u6709\u522a\u6389\u5e7e\u5f35\u800c\u5df2\u5566',
u'ts': u'1446101041.000003',
u'type': u'message',
u'user': u'U07BQB98U'}

It's any possible to delete this user's all msg?

thanks.

Document TOKEN must be user (invalid_scope)

I had an existing token I tried to with slack-cleaner; it failed with a cryptic invalid_scope error. Eventually I found documentation that certain APIs only work with user tokens (ones that start wtih xoxp and not bot tokens xoxb).

A quick note on the documentation might save others some trouble.

Silence the delete message?

I don't see a flag that will prevent terminal from showing the message content that is being deleted. I am using this to clean-up our messages and avoid that 12k message from slack. But I don't want to see the content of people's messages. Anyway to do like -silence?

Channel, direct message or private group not found

When trying to erase all messages from a private channel, but get this result:

Channel, direct message or private group not found

I used:
slack-cleaner --token TOKEN --message --group name_of_channel --before 20181101

I also used it:
slack-cleaner --token TOKEN --message --channel name_of_channel --before 20181101

I don't think it works with a Private Channel.
Can anyone tell me?

Thank's.

Disable logs

Hi,
You did a great job with this library. Thank you.
A nice feature would be to use argument --no-log to skip logging ;)

"Failed to create process"

Install on Python 3.5. When entering "slack-cleaner" into the command line (with or without a command), the response is "failed to create process".

Windows 7, ConEmu, running the process as admin. Any thoughts?

migrate project

Hi,

I like this project, however it seems to be dead. Therefore, I forked it (actually cloned) and cleaned it up.

--> https://github.com/sgratzl/slack-cleaner

changes

  • integrated all open PR of this repository
  • unify and format code
  • auto build of Docker image -> https://hub.docker.com/r/sgratzl/slack-cleaner/
  • actually show the error message why the deletion couldn't be done
  • consider rate also in case of errors while deletion
  • regex support for channel, group, direct, mpdirect

if you have further suggestions, please post issues, prs, ...

Delete message a certain BOT?

Your application is great!
It works like a charm.
I have a special case
I use some different BOT in a channel. How can I delete messages of certain BOT?
Again, thank you very much

Channel, direct message or private group not found

When trying to erase all messages from a user we get this result:

Channel, direct message or private group not found

We used:

slack-cleaner --token [TOKEN] --message --channel gossip --user [USER] --perform

Any ideas?

Unable to clean direct messages

Thanks for this tool - it's been great. However, my direct messages are building, and I can't easily clean them.

I have tried multiple variations on the following:
slack-cleaner --token --message --direct
using the token for the . I've tried adding --user (both "*" and an actual user) and --rate=1, but always get the same result - "0 message(s) will be cleaned."

Any idea what I might be doing wrong?

btw, I'd love to be able to use "*" (or similar) as the param to --direct, as I need to script through all my users one-by-one :-/

Thanks much!

jeremy.

Channel, direct message or private group not found/User ID?

I'm running
slack-cleaner --token xx-xxx-xxx --message --direct U000000 --user U000001 --before 2018-08-01
user U000000 is my user ID (copied from slack, under user "userID") and the U000001 person I have direct message with, this channel definitely exists but I'm getting direct message not found. Am I using the wrong userID? ie. should I use their email, not sure because there is no username on my slack channel ie "johndoe" the format is "john doe" and is a first/last name string

slacker.Error: missing_scope

Get this error running:

slack-cleaner --token --file --user "*"

Using the slack-cleaner installed from pip.

Tried adding all scopes to my app and reinstalling app.

syntax error near unexpected token `('

I've pulled from docker but I'm not sure whether I'm running it correctly. This is what I'm trying...

'C:\Users\me> docker run kfei/slack-cleaner slack-cleaner --token "xoxp-#####" --message --channel general --user "*"`

And this is the error I get:

import: unable to open X server `' @ error/import.c/ImportImageCommand/364.
import: unable to open X server `' @ error/import.c/ImportImageCommand/364.
/usr/local/bin/slack-cleaner: line 7: from: command not found
/usr/local/bin/slack-cleaner: slack-cleaner: line 10: syntax error near unexpected token `('
/usr/local/bin/slack-cleaner: slack-cleaner: line 10: `    sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])'

Any guidance would be greatly appreciated. I generated the token from https://api.slack.com/docs/oauth-test-tokens

slackbot problem

Display name: slackbot, member ID: USLACKBOT
slack-cleaner --token=[token] --file --user uslackbot
slack-cleaner --token=[token] --file --user slackbot
slack-cleaner --token=[token] --message --direct slackbot --bot
slack-cleaner --token=[token] --message --direct uslackbot --bot

Running slack-cleaner v0.3.0
Traceback (most recent call last):
  File "/usr/local/bin/slack-cleaner", line 11, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.6/site-packages/slack_cleaner/cli.py", line 337, in main
    message_cleaner()
  File "/usr/local/lib/python3.6/site-packages/slack_cleaner/cli.py", line 286, in message_cleaner
    _channel_id = get_direct_id_by_name(args.direct_name)
  File "/usr/local/lib/python3.6/site-packages/slack_cleaner/cli.py", line 244, in get_direct_id_by_name
    _user_id = get_user_id_by_name(name)
  File "/usr/local/lib/python3.6/site-packages/slack_cleaner/cli.py", line 224, in get_user_id_by_name
    for k, v in user_dict.iteritems():
AttributeError: 'dict' object has no attribute 'iteritems'

Python 3 support

File "c:\proj\venvs\xxx\lib\site-packages\slack_cleaner\cli.py", line 98
print 'No more messsages'
^
SyntaxError: Missing parentheses in call to 'print'

Remove messages posted by APPs?

Is there a way to remove messages posted by APPs? They dont seem to be recognized as bots. For eg, removing messages posted by Trello or Bitbucket apps,

Can't install!

Get error

root@localhost:~# pip install slack-cleaner
Traceback (most recent call last):
  File "/usr/bin/pip", line 11, in <module>
    sys.exit(main())
  File "/usr/lib/python2.7/dist-packages/pip/__init__.py", line 215, in main
    locale.setlocale(locale.LC_ALL, '')
  File "/usr/lib/python2.7/locale.py", line 581, in setlocale
    return _setlocale(category, locale)
locale.Error: unsupported locale setting

rate argument only accepts integers

The underlying python time.sleep() method accepts a float, giving you more resolution that 1s. However, the argument was typed as int, so sub-second rates (eg, 0.5 or 0.2) which may be slow enough for the API while still being significantly faster than 1s cannot be utilized.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.