-
Notifications
You must be signed in to change notification settings - Fork 13
/
config.php
34 lines (30 loc) · 1.07 KB
/
config.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<?php
require "twilio.php";
require "db.php";
define('AGENT_NUMBER', 'NNNNNNNNNN'); //set this to the phone number you'd like calls forwarded to
$ApiVersion = "2010-04-01";
$AccountSid = "ACxxxxx";
$AuthToken = "xxxxxxxx";
function format_phone($phone)
{
$phone = preg_replace("/[^0-9]/", "", $phone);
if(strlen($phone) == 7)
return preg_replace("/([0-9]{3})([0-9]{4})/", "$1-$2", $phone);
elseif(strlen($phone) == 10)
return preg_replace("/([0-9]{3})([0-9]{3})([0-9]{4})/", "($1) $2-$3", $phone);
else
return $phone;
}
class Util {
public static function get_all_twilio_numbers() {
global $ApiVersion, $AccountSid, $AuthToken;
$twilio_numbers=array();
$client = new TwilioRestClient($AccountSid, $AuthToken);
$response = $client->request("/$ApiVersion/Accounts/$AccountSid/IncomingPhoneNumbers", "GET"); // Get all twilio phone numbers
foreach($response->ResponseXml->IncomingPhoneNumbers->IncomingPhoneNumber AS $number){
$twilio_numbers[format_phone($number->PhoneNumber)]=$number->FriendlyName;
}
return $twilio_numbers;
}
}
?>