As with any for-fun softball/baseball/kickball/handball league, the availability of players can vary widely from week to week. Life has a habit of interfering, especially if you have kids, so ensuring there’s enough players to field a full team can be a difficult process. Such was the case with the Voxeo softball team, but we’re just not the type of people to let a problem like that go unsolved – especially when we have incredibly easy tools like SMSified just sitting there, asking to be used.
This post will walk through the creation of an SMS application – using SMSified, Ruby and Google Spreadsheets – that requests and then stores the expected game attendance for each member of a team of players. The app is written in Ruby, since there’s both a sweet gem for interacting with Google spreadsheets (no reinventing the wheel!) and an SMSified Ruby Library.
We’ll break it down into pieces, since there’s a few different sections – as usual, the requires:
require "google_spreadsheet"
require "sinatra"
require "json"
require "smsified"
The use for “google_spreadsheet” should be pretty obvious; we use “sinatra” as the webserver and framework; “json” is brought in so we can parse the incoming text message data from SMSified and “smsified” should also be obvious. Next portion of the app defines our Sinatra route and a few variables:
post '/' do
response = JSON.parse(request.env["rack.input"].read)
message = response["inboundSMSMessageNotification"]["inboundSMSMessage"]["message"]
callerID = response["inboundSMSMessageNotification"]["inboundSMSMessage"]["senderAddress"]
trigger = message[0..1]
datetime = message[3..message.length]
The beginning, post '/' do, defines our route as the root of our URL that we add to our phone number in SMSified, which we do here:

The rest of the section is parsing out JSON and setting some variables with the extracted data. We pull out the message and the sender’s callerID, then run a couple Ruby tricks on the message data. We yank out the first two characters and define it as trigger, and then set the rest of the message content as the datetime. Why we do this is exemplified in the next portion of code:
if trigger == "Go"
smsified = Smsified::OneAPI.new(:username => 'sms_user', :password => 'sms_pass')
smsified.send_sms :sender_address => '13215550100', :address => ['14075550100', '19545550100', '13055550100'], :message => "Can you make it to the game on #{datetime}?"
We’re using the trigger to tell the app this text message is the “trigger” message, which in turn tells SMSified to send an outbound text message to the defined list of numbers; we then include datetime in the message that goes out. To explain this a little better, the initial activation text message sent to the SMSified number might look like this:
Go 6/21 @ 6:30
This activates the app, which then splits up the body of the text into two parts: “Go” (which tells SMSified to send the text message to all the recipients) and “6/21 @ 6:30″ (the date & time for the game, which is inserted into the outbound message). The code to actually send the text message is handled by the SMSified Ruby Library; you just populate the necessary (and clearly named) fields and it sends the POST to SMSified with the data. Note that :sender_address is your SMSified number, which you can access under your Account and then Phone Numbers.
The next portion of code uses the “google_spreadsheet” gem to connect to a particular Google Spreadsheet:
else
session = GoogleSpreadsheet.login("goog_user", "goog_pass")
ws = session.spreadsheet_by_key("YOUR_SPREADSHEET_KEY").worksheets[0]
The spreadsheet key is located in the URL for your Google Spreadsheet, I’ll bold it in this pseudo URL:
https://spreadsheets.google.com/spreadsheet/pub?hl=en_US&hl=en_US&key=1234ABCDyvaLmdLmNQ05DSVAzMXc3THFfa3Y0&output=html
The last section also uses the “google_spreadsheet” gem to update particular fields, based on the callerID value:
if callerID == "tel:+14074095231"
ws[2, 1] = message
ws.save()
elsif callerID == "tel:+19545550100"
ws[2, 2] = message
ws.save()
elsif callerID == "tel:+13055550101"
ws[2, 3] = message
ws.save()
else
p "Not on the list"
end
end
end
In order to start the app, we sent it the “Go 6/21 @ 6:30″ message, which then sent out an message that said “Can you make it to the game on 6/21 @ 6:30?”; we should start getting replies back now with “Yes”, “No”, “Maybe” and we want to save that info to our spreadsheet. This part of the app is assigning a field value to a callerID – a person’s reply to a specific cell on the spreadsheet. If Justin is 14075550100, Kevin is 19545550100 and Dave is 13055550100, our spreadsheet should look something like this:

Honestly, that’s it. You shouldn’t even need to publish your spreadsheet; you’re using your Google login, so the document can be completely hidden from anyone else if you prefer. This could easily be adjusted to a survey app – send a text to a list of clients, record their answer in a private spreadsheet for your personal review.
Complete app can be downloaded from Github here, use it however you’d like. Questions or concerns? As always, hit us up on the forum.
©2011 SMSified. All Rights Reserved.
.