protected function Twilio::buildIncomingFromRequest in Twilio SMS Integration 8
Validates the webhook request and creates an SMS message object.
Parameters
\Symfony\Component\HttpFoundation\Request $request The current request.:
Return value
\Drupal\sms\Message\SmsMessage The parsed message.
1 call to Twilio::buildIncomingFromRequest()
- Twilio::processIncoming in src/
Plugin/ SmsGateway/ Twilio.php - Callback for processing incoming messages.
File
- src/
Plugin/ SmsGateway/ Twilio.php, line 167
Class
- Twilio
- Plugin annotation @SmsGateway( id = "twilio", label = @Translation("Twilio"), outgoing_message_max_recipients = 1, reports_push = TRUE, incoming = TRUE, incoming_route = TRUE )
Namespace
Drupal\sms_twilio\Plugin\SmsGatewayCode
protected function buildIncomingFromRequest(Request $request) {
$result = new SmsMessageResult();
$params = $request->request
->all();
$report = (new SmsDeliveryReport())
->setRecipient($params['To'])
->setStatus(SmsMessageReportStatus::DELIVERED);
$sms = (new SmsMessage())
->setMessage(trim($params['Body']))
->setDirection(Direction::INCOMING)
->setOption('data', $params)
->setSenderNumber($params['From'])
->addRecipients([
$params['To'],
]);
if ($files = TwilioMedia::processMedia($params)) {
$sms
->setOption('media', $files);
}
if (!TwilioValidation::validateIncoming($request, $this)) {
$report
->setStatus(SmsMessageReportStatus::REJECTED);
$report
->setStatusMessage($e
->getMessage());
$result
->setError($e
->getCode());
$result
->setErrorMessage($e
->getMessage());
}
$result
->addReport($report);
$sms
->setResult($result);
return $sms;
}