我一直在使用 twilio-ruby gem 开发 Twilio 应用程序,但我陷入了一个部分:
为呼叫构建 TwiML 响应,我拨打一些号码,以便他们也可以接听呼叫:
def handle_gather
...
...
response = Twilio::TwiML::Response.new do |r|
r.Dial do |d|
numbers.each do |number|
d.Number number
end
d.Client user_id
end
r.Say 'A ligação falhou ou o atendente desligou. Obrigado.', :voice => 'alice', language: "pt-BR"
end
render_twiml response
end
我可以使用终止连接Twilio.Device.disconnectAll()
,但应用程序不断拨打号码numbers
多变的。我怎样才能停止拨打他们的电话?
Edit:添加更多细节:
基本上,我正在遵循这两个例子:https://www.twilio.com/docs/quickstart/ruby/client/outgoing-calls https://www.twilio.com/docs/quickstart/ruby/client/outgoing-calls
https://www.twilio.com/blog/2014/02/twilio-on-rails-integrating-twilio-with-your-rails-4-app.html https://www.twilio.com/blog/2014/02/twilio-on-rails-integrating-twilio-with-your-rails-4-app.html
我有一个有 2 个操作的控制器:voice
and handle_gather
。在handle_gather
动作,我得到了呼叫者按下的选项(params['Digits']
)并拨打一些号码,如上所示。接下来,我设置了一个客户端,以便我也可以在应用程序中应答呼叫。
在应用程序中,用户可以点击“接听”或“挂断”。当用户单击“hangup”时,我在处理程序中获取此事件并调用Twilio.Device.disconnectAll()
结束连接。但是,应用程序仍然拨打我上面提到的那些号码,这是我想要改变的行为。
编辑 2:尝试将 CallSid 发送到服务器并在那里取消呼叫。咖啡脚本:
$('.hangup').click ->
Twilio.Device.disconnectAll()
ringtone.pause()
# Send call_sid to server and cancel the call
$.ajax 'twilio/cancel_call/' + conn.parameters.CallSid + '.json',
type: 'GET'
dataType: 'json'
error: (jqXHR, textStatus, errorThrown) ->
console.log "#{textStatus} - #{errorThrown}"
success: (result, textStatus, jqXHR) ->
console.log result
Action:
@client = Twilio::REST::Client.new current_user.sub_account_sid, current_user.sub_account_auth_token
@call = @client.account.calls.get(params[:call_sid])
@call.update(:status => "canceled")
respond_to do |format|
format.json { render json: @call.status.to_json }
end
作为操作的响应,我得到“取消”,但应用程序继续拨号。