Skip to content

Instantly share code, notes, and snippets.

@negeorge
Last active February 22, 2021 22:40
Show Gist options
  • Save negeorge/4409457 to your computer and use it in GitHub Desktop.
Save negeorge/4409457 to your computer and use it in GitHub Desktop.
<?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