You are here

function mobile_number_send_sms in Mobile Number 8

Same name and namespace in other branches
  1. 7 mobile_number.module \mobile_number_send_sms()
  2. 2.0.x mobile_number.module \mobile_number_send_sms()

Sms framework integration, send sms callback.

Parameters

string $number: E.164 Number.

string $message: The Message.

Return value

bool Send status.

1 string reference to 'mobile_number_send_sms'
MobileNumberUtil::smsCallback in src/MobileNumberUtil.php
Gets sms callback for sending SMS's. The callback should accept $number and $message, and returns status booleans.

File

./mobile_number.module, line 38
mobile_number.module

Code

function mobile_number_send_sms($number, $message) {

  /** @var \Drupal\sms\Provider\DefaultSmsProvider $sms_provider */
  $sms_provider = \Drupal::service('sms.provider');
  try {
    $sms_message = new SmsMessage(NULL, [
      $number,
    ], $message);

    /** @var \Drupal\sms\Message\SmsMessageResultInterface $result */
    $result = $sms_provider
      ->send($sms_message)[0];
    return $result
      ->getResult()
      ->getReport($number)
      ->getStatus();
  } catch (RecipientRouteException $e) {
    return FALSE;
  }
}