0
votes

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!

1
Is your Rails app initiating two outbound calls, or is one user starting a call to a second user?Devin Rader
This is a browser-to-browser conference call where multiple people go to a URL and are connected to each other. Here's Twilio's example: twilio.com/docs/howto/twilio-client-browser-conference-calluser1515295
@DevinRader I see that the ID/name of the conference is called "Client" in that example. I'm guessing that in a real-world example we replace that name with a unique identifier for the conference which we create on the server side. At what step in that example do we choose the unique identifier for the conference? Thanks!user1515295

1 Answers

1
votes

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 POSTed 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!