slack-bestof
find the most popular messages in your Slack workspace
slack-bestof uses a Slack "legacy api token" to crawl the entire history of the configured slack channels and outputs some primitive statistics. It also uses a MongoDB instance to cache responses from the Slack API. Suggestions welcome!
Due to rate-limiting, paging through the Slack API takes forever. We use a quick-n-dirty MongoDB in a docker container to cache slack messages locally for repeated runs.
docker pull mongo
docker run --name mongo_slack_bestof -d -p 127.0.0.1:27017:27017 mongoOpen the Legacy Tokens page in the Slack API docs. Scroll down and get yourself a token, they look like xoxp-34232...
Virtualenv prevents this python package from polluting your system path.
python3 -m venv venv
source venv/bin/activate
pip install --upgrade pipslack-bestof needs a JSON file formatted like:
{
"CAJSHDKAS": "example-channel-1",
"CSDLHFSDD": "example-channel-2"
}
You can generate such a file with the following abomination:
echo "{" > channels.json
curl -s https://slack.com/api/channels.list?token=xoxp-your-token | jq '.channels[] | "\"\(.id)\": \"\(.name)\","' -r | tee -a channels.json
sed '$ s/.$//' channels.json | tee channels.json
echo "}" >> channels.json
Note that you probably do not want to run slack-bestof on super noisy channels as it will take too long.
slack-bestof is configured to respect Slacks API rate limit (which they do enforce), so the first run will be slow but subsequent runs will use the data cached in mongodb.
export SLACK_API_TOKEN=<redacted>
export MONGODB_URI=mongodb://localhost:27017
source venv/bin/activate
pip install -e .
slack-bestof -t $SLACK_API_TOKEN -m $MONGODB_URI -c channels.jsonDo this when you want to stop and remove the docker image and mongo database.
container_id=$(docker inspect mongo_slack_bestof --format='{{json .Id}}' | xargs)
docker stop $container_id
docker rm $container_idIt only ever queries for a single message once, so if people edit/add their reactions slack-bestof will not catch them. The best workaround is to either delete recent messages from MongoDB or delete the entire collection/database and re-sync from scratch.