Skip to content

dogeared/magic-with-slack-and-twilio

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SOLID Principles with Slack and Twilio

The purpose of this app is to deliver a random Magic the Gathering playing card image.

This repo can be deployed to Heroku and integrated with both Slack and Twilio. That is, in your Slack organization, you can setup a slash command that when entered will display a card image in the channel the command was issued. And, if configured, sending the command: magic to your Twilio number will respond with the magic card image as an MMS message.

Watch for the forthcoming blog post!

In the meantime, you can follow the instructions below to get the app set up.

Deploy to Heroku

The easiest way to deploy the app to Heroku is to use the friendly purple button:

Deploy

You’ll need to provide two details: a BASE_URL and a SLACK_TOKENS.

The BASE_URL is the fully qualified name of your heroku app. For instance, I have the app deployed to: https://random-magic-card.herokuapp.com. You simply follow the same format based on the app name you enter: https://<app name>.herokuapp.com

The SLACK_TOKENS is populated with values from the Verification Token in the Slack app definition (see below). If you are configuring the app for a single Slack Workspace, then you’ll have a single token. If (like me) you have multiple Workspaces and want the app to work in all of them, then you can enter a comma-separated list of Slack tokens.

slack token

Note: you can put in a dummy placeholder for the SLACK_TOKENS for now and update it later when when you set up your Slack app.

From here, you can jump to Setup Twilio or read on to Setup Slack

Setup Slack

Navigate to https://api.slack.com/apps and click the Create New App button to get started:

create slack app

Enter in values for the App Name and choose the Workspace you’ll be adding the app to:

create slack app popup

Next, click the Slash Commands link on the left side and click the Create New Command button:

create slack app popup

Fill in values for Command (like: /magic), Request URL (like: https://.herokuapp.com/api/v1/slack), and a Short Description. Click the Save button.

create slack app popup

At this point, you Slack slash command is all setup:

create slack app popup

Click Basic Information on the left side and expand the Install app to your workspace section. Click the Install app to Workspace button.

slack install app

Click the Authorize button:

create slack app popup

Scroll down on the Basic Information screen you are returned to and make note of the Verification Token.

slack token

NOTE: If you’ve installed the Heroku CLI, you can issue this command to set the SLACK_TOKENS property properly:

heroku config:set \
SLACK_TOKENS=<comma separated tokens> \
--app <your heroku app name>

You should now be able to issue the slash command in a channel in your Slack org:

create slack app popup

Setup Twilio

Navgiate to your Twilio Console Dashboard

twilio console

Click the three dots and choose Programmable SMS:

programmable sms

Click Messaging Services:

programmable sms

Click the red plus (+) button:

messaging services

Enter a Friendly Name, Choose: Notifications, 2-Way for the Use Case and click the Create button:

messaging services

Check the Process Inbound Messages checkbox and enter in the Request URL of your Heroku app (e.g. https://<your app name>.herokuapp.com/api/v1/twilio):

messaging services

Click the Save button.

Click the Numbers link on the left and make sure your Twilio number is added to the messaging service:

twilio number

Note: I am not publishing my Twilio number as I don't want you all jacking up my SMS charges. Maybe Twilio will sponsor this app? If so, I'll publish the number!

At this point, you should be able to test out the Twilio service by sending the word magic as a text message to your Twilio number:

twilio command

Note: If you send anything other than the word magic (case insensitive), you'll get the error response shown above.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published