tzurbaev / unisender-notifications-channel
Unisender Notifications Channel for Laravel
Requires
- php: >=7.1
- guzzlehttp/guzzle: ^6.3
- illuminate/notifications: 5.5.*
- illuminate/support: 5.5.*
Requires (Dev)
- mockery/mockery: ^1.0
- phpunit/phpunit: ^6.1
This package is auto-updated.
Last update: 2024-10-07 08:22:09 UTC
README
Requirements
This package requires PHP 7.1 or higher.
Installation
You can install the package via composer:
$ composer require tzurbaev/unisender-notifications-channel
Setting up the Unisender Service
Add Unisender API key to the config/services.php
file:
'unisender' => [ 'api-key' => 'KEY_HERE', ],
This key will be used as default key for all notifications. You can always override it for concrete notifications.
Documentation
Add UnisenderChannell::class
to notification's via
method and implement toUnisender($notifiable)
method:
<?php namespace App\Notifications; use Illuminate\Notifications\Notification; use NotificationChannels\Unisender\UnisenderChannel; use NotificationChannels\Unisender\UnisenderMessage; class SubscriptionActivatedNotification extends Notification { public function via($notifiable) { return [UnisenderChannel::class]; } public function toUnisender($notifiable) { return (new UnisenderMessage) ->from('Laravel') ->content('Your subscription is active!'); } }
Also, your Notifiable
classes must have the routeNotificationForUnisender
method, which should return single phone number (E.164 format) or list of phone numbers (comma-separated or in array).
<?php namespace App; use Illuminate\Foundation\Auth\User as Authenticatable; use Illuminate\Notifications\Notifiable; class User extends Authenticatable { use Notifiable; public function routeNotificationForUnisender() { return '+79641234567'; // or ['+79641234567', '+79831234567']; } }
Available Methods
UnisenderMessage::silent(bool $flag = true)
- sets the 'silent mode' - Channel won't throw any exception while sending SMS;UnisenderMessage::usingAccessToken($token)
- reset token only for the current message;UnisenderMessage::from(string $from)
- set the sender name;UnisenderMessage::content(string $content)
- set the message content.
Change log
Please see CHANGELOG for more information on what has changed recently.
Testing
$ vendor/bin/phpunit
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email zurbaev@gmail.com instead of using the issue tracker.
License
The MIT License (MIT). Please see License File for more information.