Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ruanbekker/slack-channel-cleaner
Python Script to Remove Old Slack Messages
https://github.com/ruanbekker/slack-channel-cleaner
python slack slack-bot slack-python slack-python-script
Last synced: 20 days ago
JSON representation
Python Script to Remove Old Slack Messages
- Host: GitHub
- URL: https://github.com/ruanbekker/slack-channel-cleaner
- Owner: ruanbekker
- Created: 2019-07-16T22:41:45.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2019-07-16T22:59:00.000Z (over 5 years ago)
- Last Synced: 2025-01-01T13:47:40.299Z (25 days ago)
- Topics: python, slack, slack-bot, slack-python, slack-python-script
- Language: Python
- Homepage:
- Size: 4.88 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# slack-channel-cleaner
Python Script to Remove Slack Messages.## About
I am using a free-plan slack workspace, and I needed a way to clean some of my slack channels such as notifications, builds channels without delete/recreating them.
## Authentication
Create your app at https://api.slack.com/apps and set the application token as:
```
app_token = 'xoxo....'
```## Usage
List your slack channels:
```
>>> slack_channels = list_channels()
>>> slack_channels
{u'system_events': u'ABCDEFGHI', u'test': u'BBCDEFGHI', ...
```Get all the messages from the slack channel that you want to delete. The method 2 parameters, channel_id and the timestamp where it needs to start deleting from (in hours). In this case a hour from now to the last message:
```
>>> timestamps = list_message_timestamps_by_channel(slack_channels['test'], delete_from_in_hours(1))
>>> timestamps
[u'1563309768.000400', u'1563309754.000300',...
```Pass the timestamps with the slack channel id as parameters to this method:
```
>>> delete_messages_by_batch_timestamps(slack_channels['test'], timestamps)
message deleted
message deleted
message deleted
message deleted
message deleted
message deleted
```## Rate Limiting
The delete method uses Tier3, which gives you +- 50 calls a minute:
- https://api.slack.com/docs/rate-limits#tier_t3I have set logic that if the list of timestamps are more than 50, it will delay 1.22 seconds between each delete call, 1 second for less than 50, more than 30 and no delay for less than 30