A simple Object Oriented PHP Client for Termii SMS API.
Uses Termii API.
- PHP >= 7.2
- Guzzlehttp ~6|~7
Via Composer.
composer require mane-olawale/termii
You now have Termii Client installed in vendor/mane-olawale/termii
And an handy autoload file to include in your project in vendor/autoload.php
<?php
// This file is generated by Composer
require_once __DIR__ . '/vendor/autoload.php';
use ManeOlawale\Termii\Client;
// Create a new Client instance
$client = new Client('{api_key}');
// Create a new Client instance and set options
$client = new Client('{api_key}', [
'sender_id' => 'Olawale',
'channel' => 'generic',
"attempts" => 10,
"time_to_live" => 30,
"length" => 6,
"placeholder" => '{token}',
'pin_type' => 'ALPHANUMERIC',
'message_type' => 'ALPHANUMERIC',
'type' => 'plain',
]);
$client->sms->send('2347041945964', 'Hello World!');
// You can change any option later
$client->fillOptions([
"attempts" => 5,
"time_to_live" => 20,
"length" => 4,
"placeholder" => '{pin}',
]);
Uses Sender ID.
<?php
// This file is generated by Composer
require_once __DIR__ . '/vendor/autoload.php';
use ManeOlawale\Termii\Client;
$client = new Client('{api_key}');
$client->sender->list();
Note: We didn`t add the Sender id and channel becuase they are optional and they can always be passed later on the client object or the SMS API handler.
Uses Request Sender ID.
<?php
// This file is generated by Composer
require_once __DIR__ . '/vendor/autoload.php';
use ManeOlawale\Termii\Client;
$client = new Client('{api_key}');
$client->sender->request('Olawale', 'Friendship based Notifications', 'Mane Olawale');
Uses Switch - Messaging.
<?php
// This file is generated by Composer
require_once __DIR__ . '/vendor/autoload.php';
use ManeOlawale\Termii\Client;
$client = new Client('{api_key}', [
'sender_id' => '{sender_id}',
'channel' => '{channel}',
]);
return $client->sms->send('2347041945964', 'Testing');
Custom Sender ID or Channel
<?php
// This file is generated by Composer
require_once __DIR__ . '/vendor/autoload.php';
use ManeOlawale\Termii\Client;
$client = new Client('{api_key}', [
'sender_id' => '{sender_id}',
'channel' => '{channel}',
]);
return $client->sms->send('2347041945964', 'Hello World', 'Olawale', 'generic');
// OR probably omit sender id or channel
return $client->sms->send('2347041945964', 'Hello World', null, 'generic');
Uses Switch - Number.
<?php
// This file is generated by Composer
require_once __DIR__ . '/vendor/autoload.php';
use ManeOlawale\Termii\Client;
$client = new Client('{api_key}');
return $client->sms->number('2347041945964', 'Hello World');
Uses Switch - Template.
<?php
// This file is generated by Composer
require_once __DIR__ . '/vendor/autoload.php';
use ManeOlawale\Termii\Client;
$client = new Client('{api_key}');
return $client->sms->template('2347041945964', '{template_id}', [
'product_name' => 'Termii',
'otp' => '120435',
'expiry_time' => '10 minutes'
], '{device_id}');
Uses Send Token.
<?php
// This file is generated by Composer
require_once __DIR__ . '/vendor/autoload.php';
use ManeOlawale\Termii\Client;
$client = new Client('{api_key}', [
'sender_id' => '{sender_id}',
'channel' => '{channel}',
]);
// You can choose to omit the pin options if you have set them when creating the client instance
return $client->token->sendToken('2347041945964', '{token} is your friendship verification token', [
"attempts" => 10,
"time_to_live" => 30,
"length" => 6,
"placeholder" => '{token}',
'type' => 'NUMERIC',
]);
Custom Sender ID or Channel
<?php
// This file is generated by Composer
require_once __DIR__ . '/vendor/autoload.php';
use ManeOlawale\Termii\Client;
$client = new Client('{api_key}', [
'sender_id' => '{sender_id}',
'channel' => '{channel}',
]);
return $client->token->sendToken('2347041945964', '{token} is your friendship verification token', [
"attempts" => 10,
"time_to_live" => 30,
"length" => 6,
"placeholder" => '{token}',
'type' => 'NUMERIC',
], 'Olawale', 'generic');
// OR probably omit sender id or channel
return $client->token->sendToken('2347041945964', '{token} is your friendship verification token', [
"attempts" => 10,
"time_to_live" => 30,
"length" => 6,
"placeholder" => '{token}',
'type' => 'NUMERIC',
], null, 'generic');
Uses Verify Token.
<?php
// This file is generated by Composer
require_once __DIR__ . '/vendor/autoload.php';
use ManeOlawale\Termii\Client;
$client = new Client('{api_key}');
return $client->token->verify('a2d671d7-e4fd-41d5-9b13-30c192309306', '123456');
For men and women of few words
<?php
// This file is generated by Composer
require_once __DIR__ . '/vendor/autoload.php';
use ManeOlawale\Termii\Client;
$client = new Client('{api_key}');
// Returns True if token is verified else returns false
return $client->token->verified('a2d671d7-e4fd-41d5-9b13-30c192309306', '123456');
// Returns True if token fails to verify else returns false
return $client->token->failed('a2d671d7-e4fd-41d5-9b13-30c192309306', '123456');
// Returns True if token exists but has expired else returns false
return $client->token->expired('a2d671d7-e4fd-41d5-9b13-30c192309306', '123456');
Uses Send In App Token.
<?php
// This file is generated by Composer
require_once __DIR__ . '/vendor/autoload.php';
use ManeOlawale\Termii\Client;
$client = new Client('{api_key}');
return $client->token->sendInAppToken('2347041945964', [
"attempts" => 10,
"time_to_live" => 30,
"length" => 6,
]);
Uses Balance.
<?php
// This file is generated by Composer
require_once __DIR__ . '/vendor/autoload.php';
use ManeOlawale\Termii\Client;
$client = new Client('{api_key}');
return $client->insights->balance();
Uses Inbox.
<?php
// This file is generated by Composer
require_once __DIR__ . '/vendor/autoload.php';
use ManeOlawale\Termii\Client;
$client = new Client('{api_key}');
return $client->insights->inbox();
/**
* Get only the data of a specific message by passing its message_id
*/
return $client->insights->inbox('43224343447041945964');
Uses Search.
<?php
// This file is generated by Composer
require_once __DIR__ . '/vendor/autoload.php';
use ManeOlawale\Termii\Client;
$client = new Client('{api_key}');
return $client->insights->search('2347041945964');
The search Api is used majorly for checking if a number is DND active, so there are two helper functions to ease the check
<?php
// This file is generated by Composer
require_once __DIR__ . '/vendor/autoload.php';
use ManeOlawale\Termii\Client;
$client = new Client('{api_key}');
return $client->insights->isDnd('2347041945964');
// OR
return $client->insights->isNotDnd('2347041945964');
Uses Status.
<?php
// This file is generated by Composer
require_once __DIR__ . '/vendor/autoload.php';
use ManeOlawale\Termii\Client;
$client = new Client('{api_key}');
return $client->insights->number('2347041945964');