/** * Handle SMS from Nexmo */ public function action_reply() { include_once Kohana::find_file('vendor', 'nexmo/NexmoMessage'); // Pong Sender $ip_address = $_SERVER["REMOTE_ADDR"]; $continue = FALSE; foreach ($this->subnets as $subnet) { if ($this->_ip_in_range($ip_address, $subnet)) { throw HTTP_Exception::factory(403, 'IP Address not in allowed range'); break; } } $provider = DataProvider::factory('nexmo'); $options = $provider->options(); if (!isset($options['api_key'])) { throw HTTP_Exception::factory(403, 'Missing API key'); } if (!isset($options['api_secret'])) { throw HTTP_Exception::factory(403, 'Missing API secret'); } $sms = new NexmoMessage($options['api_key'], $options['api_secret']); if (!$sms->inboundText()) { throw HTTP_Exception::factory(400, "Invalid message"); } // Remove Non-Numeric characters because that's what the DB has $to = preg_replace("/[^0-9,.]/", "", $sms->to); $from = preg_replace("/[^0-9,.]/", "", $sms->from); $provider->receive(Message_Type::SMS, $from, $sms->text, $to, NULL, $sms->message_id); }
<?php include "lib/NexmoMessage.php"; $msg = new NexmoMessage('6e4d6866', '2af8f65e'); $txt = $msg->inboundText(); echo $txt;
/** * Handle SMS from Nexmo */ public function action_reply() { include_once Kohana::find_file('vendor', 'nexmo/NexmoMessage'); //Check if data provider is available $providers_available = Kohana::$config->load('features.data-providers'); if (!$providers_available['nexmo']) { throw HTTP_Exception::factory(403, 'The Nexmo data source is not currently available. It can be accessed by upgrading to a higher Ushahidi tier.'); } // Pong Sender $ip_address = $_SERVER["REMOTE_ADDR"]; $continue = FALSE; foreach ($this->subnets as $subnet) { if ($this->_ip_in_range($ip_address, $subnet)) { throw HTTP_Exception::factory(403, 'IP Address not in allowed range'); break; } } $provider = DataProvider::factory('nexmo'); $options = $provider->options(); if (!isset($options['api_key'])) { throw HTTP_Exception::factory(403, 'Missing API key'); } if (!isset($options['api_secret'])) { throw HTTP_Exception::factory(403, 'Missing API secret'); } $sms = new NexmoMessage($options['api_key'], $options['api_secret']); if (!$sms->inboundText()) { throw HTTP_Exception::factory(400, "Invalid message"); } // Remove Non-Numeric characters because that's what the DB has $to = preg_replace("/[^0-9,.]/", "", $sms->to); $from = preg_replace("/[^0-9,.]/", "", $sms->from); $provider->receive(Message_Type::SMS, $from, $sms->text, $to, NULL, $sms->message_id); }
<?php include "NexmoMessage.php"; $sms = new NexmoMessage(getenv('key'), getenv('secret')); if ($sms->inboundText()) { // database details $con = mysql_connect(getenv('MYSQL_DB_HOST'), getenv('MYSQL_USERNAME'), getenv('MYSQL_PASSWORD')); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db(getenv('MYSQL_DB_NAME'), $con); $text = trim($sms->text); // new poll if (strcasecmp($text, 'ask') == 0) { // Create new poll and text user function createPoll($sms) { mysql_query("INSERT INTO Poll (phone, isActive) VALUES ('{$sms->from}', 1)"); $id = mysql_insert_id(); $sms->reply("You've asked a new poll! Tell others to text '{$id} [letter of choice]' to 305-222-7004 to vote. Reply 'TALLY {$id}' to stop this poll and get results."); } // Find this user $result = mysql_query("SELECT remaining FROM Person WHERE phone = {$sms->from}"); if (mysql_num_rows($result) == 0) { // This is a new, unrecognized user. Create a user account for them. mysql_query("INSERT INTO Person (phone, remaining) VALUES ('{$sms->from}', 49)"); createPoll($sms); } else { // User found $row = mysql_fetch_assoc($result); $remaining = $row['remaining'];