alif/alif-sms-notification

v2.1.0 2023-12-06 06:25 UTC

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');
  • set priority
  • priority: integer|min:0|max:2 img_1.png
$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');