2017 © Pedro Peláez
 

library sdk-php

CALLR PHP SDK for JSON-RPC API

image

callr/sdk-php

CALLR PHP SDK for JSON-RPC API

  • Friday, August 11, 2017
  • by callr
  • Repository
  • 13 Watchers
  • 3 Stars
  • 23,863 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 4 Forks
  • 0 Open issues
  • 7 Versions
  • 14 % Grown

The README.md

PHP SDK for CALLR API

JSON-RPC 2.0 PHP class, to use with CALLR API., (*1)

  • 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, (*2)

  • Easy to use Client class, built for PHP 5.4+, (*3)

  • Can be used for both the API and Real-time calls
  • Requires: php5-curl

Composer

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., (*4)

The composer.json file should look like this:, (*5)

{
  "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., (*6)

Then you just need to include one file in your code:, (*7)

<?php

require 'vendor/autoload.php';

Usage

Init

$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'));

Login-as

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 :, (*8)

$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., (*9)

Sending SMS

Without options

$from = 'SMS';
$to   = '+33123456789';
$text = 'Hello, SMS world!';

$result = $api->call('sms.send', [$from, $to, $text, null]);

Method * sms.send, (*10)

Personalized sender

Your sender must have been authorized and respect the sms_sender format, (*11)

$from = 'Your Brand';
$to   = '+33123456789';
$text = 'Hello, SMS world!';

$result = $api->call('sms.send', [$from, $to, $text, null]);

Method * sms.send, (*12)

If you want to receive replies, do not set a sender - we will automatically use an SMS number

$from = '';
$to   = '+33123456789';
$text = 'Hello, SMS world!';

$result = $api->call('sms.send', [$from, $to, $text, null]);

Method - sms.send, (*13)

Force GSM encoding

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., (*14)

You can however force the encoding to be used at any time, using the force_encoding property., (*15)

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., (*16)

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., (*17)

$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 * sms.send, (*18)

Objects * SMS.Options, (*19)

Long SMS (availability depends on carrier)

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., (*20)

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., (*21)

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., (*22)

$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 * sms.send, (*23)

Specify your SMS nature (alerting or marketing)

$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 * sms.send, (*24)

Objects * SMS.Options, (*25)

Custom data

$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 * sms.send, (*26)

Objects * SMS.Options, (*27)

Delivery Notification - set URL to receive notifications

To receive delivery notifications (DLR), you have to subscribe to the webhook sms.mt.status_update (see below)., (*28)

Method * sms.send * webhooks.subscribe, (*29)

Inbound SMS - set URL to receive inbound messages (MO) and replies

Do not set a sender if you want to receive replies - we will automatically use an SMS number., (*30)

To receive inbound messages (MO), you have to subscribe to the webhook sms.mo (see below)., (*31)

Method * webhooks.subscribe, (*32)

Get an SMS

$result = $api->call('sms.get', ['SMSHASH']);

Method * sms.get, (*33)

Objects * SMS, (*34)


Webhooks

See our online documentation: http://www.callr.com/docs/webhooks/, (*35)

Subscribe to webhooks

$type = 'sms.mt.status_update';
$endpoint = 'http://yourdomain.com/webhook_url';

$result = $api->call('webhooks.subscribe', [ $type, $endpoint, null ]);

Method * webhooks.subscribe, (*36)

Objects * Webhook, (*37)

List available webhooks

$result = $api->call('webhooks.get_event_types');

Method * webhooks.get_event_types, (*38)


REALTIME

Create a REALTIME app with a callback URL

App name format, (*39)

$options = new stdClass;
$options->url = 'http://yourdomain.com/realtime_callback_url';

$result = $api->call('apps.create', ['REALTIME10', 'Your app name', $options]);

Method * apps.create, (*40)

Objects * REALTIME10 * App, (*41)

Start a REALTIME outbound call

$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 * calls.realtime, (*42)

Objects * Target * REALTIME10.Call.Options, (*43)

Inbound Calls - Assign a phone number to a REALTIME app

$result = $api->call('apps.assign_did', ['appHash', 'DID ID']);

Method * apps.assign_did, (*44)

Objects * App * DID, (*45)


DIDs

List available countries with DID availability

$result = $api->call('did/areacode.countries');

Method * did/areacode.countries, (*46)

Objects * DID.Country, (*47)

Get area codes available for a specific country and DID type

$result = $api->call('did/areacode.get_list', ['US', null]);

Method * did/areacode.get_list, (*48)

Objects * DID.AreaCode, (*49)

Get DID types available for a specific country

$result = $api->call('did/areacode.types', ['US']);

Method * did/areacode.types, (*50)

Objects * DID.Type, (*51)

Buy a DID (after a reserve)

$result = $api->call('did/store.buy_order', ['OrderToken']);

Method * did/store.buy_order, (*52)

Objects * DID.Store.BuyStatus, (*53)

Cancel your order (after a reserve)

$result = $api->call('did/store.cancel_order', ['OrderToken']);

Method * did/store.cancel_order, (*54)

Cancel a DID subscription

$result = $api->call('did/store.cancel_subscription', ['DID_ID']);

Method * did/store.cancel_subscription, (*55)

View your store quota status

$result = $api->call('did/store.get_quota_status');

Method * did/store.get_quota_status, (*56)

Objects * DID.Store.QuotaStatus, (*57)

Get a quote without reserving a DID

$result = $api->call('did/store.get_quote', [0, 'GOLD', 1]);

Method * did/store.get_quote, (*58)

*Objects/ * DID.Store.Quote, (*59)

Reserve a DID

$result = $api->call('did/store.reserve', [0, 'GOLD', 1, 'RANDOM']);

Method * did/store.reserve, (*60)

Objects * DID.Store.Reservation, (*61)

View your order

$result = $api->call('did/store.view_order', ['OrderToken']);

Method * did/store.buy_order, (*62)

Objects * DID.Store.Reservation, (*63)


Conferencing

Create a conference room

$params = new stdClass;
$params->open = true;

$access = [];

$result = $api->call('conference/10.create_room', ['room name', $params, $access]);

Method * conference/10.create_room, (*64)

Objects * CONFERENCE10 * CONFERENCE10.Room.Access, (*65)

Assign a DID to a room

$result = $api->call('conference/10.assign_did', ['Room ID', 'DID ID']);

Method * conference/10.assign_did, (*66)

Create a PIN protected conference room

$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 * conference/10.create_room, (*67)

Objects * CONFERENCE10 * CONFERENCE10.Room.Access, (*68)

Call a room access

$result = $api->call('conference/10.call_room_access', ['Room Access ID', 'BLOCKED', true]);

Method * conference/10.call_room_access, (*69)


Media

List your medias

$result = $api->call('media/library.get_list', [null]);

Method * media/library.get_list, (*70)

Create an empty media

$result = $api->call('media/library.create', ['name']);

Method * media/library.create, (*71)

Upload/Import a media

$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.import_file_from_base64_async, (*72)

Use Text-to-Speech

$media_id = 0;

$result = $api->call('media/tts.set_content', [$media_id, 'Hello world!', 'TTS_EN-GB_SERENA', null]);

Method * media/tts.set_content, (*73)


CDR

Get inbound or outbound CDRs

$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 * cdr.get, (*74)

Objects * CDR.In * CDR.Out, (*75)


Broadcast messages to a target

$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]);

