clevyr / laravel-twilio-channel
A Laravel Notification channel for Twilio
Installs: 19 175
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 9
Forks: 0
Open Issues: 7
Requires
- php: ^8.1
- spatie/laravel-package-tools: ^1.9.2
- twilio/sdk: ^6.40
Requires (Dev)
- laravel/pint: ^1.0
- nunomaduro/collision: ^6.0
- nunomaduro/larastan: ^2.0.1
- orchestra/testbench: ^7.0
- pestphp/pest: ^1.21
- pestphp/pest-plugin-laravel: ^1.1
- phpstan/extension-installer: ^1.1
- phpstan/phpstan-deprecation-rules: ^1.0
- phpstan/phpstan-phpunit: ^1.0
- phpunit/phpunit: ^9.5
- spatie/laravel-ray: ^1.26
- dev-main
- v1.0.0
- v0.2.0
- v0.1.1
- v0.1.0
- dev-renovate/configure
- dev-dependabot/github_actions/stefanzweifel/git-auto-commit-action-5
- dev-dependabot/github_actions/actions/checkout-4
- dev-laravel-10-upgrade
- dev-dependabot/github_actions/aglipanci/laravel-pint-action-2.3.0
- dev-dependabot/github_actions/ramsey/composer-install-2
This package is auto-updated.
Last update: 2024-11-15 04:17:55 UTC
README
A Laravel Notification channel for sending SMS messages with Twilio.
Installation
You can install the package via composer:
composer require clevyr/laravel-twilio-channel
Configure an account on Twilio, and then add the following env vars:
TWILIO_SID=
TWILIO_AUTH_TOKEN=
TWILIO_PHONE_NUMBER=
Next, publish the config file with:
php artisan vendor:publish --provider="Clevyr\LaravelTwilioChannel\LaravelTwilioChannelServiceProvider"
This is the contents of the published config file (without descriptive comments):
return [ 'sid' => env('TWILIO_SID'), 'auth_token' => env('TWILIO_AUTH_TOKEN'), 'phone_number' => env('TWILIO_PHONE_NUMBER'), ];
Usage
In your Laravel notifications:
- Implement the
TwilioNotification
interface - Add the
TwilioChannel
to yourvia
return array value - Build a
toTwilio
function that returns aTwilioMessage
object
By default, the Twilio Channel will use your notifiable's phone_number
field
to send a phone number, which must be in a format such as 18884445555
. See
below how to override this.
<?php namespace App\Notifications; use Clevyr\LaravelTwilioChannel\Channels\TwilioChannel; use Clevyr\LaravelTwilioChannel\Contracts\TwilioNotification; use Clevyr\LaravelTwilioChannel\Messages\TwilioMessage; use Illuminate\Notifications\Notification; class MyNotification extends Notification implements TwilioNotification { /** * Get the notification's delivery channels. * * @param mixed $notifiable * @return array */ public function via($notifiable) { return [TwilioChannel::class]; } /** * Get the twilio representation of the notification. * * @param mixed $notifiable * @return \Clevyr\LaravelTwilioChannel\Messages\TwilioMessage */ public function toTwilio($notifiable) { return (new TwilioMessage) ->line('Your first line.') ->line('A second line, with a break between the last line.'); }
Overriding the Notifiable Phone Number Field
By default, TwilioChannel
will use your notifiable's phone_number
field
to send an SMS message. To override this and use a different field, set the
twilioPhoneNumberField
instance variable in your notifiable class:
class User extends Authenticatable { public $twilioPhoneNumberField = 'primary_phone_number'; // } Now if you generate a notification from a `User` object, `TwilioChannel` will use the user's `primary_phone_number` field to send messages.
Testing
composer test
Linting
composer analyse
Formatting w/ Laravel Pint
composer format
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.