php - twilio dynamic voice url number? -


i'm using twlio rest api in php application make phone calls.

everything works fine should.

however, need allow users use own phone number if want.

for don't know how should proceed because current twilio voice url static url (php file xml output) has caller id within it!

i can verify numbers via rest api , add them twilio account how use numbers in application dynamically opposed adding them manually voice url page?

this voice url page:

<?php header('content-type: text/xml');  // put phone number you've verified twilio use caller id number $callerid = "+44xxxxxxxx0";  // put default twilio client name here, when phone number isn't given $number   = "michelle";  // phone number page request parameters, if given if (isset($_request['phonenumber'])) {     $number = htmlspecialchars($_request['phonenumber']); }  // wrap phone number or client name in appropriate twiml verb // checking if number given has digits , format symbols if (preg_match("/^[\d\+\-\(\) ]+$/", $number)) {     $numberorclient = "<number>" . $number . "</number>"; } else {     $numberorclient = "<client>" . $number . "</client>"; } ?>  <response>     <dial callerid="<?php echo $callerid ?>">           <?php echo $numberorclient ?>     </dial> </response>  

any appreciated.

revised

to allow user choose own caller id while making calls, we'll assume you've provided way in web ui them specify phone number can verify rest api.

once verified, save phone number user profile, represented below $userverifiedcallerid, can pass number client script.

var params = {     "phonenumber": $("#number").val(),     "verifiedcallerid": "<?php echo $userverifiedcallerid; ?>" }; twilio.device.connect(params); 

when twilio calls php script twiml handling call, twilio send verifiedcallerid parameter, can use set $callerid:

<?php header('content-type: text/xml');  // grab verfiedcallerid request $callerid = $_request['verifiedcallerid'];  ... 

now when user makes calls, own verified caller id show instead of hard-coded number.


Comments

Popular posts from this blog

javascript - oscilloscope of speaker input stops rendering after a few seconds -

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -