Home

Awesome

SENDER.GE Integration for Laravel

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

KeyValue
Advertising1
Information2

MessageStatus

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

KeyValue
Pending0
Delivered1
Undelivered2

Configuration

You can configure environment file with following variables:

KeyTypeDefaultMeaning
SENDER_DEBUGboolfalseThis value decides to log or not to log requests.
SENDER_API_KEYstringThis is the api key, which should be generated by sender.ge tech stuff.
SENDER_API_URLstringhttps://sender.ge/apiThis is the url provided by sender.ge support.

License

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