Skip to content

Instantly share code, notes, and snippets.

@tjlytle
Created May 7, 2018 13:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tjlytle/c9af6260aa27250c1ae3429dd2a40efe to your computer and use it in GitHub Desktop.
Save tjlytle/c9af6260aa27250c1ae3429dd2a40efe to your computer and use it in GitHub Desktop.
<?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