0

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!

4

1 回答 1

1

Twilio 开发人员布道者在这里。

在使用 Twilio Client 进行调用时,您确实可以传递更多参数。

当您调用Twilio.Device.connect()进行调用时,您可以将带有参数的对象传递POST给您的控制器。例如:

// In your front end code
Twilio.Device.connect({ userId: '<%= current_user.id %>' });

然后,在您的控制器代码中,您将收到它userIdparams您可以像这样使用它:

def start_conference
  user_id = params.delete('userId')
  @call = Call.create_from_twilio_params(params)

  @call.user_id = user_id
  @call.save
end

让我知道这是否有帮助!

于 2015-02-09T13:28:05.320 回答