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!