function twilio_receive_message in Twilio 7
Callback for incoming messages.
1 string reference to 'twilio_receive_message'
- twilio_menu in ./
twilio.module - Implements hook_menu().
File
- ./
twilio.module, line 290 - Twilio module
Code
function twilio_receive_message() {
if (!empty($_REQUEST['From']) && !empty($_REQUEST['Body']) && !empty($_REQUEST['ToCountry']) && twilio_command('validate')) {
$codes = twilio_country_codes();
$message_code = twilio_get_country_short_codes($_REQUEST['ToCountry']);
if (empty($codes[$message_code])) {
watchdog('Twilio', 'A message was blocked from the country @country, due to your currrent country code settings.', array(
'@country' => $_REQUEST['ToCountry'],
));
return;
}
$number = check_plain(str_replace('+' . $message_code, '', $_REQUEST['From']));
$number_twilio = !empty($_REQUEST['To']) ? check_plain(str_replace('+', '', $_REQUEST['To'])) : '';
$message = check_plain(htmlspecialchars_decode($_REQUEST['Body'], ENT_QUOTES));
// @todo: Support more than one media entry.
$media = !empty($_REQUEST['MediaUrl0']) ? $_REQUEST['MediaUrl0'] : '';
$options = array();
// Add the receiver to the options array.
if (!empty($_REQUEST['To'])) {
$options['receiver'] = check_plain($_REQUEST['To']);
}
watchdog('Twilio', 'An SMS message was sent from @number containing the message "@message"', array(
'@number' => $number,
'@message' => $message,
));
twilio_sms_incoming($number, $number_twilio, $message, $media, $options);
}
}