Laravel & Php

How to us Africas Talking (AT) to send SMS with Laravel


How to us Africas Talking (AT) to send sms with laravel

Africa’s Talking is a mobile technology company that offers developers integrated mobile APIS to simplify the processes involved in interacting with SMS/ USSD / Voice and Airtime.

In order to get started, head over to Africas Talking and register an account.

Upon registration and verification of your account, you will be presented with a dashboard that looks like this;

Whilst your application is still in development, you will want to use the sandbox in order to test it without incurring any charges. You can do this by clicking the orange “Go To Sandbox App” button.

There you will see a dashboard with cards detailing your usage of the available APIS.

In order to use the API, you will need to obtain a username and a token that you can then plug in to your application.

By default the username that you will use while in the sandbox testing environment will be “sandbox”.

To obtain a token, click on settings > API Key from the applications drawer as indicated below. This will present a screen that will have a textfield prompting you for your password. Enter the password you used during registration and click on the generate button.

If successful, a token will be generated and appear right above the textfield, with a success message displayed at the top of the application.

In case of failure, an error alert will be displayed.

Install SDK

You can install the PHP SDK via composer or by downloading the source

Via Composer

The recommended way to install the SDK is with Composer.

composer require africastalking/africastalking

Usage

use AfricasTalking\SDK\AfricasTalking;

$username = 'YOUR_USERNAME'; // use 'sandbox' for development in the test environment
$apiKey   = 'YOUR_API_KEY'; // use your sandbox app API key for development in the test environment
$AT       = new AfricasTalking($username, $apiKey);

// Get one of the services
$sms      = $AT->sms();

// Use the service
$result   = $sms->send([
    'to'      => '+2XXYYYOOO',
    'message' => 'Hello World!'
]);

return $result;

Africas Talking SMS USSD Laravel
Share with Friends

Like this chef? Share with friends..