This is a fork of Symantec/slack-autoarchive. We forked the repository and made the following changes:
- Migrated to the new Slack API (using the changes from from Symantec#51)
- Improved the
README.md
- Other small improvements & fixes (see ce84d1, 8209175, 914b0cc).
- python3
- Install requirements.txt (
pip install -r requirements.txt
) - An OAuth token from a Slack app on your workspace that has the following permission scopes:
channels:history
channels:read
channels:manage
channels:join
chat:write
chat:write.customize
chat:write.public
Here is quick tutorial on how to configure a slack app and get the OAuth token:
ConfigureSlackApp.mp4
The SLACK_TOKEN
must be exposed as a environment variable before running your script. By default, the script will do a DRY_RUN
. To perform a non-dry run, specify DRY_RUN=false
as an environment variable as well. See sample usages below.
# Run the script in dry run archive mode...This will output a list of channels that will be archived.
SLACK_TOKEN=<TOKEN> python slack_autoarchive.py
# Run the script in active archive mode...THIS WILL ARCHIVE CHANNELS!
DRY_RUN=false SLACK_TOKEN=<TOKEN> python slack_autoarchive.py
Name | Description | Default | Example Usage |
---|---|---|---|
ADMIN_CHANNEL |
The ID of the Slack channel where notifications about the reaper's actions will be sent. | '' (empty) |
C12345678 |
DAYS_INACTIVE |
The number of days a channel must be inactive before it is eligible for archiving. | 60 |
60 |
MIN_MEMBERS |
The minimum number of members a channel must have to be exempt from archiving. | 0 |
5 |
DRY_RUN |
Flag to indicate whether the script should run in dry mode (no actual changes made) or not. | true |
true or false |
SLACK_TOKEN |
The Slack API token required to authenticate the bot performing the archiving. | '' (empty) |
xoxb-1234-5678-abcdef |
WHITELIST_KEYWORDS |
Comma-separated keywords; channels containing these in their name will not be archived. | '' (empty) |
important,permanent |
SLACK_SKIP_PURPOSE |
A keyword used in channel purposes to mark channels that should not be archived. | %noarchive |
%noarchive |
You can add the string %noarchive
to your channel purpose or topic. There is also a whitelist file or env variable if you prefer.
A channel will be archived by this script if it doesn't meet any of the following criteria:
- Has a messages in the past 60 days (use
DAYS_INACTIVE
environment variable to change this) - Is whitelisted. A channel is considered to be whitelisted if the channel name contains keywords in the
WHITELIST_KEYWORDS
environment variable. Multiple keywords can be provided, separated by comma.
- Don't panic! It can be unarchived by following these instructions. However all previous members would be kicked out of the channel and not be automatically invited back.
- A message will be dropped into the channel saying the channel is being auto archived because of low activity.
- You can always whitelist a channel if it indeed needs to be kept despite meeting the auto-archive criteria.
Just before a channel is archived, a message will be sent with information about the archive process. The default message is:
This channel has had no activity for {} days. It is being auto-archived. If you feel this is a mistake you can <https://slack.com/archives/archived|unarchive this channel> to bring it back at any point. In the future, you can add '%noarchive' to your channel topic or purpose to avoid being archived. This script was run from this repo: https://github.com/Symantec/slack-autoarchive
To provide a custom message, simply edit templates.json
.
In case you want to contribute to this project, please make sure your changes work correctly. Currently, there are no tests for this project. This means that you will have to test your changes manually.
Follow these steps to test your changes:
- Have a playground Slack workspace where you can test the script.
- Create a new slack app and generate a new OAuth token.
- Run the script with your new OAuth token and make sure it works as expected.
- Make sure to have some channels that meet the criteria for archiving and some that don't.
In case you want to use docker to run the script, here is how you can do it:
- First build the docker image (in the root of the project):
docker build --tag autoarchive .
- Run the container (
DRY_RUN
is set to true by default):docker run -e SLACK_TOKEN=<YOUR_AWESOME_TOKEN> autoarchive
- If your ready to archive run:
docker run -e SLACK_TOKEN=<YOUR_AWESOME_TOKEN> -e DRY_RUN=false autoarchive