Question

I want to redirect a call to voicemail if it is unanswered. The code is:

get '/inbound' do
CALLER_ID = 'caller_number'
to = 'dest_number'
r = Response.new()
r.addSpeak('Thanks for calling acme, if someone does not answer within 20 seconds you will be directed to voicemail')
r.addDial({'callerId' => CALLER_ID, 'timeout' => '20'}).addNumber(to)
r.addSpeak("The number you're trying is not reachable at the moment. You are being redirected to the voice mail")
r.addDial('action' => 'http://frozen-lake-7349.herokuapp.com/voicemail', 'method' => 'GET')
 content_type 'text/xml'
    r.to_xml()
end

This partially works in that it does forward to the voicemail URL and a recording is made but if the call is answered then, when the responding party hangs up, the flow continues and the caller is routed to voicemail anyway which, of course, is now unnecessary because the parties have spoken.

So, should there be an if clause in there somewhere which basically says: if call answered end on hangup if not go to voicemail? How can I do this?

Thanks!

Was it helpful?

Solution

Solved. The following receives the call and, in all cases, transfers to the voicemail URL (observing the timeout if the call is unanswered)

get '/inbound' do
#from = params[:From]
CALLER_ID = 'from caller'
#to = lookup in DB routing
to = 'destination_number'
r = Response.new()
r.addSpeak('Thanks for calling acme, you will be routed to voicemail in 25 seconds if he does not answer!')
r.addDial({'callerId' => CALLER_ID, 'action' => 'http://frozen-lake-7349.herokuapp.com/voicemail', 'method' => 'GET', 'timeout' => '25'}).addNumber(to)
content_type 'text/xml'
    r.to_xml()
end

Then the if clause goes in the voicemail section, as follows:

get '/voicemail' do
r = Response.new()
if params['CallStatus'] != 'completed'
r.addSpeak('Please leave a message and press the hash sign when done.')
r.addRecord({'method' => 'GET', 'maxLength' => '60', 'finishOnKey' => '#', 'playBeep' => 'true'}) 
r.addHangup()
else
r.addHangup()
end
content_type 'text/xml'
    r.to_xml()
end

I hope this helps somebody else, it took me a good number of experimentations to get there!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top