Without options

$target = new stdClass;
$target->number = '+33123456789';
$target->timeout = 30;

$messages = [131, 132, 134];

$result = $api->call('calls.broadcast_1', [$target, $messages, null]);

Method * calls.broadcast_1, (*76)

Objects * Target * Calls.Broadcast1.Options, (*77)

The Versions

11/08 2017

dev-master

9999999-dev https://github.com/THECALLR/sdk-php

CALLR PHP SDK for JSON-RPC API

  Sources   Download

MIT

The Requires

  • php >=5.4.0
  • ext-curl *
  • ext-json *

 

by Florent CHAUVEAU
by Michael JACQUIN

sdk thecallr callr

12/07 2017

v0.11.1

0.11.1.0 https://github.com/THECALLR/sdk-php

CALLR PHP SDK for JSON-RPC API

  Sources   Download

MIT

The Requires

  • php >=5.4.0
  • ext-curl *
  • ext-json *

 

by Florent CHAUVEAU
by Michael JACQUIN

sdk thecallr callr

10/05 2017

v0.11.0

0.11.0.0 https://github.com/THECALLR/sdk-php

CALLR PHP SDK for JSON-RPC API

  Sources   Download

MIT

The Requires

  • php >=5.4.0
  • ext-curl *
  • ext-json *

 

by Florent CHAUVEAU
by Michael JACQUIN

sdk thecallr callr

14/02 2017

0.10.1

0.10.1.0 https://github.com/THECALLR/sdk-php

CALLR PHP SDK for JSON-RPC API

  Sources   Download

MIT

The Requires

  • php >=5.4.0
  • ext-curl *
  • ext-json *

 

by Florent CHAUVEAU
by Michael JACQUIN

sdk thecallr callr

06/02 2017

0.10.0

0.10.0.0 https://github.com/THECALLR/sdk-php

CALLR PHP SDK for JSON-RPC API

  Sources   Download

MIT

The Requires

  • php >=5.4.0
  • ext-curl *
  • ext-json *

 

by Florent CHAUVEAU
by Michael JACQUIN

sdk thecallr callr

22/12 2016

v0.9.2

0.9.2.0 https://github.com/THECALLR/sdk-php

CALLR PHP SDK for JSON-RPC API

  Sources   Download

MIT

The Requires

  • php >=5.4.0
  • ext-curl *
  • ext-json *

 

by Florent CHAUVEAU
by Michael JACQUIN

sdk thecallr callr

25/10 2016

v0.9.1

0.9.1.0 https://github.com/THECALLR/sdk-php

CALLR PHP SDK for JSON-RPC API

  Sources   Download

MIT

The Requires

  • php >=5.4.0
  • ext-curl *
  • ext-json *

 

by Florent CHAUVEAU
by Michael JACQUIN

sdk thecallr callr