Created
October 3, 2021 14:21
-
-
Save ochui/a9d402695f5fea9772774622b88e0707 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 | |
function get_caller_id( $phone_number ) { | |
// Your Signalwire project id | |
$project_id = ''; | |
// Your signalwire API Auth Token | |
$auth_token = ''; | |
// Your signalwire Space URL | |
$space_url = ''; | |
$ch = curl_init(); | |
curl_setopt( $ch, CURLOPT_URL, "https://$space_url/api/relay/rest/lookup/phone_number/$phone_number?include=cnam" ); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | |
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET'); | |
curl_setopt( $ch, CURLOPT_USERPWD, "$project_id" . ':' . "$auth_token" ); | |
$get_response = curl_exec( $ch ); | |
if ( curl_errno( $ch ) ) { | |
echo 'Error:' . curl_error( $ch ); | |
} | |
$phone_number_data = json_decode( $get_response, true ); | |
$phone_number_cnam_data = $phone_number_data['cnam']; // now you have all info about the number | |
// you can get the number type like so | |
return $phone_number_cnam_data['caller_id']; | |
} | |
// use function | |
$caller_id = get_caller_id( '+1xxxxxxxxxx'); // this function returns an array | |
echo $caller_id; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment