README_FOR_APP

Path: doc/README_FOR_APP
Last Update: Fri Dec 07 11:57:40 -0800 2007

www.restphone.com - the RESTPhone service

$LastChangedRevision: 5865 $

Code samples

If you‘d prefer, you can start with code samples

Getting started

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:

  • Play text (using a text-to-speech system)
  • Play an audio file
  • Get input from a user
  • GET a URL
  • POST to a url
  • Change to a different menu
  • Dial a phone number

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.

DETAILS

See RestPhone::PhoneMenuBuilder for documentation on how to create and use RESTPhone in your Ruby application.

The basic pieces of RESTPhone are:

RestPhone::PhoneMenuBuilder
The easiest way to create RESTPhone menus.
RestPhone::Service
Upload your phone menus to the RESTPhone service, make phone calls

RestPhone::PhoneMenuBuilder is a convenient way to create phone menus, but you can also create them by hand by putting together these building blocks:

RestPhone::PhoneMenu
A combination of PhoneAction objects
RestPhone::PhoneAction
A specific action to take. For example, when the caller presses 3, transfer them to a new number.
RestPhone::PhoneMenuCondition
Execute actions if they match the condition
RestPhone::PhoneMenuHandler
Event handlers - RestPhone::PhoneMenuHandler::OnTimeout, etc.

INSTALL

Coming soon.

LICENSE

[Validate]