SDK in NodeJS for THECALLR API
JavaScript
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib
samples Update sample Jun 10, 2015
.gitignore Update SDK Jun 5, 2015
LICENSE
README.md Update README.md Jul 22, 2016
index.js Update SDK Jun 5, 2015
package.json update package Jun 5, 2015

README.md

sdk-nodejs

SDK in NodeJS for CALLR API
For more examples see the the nodejs examples (https://github.com/THECALLR/examples-nodejs) repo.

Quick start

Install via NPM

npm install callr

Or get sources from Github

Init

var callr = require('callr');

var api = new callr.api('login', 'password');

API return value management

Set your success/error callback to get data returned by the API

api.call('system.get_timestamp').success(function(response) {
    // success callback
}).error(function(error) {
    // error callback
});

Usage

Sending SMS

Without options

api.call('sms.send', 'CALLR', '+33123456789', 'Hello world!', null).success(function(response) {
    // success callback
});

Method

Personalized sender

Your sender must have been authorized and respect the sms_sender format

api.call('sms.send', 'Your Brand', '+33123456789', 'Hello world!', null);

Method

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

api.call('sms.send', '', '+33123456789', 'Hello world!', null);

Method

Force GSM encoding

var optionSMS = { force_encoding: 'GSM' };

api.call('sms.send', '', '+33123456789', 'Hello world!', optionSMS);

Method

Objects

Long SMS (availability depends on carrier)

var 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';
api.call('sms.send', 'CALLR', '+33123456789', text, null);

Method

Specify your SMS nature (alerting or marketing)

var optionSMS = { nature: 'ALERTING' };

api.call('sms.send', 'CALLR', '+33123456789', 'Hello world!', optionSMS);

Method

Objects

Custom data

var optionSMS = { user_data: '42' };

api.call('sms.send', 'CALLR', '+33123456789', 'Hello world!', optionSMS);

Method

Objects

Delivery Notification - set URL to receive notifications

var optionSMS = {
    push_dlr_enabled: true,
    push_dlr_url: 'http://yourdomain.com/push_delivery_path',
    // push_dlr_url_auth: 'login:password' // needed if you use Basic HTTP Authentication
};

api.call('sms.send', 'CALLR', '+33123456789', 'Hello world!', optionSMS).success(function(response) {
    // success callback
});

Method

Objects

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 a shortcode.

var optionSMS = {
    push_mo_enabled: true,
    push_mo_url: 'http://yourdomain.com/mo_delivery_path',
    // push_mo_url_auth: 'login:password' // needed if you use Basic HTTP Authentication
};

api.call('sms.send', '', '+33123456789', 'Hello world!', optionSMS).success(function(response) {
    // success callback
});

Method

Objects

Get an SMS

api.call('sms.get', 'SMSHASH').success(function(response) {
    // success callback
});

Method

Objects

SMS Global Settings

Get settings

api.call('sms.get_settings').success(function(response) {
    // success callback
});

Method

Objects

Set settings

Add options that you want to change in the object

var settings = {
    push_dlr_enabled: true,
    push_dlr_url: 'http://yourdomain.com/push_delivery_path',
    push_mo_enabled: true,
    push_mo_url: 'http://yourdomain.com/mo_delivery_path'
};

api.call('sms.set_settings', settings).success(function(response) {
    // success callback
});

Returns the updated settings.

Method

Objects


REALTIME

Create a REALTIME app with a callback URL

var options = {
    url: 'http://yourdomain.com/realtime_callback_url'
};

api.call('apps.create', 'REALTIME10', 'Your app name', options).success(function(app) {
    // app.hash will be used for realtime call
});

Method

Objects

Start a REALTIME outbound call

var target = {
    number: '+33132456789',
    timeout: 30
};

var callOptions = {
    cdr_field: '42',
    cli: 'BLOCKED'
};

api.call('dialr/call.realtime', 'appHash', target, callOptions).success(function(callID) {
    // success callback
}).error(function(error) {
    // error callback
});

Method

Objects

Inbound Calls - Assign a phone number to a REALTIME app

api.call('apps.assign_did', 'appHash', 'DID ID').success(function(result) {
    //
});

Method

Objects


DIDs

List available countries with DID availability

api.call('did/areacode.countries').success(function(result) {
    //
});

Method

Objects

Get area codes available for a specific country and DID type

api.call('did/areacode.get_list', 'US', null).success(function(result) {
    //
});

Method

Objects

Get DID types available for a specific country

api.call('did/areacode.types', 'US').success(function(result) {
    //
});

Method

Objects

Buy a DID (after a reserve)

api.call('did/store.buy_order', 'OrderToken').success(function(result) {
    //
});

Method

Objects

Cancel your order (after a reserve)

api.call('did/store.cancel_order', 'OrderToken').success(function(result) {
    //
});

Method

Cancel a DID subscription

api.call('did/store.cancel_subscription', 'DID ID').success(function(result) {
    //
});

Method

View your store quota status

api.call('did/store.get_quota_status').success(function(result) {
    //
});

Method

Objects

Get a quote without reserving a DID

api.call('did/store.get_quote', 0, 'GOLD', 1).success(function(result) {
    //
});

Method

*Objects/

Reserve a DID

api.call('did/store.reserve', 0, 'GOLD', 1, 'RANDOM').success(function(result) {
    //
});

Method

Objects

View your order

api.call('did/store.view_order', 'OrderToken').success(function(result) {
    //
});

Method

Objects


Conferencing

Create a conference room

var params = { open: true };
var access = [];

api.call('conference/10.create_room', 'room name', params, access).success(function(result) {
    //
});

Method

Objects

Assign a DID to a room

api.call('conference/10.assign_did', 'Room ID', 'DID ID');

Method

Create a PIN protected conference room

var params = { open: true };
var access = [
    { pin: '1234', level: 'GUEST' },
    { pin: '4321', level: 'ADMIN', phone_number: '+33123456789' }
];

api.call('conference/10.create_room', 'room name', params, access).success(function(result) {
    //
});

Method

Objects

Call a room access

api.call('conference/10.call_room_access', 'Room Access ID', 'BLOCKED', true).success(function(result) {
    //
});

Method


Media

List your medias

api.call('media/library.get_list', null).success(function(result) {
    //
});

Method

Create an empty media

api.call('media/library.create', 'name').success(function(media_id) {
    //
});

Method

Upload a media

var media_id = 0;

api.call('media/library.set_content', media_id, 'text', 'base64_audio_data').success(function(result) {
    //
});

Method

Use Text-to-Speech

var media_id = 0;

api.call('media/tts.set_content', media_id, 'Hello world!', 'TTS-EN-GB_SERENA', null).success(function(result) {
    //
});

Method


CDR

Get inbound or outbound CDRs

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

api.call('cdr.get', 'OUT', from, to, null, null).success(function(result) {
    //
});

Method

Objects


SENDR

Broadcast messages to a target (BETA)

var target = {
    number: '+33123456789',
    timeout: 30
};

var messages = [131, 132, 'TTS|TTS_EN-GB_SERENA|Hello world! how are you ? I hope you enjoy this call. good bye.'];

var options = {
    cdr_field: 'userData',
    cli: 'BLOCKED',
    loop: 2
};

api.call('sendr/simple.broadcast_1', target, messages, options).success(function(result) {
    //
});
Without options
var target = {
    number: '+33123456789',
    timeout: 30
};

var messages = [131, 132, 134];

api.call('sendr/simple.broadcast_1', target, messages, null).success(function(result) {
    //
});

Method

Objects


Fatal error management

try {
    api.call('sms.get', 'unknown hash');
} catch (e) {
    console.log('Error\n', e);
}