Have you ever thought about starting a Reminder Service company and getting millions of dollars in funding all from a weekend project? Tropo is here to help you with your communications needs in this endeavor!
The Reminder Service source code that I am about to share with you was started on the Nerd Bird (good to have in-flight WiFi) from Orlando to Phoenix, on my way back from the HIMSS conference. It’s written in Ruby on Rails 3.0.4 and the Tropo Scripting API.
This is Tropo application is designed to demonstrate building a Reminder Service application using both Voice and SMS alerts. The application will place an outbound reminder call to you 1 week in advance and then 1 day in advance and an SMS message 1 hour in advance of your appointment time.
You can demo the Reminder Service running on Heroku now. It’s a basic Ruby on Rails scaffolding interface with the ability to create, update, and delete reminders. All reminders are tracked in UTC time to simplify the demo and there is no authentication because IT’S A DEMO.
The source code is on GitHub. Simply clone this application from GitHub and run the following statements from your command line:
bundle install
rake db:create
rake db:migrate
Setup an account at Tropo and create a new Scripting API application. Copy and paste the source code from tropo_scripting_api.rb into separate scripts running under the same application. One for placing outbound voice call reminders and one for sending SMS message reminders.
Here is the source code to place the phone call on Tropo.
1 | message($remindermessage, { |
Here is the source code to send an SMS message on Tropo.
1 | message($remindermessage, { |
Add a phone number to your Tropo application. SMS messages will not work without one.
The rest of the magic happens in the API controller as shown below:
01 | class ApiController < ApplicationController |
05 | @reminders = Reminder.where( "(appointment > ?) and (appointment < ?) and ( flag1 IS NULL or flag2 IS NULL or flag3 IS NULL)" , Time.now.utc, Time.now.utc+ 1 .week ) |
07 | @reminders .each do |reminder| |
09 | if reminder.appointment- 1 .hour < Time.now.utc && reminder.flag3.nil? |
14 | :token => '848b6b17c6229844827847b381...58eaa12683b6ea0a8aa5e166ee7bfcc8' , |
15 | :phonenumber => formatphone(reminder.phonenumber), |
16 | :remindermessage => 'dont forget ' + reminder.message.to_s + ' at ' + reminder.appointment.to_s}} |
19 | @reminder = Reminder.find(reminder.id) |
20 | @reminder .flag3 = true |
23 | elsif reminder.appointment- 1 .day < Time.now.utc && reminder.flag2.nil? |
25 | # Place outbound reminder call |
28 | :token => '3d5eed33429706408efcc0e92307b...d04af908e583112195de9ec7b05b9e' , |
29 | :phonenumber => formatphone(reminder.phonenumber), |
30 | :remindermessage => 'dont forget ' + reminder.message.to_s + ' at ' + reminder.appointment.to_s}} |
33 | @reminder = Reminder.find(reminder.id) |
34 | @reminder .flag2 = true |
37 | elsif reminder.appointment- 1 .week < Time.now.utc && reminder.flag1.nil? |
39 | # Place outbound reminder call |
42 | :token => '3d5eed33429706408efcc0e92307b04...908e583112195de9ec7b05b9e' , |
43 | :phonenumber => formatphone(reminder.phonenumber), |
44 | :remindermessage => 'dont forget ' + reminder.message.to_s + ' at ' + reminder.appointment.to_s}} |
47 | @reminder = Reminder.find(reminder.id) |
48 | @reminder .flag1 = true |
54 | render :text => "sent " + @reminders .length.to_s + " reminders" |
56 | render :text => "no reminders" |
60 | def formatphone(phone) |
61 | @phone = phone.gsub( "(" , "" ).gsub( ")" , "" ).gsub( "-" , "" ).gsub( "." , "" ).gsub( " " , "" ) |
62 | if @phone [ 0 .. 0 ] != '1' |
Now for the drum roll! Setup a cron job to call http://localhost:3000/api/check every 5 minutes, run rails server, and open your web browser to http://localhost:3000! Oh, one last thing…Go ask one of those “super angels” for some cash-money :)
ShareThis
Related posts:
- Create a Group SMS Service Using Tropo in 5 Lines of Code!
- Command Line SMS
- How to Build a VoIP-Based Baby Monitor
- Customer Service Hotline
- Scotty, We Need More Power!
Tags: outbound, phone, rails, reminders, Ruby, SMS, source, Tropo
You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.