| Path: | doc/README_FOR_APP |
| Last Update: | Fri Dec 07 11:57:40 -0800 2007 |
www.restphone.com - the RESTPhone service
$LastChangedRevision: 5865 $
If you‘d prefer, you can start with code samples
RESTPhone is a service that allows you to use telephones as another interface to your web site.
You create a description of the call that says what to play to the caller, what to do when the caller presses keys on their phone, and how to send that information back and forth to your web site.
Think of RESTPhone as another kind of hosting provider. Your regular hosting provider serves the HTML interface to your web site. RESTPhone serves a phone interface. It’s straightforward to set things up so that the user’s action on the phone turns into http GETs and POSTs to your regular site.
RESTPhone interacts with callers by building menus. Each menu contains actions that can do various things:
Start with the RESTPhone version of "hello world:"
require 'rubygems'
require 'rest_phone'
service = RestPhone::Service.new(
:username => 'james',
:password => 'secret'
)
register_menu = RestPhone::PhoneMenuBuilder.create_menu do |m|
m.play :play_text => "Welcome to the sample call."
end
service.create_outbound_call(:phone_menu => register_menu, :src_number => 12065551212, :destination_number => 12065551212)
puts "Call requested."
That says to take the text "hello world," turn it into an audio file, play it to the user, and then hang up.
Let‘s add some interaction:
require 'rubygems'
require 'rest_phone'
service = RestPhone::Service.new(
:username => 'james',
:password => 'secret'
)
register_menu = RestPhone::PhoneMenuBuilder.create_menu do |m|
m.play :play_text => "Please enter your secret code."
m.on_key :key => 1234 do |n|
n.play :play_text => "Thank you. You've confirmed your code."
n.hangup
end
m.on_key :key => :any do |n|
n.play :play_text => "That's not your code."
end
end
service.create_outbound_call(:phone_menu => register_menu, :src_number => 12065551212, :destination_number => 12065551212)
puts "Call requested."
Now we‘re playing messages, but we‘re also asking RESTPhone to get a response from the user.
Let‘s take that response from the user and pass it through to a website:
require 'rubygems'
require 'rest_phone'
service = RestPhone::Service.new(
:username => 'james',
:password => 'secret'
)
register_menu = RestPhone::PhoneMenuBuilder.create_menu do |m|
m.play :play_text => "Please enter your secret code."
m.on_key :key => 1234 do |n|
n.play :play_text => "Thank you. You've confirmed your code."
n.post_url :url => 'http://www.restphone.com/user_call_logs/list/$last_key'
n.hangup
end
m.on_key :key => :any do |n|
n.play :play_text => "That's not your code."
end
end
service.create_outbound_call(:phone_menu => register_menu, :src_number => 12065551212, :destination_number => 12065551212)
puts "Call requested."
Here‘s the post to the site:
POST /user_call_logs/list/1234 HTTP/1.1 Accept: */* Content-Type: application/x-www-form-urlencoded Content-Length: 114 Host: www.restphone.com called_number=&last_key=1234&call_identifier=domU-12-31-39-00-30-62%2f1194038585.52&caller_id_raw=&caller_id_text=
That‘s the complete cycle of a basic RESTPhone call. For other things that you can put in menus, see RestPhone::PhoneMenuBuilder.
See RestPhone::PhoneMenuBuilder for documentation on how to create and use RESTPhone in your Ruby application.
The basic pieces of RESTPhone are:
RestPhone::PhoneMenuBuilder is a convenient way to create phone menus, but you can also create them by hand by putting together these building blocks:
Coming soon.