JSON-RPC 2.0 PHP class, to use with CALLR API.
-
API documentation: http://www.callr.com/docs/
-
SDK Installation guide: see INSTALLING.php.md
-
Example projects: https://github.com/THECALLR/examples-php
-
JSON-RPC 2.0 Specification: http://www.jsonrpc.org/specification
-
Easy to use Client class, built for PHP 5.4+
-
Requires:
php5-curl
You should use Composer (https://getcomposer.org/) to manage your PHP dependencies.
If you do not have a composer.json
file yet, create one at the root of your project, download Composer, and launch composer update
.
The composer.json
file should look like this:
{
"require": {
"callr/sdk-php": "^0.11"
}
}
Add all the libraries you need in composer.json
. Do not forget to run composer update
each time you edit the file.
Then you just need to include one file in your code:
<?php
require 'vendor/autoload.php';
$api = new CALLR\API\Client;
// using login + password (note ; that is to be deprecated)
$api->setAuth(new CALLR\API\Authentication\LoginPasswordAuth('username', 'password'));
// If you are using a long-term token ("api-key"), here is what you need to do ;
$api->setAuth(new CALLR\API\Authentication\ApiKeyAuth('your-api-key'));
If you want to log in as another sub-customer or sub-user (one you have access
to), you can call the logAs
method on the chosen authenticator :
$auth = new CALLR\API\Authentication\LoginPasswordAuth('username', 'password');
$auth = $auth->logAs('User', 'username_2');
$api = new CALLR\API\Client;
$api->setAuth($auth);
Available authenticators are the classic login / password (sent through a BASIC http request) or the Api-Key. Both supports the Login-As feature.
$from = 'SMS';
$to = '+33123456789';
$text = 'Hello, SMS world!';
$result = $api->call('sms.send', [$from, $to, $text, null]);
Method
Your sender must have been authorized and respect the sms_sender format
$from = 'Your Brand';
$to = '+33123456789';
$text = 'Hello, SMS world!';
$result = $api->call('sms.send', [$from, $to, $text, null]);
Method
$from = '';
$to = '+33123456789';
$text = 'Hello, SMS world!';
$result = $api->call('sms.send', [$from, $to, $text, null]);
Method
The default behaviour is to send your SMS with GSM 7-bit encoding. However, if your text contains a character that is not in the GSM 7-bit charset (Basic Character Set), we will send it as 16-bit UCS-2 (UNICODE) - using 2 bytes per character.
You can however force the encoding to be used at any time, using the force_encoding property.
If you force a GSM encoding, we will try to convert non-GSM characters to GSM ones. « becomes ", € becomes e, etc. The full mapping is available when calling the method sms.get_gsm_charset_mapping.
Please note that whatever the encoding forced or used, you always send your text as a JSON string to our API, without any special processing. The charset is applied in our platform before sending to the carriers.
$from = '';
$to = '+33123456789';
$text = 'Hello, SMS world!';
$options = new stdClass;
$options->force_encoding = 'GSM'; // or 'UNICODE'
$result = $api->call('sms.send', [$from, $to, $text, $options]);
Method
Objects
We automatically handle concatenated SMS. The number of SMS parts billed will be set on the parts property of the SMS object. The object can be sent to you using Webhooks.
If your SMS is GSM 7-bit encoded:
- If it's equals or less than 160 characters, it counts as 1 SMS.
- If it's more than 160 characters, the split is done every 153 characters.
If your SMS is UNICODE encoded:
- If it's equals or less than 70 characeters, it counts as 1 SMS.
- If it's more than 70 characters, the split is done every 67 characters.
$from = 'SMS';
$to = '+33123456789';
$text = 'Some super mega ultra long text to test message longer than 160 characters '.
'Some super mega ultra long text to test message longer than 160 characters '.
'Some super mega ultra long text to test message longer than 160 characters';
$result = $api->call('sms.send', [$from, $to, $text, null]);
Method
$from = 'SMS';
$to = '+33123456789';
$text = 'Hello, SMS world!';
$options = new stdClass;
$options->nature = 'ALERTING'; // or 'MARKETING'
$result = $api->call('sms.send', [$from, $to, $text, $options]);
Method
Objects
$from = 'SMS';
$to = '+33123456789';
$text = 'Hello, SMS world!';
$options = new stdClass;
$options->user_data = '42';
$result = $api->call('sms.send', [$from, $to, $text, $options]);
Method
Objects
To receive delivery notifications (DLR), you have to subscribe to the webhook sms.mt.status_update (see below).
Method
Do not set a sender if you want to receive replies - we will automatically use an SMS number.
To receive inbound messages (MO), you have to subscribe to the webhook sms.mo (see below).
Method
$result = $api->call('sms.get', ['SMSHASH']);
Method
Objects
See our online documentation: http://www.callr.com/docs/webhooks/
$type = 'sms.mt.status_update';
$endpoint = 'http://yourdomain.com/webhook_url';
$result = $api->call('webhooks.subscribe', [ $type, $endpoint, null ]);
Method
Objects
$result = $api->call('webhooks.get_event_types');
Method
App name format
$options = new stdClass;
$options->url = 'http://yourdomain.com/realtime_callback_url';
$result = $api->call('apps.create', ['REALTIME10', 'Your app name', $options]);
Method
Objects
$target = new stdClass;
$target->number = '+33132456789';
$target->timeout = 30;
$callOptions = new stdClass;
$callOptions->cdr_field = '42';
$callOptions->cli = 'BLOCKED';
$result = $api->call('calls.realtime', ['appHash', $target, $callOptions]);
Method
Objects
$result = $api->call('apps.assign_did', ['appHash', 'DID ID']);
Method
Objects
$result = $api->call('did/areacode.countries');
Method
Objects
$result = $api->call('did/areacode.get_list', ['US', null]);
Method
Objects
$result = $api->call('did/areacode.types', ['US']);
Method
Objects
$result = $api->call('did/store.buy_order', ['OrderToken']);
Method
Objects
$result = $api->call('did/store.cancel_order', ['OrderToken']);
Method
$result = $api->call('did/store.cancel_subscription', ['DID_ID']);
Method
$result = $api->call('did/store.get_quota_status');
Method
Objects
$result = $api->call('did/store.get_quote', [0, 'GOLD', 1]);
Method
*Objects/
$result = $api->call('did/store.reserve', [0, 'GOLD', 1, 'RANDOM']);
Method
Objects
$result = $api->call('did/store.view_order', ['OrderToken']);
Method
Objects
$params = new stdClass;
$params->open = true;
$access = [];
$result = $api->call('conference/10.create_room', ['room name', $params, $access]);
Method
Objects
$result = $api->call('conference/10.assign_did', ['Room ID', 'DID ID']);
Method
$params = new stdClass;
$params->open = true;
$access = [
(object)['pin' => '1234', 'level' => 'GUEST'],
(object)['pin' => '4321', 'level' => 'ADMIN', 'phone_number' => '+33123456789']
];
$result = $api->call('conference/10.create_room', ['room name', $params, $access]);
Method
Objects
$result = $api->call('conference/10.call_room_access', ['Room Access ID', 'BLOCKED', true]);
Method
$result = $api->call('media/library.get_list', [null]);
Method
$result = $api->call('media/library.create', ['name']);
Method
$webhook_url = 'http://yourdomain.com/webhook_url';
$audio_data = base64_encode(file_get_contents('/tmp/audio.mp3'));
$result = $api->call('media.import_file_from_base64_async', [$audio_data, $webhook_url]);
Method
$media_id = 0;
$result = $api->call('media/tts.set_content', [$media_id, 'Hello world!', 'TTS_EN-GB_SERENA', null]);
Method
$from = 'YYYY-MM-DD HH:MM:SS';
$to = 'YYYY-MM-DD HH:MM:SS';
$result = $api->call('cdr.get', ['OUT', $from, $to, null, null]);
Method
Objects
$target = new stdClass;
$target->number = '+33123456789';
$target->timeout = 30;
$messages = [131, 132, 'TTS|TTS_EN-GB_SERENA|Hello world! how are you ? I hope you enjoy this call. good bye.'];
$options = new stdClass;
$options->cdr_field = 'userData';
$options->cli = 'BLOCKED';
$options->loop = 2;
$result = $api->call('calls.broadcast_1', [$target, $messages, $options]);
$target = new stdClass;
$target->number = '+33123456789';
$target->timeout = 30;
$messages = [131, 132, 134];
$result = $api->call('calls.broadcast_1', [$target, $messages, null]);
Method
Objects