GithubHelp home page GithubHelp logo

mubarakcoded / hubtel-sms-php Goto Github PK

View Code? Open in Web Editor NEW

This project forked from hubtel/hubtel-sms-php

0.0 1.0 0.0 163 KB

A PHP SDK for developers to interact with the Hubtel SMS REST API.

PHP 100.00%

hubtel-sms-php's Introduction

Hubtel SMS API PHP SDK

Overview

This is an open source PHP SDK that allows you to access the Hubtel REST SMS API from your PHP application. You need to create a Hubtel account in order to use this API.

Installation

The SDK can smoothly run on PHP 5.3 and above with CURL extension enabled. The Hubtel PHP SDK can be installed with Composer. Run this command:

composer require hubtel/hubtel-sms

You can also download the Hubtel folder from the repository and add it to your project. You may then include the Hubtel/Api.php file by referring to the appropriate path like such:

include '/path/to/location/Hubtel/Api.php';

Usage

The SDK currently is organized around four main classes:

  • MessagingApi.php : It handles sending and receiving messages, NumberPlans, Campaigns, Keywords, Sender IDs and Message Templates management.(For more information about these terms refer to Our developer site.)
  • ContactApi.php : It handles all contacts related tasks.
  • AccountApi.php : It handles the API Account Holder data.
  • SupportApi.php : It helps any developer to interact with our support platform via his application.
  • ContentApi.php : It handles all content related tasks.

Examples

  • How to Send a Message

To send a message just copy this code snippet and do the necessary modifications:

require './vendor/autoload.php';

$auth = new BasicAuth("user123", "pass123");
// instance of ApiHost
$apiHost = new ApiHost($auth);
// instance of AccountApi
$accountApi = new AccountApi($apiHost);
// Get the account profile
// Let us try to send some message
$messagingApi = new MessagingApi($apiHost);
try {
    // Send a quick message
    $messageResponse = $messagingApi->sendQuickMessage("DevUniverse", "+233207110652", "Welcome to planet Hubtel!");

    if ($messageResponse instanceof MessageResponse) {
        echo $messageResponse->getStatus();
    } elseif ($messageResponse instanceof HttpResponse) {
        echo "\nServer Response Status : " . $messageResponse->getStatus();
    }
} catch (Exception $ex) {
    echo $ex->getTraceAsString();
}
  • How to Schedule a Message

To schedule a message just copy this code snippet and do the necessary modifications. However please do refer to PHP datetime functions to know how to set the message time it is very crucial.

    require './vendor/autoload.php';

    // Here we assume the user is using the combination of his clientId and clientSecret as credentials
    $auth = new BasicAuth("user233", "password23");

    // instance of ApiHost
    $apiHost = new ApiHost($auth);
    $enableConsoleLog = TRUE;
    $messagingApi = new MessagingApi($apiHost, $enableConsoleLog);
    try {
        // Default Approach
        $mesg = new Message();
        $mesg->setContent("I will see you soon...");
        $mesg->setTo("+233245098456");
        $mesg->setFrom("+233245657867");
        $mesg->setRegisteredDelivery(true);
        $mesg->setTime(date('Y-m-d H:i:s', strtotime('+1 week'))); // Here we are scheduling the message to be sent next week
        $messageResponse = $messagingApi->sendMessage($mesg);
    
        if ($messageResponse instanceof MessageResponse) {
            echo $messageResponse->getStatus();
        } elseif ($messageResponse instanceof HttpResponse) {
            echo "\nServer Response Status : " . $messageResponse->getStatus();
        }
    } catch (Exception $ex) {
        echo $ex->getTraceAsString();
    }

Please do explore the MessagingApi class for more functionalities.

  • How to view Account Details

To send a message just copy this code snippet and do the necessary modifications:

    require './vendor/autoload.php';

    // Here we assume the user is using the combination of his clientId and clientSecret as credentials
    $auth = new BasicAuth("user233", "password23");

    // instance of ApiHost
    $apiHost = new ApiHost($auth);
    // instance of AccountApi
    $enableConsoleLog = TRUE;
    $accountApi = new AccountApi($apiHost, $enableConsoleLog);
    try {
        // Get the Account Profile
        $profile = $accountApi->getProfile();
        if ($profile instanceof AccountProfile) {
            echo "\n\n" . $profile->getAccountId();
        } else if($profile instanceof HttpResponse){
            echo "\n\n".$profile->getStatus();
        }
    } catch (Exception $ex) {
        echo $ex->getTraceAsString();
    }

Please do explore the AccountApi class for more functionalities.

Notes

The ContactApi, SupportApi and ContentApi classes follow almost the same pattern of functionalities, please do explore them to grab their capabilities.

Getting help

If you need help using the library, please contact Hubtel Support at [email protected]. Our friendly support staff usually reply within 24 hours.

hubtel-sms-php's People

Contributors

aagalic avatar daverockz avatar kenny-rogers avatar

Watchers

 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.