touchsms/touchsms

touchSMS Api Client

2.0.0 2024-02-10 16:00 UTC

This package is not auto-updated.

Last update: 2024-03-16 13:48:06 UTC


README

Latest Stable Version

PHP SDK for touchSMS.

This SDK is generated automatically with JanePHP. It provides a full object-oriented interface for the endpoints, requests and responses.

You can explore the \TouchSms\ApiClient\Api namespace to see the generated classes.

Currently, only a portion of the API has been converted to openAPI, and thus this client. If you would like support for a method, please open an issue and our team will address it.

Installation

composer require touchsms/touchsms

Usage

Use the ClientFactory to create an API client.

// access token & token id can be generated at https://app.touchsms.com.au/settings/api
$client = \TouchSms\ApiClient\ClientFactory::create('ACCESS_TOKEN', 'TOKEN_ID');

$res = $client->getAccount();

Send SMS

$client = ClientFactory::create($_ENV['ACCESS_TOKEN'], $_ENV['TOKEN_ID']);

$res = $client->sendMessages(new SendMessageBody([
    'messages' => [ // Up to 1000 messages supported
        new OutboundMessage([
            'to' => '61491578888', // Test number
            'from' => 'SHARED_NUMBER',
            'body' => 'Text',
        ]),
    ],
]));

var_dump($res->getData()->getMessages()); // Successful messages, \TouchSms\ApiClient\Api\Model\OutboundMessageResponse
var_dump($res->getData()->getErrors()); // Messages with errors, \TouchSms\ApiClient\Api\Model\OutboundMessageError

Output

// array of OutboundMessageResponse objects
$message = $res->getData()->getMessages()[0];
$message->getTo();
$message->getMeta()->getParts();
$message->getMeta()->getCost();
//etc

View User Details

$res = $client->getAccount();

Output

var_dump($res->getData()); // object, \TouchSms\ApiClient\Api\Model\AccountInformation
var_dump(
    $res->getData()->getEmail(), // user
    $res->getData()->getCredits() // credit balance
);

Examples

Examples can be found in examples directory.