You are here

public function Twilio::processIncoming in Twilio SMS Integration 8

Callback for processing incoming messages.

Parameters

\Symfony\Component\HttpFoundation\Request $request The active request.:

\Drupal\sms\Entity\SmsGatewayInterface $gateway The SMS gateway.:

Return value

\Drupal\sms\SmsProcessingResponse The processing response.

File

src/Plugin/SmsGateway/Twilio.php, line 201

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\SmsGateway

Code

public function processIncoming(Request $request, SmsGatewayInterface $sms_gateway) {
  $task = new SmsProcessingResponse();
  $sms = $this
    ->buildIncomingFromRequest($request);
  $sms
    ->setGateway($sms_gateway);

  // Replies should be handled in implementing code.
  $response = new Response();
  if ($sms
    ->getResult()
    ->getError()) {
    $response = new Response($sms
      ->getResult()
      ->getErrorMessage(), $sms
      ->getResult()
      ->getError());
  }
  $task
    ->setMessages([
    $sms,
  ]);
  $task
    ->setResponse($response);
  return $task;
}