-
Initiate outbound calls to 15551112222 and to 15553334444 using the Twilio REST API
-
Set the Voice Request URL to:
-
The call that is connected first will request this URL and the caller will hear the message "Twilio is fun" read to them via TwiML. The script will then hangup on all the other ringing calls.
Last active
February 22, 2021 22:40
-
-
Save negeorge/4409457 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
$base_url = "http://example.com/call.php"; | |
//log file if needed | |
//file_put_contents("call.log", print_r($_REQUEST, true), FILE_APPEND); | |
require 'twilio-php/Services/Twilio.php'; | |
// initiate response library | |
$response = new Services_Twilio_Twiml; | |
// if PhoneNumbers isn't an array, make it one | |
if(!is_array($_REQUEST['PhoneNumbers'])) | |
$_REQUEST['PhoneNumbers'] = array($_REQUEST['PhoneNumbers']); | |
// remove empty entries from PhoneNumbers | |
$_REQUEST['PhoneNumbers'] = array_filter($_REQUEST['PhoneNumbers']); | |
// Tell the person who picked up the message | |
$response->say($_REQUEST['Message']); | |
print $response; | |
/* Now hang up on all of the other slow-pokes */ | |
$client = new Services_Twilio('Accountsid', 'Authtoken'); | |
$calls = $client->account->calls->getIterator(0, 50, array('Status' => 'ringing')); | |
foreach ($calls as $call) { | |
foreach ($_REQUEST['PhoneNumbers'] as $num) { | |
if ($call->to == $num) { | |
$call->hangup(); | |
} | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment