codybreene / slack_bot

Track My Slack -- A slack bot for tracking key phrases in messages.
1 stars 0 forks source link

Track My Slack

Track My Slack is a slack bot that alerts workspace members when they mention a key phrase. Users have the ability to add or delete trackable phrases.

image

Setup

Before we can run docker-compose up, we'll need to take care of a few things related to the way Slack grants permissions and routes requests.

Setup ngrok, a tunnelling software

  1. Navigate to https://ngrok.com/ and download ngrok for your operating system (this is required because Slack uses request URLs)
  2. Open up a terminal window
  3. Unzip ngrok: unzip /path/to/ngrok.zip
  4. Run the following command: ./ngrok authtoken <AUTH_TOKEN> -- replace auth token with the auth token listed on step two of this page: https://dashboard.ngrok.com/get-started/setup
  5. Run ./ngrok http 5000 -- you should see the following: image
  6. Save the second "Forwarding" URL for later. It will look like this: https://<some-string>.ngrok.io

Configure slash commands

  1. Login to a Slack workspace of your choosing through the browser, where you'll be creating an app to test the bot
  2. Navigate to https://api.slack.com/
  3. Click 'Your Apps' in the top right corner
  4. Create an app
  5. Click 'Basic Information' within the 'Settings' menu, and scroll to 'Add Credentials' -- next to 'Signing Secret' click 'Show' -- copy and save for later
  6. Click "Slash Commands" within the "Features" menu -- this is where we'll configure our commands for adding and deleting phrases to the watch-list
  7. Click 'Create New Command'
  8. Fill it out like so: image
  9. For the 'Request URL' field, copy and paste the ngrok url from step (6), and add /add_phrase to the end of it
  10. Save changes!
  11. Duplicate steps 6 - 8 for 'delete_phrase'

Congrats! You've configured the slash commands to add and remove watch phrases.

Configure permissions

  1. Navigate to "OAuth & Permissions" in the "Features" menu
  2. Click 'Install App to Workspace'
  3. Click 'Allow'
  4. Copy the 'Bot User OAuth Access Token' for later
  5. Scroll down to 'Scopes'
  6. Under 'Bot Token Scopes', click 'Add an OAuth Scope'
  7. Add the following bot scopes: image
  8. Re-install your app: image

Setup Environment Variables

  1. Open up a terminal window
  2. Clone the respository into a directory of your choice: git clone https://github.com/codybreene/slack_bot.git
  3. cd into the slack_bot directory
  4. Create a file in that directory to store your environment variables: touch .env
  5. Open up the directory in a coding editor of your chosing, and navigate to the .env file
  6. Add the following:
    SLACK_SIGNING_SECRET=<SIGNING_SECRET>
    SLACK_BOT_TOKEN=<BOT_TOKEN>
    AIRTABLE_BASE_KEY=appvq9i1bO2gEbi6Y
    AIRTABLE_API_KEY=key54bic9Lngk71On
  7. Replace with the signing secret you copied from 'Basic Information' (three sections up, step 5)
  8. Replace with the Bot User OAuth Access Token you copied (two sections up, step 4)
  9. Save the file

Launch the app

  1. Ensure you have Docker installed: https://docs.docker.com/get-docker/
  2. Ensure you're not running any docker containers: docker ps then docker stop <CONTAINER_ID>
  3. Run: docker-compose up
  4. Navigate to localhost:5000, and you should see an indication the app is running

Add Event Subscriptions

  1. Navigate back to your app dashboard on the Slack website
  2. Click on 'Event Subscriptions' in the 'Features' menu
  3. Toggle events on
  4. Copy the ngrok URL from the previous section, paste it into the 'Request URL' field and add /events: image
  5. Click 'Subscribe to bot events'
  6. Click 'Add Bot User Event' and add the message.channels event: image
  7. Save changes!

Test it out!

  1. Open up the slack workspace
  2. Click on a channel where you'd like to test the bot
  3. Click 'Add an App' right below the channel description
  4. You should see your app -- add it!
  5. Type some test messages
  6. Type some slash commands /add_phrase and /delete_phrase

Technologies