function sms_twilio_incoming in Twilio SMS Integration 7
Same name and namespace in other branches
- 6 sms_twilio.module \sms_twilio_incoming()
- 7.2 sms_twilio.module \sms_twilio_incoming()
Informs the SMS Framework of the incoming SMS
1 string reference to 'sms_twilio_incoming'
- sms_twilio_menu in ./
sms_twilio.module - Implements hook_menu().
File
- ./
sms_twilio.module, line 204 - Adds support for sending SMS messages using the Twilio gateway.
Code
function sms_twilio_incoming() {
global $base_url;
if (isset($_REQUEST['From']) and isset($_REQUEST['To']) and isset($_REQUEST['FromCountry']) and isset($_REQUEST['FromCity']) and isset($_REQUEST['FromState']) and isset($_REQUEST['FromZip'])) {
// Details on validating the Twilio signature: http://www.twilio.com/docs/security
$gateway = sms_gateways('gateway', 'twilio');
$config = $gateway['configuration'];
$string_to_sign = $base_url . "/sms/twilio/incoming";
ksort($_POST);
foreach ($_POST as $key => $value) {
$string_to_sign .= $key . $value;
}
$sig = base64_encode(hash_hmac("sha1", $string_to_sign, $config['sms_twilio_api_auth_token'], TRUE));
$from = $_REQUEST['From'];
$body = $_REQUEST['Body'];
if (strcmp($_SERVER["HTTP_X_TWILIO_SIGNATURE"], $sig) != 0) {
watchdog('sms_twilio', 'Incoming sms from @from has a bad Twilio signature - dropping!', array(
'@from' => $from,
), WATCHDOG_WARNING);
}
else {
// watchdog('sms_twilio', 'Handling incoming sms from '.$from.': '.$body);
$opts = array();
$opts['to'] = $_REQUEST['To'];
$opts['fromcountry'] = $_REQUEST['FromCountry'];
$opts['fromcity'] = $_REQUEST['FromCity'];
$opts['fromstate'] = $_REQUEST['FromState'];
$opts['fromzip'] = $_REQUEST['FromZip'];
sms_incoming($from, $body, $opts);
}
}
}