webup / laravel-twilio-channel
Laravel's notification channel for twilio
Requires
- php: >=5.5.9
- illuminate/events: ^5.1|^6.0|^7.0|^8.0|^9.0|^10.0|^11.0
- illuminate/notifications: ^5.1|^6.0|^7.0|^8.0|^9.0|^10.0|^11.0
- illuminate/queue: ^5.1|^6.0|^7.0|^8.0|^9.0|^10.0|^11.0
- illuminate/support: ^5.1|^6.0|^7.0|^8.0|^9.0|^10.0|^11.0
- twilio/sdk: ^5.16|^6.0
Requires (Dev)
- mockery/mockery: ^0.9.5
- phpunit/phpunit: 5.*
README
This was previously the laravel-notification-channels/twilio:2.0.11
lib
This package makes it easy to send Twilio notifications with Laravel 5.3.
Contents
Installation
You can install the package via composer:
composer require webup/laravel-twilio-channel
Add the service provider (only required on Laravel 5.4 or lower):
// config/app.php 'providers' => [ ... Webup\LaravelTwilioChannel\TwilioProvider::class, ],
Setting up your Twilio account
Add your Twilio Account SID, Auth Token, and From Number (optional) to your config/services.php
:
// config/services.php ... 'twilio' => [ 'username' => env('TWILIO_USERNAME'), // optional when using auth token 'password' => env('TWILIO_PASSWORD'), // optional when using auth token 'auth_token' => env('TWILIO_AUTH_TOKEN'), // optional when using username and password 'account_sid' => env('TWILIO_ACCOUNT_SID'), 'from' => env('TWILIO_FROM'), // optional ], ...
Usage
Now you can use the channel in your via()
method inside the notification:
use Webup\LaravelTwilioChannel\TwilioChannel; use Webup\LaravelTwilioChannel\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 send an MMS:
use Webup\LaravelTwilioChannel\TwilioChannel; use Webup\LaravelTwilioChannel\TwilioMmsMessage; use Illuminate\Notifications\Notification; class AccountApproved extends Notification { public function via($notifiable) { return [TwilioChannel::class]; } public function toTwilio($notifiable) { return (new TwilioMmsMessage()) ->content("Your {$notifiable->service} account was approved!") ->mediaUrl("https://picsum.photos/300"); } }
Or create a Twilio call:
use Webup\LaravelTwilioChannel\TwilioChannel; use Webup\LaravelTwilioChannel\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, the channel will look for the phone_number
attribute of the Notifiable model. If you want to override this behaviour, add the routeNotificationForTwilio
method to your Notifiable model.
public function routeNotificationForTwilio() { return '+1234567890'; }
Available Message methods
TwilioSmsMessage
from('')
: Accepts a phone to use as the notification sender.content('')
: Accepts a string value for the notification body.
TwilioCallMessage
from('')
: Accepts a phone to use as the notification sender.url('')
: Accepts an url for the call TwiML.
Changelog
Please see CHANGELOG for more information what has changed recently.
Testing
$ composer test
Security
If you discover any security related issues, please email gregoriohc@gmail.com instead of using the issue tracker.
Contributing
Please see CONTRIBUTING for details.
Credits
License
The MIT License (MIT). Please see License File for more information.