Rolld - RPG-dice Slack integration

Source on GitHub

Rolld is a Slack Integration that makes it easy to roll dice in a Slack Channel. That’s really all there is to it. I put this thing together in a few hours downtime when I needed to take a break from writing the book. I don’t plan to distribute it via Slack because I don’t want the dozens (there are dozens of us!) of Slack gamers banging on my free-tier Heroku dyno. But you can deploy your own Rolld app to a Heroku dyno and integrate it into a Slack channel of your choosing.

Rolld demo

Usage

Roll + modifiers. Roll results are broken down inside the [] brackets and modifier is appended with a +.

Rolld usage

Rolld also supports multiple rolls, eg: /roll 2d6

Multiple rolls

Steps to Setup your own Rolld App

Steps to set up this integration for your local Slack channel, using a free dyno on Heroku to host:

  1. Clone the repo: git clone git@github.com:JaredHalpern/Rolld.git
  2. Make sure you have Homebrew installed. If not:
    /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
    

Heroku Setup

  1. Install the Heroku CLI: brew install heroku/brew/heroku
  2. Verify Heroku CLI installation:
    heroku --version
    
    Should show something like: heroku/7.0.35 (darwin-x64) node-v10.0.0
  3. Ensure you’ve created an account at https://www.heroku.com (free tier works)
  4. Login to Heroku via command line: heroku login
  5. Change to the cloned Rolld directory: cd Rolld
  6. Set the Heroku buildpack: heroku buildpacks:set heroku/python
  7. Create a heroku app: heroku create (we’ll configure Slack to point to this URL soon)
  8. Verify the remote is set up: git remote -v You should see something like:
    heroku https://git.heroku.com/yass-rangers-61413.git (fetch)
    heroku https://git.heroku.com/yass-rangers-61413.git (push)
    
  9. Go to Heroku Settings and find the Domain. Note down this URL for the next step.

Create a Slack App

  1. Log into your Slack account via the web: https://api.slack.com/apps
  2. Hit the Create New App button
  3. Name the app and choose a workspace in which to deploy it
  4. In the Add features and functionality Section, Click Slash Commands
  5. Hit the Create New Command button
  6. Enter the Command you’d like to use to invoke the integration. /roll seems natural
  7. In Request URL, use the url from your Heroku app
  8. Hit the Save button in the lower right
  9. In the Install your app to your workspace section, hit the Install App to Workspace button

Verification / Permissioning

  1. On the Basic Information page, copy the Verification Token and save it temporarily

  2. Click on OAuth & Permissions on the left-hand side. Copy the OAuth token and save it temporarily

  3. To get the Team-ID: navigate to your team’s Slack channel in a web browser, right-click and inspect the source. Find the text team_id and grab the value (something like Z4KRT3F6A)

  4. Set the environmental variables in Heroku. Go to your app’s Settings and tap Reveal Config Vars. Enter these Key-Value pairs:

    • SLACK_VERIFICATION_TOKEN | value from step 1
    • SLACK_ROLLD_TOKEN | value from step 2
    • SLACK_TEAM_ID | value from step 3

    Alternatively, use the Heroku CLI:

    heroku config:set SLACK_VERIFICATION_TOKEN=....your token....
    

Deploy

  1. Push to the Heroku remote: git push heroku master
  2. Open Slack, and run your command! /roll 1d20

I’ve probably missed a step or two. If you see something, feel free to file a PR and I’ll update. Thanks!

Development and Testing

  • Use ngrok for testing locally via “tunneling”
  • Instructions to set up ngrok specifically to test a Slack bot are here
  • Command: ngrok http 5000
  • Ensure local ENV variables are set - either in .bashrc or temporarily
  • Create a virtualenv for Rolld and run: /Rolld/bin/activate
  • With the activated virtualenv, run: python app.py
  • Copy the url from ngrok’s Forwarding field to the Request URL field in your Slack app’s Slash Commands settings
  • When done testing, don’t forget to set the Request URL back to your Heroku App’s URL
  • Testing Slack integrations locally with ngrok
  • Easily resize gifs online

Credits

Thanks to Justin Isaf (jisaf on GitHub) for adding modifiers and The Light of the Spoon™ for testing it.