Skip to content

Latest commit

 

History

History
135 lines (86 loc) · 3.36 KB

README.md

File metadata and controls

135 lines (86 loc) · 3.36 KB

Clickatell SMS Messenger Library

Master: Build Status

This library allows easy access to connecting the Clickatell's different messenging API's.

Table of Contents

  • Installation
  • Usage
  • Supported API calls
  • Events
  1. Installation

This library uses composer and can be acquired using the following in your composer.json file.

{
    "require": {
        "arcturial/clickatell": "*"
    }
}
  1. Usage

The Clickatell library allows you specify several ways to connect to Clickatell. The current ones supported are HTTP and XML. These connections are called "Transports".

The default transport is HTTP.

$clickatell = new Clickatell($username, $password, $apiID);

$clickatell->sendMessage(1111111111, "My Message");

You can specify a different output using the Clickatell constructor or using the setTransport() method.

$clickatell = new Clickatell($username, $password, $apiID, Clickatell::TRANSPORT_XML);

// OR

$clickatell = new Clickatell($username, $password, $apiID);

$clickatell->setTransport(new Clickatell\Component\Transport\TransportXml);

NOTE: The library uses name spaces, and the Clickatell messenger is located at Clickatell\Clickatell

  1. Supported API calls

Clickatell has a couple of different API's that each support a subset of functions. We are going to refer to them as Messaging and Bulk Messaging API's for this document.

Messaging API's

The following are all messaging API's.

use Clickatell\Component\Transport\TransportHttp;

use Clickatell\Component\Transport\TransportSoap;

use Clickatell\Component\Transport\TransportXml;

use Clickatell\Component\Transport\TransportSmtp;

These Transports all support the following functions

sendMessage(array $to, string $message, $from = "", $callback = true);

getBalance();

queryMessage($apiMsgId);

routeCoverage($msisdn);

getMessageCharge($apiMsgId);

Bulk Messaging API's

The following are bulk messaging API's. The have only a limited number of functions and are more suited for bulk messaging. Since they aren't processed in real time, these Transports do not return the same results as the normal messaging API's.

use Clickatell\Component\Transport\TransportSMTP;

These Transports all support the following functions

sendMessage(array $to, string $message, $from = "", $callback = true);
  1. Events

This library provides a couple of events to extend the ability of the API's. Current support events are request and response.

Example

<?php

use Clickatell\Clickatell;

$clickatell = new Clickatell('[username]', '[password]', [api_id], Clickatell::HTTP_API);

$clickatell->on('request', function($data) {
	// $data = The parameters passed to the request
	print_r($data);
});

$clickatell->on('response', function($data) {
	// $data = The result of the API call.

	// This hook can be used to register multiple
	// listeners that can log to file/db or call another
	// service.
	print_r($data);
});

?>