alif / alif-sms-notification
Installs: 42
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 1
Forks: 2
Open Issues: 0
Type:package
Requires
- php: ^8.1
- guzzlehttp/guzzle: ^7.4.1
This package is not auto-updated.
Last update: 2024-11-04 16:33:26 UTC
README
prerequisites
To use this package you need:
- composer 2.2 and above
- php 8.1 and above
- guzzlehttp/guzzle
- laravel 9 and above
Installation
install package by running the below commands:
composer require alif/alif-sms-notification
it will create and past the following code in the file named config/sms-notification.php
<?php return [ 'host' => env('SMS_NOTIFICATION_HOST'), 'method' => 'POST', 'headers' => [ 'X-Api-Key' => env('SMS_NOTIFICATION_API_KEY'), 'Content-type' => 'application/json', 'charset' => 'utf-8' ], 'routes' => [ 'send_sms' => '/api/v1/Sms' ], ];
Usage
- simple send
$smsSender = new SmsNotificationSender(); //OR $smsSender = SmsNotificationSender::make(); $smsSender->from('John Doe') ->to('123456789') ->send('Message text'); //or SmsNotificationSender::make() ->from('John Doe') ->to('123456789') ->send('Message text');
- send async
$smsSender = new SmsNotificationSender(); //OR $smsSender = SmsNotificationSender::make(); $smsSender->from('John Doe') ->to('123456789') ->sendAsinc('Message text');
- handle exceptions
$smsSender = SmsNotificationSender::make(); $smsSender->from('John Doe') ->to('123456789') ->onFail(function(Exception $e) { // do something ... })->onSuccess(function(ResponseInterface $response) { // do smth ... })->send('Message text');
- with headers
$smsSender = SmsNotificationSender::make(); $smsSender->from('John Doe') ->to('123456789') ->headers($headers) ->onFail(function(Exception $e) { //... })->onSuccess(function(ResponseInterface $response) { //... })->send('Message text');
$smsSender = SmsNotificationSender::make(); $smsSender->from('John Doe') ->to('123456789') ->priority($priority) ->onFail(function(Exception $e) { //... })->onSuccess(function(ResponseInterface $response) { //... })->send('Message text');
- set expiresIn
$smsSender->from('John Doe') ->to('123456789') ->expiresIn($expiresIn) ->onFail(function(Exception $e) { //... })->onSuccess(function(ResponseInterface $response) { //... })->send('Message text');
- set countryCode
$smsSender->from('John Doe') ->to('123456789') ->countryCode($countryCode) ->onFail(function(Exception $e) { //... })->onSuccess(function(ResponseInterface $response) { //... })->send('Message text');