/slapp-slack-example

An example Slapp Slack App using Firebase as the persistence layer

Primary LanguageJavaScriptMIT LicenseMIT

slapp-slack-example

NOTE: this repository is archived, and I will not be updating it further. We have moved to Discord, and the reimplementation of this bot is here.

This repo should be a reasonable starting point if you want to host your own SLAPP-based Slackbot.

A reimplementation of [Radiospiral][http://radiospiral.com] Slack bot using this library, and self-hosted at Heroku rather than at BeepBoopHQ (thanks for all the support, folks!)

This Slapp-based app uses Firebase as the persistence layer for all the stuff that BeepBoop used to host for us.

Expects the following environment variables:

  • PORT - port to start http server on - defaults to 3000
  • DOMAIN - domain name - defaults to pulling from host headers on requests
  • SLACK_VERIFY_TOKEN - Your Slack App's verify token
  • SLACK_CLIENT_ID - Your Slack App's Client ID
  • SLACK_CLIENT_SECRET - Your Slack App's Client Secret
  • FIREBASE_DB_URL - Your Firebase project's Database URL
  • FIREBASE_SERVICE_ACCOUNT_BASE64 - Your Firebase project's ID

To create your FIREBASE_SERVICE_ACCOUNT_BASE64 value you'll want to head to your Firebase project's Service Accounts settings and generate a new Private Key json file. You'll need to base64 encode the contents of the file to be able to set it as an environment variable.

base64 /path/to/service-account.json

For development you can set your environment variables in an env.sh file (which is .gitignored for you), and then just source it. yarn run start will run it locally and help you avoid embarrassing 'I pushed a syntax error to heroku' problems.

export PORT="8080"
export SLACK_VERIFY_TOKEN="your-slack-verify-token"
export SLACK_CLIENT_ID="your-slack-app-client-id"
export SLACK_CLIENT_SECRET="your-slack-app-client-secret"
export FIREBASE_DB_URL="your-firebase-url"
export FIREBASE_SERVICE_ACCOUNT_BASE64="base64 encoded service account key file contents"

Getting Started

You'll need to setup a new Slack App and add a Bot User, as well as enable Event Subscriptions. Pick any username for your Bot User, and for your Event Subscrition, use the following details:

  • Request URL: https://<your-domain>/slack/event
  • Add the following Bot Events
    • message.channels
    • message.groups
    • message.im
    • message.mpim

A Firebase project is also required. Slack Team data from the "Add to Slack" OAuth flow, as well as conversation state is stored there.

Running App

Once you have your app running, if you visit the root, https://<your-domain>/ it will render a page with an "Add to Slack" button you can use to add it to one of your Slack teams and start sending it messages.

Try asking the bot for help in a direct message

image

Try changing the messages the bot is listening for to get a feel for how things work by looking in lib/slapp.js