Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/zgabievi/laravel-sender

SENDER.GE Integration for Laravel
https://github.com/zgabievi/laravel-sender

Last synced: 7 days ago
JSON representation

SENDER.GE Integration for Laravel

Awesome Lists containing this project

README

        

# SENDER.GE Integration for Laravel

[![Packagist](https://img.shields.io/packagist/v/zgabievi/laravel-sender.svg)](https://packagist.org/packages/zgabievi/laravel-sender)
[![Packagist](https://img.shields.io/packagist/dt/zgabievi/laravel-sender.svg)](https://packagist.org/packages/zgabievi/laravel-sender)
[![license](https://img.shields.io/github/license/zgabievi/laravel-sender.svg)](https://packagist.org/packages/zgabievi/laravel-sender)

[![laravel-sender](https://raw.githubusercontent.com/zgabievi/laravel-sender/main/assets/sender.png)](https://github.com/zgabievi/laravel-sender)

## Table of Contents
- [Installation](#installation)
- [Usage](#usage)
- [Send Message](#send-message)
- [Check Status](#check-status)
- [Notification](#notification)
- [Configuration](#configuration)
- [License](#license)

## Installation

To get started, you need to install package:

```shell script
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*:

```php
'providers' => [
...
Zorb\Sender\SenderServiceProvider::class,
...
];
```

You can publish config file using this command:

```shell script
php artisan vendor:publish --provider="Zorb\Sender\SenderServiceProvider"
```

This command will copy config file in your config directory.

## Usage

- [Send Message](#send-message)
- [Check Status](#check-status)

### Send Message

```php
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

```php
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.

```php
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](https://github.com/zgabievi/laravel-sender) is licensed under a [MIT License](https://github.com/zgabievi/laravel-sender/blob/master/LICENSE).