Automatically kicks users that are not on a whitelist from certain Slack channels, like so:
- The latest Node.js LTS release (at the time of this document being written, 8.9.x). This app only works with versions of
node >= 8
becauseasync
/await
is used and those JS language features are not available in earlier versions of node. - A MongoDB collection to store the whitelist in. You can sign up for a free MongoDB Server here: https://mlab.com/plans/pricing/#plan-type=sandbox
- Somewhere to deploy a Node application to. See "Deploying the service" for more details.
Here are all of the environment variables used by the app and some example values to help you understand which values to use:
MONGODB_COLLECTION_NAME
=whitelist
MONGODB_CONNECTION_STRING
=mongodb://<username>:<password>@<server>:<port>/somedatabasename
MONGODB_DATABASE_NAME
=somedatabasename
SLACK_OAUTH_TOKEN
=xoxp-...
- NOTE:
SLACK_OAUTH_TOKEN
cannot be a bot token because bots do not have permission to kick users.
- NOTE:
SLACK_VERIFICATION_TOKEN
=<token found under 'Basic Information' -> 'App Credentials' in your Slack App>
See "Configuring the Slack App" to figure out where to find the SLACK_
values above.
- Set all of the environment variables noted in "Environment Variables"
- Run
npm install
to install all required libraries. - Run
npm start
to start a local development server on port 3000.
Since this service fetches the whitelist from MongoDB, you'll need to connect to your MongoDB instance (i.e. using MONGODB_CONNECTION_STRING
) when you want to update the whitelist. The app expects the collection defined by the environment variable MONGODB_COLLECTION_NAME
to have exactly one document which is the whitelist. Said document has the following format:
{
"name-of-channel-without-hash-prefix": ["username1", "username2", "username_n"],
"some-other-channel": ["username4"]
}
For example, if a user named username5
were to join #some-other-channel
then they would be kicked since they're not on the whitelist for that channel. username4
would be allowed in this case. Also, all bots are whitelisted.
-
Create a user for this app in Slack with some relevant username i.e.
veyo-ban-hammer
. This user will be used to both kick users and notify the channel whenever someone is kicked. -
Invite the user to all the channels that you want to be controlled by a whitelist.
-
Log in as the user, i.e.
veyo-ban-hammer
-
Create a new Slack App with the following settings:
- Deploy the app to the URL you defined in "Request URL" in Slack -> Event Subscriptions.
- Use the "Install App" menu to install the app to the workspace.
Pretty much anything that supports Node 8.x will work including AWS Elastic Beanstalk, Azure App Service, Heroku, Zeit.co, etc.
When you deploy, make sure that all environment variables noted in "Environment Variables" are set, otherwise the app will fail to start.
If you would like to contribute, feel free to open a pull request: https://github.com/veyo/slack-banhammer/pulls. In your PR, please include an appropriate title which cleanly summarizes the change that you're making.
If you have any issues, comments or want to see new features, please file an issue: