This library allows easy access to connecting the Clickatell's different messenging API's.
- Installation
- Usage
- Supported API calls
- Events
- Installation
This library uses composer and can be acquired using the following in your composer.json file.
{
"require": {
"arcturial/clickatell": "*"
}
}
- 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
- 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.
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);
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);
- 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);
});
?>