Code Monkey home page Code Monkey logo

africas-talking's Introduction

AfricasTalking Laravel Package

Introduction

AfricasTalking Laravel package provides an expressive, fluent interface to Subscription, SMS and Voice to the Africa's Talking API. It handles all the boilerplate to get you up and running with SMS and Voice.

License

The AfricasTalking Laravel package is open-sourced software licensed under the MIT license.

Installation

Install the package via composer.

$ composer require derrickjames/africas-talking

Add the service provider by modifying the providers array in config/app.php to include AfricasTalkingServiceProvider.

'providers' => [
    //...
    'DerrickJames\AfricasTalking\AfricasTalkingServiceProvider'
],

Add the facade to the aliases array in config/app.php.

'aliases' => [
    //...
    'AfricasTalking' => 'DerrickJames\AfricasTalking\Facades\AfricasTalking'
],
$ php artisan vendor:publish

In your .env file, setup your API Key and username.

AFRICAS_TALKING_API_KEY=your-africas-talking-api-key-string
AFRICAS_TALKING_USERNAME=your-africas-talking-username

Usage

The package uses three different drivers which expose fluent interfaces for subscription, sms and voice.

  • Subscription - Create a subscription to Africa's Talking service.
  • SMS - Send SMS messages and fetch messages.
  • Voice - Make voice calls

Be sure to specify the driver when interacting with the package.

Using the helper.

public function sendSMS()
{
    $response = africasTalking()
        ->driver('sms')
        ->to(['+254721234567'])
        ->message('Test Africas Talking API service SMS driver.')
        ->send();

    dd(json_decode($response)); // instance of GuzzleHttp/Psr7/Response
}
public function sendSMS()
{
    $response = africasTalking('sms')
        ->to(['+254721234567'])
        ->message('Test Africas Talking API service SMS driver.')
        ->send();

    dd(json_decode($response)); // instance of GuzzleHttp/Psr7/Response
}

Using the factory.

use DerrickJames\AfricasTalking\Contracts\Factory;

class NotifierController extends Controller
{
    protected $provider;

    public function __construct(Factory $provider) {
        $this->provider = $provider;
    }

    public function sendSMS() {
        $response = $this->provider
             ->driver('sms')
             ->to(['+254724147352'])
             ->message('Test Africas Talking API SMS driver.')
             ->send();

        dd(json_decode($response)); // instance of GuzzleHttp/Psr7/Response
    }
}

Using the facade.

use AfricasTalking;

public function sendSMS()
{
    $response = AfricasTalking::driver('sms')
         ->to(['+254724147802'])
         ->message('Test Africas Talking API SMS driver.')
         ->send();

    dd(json_decode($response)); // instance of GuzzleHttp/Psr7/Response
}

africas-talking's People

Contributors

derrickjames avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.