princeton255 / laravel-notifications-infobip
A custom Laravel notifications channel for Infobip SMS API
Installs: 6 688
Dependents: 0
Suggesters: 0
Security: 0
Stars: 3
Watchers: 2
Forks: 3
Open Issues: 0
Requires
- php: >=7.1
- infobip/infobip-api-php-client: ^2.3
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.13
- illuminate/events: ^7.0@dev
- illuminate/notifications: ^7.0@dev
- illuminate/queue: ^7.0@dev
- illuminate/support: ^7.0@dev
- phpunit/phpunit: ^8.5@dev
This package is auto-updated.
Last update: 2022-10-11 12:45:41 UTC
README
This package makes it easy to send Sms notifications using Infobip service with Laravel 5.5 and above.
Contents
Installation
You can install the package via composer:
composer require princeton255/laravel-notifications-infobip
Setting up your Infobip account
Add your Infobip Account Username, Password, and From Number to your config/services.php
:
// config/services.php ... 'infobip' => [ 'username' => env('INFOBIP_USERNAME'), 'password' => env('INFOBIP_PASSWORD'), 'from' => env('INFOBIP_FROM', 'IBTEST'), ], ...
To change Base URL
to personal use this (See more)
... 'infobip' => [ ... 'baseUrl' => env('INFOBIP_BASE_URL', null), ], ...
Usage
Now you can use the channel in your via()
method inside the notification:
use NotificationChannels\Infobip\InfobipChannel; use NotificationChannels\Infobip\InfobipMessage; use Illuminate\Notifications\Notification; class AccountApproved extends Notification { public function via($notifiable) { return [InfobipChannel::class]; } public function toInfobip($notifiable) { return (new InfobipMessage()) ->content("Your {$notifiable->service} account was approved!"); } }
In order to let your Notification know which phone are you sending to, the channel will look for the phone_number
attribute of the Notifiable model. If you want to override this behaviour, add the routeNotificationForInfobip
method to your Notifiable model.
public function routeNotificationForInfobip() { return '+1234567890'; }
Available Message methods
InfobipMessage
from('')
: Accepts a phone to use as the notification sender.content('')
: Accepts a string value for the notification body.
Examples
Dispatching the notification
A. Using Laravel's notification facade
use App\Notifications\ExampleInfobipNotification; use Illuminate\Support\Facades\Notification; Notification::send($user, new ExampleInfobipNotification()); // where $user implements `Illuminate\Notifications\Notifiable` trait
B. Using the notify()
method from Notifiable
trait
use App\Notifications\ExampleInfobipNotification; $user->notify(new ExampleInfobipNotification($invoice));
Example Notification class
<?php namespace App\Notifications; use Illuminate\Notifications\Notification; use NotificationChannels\Infobip\InfobipChannel; use NotificationChannels\Infobip\InfobipMessage; class ExampleInfobipNotification extends Notification { public function via($notifiable) { return [InfobipChannel::class]; } public function toInfobip($notifiable) { return (new InfobipMessage()) // Customize your msg content here ->content("Your {$notifiable->service} account was approved!"); } }
Example Notifiable class
<?php namespace App\Models; use Illuminate\Foundation\Auth\User as Authenticatable; use Illuminate\Notifications\Notifiable; class User extends Authenticatable { use Notifiable; }
For more details you can check out this link on Laravel documentation
Testing
$ ./vendor/bin/phpunit
Security
If you discover any security related issues, please email princeton.mosha@gmail.com instead of using the issue tracker.
Credits
- Based on Twilio SMS Notification channel for Laravel
- This project uses the Infobip Client library, and wraps it for smooth use in Laravel
License
The MIT License (MIT).