zgabievi/laravel-sender

SENDER.GE Integration for Laravel

0.5.2 2021-08-10 09:45 UTC

This package is auto-updated.

Last update: 2024-02-10 15:24:45 UTC


README

Packagist Packagist license

laravel-sender

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

Key Value
Advertising 1
Information 2

MessageStatus

Message statuses has its own enum Zorb\Sender\Enums\MessageStatus

Key Value
Pending 0
Delivered 1
Undelivered 2

Configuration

You can configure environment file with following variables:

Key Type Default Meaning
SENDER_DEBUG bool false This value decides to log or not to log requests.
SENDER_API_KEY string This is the api key, which should be generated by sender.ge tech stuff.
SENDER_API_URL string https://sender.ge/api This is the url provided by sender.ge support.

License

zgabievi/laravel-sender is licensed under a MIT License.