tnchalise
tnchalise

Reputation: 1583

How to make browser-phone call with twilio

i am currently stacked with twilio client call where i have to call a user from browser. Lets see the scenario.

start snippet:

include 'twilio/Services/Twilio/Capability.php';
include 'twilio/Services/Twilio.php';

$accountSid = 'ACxxxxxxxxxxxxxxx';
$authToken  = 'xxxxxxxxxxxxxxxxx';

$token = new Services_Twilio_Capability($accountSid, $authToken);
$token->allowClientOutgoing('APXXXXXXXXXXX');

$client = new Services_Twilio($accountSid, $authToken);
$call = $client->account->calls->create("twilio Number", "client number", "https://www.mysite.com/twilio/callback", array());

And my call back goes like this:

function callback(){
$xml = "<Response><Say>Placing your call now.</Say><Dial callerId='twilio verified number' timeout='40' record='true'></Dial></Response>";
        header("content-type: text/xml");
        echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" . $xml;
        exit();
}

I dont know what exactly the $from, $to parameters with in the calls->create() function takes. If we are initially initiating the call to $to then, it should work. My requirement is to call a client to client number from my browser. Yes, i see the referencees here but stacked again.

Upvotes: 1

Views: 4415

Answers (2)

Devin Rader
Devin Rader

Reputation: 10366

Twilio evangelist here.

Looks like your current code is using the REST library to initiate the call. This send a message to Twilio to initiate a phone call from Twilio to some phone. All of that happens on the server, not in the browser.

In your case it sounds like you want to actually make a phone call right from the browser. To do that you need to use Twilio Client, which is a JavaScript framework that lets you create an audio connection from a browser to Twilio, and the connection is made using WebRTC (or Flash if needed). Its the job of the Twilio Client SDK to figure out how to create and manage the actual audio connection between your browser and Twilio.

http://www.twilio.com/client

https://www.twilio.com/docs/tutorials/walkthrough/browser-calls/php/laravel

This is different than initiating a call using the REST API. When you initiate an outbound call using the REST API, the API does not actually manage the audio connection. Your using the API simply to tell Twilio to initiate a phone call between Twilio and a phone (or to send a text message), or to ask Twilio for information (like getting list of send SMS messages). The management of the actual audio connection is handled by Twilios internal systems.

The first part of your PHP code is correct you need to create a Twilio Capability token. That token is used by our JavaScript library. This tutorial shows the JavaScript code that you can use to make a call from your browser to Twilio:

https://www.twilio.com/docs/tutorials/walkthrough/browser-calls/php/laravel

Once the browser connects to Twilio, Twilio will make a request to the URL you've set on your TwiML App (the string starting with "AP" that you specified when you created the capability token). You can return whatever TwiML you like from this URL, including using the <Dial> very to tell Twilio to bridge the Twilio Client connection into a <Conference>.

Hope that helps.

Devin

Upvotes: 2

Roger
Roger

Reputation: 2953

This will be helpful. If you look through the code, there is some api (i think callFromBrowser()) which does the trick.

Upvotes: 0

Related Questions