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!