SDK in NodeJS for CALLR API For more examples see the the nodejs examples (https://github.com/THECALLR/examples-nodejs) repo.
Install via NPM
npm install callr
Or get sources from Github
- Please see the documentation here for how to authenticate using older
1.x
versions of the SDK.
When you initialise the callr api object with your chosen authentication method, you can also pass in any options like the following:
var options = {
...
}
var callr = require('callr');
var api = new callr.api(<authentication method>, options);
...
var callr = require('callr');
var api = new callr.api(callr.loginPasswordAuth('login', 'password'));
var callr = require('callr');
var api = new callr.api(callr.apiKeyAuth('987654321abcdef987654321abcdef987654321abcdef987654321abcdef987654321abcdef987654321abcdef987654321a'));
var callr = require('callr');
var api = new callr.api(callr.userSessionAuth('987654321abcdef987654321abcdef987654321a'));
var callr = require('callr');
var options = {
loginas: {
type: 'user', // available types: user, account
target: '<login>' // available targets: <login> for type user,
} // <hash> for type account
}
var api = new callr.api(callr.loginPasswordAuth('login', 'password'), options);
var callr = require('callr');
var api = new callr.api('login', 'password');
...
api.setLoginAs('user', '<login>'); // available types: user, account
// available targets: <login> for type user,
// <hash> for type account
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
});
api.call('sms.send', 'SMS', '+33123456789', 'Hello world!', null).success(function(response) {
// success callback
});
Method
Your sender must have been authorized and respect the sms_sender format
api.call('sms.send', 'Your Brand', '+33123456789', 'Hello world!', null);
Method
api.call('sms.send', '', '+33123456789', 'Hello world!', null);
Method
var optionSMS = { force_encoding: 'GSM' };
api.call('sms.send', '', '+33123456789', 'Hello world!', optionSMS);
Method
Objects
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', 'SMS', '+33123456789', text, null);
Method
var optionSMS = { nature: 'ALERTING' };
api.call('sms.send', 'SMS', '+33123456789', 'Hello world!', optionSMS);
Method
Objects
var optionSMS = { user_data: '42' };
api.call('sms.send', 'SMS', '+33123456789', 'Hello world!', optionSMS);
Method
Objects
var optionSMS = {
webhook: {
endpoint: 'http://yourdomain.com/webhook_endpoint'
}
};
api.call('sms.send', 'SMS', '+33123456789', 'Hello world!', optionSMS).success(function(response) {
// success callback
});
Method
Objects
Do not set a sender if you want to receive replies - we will automatically use a shortcode.
var optionSMS = {
webhook: {
endpoint: 'http://yourdomain.com/webhook_endpoint'
}
};
api.call('sms.send', '', '+33123456789', 'Hello world!', optionSMS).success(function(response) {
// success callback
});
Method
Objects
api.call('sms.get', 'SMSHASH').success(function(response) {
// success callback
});
Method
Objects
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
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
api.call('apps.assign_did', 'appHash', 'DID ID').success(function(result) {
//
});
Method
Objects
api.call('did/areacode.countries').success(function(result) {
//
});
Method
Objects
api.call('did/areacode.get_list', 'US', null).success(function(result) {
//
});
Method
Objects
api.call('did/areacode.types', 'US').success(function(result) {
//
});
Method
Objects
api.call('did/store.buy_order', 'OrderToken').success(function(result) {
//
});
Method
Objects
api.call('did/store.cancel_order', 'OrderToken').success(function(result) {
//
});
Method
api.call('did/store.cancel_subscription', 'DID ID').success(function(result) {
//
});
Method
api.call('did/store.get_quota_status').success(function(result) {
//
});
Method
Objects
api.call('did/store.get_quote', 0, 'GOLD', 1).success(function(result) {
//
});
Method
*Objects/
api.call('did/store.reserve', 0, 'GOLD', 1, 'RANDOM').success(function(result) {
//
});
Method
Objects
api.call('did/store.view_order', 'OrderToken').success(function(result) {
//
});
Method
Objects
var params = { open: true };
var access = [];
api.call('conference/10.create_room', 'room name', params, access).success(function(result) {
//
});
Method
Objects
api.call('conference/10.assign_did', 'Room ID', 'DID ID');
Method
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
api.call('conference/10.call_room_access', 'Room Access ID', 'BLOCKED', true).success(function(result) {
//
});
Method
api.call('media/library.get_list', null).success(function(result) {
//
});
Method
api.call('media/library.create', 'name').success(function(media_id) {
//
});
Method
var media_id = 0;
api.call('media/library.set_content', media_id, 'text', 'base64_audio_data').success(function(result) {
//
});
Method
var media_id = 0;
api.call('media/tts.set_content', media_id, 'Hello world!', 'TTS-EN-GB_SERENA', null).success(function(result) {
//
});
Method
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
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('calls.broadcast_1', target, messages, options).success(function(result) {
//
});
var target = {
number: '+33123456789',
timeout: 30
};
var messages = [131, 132, 134];
api.call('calls.broadcast_1', target, messages, null).success(function(result) {
//
});
Method
Objects
try {
api.call('sms.get', 'unknown hash');
} catch (e) {
console.log('Error\n', e);
}
- Deprecated method for authenticating with
1.x
versions of the SDK.
For authenticating with older versions of the API SDK can be done the following way:
var callr = require('callr');
var api = new callr.api('login', 'password');
...
Or when passing options
var callr = require('callr');
var options = {
loginas: {
type: 'user', // available types: user, account
target: '<login>' // available targets: <login> for type user,
} // <hash> for type account
}
var api = new callr.api('login', 'password', options);
...