Logo Lanfrica

weezqyd/africas-talking

Domain:

digital infrastructure

Record type:

software
Creator:
wee
Host:
PHP package for sending messages through Africa's talking API Geting Started -------------- Install the package from composer ```bash $ composer require weezqyd/africastalking @dev ``` You then need to install **one** of the following: But we recomend GuzzleHttp ```bash $ composer require guzzlehttp/guzzle $ composer require kriswallsmith/buzz $ composer require nategood/httpful ``` Configure the Adapter --------------------- This package uses guzzlehttp as the default adapter, if you decide to use another http client good for you all you need is to configure your client and pass the adapter as the fourth parameter to the gateway's constructor. You can also create your own adapter as long as it implements `Http\Adapter\AdapterInterface`. An example is worth a thousand words ```php require_once 'vendor/autoload.php'; use AfricasTalking\Gateway; use Http\Adapter\BuzzAdapter; // These Headers are required $headers = [ 'apikey' => 'API-KEY', 'Accept' => 'application/json', 'Content-Type' => 'application/x-www-form-urlencoded', ]; $adapter = new BuzzAdapter($headers); // Pass the adapter and your Africastalking Username to the gateway // The third parameter is a sandbox flag when true the Api wiil run in the sandbox, The defaults is false // Because we are using a custom client you dont need provide the API KEY to the gateway // Instead pass an empty string or null $gateway = new Gateway('USERNAME', null, true, $adapter); ``` ### Sending an SMS Message Now let us send an SMS notification ```php use AfricasTalking\Gateway; use Http\Exceptions\HttpException; $gateway = new Gateway('API-TOKEN', 'USERNAME'); try { $response = $gateway->sms->sendMessage('+254700123XXX', 'My sample message'); var_dump($response); } catch(HttpException $e) { print_r($e); } ``` #### Passing additional options The SMS API accept additional options to be passed allong with the request | Parameter | Description …