Skip to content

A community maintained Laravel package for SmartSMSSolutions' API-x. The Package that helps deliver SMS to phone numbers on Do Not Disturb (DND)

License

Notifications You must be signed in to change notification settings

abdulmatinsanni/api-x

Repository files navigation

api-x

Latest Version on Packagist Software License Total Downloads

An unofficial laravel package for SmartSMSSolutions' API-x. The Package that helps deliver SMS to phone numbers on Do Not Disturb (DND).

Structure

Below is the file structure of this package.

\---src
    |   APIx.php
    |   APIxMessage.php
    |   APIxServiceProvider.php
    |
    +---Channels
    |       SmartSMSChannel.php
    |
    +---Commands
    |   \---Log
    |           ClearCommand.php
    |           DisplayCommand.php
    |
    +---config
    |       api-x.php
    |
    +---Controllers
    |       LogController.php
    |
    +---Exceptions
    |       CouldNotSendNotification.php
    |       InvalidConfiguration.php
    |
    +---Facades
    |       APIxFacade.php
    |
    \---resources
        \---views
                log.blade.php

Install

You can install the package via composer:

$ composer require abdulmatinsanni/api-x

Add the service provider (only required on Laravel 5.4 or lower):

// config/app.php

'providers' => [
    ...
    AbdulmatinSanni\APIx\APIxServiceProvider::class,
],

'aliases' => [
    'APIx' => AbdulmatinSanni\APIx\Facades\APIxFacade::class,
],

Setting up your API-x account

Add your API-x API Token (string), Log Message (boolean), Mock SMS (boolean) and Sender Name (optional|string) to your .env (environment) file:

SMARTSMSSOLUTIONS_API_TOKEN=apixtokenhere
SMARTSMSSOLUTIONS_LOG_MESSAGES=true
SMARTSMSSOLUTIONS_FAKE_SMS=true
SMARTSMSSOLUTIONS_SENDER_NAME=sendernamehere

Usage

In Controllers:

Below is an example of API-x usage in controllers.

...

use APIx;

class SMSController extends Controller
{
    public function send(Request $request)
    {
        $response = APIx::to($request->recipient)
            ->from($request->name)
            ->message($request->message)
            ->send();
        
        return $response;
    }
}

For Notifications:

Setting up in model:

...

class User extends Model
{
    use Notifiable;

    public function routeNotificationForSmartSMS($notification)
    {
        return $this->phone_column;
    }
}

Setting up in notifications

...

use AbdulmatinSanni\APIx\APIxMessage;
use AbdulmatinSanni\APIx\Channels\SmartSMSChannel;

class DemoNotification extends Notification
{
    use Queueable;
    
    ...
    
    public function via($notifiable)
    {
        return [SmartSMSChannel::class];
    }

    ...
    
    public function toSmartSMS($notifiable)
    {
        return (new APIxMessage())
                    ->from($this->from)
                    ->message($this->message);
    }
}

Setting up in controllers

...

public class NotificationsController extends Controller
{
    public function notify()
    {
        $user = User::firstOrFail();
        $user->notify(new DemoNotification("SarahFound", "Hi, you are invited to our seminar!!!!!"));
    }
}

Available message methods

  • to([]) : Accepts an array or string of recipients' phone number(s).
  • from('') : Accepts a phone to use as the sms sender.
  • message('') : Accepts a string value for the sms body.
  • send() : Does the sending of the sms. Can also accept a string which represent sms body if message('') was skipped.

Command line

Showing all entries of log:

$ php artisan api-x:log

Showing the last logged sms:

$ php artisan api-x:log --latest

Limiting the entries of log to be displayed:

$ php artisan api-x:log --limit={no_of_messages}

Clearing all entries of log:

$ php artisan api-x:log clear

Change log

Please see CHANGELOG for more information on what has changed recently.

Testing

$ composer test (NOT YET)

Contributing

Please see CONTRIBUTING and CODE_OF_CONDUCT for details.

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

About

A community maintained Laravel package for SmartSMSSolutions' API-x. The Package that helps deliver SMS to phone numbers on Do Not Disturb (DND)

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published