Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
CRAP | |
88.89% |
8 / 9 |
| SmsChannel | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
3.01 | |
88.89% |
8 / 9 |
| send | |
0.00% |
0 / 1 |
3.01 | |
88.89% |
8 / 9 |
|||
| 1 | <?php |
| 2 | |
| 3 | namespace AGILEDROP\LaravelTelnyx\Channels; |
| 4 | |
| 5 | use Illuminate\Notifications\Notification; |
| 6 | use Telnyx\Message; |
| 7 | use Telnyx\Telnyx; |
| 8 | |
| 9 | class SmsChannel extends BaseChannel |
| 10 | { |
| 11 | /** |
| 12 | * Send the given notification trough SMS. |
| 13 | * |
| 14 | * @param mixed $notifiable |
| 15 | * @param \Illuminate\Notifications\Notification $notification |
| 16 | * |
| 17 | * @return \Telnyx\ApiResource|void|null |
| 18 | */ |
| 19 | public function send($notifiable, Notification $notification) |
| 20 | { |
| 21 | // routeNotificationFor() has to be overridden in the user model of the app |
| 22 | if (! $to = $notifiable->routeNotificationFor('telnyx', $notification)) { |
| 23 | return; |
| 24 | } |
| 25 | |
| 26 | // toTelnyx() has to be implemented in the notification |
| 27 | $message = $notification->toTelnyx($notifiable); |
| 28 | |
| 29 | Telnyx::setApiKey(config('laravel-telnyx.api_key')); |
| 30 | |
| 31 | return Message::Create([ |
| 32 | "messaging_profile_id" => $this->profileId, |
| 33 | 'from' => $message->from ?: $this->from, |
| 34 | 'to' => $to, |
| 35 | 'text' => trim($message->content), |
| 36 | ]); |
| 37 | } |
| 38 | } |