vmosoti/bongatech-sms

A PHP client library for BongaTech's API (http://bongatech.co.ke)

v2.0.1 2017-04-15 14:06 UTC

This package is auto-updated.

Last update: 2024-03-16 21:38:59 UTC


README

Latest Stable Version Latest Unstable Version StyleCI Build Status Scrutinizer Code Quality SensioLabsInsight Total Downloads License

This is a PHP client library to be used with BongaTech's SMS API See Bonga Tech's Website for more

Installation

You can install the package via composer:

composer require vmosoti/bongatech-sms

Usage

Providing variables

The Config class requires to fetch some variable from the system environment. These variables are the ones used in initialization of the SMS class. In your .env file:

BONGATECH_USER_ID=
BONGATECH_PASSWORD=
BONGATECH_SENDER_ID=
BONGATECH_CALL_BACK_URL=

Initializing the SMS class

To initialize:

$sms = new  \VMosoti\BongaTech\SMS();

or simply use the magic helper function:

sms()  // you have the SMS object

Recipients and Messages

Each of them is an array of arrays. i.e

$recipients = array(
        array(
            'MSISDN' => '0722123456',
            'LinkID' => '',
            'SourceID' => 'your source id here'
        ),
        array(
            'MSISDN' => '0775345678',
            'LinkID' => '',
            'SourceID' => 'source id for this here'
        )
    );

and messages

$messages = array(
        array(
            'Text' => 'Message 1 goes here'
        ),
        array(
            'Text' => 'Message 2 goes here'
        )
    );

Sending to a single Recipient

$message = array(
        array(
            'Text' => 'This message is for a single recipient'
        )
    );
    
$recipient = array(
        array(
            'MSISDN' => '0722123456',
            'LinkID' => '',
            'SourceID' => 'your source id here'
        )
    );
    
$response = $sms->bulk()->toOne()->send($recipient, $message);

or use helper function

$response = sms()->bulk()->toOne()->send($recipient, $message);

The above returns a single Response object

Sending same sms to many recipients

$message = array(
        array(
            'Text' => 'This message goes to many recipients'
        )
    );
    
$recipients = array(
        array(
            'MSISDN' => '0722123456',
            'LinkID' => '',
            'SourceID' => 'source id for recipient 1'
        ),
        array(
            'MSISDN' => '0713678900',
            'LinkID' => '',
            'SourceID' => 'source id for recipient 2'
            ),
    );
    
$responses = $sms->bulk()->toMany()->send($recipients, $message);

Sending different sms to each recipient

$messages = array(
        array(
            'Text' => 'This is message for recipient 1'
        ),
        array(
             'Text' => 'This is message for recipient 2'
        )
    );
    
$recipients = array(
        array(
            'MSISDN' => '0722123456',
            'LinkID' => '',
            'SourceID' => 'source id for recipient 1'
        ),
        array(
            'MSISDN' => '0713678900',
            'LinkID' => '',
            'SourceID' => 'source id for recipient 2'
            ),
    );
    
$responses = $sms->bulk()->toMany()->send($recipients, $messages);

The above two examples returns an array of the Response object. Thus:

foreach($responses as $response){
$response->getCode();
------
}

Querying SMS units balance

$response = SMS::getBalance();

or just throw in the helper function

get_balance();

$response is Response object. thus

$response->getBalance()

Delivery Reports

In your callback,

$response = \VMosoti\BongaTech\DeliveryReport::get();

It returns Response object,

thus:

$response->getReport();
$response->getMessageID();
$response->getCorrelator();
$response->getSourceID();

See all possible reports here

Exceptions

catch \VMosoti\BongaTech\Exceptions\BongaTechException;

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Suggestions, pull requests , bug reporting and code improvements are all welcome. Feel free to get in touch.

Security

If you discover any security related issues, please email vincent@vmosoti.com.

Credits

License

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