Reputation: 1211
Problem: I'm unable to determine which of my Rails app's users are making which browser-to-browser calls using Twilio.
I am able to make browser to browser calls with Twilio and I am able to store the @call object in the Calls table like this:
def start_conference
@call = Call.create_from_twilio_params(params)
@call.user_id = current_user.id #current_user doesn't work in this Twilio request even when the user is signed into the Rails app
@call.save
end
Here are the parameters that Twilo app returns in the log when it processes a user's call: TwilioController#start_conference as HTML Parameters: {"AccountSid"=>"AC123", "ApplicationSid"=>"AP234", "Caller"=>"client:test", "CallStatus"=>"ringing", "Called"=>"", "To"=>"", "CallSid"=>"CAxyz", "From"=>"client:test", "Direction"=>"inbound", "ApiVersion"=>"2010-04-01"}
Is it possible to add my own parameters such as user_id? Or maybe there is another way for me to connect the call to the user?
From this StackOverflow question, it seems possible to attach parameters to the callback URL, but where is the Twilio documentation about specifying a custom callback URL?
Thank you!
Upvotes: 0
Views: 133
Reputation: 73055
Twilio developer evangelist here.
You can indeed pass more parameters around when making a call with Twilio Client.
When you call Twilio.Device.connect()
to make the call you can pass an object with parameters in that will get POST
ed to your controller. For example:
// In your front end code
Twilio.Device.connect({ userId: '<%= current_user.id %>' });
And then, in your controller code, you will receive that userId
in the params
and you could use it like this:
def start_conference
user_id = params.delete('userId')
@call = Call.create_from_twilio_params(params)
@call.user_id = user_id
@call.save
end
Let me know if this helps!
Upvotes: 1