You are here

protected function AccountRegistration::sendReply in SMS Framework 8

Same name and namespace in other branches
  1. 2.x modules/sms_user/src/AccountRegistration.php \Drupal\sms_user\AccountRegistration::sendReply()
  2. 2.1.x modules/sms_user/src/AccountRegistration.php \Drupal\sms_user\AccountRegistration::sendReply()

Send a reply message to the sender of a message.

Parameters

string $sender_number: Phone number of sender of incoming message. And if a user was created, this number was used.

\Drupal\user\UserInterface $user: A user account. The account may not be saved.

string $message: Message to send as a reply.

2 calls to AccountRegistration::sendReply()
AccountRegistration::allUnknownNumbers in modules/sms_user/src/AccountRegistration.php
Process incoming message and create a user if the phone number is unknown.
AccountRegistration::incomingPatternMessage in modules/sms_user/src/AccountRegistration.php
Creates a user if an incoming message contents matches a pattern.

File

modules/sms_user/src/AccountRegistration.php, line 238

Class

AccountRegistration
Defines the account registration service.

Namespace

Drupal\sms_user

Code

protected function sendReply($sender_number, UserInterface $user, $message) {
  $sms_message = SmsMessage::create();
  $sms_message
    ->addRecipient($sender_number)
    ->setDirection(Direction::OUTGOING);
  $data['sms-message'] = $sms_message;
  $data['user'] = $user;
  $sms_message
    ->setMessage($this->token
    ->replace($message, $data));

  // Use queue(), instead of phone number provider sendMessage()
  // because the phone number is not confirmed.
  try {
    $this->smsProvider
      ->queue($sms_message);
  } catch (\Exception $e) {
    $t_args['%recipient'] = $sender_number;
    $t_args['%error'] = $e
      ->getMessage();
    \Drupal::logger('sms_user.account_registration.incoming_pattern')
      ->warning('Reply message could not be sent to recipient %recipient: %error', $t_args);
  }
}