This package makes it easy to send Twilio notifications with Laravel 5.3.
You can install the package via composer:
composer require laravel-notification-channels/twilioYou must install the service provider:
// config/app.php
'providers' => [
...
NotificationChannels\Twilio\TwilioProvider::class,
];Add your Twilio Account SID, Auth Token, and From Number (optional) to your config/services.php:
// config/services.php
'twilio' => [
'account_sid' => env('TWILIO_ACCOUNT_SID'),
'auth_token' => env('TWILIO_AUTH_TOKEN'),
'from' => env('TWILIO_FROM'), // optional
]Now you can use the channel in your via() method inside the notification:
use NotificationChannels\Twilio\TwilioChannel;
use NotificationChannels\Twilio\TwilioSmsMessage;
use Illuminate\Notifications\Notification;
class AccountApproved extends Notification
{
public function via($notifiable)
{
return [TwilioChannel::class];
}
public function toTwilio($notifiable)
{
return (new TwilioSmsMessage())
->content("Your {$notifiable->service} account was approved!");
}
}You can also create a Twilio call:
use NotificationChannels\Twilio\TwilioChannel;
use NotificationChannels\Twilio\TwilioCallMessage;
use Illuminate\Notifications\Notification;
class AccountApproved extends Notification
{
public function via($notifiable)
{
return [TwilioChannel::class];
}
public function toTwilio($notifiable)
{
return (new TwilioCallMessage())
->url("http://example.com/your-twiml-url");
}
}In order to let your Notification know which phone are you sending/calling to, add the routeNotificationForTwilio method to your Notifiable model.
public function routeNotificationForTwilio()
{
return '+1234567890';
}from(''): Accepts a phone to use as the notification sender.content(''): Accepts a string value for the notification body.
from(''): Accepts a phone to use as the notification sender.url(''): Accepts an url for the call TwiML.
Please see CHANGELOG for more information what has changed recently.
$ composer testIf you discover any security related issues, please email [email protected] instead of using the issue tracker.
Please see CONTRIBUTING for details.
The MIT License (MIT). Please see License File for more information.