zgabievi / laravel-sender
SENDER.GE Integration for Laravel
Installs: 247
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Type:project
Requires
- php: ^7.2
- bensampo/laravel-enum: ^1.38|^2.1|^3.0
- illuminate/config: ^6.0|^7.0|^8.0
- illuminate/support: ^6.0|^7.0|^8.0
README
Table of Contents
Installation
To get started, you need to install package:
composer require zgabievi/laravel-sender
If your laravel version is older than 5.5, then add this to your service providers in config/app.php:
'providers' => [ ... Zorb\Sender\SenderServiceProvider::class, ... ];
You can publish config file using this command:
php artisan vendor:publish --provider="Zorb\Sender\SenderServiceProvider"
This command will copy config file in your config directory.
Usage
Send Message
use Zorb\Sender\Enums\MessageStatus; use Zorb\Sender\Enums\MessageType; use Zorb\Sender\Facades\Sender; class SenderController extends Controller { // public function __invoke() { // recipient who should get sms $mobile_number = '5XXXXXXXX'; // content of the message $message = 'Welcome, you are getting this message from integration'; // type of the message $type = MessageType::Advertising; // MessageType::Information $result = Sender::send($mobile_number, $message, $type); if (isset($result->data[0])) { // $result->data[0]->messageId // $result->data[0]->statusId if ((int)$result->data[0]->statusId === MessageStatus::Delivered) { // message has been sent } } else { // message was not sent } } }
Check Status
use Zorb\Sender\Enums\MessageStatus; use Zorb\Sender\Facades\Sender; class SenderController extends Controller { // public function __invoke() { // message id provided by send method $message_id = 0000; $result = Sender::check($message_id); if (isset($result->data[0])) { // $result->data[0]->messageId // $result->data[0]->statusId // $result->data[0]->timestamp if ((int)$result->data[0]->statusId === MessageStatus::Delivered) { // message has been delivered } } else { // message status check failed } } }
Notification
You can use this package as notification channel.
use Illuminate\Notifications\Notification; use Zorb\Sender\Notifications\SMSMessage; use Zorb\Sender\Channels\SenderChannel; use Illuminate\Support\Facades\Log; class WelcomeNotification extends Notification { // public function via($notifiable) { return [SenderChannel::class]; } // public function toSender($notifiable): SMSMessage { return (new SMSMessage()) ->content('Your message goes here.') ->recipient($notifiable->phone) ->callback(function ($response) { // optional // use response here }); } }
Additional Information
MessageType
Message types has its own enum Zorb\Sender\Enums\MessageType
MessageStatus
Message statuses has its own enum Zorb\Sender\Enums\MessageStatus
Configuration
You can configure environment file with following variables:
License
zgabievi/laravel-sender is licensed under a MIT License.