Reputation: 11
In order to make outbound call from browser, I followed "https://www.twilio.com/docs/quickstart/php/client/outgoing-calls" link, and now I can make outbound browser call to a particular number(Which hardcoded behind).
But If I am entering a number in the text-field, to make call to this number, then how can I do this? Please help me.
for your reference I have attached the screen-shot.
Thanks
Upvotes: 0
Views: 62
Reputation: 10366
Twilio evangelist here.
The Outgoing Calls sample code already includes the client side JavaScript to grab a phone number from an input field in the webpage and include it as a parameter in the connect()
function:
function call() {
// get the phone number to connect the call to
params = {"PhoneNumber": $("#number").val()};
Twilio.Device.connect(params);
}
Specifically this code: $("#number").val()
gets the value from an input field named number
.
One the server side, Twilio will take the collection of parameters that you provide to the connect
function and forward those to the URL you have specified as your TwiML Application URL as simple form-encoded values. You can use PHP's $_REQUEST
global function to grab those and dynamically generate a TwiML response:
<?php
if (isset($_REQUEST['PhoneNumber'])) {
$number = htmlspecialchars($_REQUEST['PhoneNumber']);
}
?>
<Response>
<Dial callerId="+15555555555">
<?php echo $numberOrClient ?>
</Dial>
</Response>
Hope that helps.
Upvotes: 0