Greet Caller by Name in Ruby
class GreetCallerController < ApplicationController
protect_from_forgery except: :greetings
# In routes.rb you need to set the following routing rule
# post '/greet_caller' => 'greet_caller#index'
def index
phone_book =
{
"+12345671" => "John",
"1001" => "Kevin",
"+12345675" => "Jack"
}
caller_name = phone_book[params[:Caller]] || "Sir or Madam";
render :xml => '<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Speak>Hello ' + caller_name + '</Speak>
</Response>'
end
end
Code example 1
- Greeting the caller by using a phonebook
IN MORE DETAILS
- When your application receives a call, you will get a Request with all of the call details.
- Fill an associative array with telephone numbers and names.
- In this associative array (phonebook) we are looking for the Caller parameter of the Request.
- After that, send back the response OzML to the caller.