Skip to content

Instantly share code, notes, and snippets.

@tjlytle
Created May 7, 2018 13:30
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/0e2699867d662b46d49b3351b37ce3f5 to your computer and use it in GitHub Desktop.
Save tjlytle/0e2699867d662b46d49b3351b37ce3f5 to your computer and use it in GitHub Desktop.
<?php
require_once __DIR__ . '/vendor/autoload.php';
$client = new \Nexmo\Client(new \Nexmo\Client\Credentials\Basic(NEXMO_KEY, NEXMO_SECRET));
try {
$inbound = \Nexmo\Message\InboundMessage::createFromGlobals();
} catch (Exception $e) {
error_log('could not parse inbound message');
}
// here's where you need to do something to store the inbound phone number
error_log('got message from: ' . $inbound->getFrom());
if ('yes' === strtolower(substr($inbound->getBody(), 0, 3))) {
$reply = $inbound->createReply("Here's a link: http://example.com");
}
// perhaps other keywords
if (!isset($reply)) {
return;
}
try {
$client->message()->send($reply);
} catch (Exception $e) {
error_log('could not send reply: ' . $e->getMessage());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment