require 'rubygems' require 'rest_phone' # There's only one menu in this system. It plays a prompt asking # the caller to enter their confirmation code. If the user enters # the right code (hardcoded here to 1234) it POSTs the information to # http://www.restphone.com/user_call_logs/list/1234 and tells the # caller that they've confirmed their code. # # If the user enters anything other than 1234, an error prompt is played. # # If the user doesn't enter anything, the timeout message is played. confirmation_menu = RestPhone::PhoneMenuBuilder.create_menu do |m| m.play :play_text => "Please enter your confirmation code." # If the user enters 1234, play the 'thank you' message and do the post. 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', :params => {:extra_information => "something extra"} n.hangup end # If the user entered anything else, play the error message. m.on_key :key => :any do |n| n.play :play_text => "That's not your code." end # If the user doesn't enter anything before the timeout, play a timeout # message. m.on_timeout do |n| n.play :play_text => "Sorry, I didn't get that." end end # Now we have a menu, and we need to put it up on the RESTPhone server. # Create the service object with the right credentials. # You can either specify them in a file (using :credentials_file) # or specify them directly (using :username and :password). # # The credentials file is YAML, so just has: # # username: myusername # password: mypassword service = RestPhone::Service.new( :credentials_file => File.dirname(__FILE__) + '/../../config/api_auth.yml' ) # create_outbound_call creates a new request for a call using the menu we built. # If you're sending this to yourself, your phone should ring in a few seconds # after this completes. service.create_outbound_call( :phone_menu => confirmation_menu, :src_number => 12065551212, :destination_number => 12065551212 ) puts "Call requested.\n" # If the user types in 1234, the post to the URL contains: # # Parameters: {"remote_caller_id_text"=>"", "last_key"=>"1234", "extra_information"=>"something extra", "call_identifier"=>"domU-12-31-39-00-30-62/1196881171.43", "action"=>"list", "id"=>"1234", "remote_number"=>"12067840496", "user_call_request_id"=>"457", "controller"=>"user_call_logs", "local_number"=>"unknown", "local_caller_id_text"=>""}