Tropo is part of CiscoLearn More

Add Super Simple SMS Notifications to Slack with Tropo

Posted on April 28, 2015 by Johnny Diggz

It’s no secret, at Tropo we love Slack. We previously announced Ito, a personal communications assistant for Slack and we use Slack almost exclusively for internal communications at Tropo.

slack-200x200I’m also a co-founder of a makerspace in Orlando called Factur. As Factur started to grow, it became apparent that we needed a way to communicate between our members, especially between the core founding team because we need to coordinate for in-person board meetings.  I suggested that we try Slack as a collaborative tool and overall it’s been great…except for the handful of people who never log into Slack.  Right now there’s no Slack mobile app for Windows Phone, and even for people who do have the app, if they don’t have notifications turned on, they’ll never know there’s an action required by them, such as to pick a time they are available for a board meeting.

The workaround so far has been for someone to manually call or text the person ignoring Slack and say “HEY, LOG INTO SLACK YOU SLACKER!”, but that’s inefficient and an undue burden. But what if you could automate that somehow?  That got my wheels turning.

I’d never played with Slack’s API, but I knew they have one so I started poking around their site. I thought maybe if I could make a slash command and then have Slack send it to Tropo to send out SMS messages to all the board members, that would make it easy…something like:

/slackSMS Everyone needs to log into slack and pick a time for the next board meeting!

So yesterday I did a quick integration that does exactly that. It’s not full-featured, but it shows a simple way to send out SMS messages directly from the Slack command line using Tropo Scripting.

A couple of things to note before you try this:

  1. You need to be an administrator of your Slack account
  2. You need a Tropo account with outbound SMS enabled (open a support ticket in your Tropo account to enable outbound SMS)

Set up your Tropo App

  1. Log into Tropo and create a new scripting application. (Make sure you have outbound SMS enabled on your Tropo Account)
  2. Under scripting choose “New Script”.
  3. Copy the code from my Github Slack Tropo SMS example and paste it into the code window.
  4. Name the file slacktroposms.rb
  5. Save and Close the window
  6. Choose any U.S. phone number and click “Create App”
  7. Now that your app is created you’re going to want to copy the phone number assigned to your app and click Edit Script (doesn’t matter which one because they both point to the same script…slacktroposms.rb)
  8. Go down to the line that says :callerID => “+14155551212” and replace the phone number with the one that’s assigned to your app.
  9. Save and close that window.
  10. Scroll down to API keys. Under the Messaging one click “Copy to Clipboard”
  11. Take a break, pat yourself on the back and watch this video.

Set up your Slack Slash Command

  1. Ensure you have Administrator privileges on your Slack account and login via the web.
  2. From your Slack home page, scroll down to “Integrations” and choose “Add new Integration”
  3. Under DIY Integrations & Customizations, find “Slash Commands” and click “Add”
  4. Under “Choose a Command” type /slacksms (you can customize this to your liking) and then click “Add Slash Command Integration”
  5. Open a text editor and paste your API key there for safe keeping.
  6. Copy the following URL and paste it into the same text editor:  http://api.tropo.com/1.0/sessions?action=create&token=myToken&myString=Slack+notification+from&myNumbers=14155551212,16507771313
  7. Replace the myToken part of that URL with the API Key you copied from Tropo
  8. Change the phone number(s) to the numbers of the people you want to notify.  Note: you can use just one number (such as your own) for testing, but if you have multiple numbers just use the same format and separate by a comma.
  9. Copy that entire URL, complete with your Tropo API and your phone number and paste into your Slack Integration Settings in the URL field
  10. Change Method to “GET”
  11. Click Save Integration

Test your Integration

  1. Open up Slack and choose a channel
  2. type /slacksms hello world
  3. You should see a response from Slackbot that looks like ”
    <session><success>true</success><token>12ed1f23e158d4dbb4a99c8358d5d5e8fb0b8c4fa04af7a6td70d715ff52a07854b6389644e923958a7a48c</token><id>5a506434b6b63340e8fe6e029161d070d0b </id></session>
  4. Don’t worry…no one in the room will see that…the important thing is that you see the <success>true</success>
  5. Wait for your text message. You should see a message that says “Slack notification from Bob: hello world” (whereas Bob is whatever your Slack username is)

That’s it!

But what if it didn’t work?

Bugger!  But here are some troubleshooting tips:

  1. Make sure you have outbound SMS enabled in your Tropo account
  2. Make sure you copied your Tropo phone number correctly into the Tropo script.
  3. Ensure you copied your Tropo API key into the URL correctly
  4. Make sure you put your mobile phone number in correctly

What next?

Obviously we’re hard-coding phone numbers here, but it would be nice to use the phone number in each user’s Slack profile. For ease, I chose to use Tropo’s Scripting platform for this example, but Slack has a more robust REST/JSON API to access user profile data, so we could change this whole application to a Tropo WebAPI application and grab each user’s phone number in a specific channel to send them messages without hard coding.

Also, you can write some code to capture any replies and post them back to Slack.  But that’s for a future post 🙂

Happy Coding!

 

 

Leave a Reply