1

The Twilio JS library has a function called Twilio.Device.connect() which takes params. In the documentation it says these params get sent to the server, but it never specifies which server endpoint it goes to or how to set this up. https://www.twilio.com/docs/client/device

Can anybody explain?

GameDroids
  • 5,584
  • 6
  • 40
  • 59
user2158382
  • 4,430
  • 12
  • 55
  • 97

2 Answers2

2

Twilio evangelist here.

The parameters get converted into form encoded values and included in the HTTP request that is made to the URL configured for your TwiML App.

So for example, if you include parameters like this:

params = {"PhoneNumber": "+15555555555"};
Twilio.Device.connect(params);

they will get converted into this set of form encoded values and included in the POST request Twilio makes to your Twiml Apps Voice URL:

PhoneNumber=+15555555555

You can use whatever mechanism in your server side framework that exposes form values to grab those parameters and use them to generate and return TwiML. For example, in PHP:

$phoneNumber = $_REQUEST["PhoneNumber"];

Hope that helps.

Megan Speir
  • 3,745
  • 1
  • 15
  • 25
Devin Rader
  • 10,260
  • 1
  • 20
  • 32
  • How do you set Record the calls param? I tried with var params = { To: document.getElementById('phone-number').value, Record:true }; That did not work – HaBo Feb 16 '19 at 20:27
0

Twilio provide web-hook for different events like when call initiated, ringing, completed etc, so you can get your custom parameter from web-hook ,

For Example Lets suppose you want channelId in server side, so First create one GET/POST API and assign to statusCallback url like in TwiML Bin

<Client 
  statusCallbackEvent='initiated ringing answered completed'
  statusCallbackMethod= "GET" statusCallback="https://{{SERVER_ENDPOINT}}/twilio/peer-to-peer-call/{{channelId}}" >
  {{To}}
</Client>

Now you can retrieve channelId as request params or request query in your server

Om Prakash Sharma
  • 1,682
  • 22
  • 13