Africa’s talking released their own SDK that handles SMS, Payments, Voice etc., removing the need of manually generating the calls. This has now become a wrapper that offers efficiency and helper functions.
Installation
Pull in the package using composer:
composer require smodav/africastalking
When using Laravel 5.5+, the package will auto-discover, otherwise register the package on your config/app.php
file:
‘providers’ => [
...
SmoDav\AfricasTalking\Laravel\ServiceProvider::class,
...
],
‘aliases’ => [
...
‘Airtime’ => SmoDav\AfricasTalking\Laravel\Facades\Airtime::class,
‘Application’ => SmoDav\AfricasTalking\Laravel\Facades\Application::class,
‘Payments’ => SmoDav\AfricasTalking\Laravel\Facades\Payments::class,
‘SMS’ => SmoDav\AfricasTalking\Laravel\Facades\SMS::class,
‘Token’ => SmoDav\AfricasTalking\Laravel\Facades\Token::class,
‘Voice’ => SmoDav\AfricasTalking\Laravel\Facades\Voic::class’
...
],
Once registered, you can publish the config file using
php artisan vendor:publish --provider=""SmoDav\AfricasTalking\Laravel\ServiceProvider""
Helper Functions
sms(array $numbers = [], string $message = null, int $from = null, bool $enqueue = false)
To get the SMS instance, call the sms
function without any arguments. Calling the function with the arguments below will send an SMS to the provided numbers using the short code provided by the $from
parameter.
sms(array $numbers = [], string $message = null, int $from = null, bool $enqueue = false)
fetchSms(int $lastReceivedId = 0)
Get SMSes from your inbox. The last received ID is used as a reference in order to fetch only new SMSes.
fetchSms(int $lastReceivedId = 0)
subscribeMobile(string $mobile, int $shortCode, string $keyword)
Use this function to subscribe a mobile number to the desired keyword.
subscribeMobile(string $mobile, int $shortCode, string $keyword)
subscriptions(int $shortCode, string $keyword, int $lastReceivedId = 0)
Use this function to get the subscribers of the desired keyword.
subscriptions(int $shortCode, string $keyword, int $lastReceivedId = 0)
unsubscribeMobile(string $mobile, int $shortCode, string $keyword)
Use this function to unsubscribe a mobile number from the keyword.
unsubscribeMobile(string $mobile, int $shortCode, string $keyword)
Laravel Facades
The package provides these facades that return instances of the Africa’s talking module:
‘Airtime’ => AfricasTalking\SDK\Airtime::class,
‘Application’ => AfricasTalking\SDK\Application::class,
‘Payments’ => AfricasTalking\SDK\Payments::class,
‘SMS’ => AfricasTalking\SDK\SMS::class,
‘Token’ => AfricasTalking\SDK\Token::class,
‘Voice’ => AfricasTalking\SDK\Voic::class’
To use the facades, you can follow the documentation as per the SDK found here.