/smsfactor-php-sdk

SMSFactor API SDK for PHP.

Primary LanguagePHPMIT LicenseMIT

SMSFactor Client library for PHP

The PHP client library makes it easy for developers to use SMSFactor's API.

In order to use it, make sure to have an account. You can register here. Once your account is created, you need to generate your first API token. You can find the complete documentation of our API here.

Installation

We recommend using Composer to install the PHP client library to your project.

composer require smsfactor/smsfactor-php-sdk

Usage

Make sure to autoload the library in your bootstrap file :

require_once __dir__ . 'vendor/autoload.php';

Set your token :

\SMSFactor\SMSFactor::setApiToken('your token');

Send a message :

$response = \SMSFactor\Message::send([
	'to' => '33601000000',
	'text' => 'Did you ever dance whith the devil in the pale moonlight ?'
]);
print_r($response->getJson());

Examples

Account

Get credits

$response = \SMSFactor\Account::credits();

Get account

$response = \SMSFactor\Account::get();

Get subaccounts

$response = \SMSFactor\Account::subAccounts();

Create an account

$response = \SMSFactor\Account::create([
	'account' => [
		"firstname" => "firstname",
		"lastname" => "lastname",
		"city" => "city",
		"phone" => "phone",
		"address1" => "address",
		"zip" => "zip",
		"country_code" => "country code",
		"isChild" => 0, //Is the account a subaccount ?
		"unlimited" => 0, //If isChild, should the subaccount use the parent's credits
		'email' => 'your@email.com',
		'password' => 'password'
	]
]);

Campaign

Send a campaign

$delay = date('Y-m-d H:i:s', strtotime('+1 hour')); // now + 1 hour
$response = \SMSFactor\Campaign::send([
    'sms' => [
	    'message' => [
		    'text' => 'test skd php',
		    'pushtype' => 'alert', //alert(default) or marketing
		    'sender' => 'SDK', //Optional
		    'delay' => $delay //Optional. Omit for immediate send
	    ],
	    'recipients' => [
		    'gsm' => [
			    [
				    'value' => '33601000000'
			    ]
		    ]
	    ]
    ]
], false); // True to simulate the campaign (no SMS sent)

Send a campaign to a list

$delay = date('Y-m-d H:i:s', strtotime('+1 hour')); // now + 1 hour
$response = \SMSFactor\Campaign::sendToLists([
    'sms' => [
	    'message' => [
		    'text' => 'test skd php',
		    'pushtype' => 'alert', //alert(default) or marketing
		    'sender' => 'SDK', //Optional
		    'delay' => $delay //Optional. Omit for immediate send
	    ],
	    'lists' => [
		    [
			    'value' => 'your_list_id'
		    ]
	    ]
    ]
], false); // True to simulate the campaign (no SMS sent)

Get information about a campaign

Use the campaign ticket value returned by our API after sending a campaign to get information about that campaign. Given the last example :

$response = \SMSFactor\Campaign::get($response->ticket);

Cancel a delayed campaign

$response = \SMSFactor\Campaign::cancel($response->ticket);

Get campaign history

$response = \SMSFactor\Campaign::history(['length' => 5]); //Get the last 5 campaigns

List

Create a list

You can customize each contact with up to 4 optional information

$response = \SMSFactor\ContactList::create([
    'list' => [
	    'name' => 'Your list name',
	    'contacts' => [
		    'gsm' => [
			    [
				    'value' => '33600000001',
				    'info1' => 'Lastname',
				    'info2' => 'Firstname',
				    'info3' => 'Gender'
			    ],
			    [
				    'value' => '33600000002',
				    'info1' => 'Lastname',
				    'info2' => 'Firstname',
				    'info3' => 'Gender'
			    ]
		    ]
	    ]
    ]
]);
$list_id = $response->id

Add contacts to a list

$response = \SMSFactor\ContactList::addContacts([
    'list' => [
	    'list_id' => $list_id
	    'contacts' => [
		    'gsm' => [
			    [
				    'value' => '33600000003',
				    'info1' => 'Lastname',
				    'info2' => 'Firstname',
				    'info3' => 'Gender'
			    ],
			    [
				    'value' => '33600000004',
				    'info1' => 'Lastname',
				    'info2' => 'Firstname',
				    'info3' => 'Gender'
			    ]
		    ]
	    ]
    ]
]);

Get a list

$response = \SMSFactor\ContactList::get($list_id);

Remove a contact from a list

$response = \SMSFactor\ContactList::removeContact($contact_id); //use Get list to get contact id

Deduplicate a list

$response = \SMSFactor\ContactList::deduplicate($list_id);

Get all lists

$response = \SMSFactor\ContactList::all();

Remove a list

$response = \SMSFactor\ContactList::delete($list_id);

Add contacts to the blacklist

 $response = \SMSFactor\ContactList::addToBlacklist([
	'blacklist' => [
		'contacts' => [
			'gsm' => [
				[
					'value' => '33600000003'
				],
				[
					'value' => '33600000004'
				]
			]
		]
	]
]);

Get blacklist

$response = \SMSFactor\ContactList::blacklist();

Add contacts to the NPAI list

$response = \SMSFactor\ContactList::addToNpai([
	'npai' => [
		'contacts' => [
			'gsm' => [
				[
					'value' => '33600000003'
				],
				[
					'value' => '33600000004'
				]
			]
		]
	]
]);

Get NPAI list

$response = \SMSFactor\ContactList::npai();

Token

Create a token

$response = \SMSFactor\Token::create([
    'token' => [
	    'name' => 'token sdk'
    ]
]);
$token = $response->token;
$token_id = $response->token_id;

Get your tokens

$response = \SMSFactor\Token::all();

Delete a token

$response = \SMSFactor\Token::delete($token_id);

Webhook

To see all available webhooks, please go to our official documentation.

Create a webhook

$response = \SMSFactor\Webhook::create([
	'webhook' => [
		'type' => 'DLR',
		'url' => 'https://yourserverurl.com'
	]
]);
$webhook_id = $response->webhook->webhook_id;

Get your webhooks

$response = \SMSFactor\Webhook::all();

Update a webhook

$response = \SMSFactor\Webhook::update($webhook_id, [
    'webhook' => [
	    'type' => 'MO',
	    'url' => 'https://yourserverurl.net'
    ]
]);

Delete a webhook

$response = \SMSFactor\Webhook::delete($webhook_id);