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

时间:2014-04-06 00:22:17

标签: 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' => 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子句基本上说:如果没有去语音邮件,如果呼叫应答在挂断时结束?我怎样才能做到这一点?

谢谢!

1 个答案:

答案 0 :(得分:3)

解决。以下接收呼叫,并且在所有情况下都转移到语音邮件URL(如果呼叫未得到应答,则观察超时)

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

然后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

我希望这有助于其他人,我花了很多实验来实现目标!