%PDF- %GIF98; %PNG;
Server : ApacheSystem : Linux host.digitalbabaji.in 4.18.0-513.11.1.el8_9.x86_64 #1 SMP Wed Jan 17 02:00:40 EST 2024 x86_64 User : addictionfreeind ( 1003) PHP Version : 7.2.34 Disable Function : exec,passthru,shell_exec,system Directory : /home/addictionfreeind/www/admin1/vendor/laravel-notification-channels/twilio/src/ |
Upload File : |
<?php
namespace NotificationChannels\Twilio;
use Exception;
use Illuminate\Contracts\Events\Dispatcher;
use Illuminate\Notifications\Events\NotificationFailed;
use Illuminate\Notifications\Notification;
use NotificationChannels\Twilio\Exceptions\CouldNotSendNotification;
class TwilioChannel
{
/**
* @var Twilio
*/
protected $twilio;
/**
* @var Dispatcher
*/
protected $events;
/**
* TwilioChannel constructor.
*
* @param Twilio $twilio
* @param Dispatcher $events
*/
public function __construct(Twilio $twilio, Dispatcher $events)
{
$this->twilio = $twilio;
$this->events = $events;
}
/**
* Send the given notification.
*
* @param mixed $notifiable
* @param Notification $notification
*
* @return mixed
* @throws Exception
*/
public function send($notifiable, Notification $notification)
{
try {
$to = $this->getTo($notifiable, $notification);
$message = $notification->toTwilio($notifiable);
$useSender = $this->canReceiveAlphanumericSender($notifiable);
if (is_string($message)) {
$message = new TwilioSmsMessage($message);
}
if (! $message instanceof TwilioMessage) {
throw CouldNotSendNotification::invalidMessageObject($message);
}
return $this->twilio->sendMessage($message, $to, $useSender);
} catch (Exception $exception) {
$event = new NotificationFailed(
$notifiable,
$notification,
'twilio',
['message' => $exception->getMessage(), 'exception' => $exception]
);
$this->events->dispatch($event);
if ($this->twilio->config->isIgnoredErrorCode($exception->getCode())) {
return;
}
throw $exception;
}
}
/**
* Get the address to send a notification to.
*
* @param mixed $notifiable
* @param Notification|null $notification
*
* @return mixed
* @throws CouldNotSendNotification
*/
protected function getTo($notifiable, $notification = null)
{
if ($notifiable->routeNotificationFor(self::class, $notification)) {
return $notifiable->routeNotificationFor(self::class, $notification);
}
if ($notifiable->routeNotificationFor('twilio', $notification)) {
return $notifiable->routeNotificationFor('twilio', $notification);
}
if (isset($notifiable->phone_number)) {
return $notifiable->phone_number;
}
throw CouldNotSendNotification::invalidReceiver();
}
/**
* Get the alphanumeric sender.
*
* @param $notifiable
*
* @return mixed|null
* @throws CouldNotSendNotification
*/
protected function canReceiveAlphanumericSender($notifiable)
{
return method_exists($notifiable, 'canReceiveAlphanumericSender') &&
$notifiable->canReceiveAlphanumericSender();
}
}