Ruby 使用Plivo,如何将未应答的呼叫转发到语音邮件?

Ruby 使用Plivo,如何将未应答的呼叫转发到语音邮件?,ruby,sinatra,plivo,Ruby,Sinatra,Plivo,如果电话无人接听,我想将其重定向到语音信箱。代码是: 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'

如果电话无人接听,我想将其重定向到语音信箱。代码是:

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
这在一定程度上是有效的,因为它确实转发到语音邮件URL并进行录音,但是如果呼叫被应答,那么当响应方挂断时,流继续,并且呼叫方被路由到语音邮件,当然,这现在是不必要的,因为双方已经进行了通话

所以,应该有一个if子句在那里的某个地方,基本上说:如果电话被接听,在挂断时结束,如果不去语音信箱?我该怎么做


谢谢

已解决。以下用户接收呼叫,并在所有情况下传输到语音邮件URL(如果呼叫未应答,则观察超时)

然后if子句出现在语音信箱部分,如下所示:

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
我希望这对其他人有所帮助,我花了大量的实验才达到目的

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