2014-04-06 63 views
1

如果沒有答覆,我想將呼叫重定向到語音郵件。該代碼是:使用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語句基本上說:如果呼叫應答在掛斷時結束,如果不去語音郵件?我怎樣才能做到這一點?

謝謝!

回答

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 

我希望這可以幫助別人,它花了我大量的實驗到達那裏!

相關問題