You are here

public function TwilioController::receiveVoice in Twilio 8

Handle incoming voice requests.

@todo Needs Work.

1 string reference to 'TwilioController::receiveVoice'
twilio.routing.yml in ./twilio.routing.yml
twilio.routing.yml

File

src/Controller/TwilioController.php, line 52

Class

TwilioController
Default controller for the twilio module.

Namespace

Drupal\twilio\Controller

Code

public function receiveVoice() {
  if (!empty($_REQUEST['From']) && twilio_command('validate', [
    'type' => 'voice',
  ])) {
    $number = SafeMarkup::checkPlain(str_replace('+1', '', $_REQUEST['From']));
    $number_twilio = !empty($_REQUEST['To']) ? SafeMarkup::checkPlain(str_replace('+', '', $_REQUEST['To'])) : '';
    $options = [];
    if (!empty($_REQUEST['To'])) {
      $options['receiver'] = SafeMarkup::checkPlain($_REQUEST['To']);
    }
    $this
      ->logger('Twilio')
      ->notice('A voice call from @number was received.', [
      '@number' => $number,
    ]);
    $this
      ->voiceIncoming($number, $number_twilio, $options);
  }
}