-
-
Save jaboutboul/8bb0f321ce0a253f8517 to your computer and use it in GitHub Desktop.
Twilio Example: Anonymously Connecting Two Callers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//Include the Twilio PHP Helper Library | |
include "Services/Twilio.php"; | |
//Set the variables for out accountSID and authToken | |
$account_sid = ""; | |
$auth_token = ""; | |
//Set our outgoing caller id as our Twilio number | |
$your_twilio_number = ""; | |
//Assign the phone number of the first participant | |
$participant1 = ""; | |
//Define a new object to interact with the API. Give it out Account SID and Auth Token | |
$client = new Services_Twilio($account_sid, $auth_token); | |
//Make the call to the first participant using the Twilio API. Once answered, the call flow will go to the url we are passing in | |
$call = $client->account->calls->create( | |
$your_twilio_number, | |
$participant1, | |
'http://example.com/secondleg.php' | |
); | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//Set our header so that we return TwiML | |
header("Content-type: text/xml"); | |
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; | |
//Set our outgoing caller id as our Twilio number | |
$your_twilio_number = ""; | |
//Assign the phone number of the second participant | |
$participant2 = ""; | |
//Below we return our TwiML telling our call flow to now dial the second participant, connecting both participants. | |
?> | |
<Response> | |
<Dial callerId="<?php echo "$your_twilio_number";?>"><Number> | |
<?php echo "$participant2";?> | |
</Number></Dial> | |
</Response> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
There are two files here, firstleg.php and second leg.php. They way they work is as follows:
The first participant will hear the call connecting and once the second picks up, they will be able to speak to each other, each seeing our Twilio number as the caller ID and not the other party.