Skip to content

A slack bot that notifies a channel whenever a new channel is created

License

Notifications You must be signed in to change notification settings

Grammarian/SlackChannelTellTale

Repository files navigation

Slack channel tell tale

Overview

In any organisation, there are always new discussions and groups being formed. It can be impossible to even know what people are discussing, let alone to keep up.

This app at least lets people know what new discussions are being created.

When a new channel is created, this app will send a notification to a configured channel:

New channel notification

Configuration

This app requires a couple of pieces of configuration, supplied via environment variables:

export CHANNEL_PREFIXES="prefix1 prefix2" # only channels that start with one of these will trigger a notification
export SLACK_BOT_TOKEN="PUT_YOUR_SLACKBOT_TOKEN_HERE"
export SLACK_VERIFICATION_TOKEN="PUT_YOUR_TOKEN_HERE"
export TARGET_CHANNEL_ID="#your-channel"
export REDIS_URL="PUT_REDIS_CONNECTION_URL_HERE"

CHANNEL_PREFIXES is a whitespace separated list of prefixes. OPTIONAL

A new channel name must begin with one of these prefixes in order to generate a notification.

For example, if this is set to "eng- biz- ops-", then a new channel #biz-excel would be reported, but #pics-puppies would not.

If this is not set or is empty, all new channels will generate a notification.

SLACK_BOT_TOKEN is the token that allows your app to post messages. REQUIRED

SLACK_VERIFICATION_TOKEN is the token generated by the Slack integration process to ensure that your app is working and authenticated. REQUIRED

TARGET_CHANNEL_ID is the channel name where the notifications will be posted. REQUIRED

REDIS_URL is the connection string for a redis instance. OPTIONAL

If this is given, the bot will store whether or not it has already processed a channel notification (Slack can sometimes sent multiple creation events for the same channel). If this is not given, the bot will store this information in memory, which is not very reliably since a hosted instance can be restarted at any instance.

Slack integrations

This project uses Slack's python api toolkit: https://github.com/slackapi/python-slack-events-api

You will need to follow the instructions given in that project about how to create an app for slack, and configure it to receive events from your Slack instance.

Hosting

This app can be run locally, via ngrok. But, more normally, it would be hosted somewhere: heroku, zeit, aws, GCE.

The app is pure python, so it should be easy to host wherever you want.

I have had a good results using Zappa to host the application within AWS Lambda.

Local testing

Set up the above environment variables, then run it:

> python app.py

When it is up and running, you can send messages to it. The test-messages directory contains some samples:

> curl -s --header "Content-Type: application/json" --data @test-messages/channel-create-good.json http://localhost:3000/slack/events

You will have to put your SLACK_VERIFICATION_TOKEN into the json files, or your bot will reject them.

Zappa usages

Activate the virtual environment:

> . .\venv\Scripts\activate

To see the production logs:

(venv) > zappa tail prod
(venv) > zappa tail prod --filter "?ERROR ?WARN ?INFO" --since 1h

To push a new version:

(venv) > zappa update prod

About

A slack bot that notifies a channel whenever a new channel is created

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages