PHP code example of callr / sdk-php

1. Go to this page and download the library: Download callr/sdk-php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

callr / sdk-php example snippets





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

$auth = new CALLR\API\Authentication\LoginPasswordAuth('username', 'password');
$auth = $auth->logAs('User', 'username_2');

$api = new CALLR\API\Client;
$api->setAuth($auth);

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

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

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

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

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

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

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

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

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

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

$options = new stdClass;
$options->user_data = '42';

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

$access = [];

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

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

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

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

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

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

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

$media_id = 0;

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

$from = 'YYYY-MM-DD HH:MM:SS';
$to = 'YYYY-MM-DD HH:MM:SS';

$result = $api->call('cdr.get', ['OUT', $from, $to, null, null]);

$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]);
json
{
  "lr/sdk-php": "^0.11"
  }
}