Created
October 2, 2022 15:59
-
-
Save pamjadz/8f229a3da8ab052425eda91a314dbe31 to your computer and use it in GitHub Desktop.
Twilio Wordpress Send SMS API
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
function twilioSendSMS($params = [], $endpoint = 'Messages.json'){ | |
$sid = 'SID HERE'; | |
$token = 'TOKEN HERE'; | |
$request = wp_remote_get("https://api.twilio.com/2010-04-01/Accounts/{$sid}/{$endpoint}", [ | |
'headers' => [ | |
'Authorization' => 'Basic ' . base64_encode($sid . ':' . $token), | |
'Content-Type' => 'application/x-www-form-urlencoded;charset=UTF-8', | |
], | |
'body' => $params | |
]); | |
if( is_wp_error($request) ){ | |
return wp_send_json(json_encode([ | |
'status' => -1000, | |
'code' => $request->get_error_code(), | |
'message' => $request->get_error_message() | |
])); | |
} else { | |
return wp_send_json(wp_remote_retrieve_body($request)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment