Created
May 7, 2018 13:28
-
-
Save tjlytle/c9af6260aa27250c1ae3429dd2a40efe 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 | |
if (!isset($_POST['msisdn'], $_POST['to'], $_POST['text'])) { | |
return; // not a nexmo request | |
} | |
if ("yes" === strtolower(substr($_POST['text'], 0, 3))) { | |
// here's where you need to do something to store the inbound phone number | |
error_log('got message from: ' . $_POST['msisdn']); | |
// reply with the message (this is a bit hacky, but should work anywhere) | |
$data = [ | |
'api_key' => NEXMO_KEY, | |
'api_secret' => NEXMO_SECRET, | |
'from' => $_POST['to'], // simple way to use the same code for multiple numbers | |
'to' => $_POST['msisdn'], | |
'text' => "Here's a link: http://example.com" | |
]; | |
$url = "https://rest.nexmo.com/sms/json?" . http_build_query($data); | |
$response = file_get_contents($url); | |
$response = json_decode($response, true); | |
if ("0" === $response['status']){ | |
error_log('sent reply'); | |
} else { | |
error_log('could not send reply, status: ' . $response['status']); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment