I've been developing a Twilio application using the twilio-ruby gem, but I'm stuck in one part:
Building the TwiML response for a call, I dial some numbers so they can answer the call as well:
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
I can terminate the connection using Twilio.Device.disconnectAll()
, but the application keeps dialing the numbers in numbers
variable. How can I stop dialing them ?
Edit: Adding more details:
Basically, I'm following this 2 examples: 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
I have a controller with 2 actions: voice
and handle_gather
. At the handle_gather
action, I get the option pressed by the caller (with params['Digits']
) and dial some numbers, as shown above. Next, I set up a client so I can answer the call in the application as well.
In the application, the user can click on "answer" or "hangup". When the user click on "hangup", I get this event in a handler and call Twilio.Device.disconnectAll()
to end the connection. However, the application still dialing those numbers I've mentioned above, which is the behaviour I want to change.
Edit 2: Trying to send CallSid to server and cancel the call there. Coffescript:
$('.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
I got "canceled" as a response from the action but the application keeps dialing.
r.Dial do |d|
block, first I'm dialing some numbers (for testing, only my mobile phone) and after I'm dialing the client I've just registered for the user that is logged in, withd.Client user_id
. So I believe the client you mean is my user's browser. – Gustavo Costa