This package makes it easy to send Sms notifications using Infobip service with Laravel 5.5 and above.
You can install the package via composer:
composer require caherrera/laravel-notifications-infobip
Add this settings to config/services.php
:
// config/services.php
...
'infobip' => [
'auth' => env('INFOBIP_AUTH','basic'),
'username' => env('INFOBIP_USERNAME'),
'password' => env('INFOBIP_PASSWORD'),
'baseUrl' => env('INFOBIP_BASE_URL'),
'apikey' => env('INFOBIP_PUBLIC_KEY'),
'scenarioKey' => env('INFOBIP_SCENARIO_KEY'),
],
...
To change Base URL
to personal use this (See more)
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)
{
$message = new InfobipMessage();
$message->setTemplateName("infobip_test_hsm");
$message->setTemplateNamespace("whatsapp:hsm:it:infobip");
$message->setTemplateData(["Jhon","Snow"]);
$message->setLanguage("es");
return $message;
}
}
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';
}
setTemplateName('')
: Accepts a string value.setTemplateNamespace('')
: Accepts a string value.setTemplateData(['','',...])
: Accepts an array of string.setLanguage('')
: Accepts a string value
use App\Notifications\ExampleInfobipNotification;
use Illuminate\Support\Facades\Notification;
Notification::send($user, new ExampleInfobipNotification());
// where $user implements `Illuminate\Notifications\Notifiable` trait
use App\Notifications\ExampleInfobipNotification;
$user->notify(new ExampleInfobipNotification($invoice));
<?php
namespace App\Notifications;
use Illuminate\Notifications\Notification;
use Caherrera\Laravel\Notifications\Channels\Infobip\Omni\InfobipChannel;
use Caherrera\Laravel\Notifications\Channels\Infobip\Omni\InfobipMessage;
class ExampleInfobipNotification extends Notification
{
public function via($notifiable)
{
return [InfobipChannel::class];
}
public function toInfobip($notifiable)
{
$message = new InfobipMessage();
$message->setTemplateName("infobip_test_hsm");
$message->setTemplateNamespace("whatsapp:hsm:it:infobip");
$message->setTemplateData(["Jhon","Snow"]);
$message->setLanguage("es");
return $message;
}
}
<?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
$ ./vendor/bin/phpunit
If you discover any security related issues, please help me and rise a ticket on issue tracker or simply fix it and I'll merge
- Based on Twilio SMS Notification channel for Laravel
- Based on princeton255/laravel-notifications-infobip Infobip Notifications Channel for Laravel 5.5+
- This project uses the Infobip Client library, and wraps it for smooth use in Laravel
The MIT License (MIT).