In order to use Voximplant Node.js SDK, you need the following:
- A developer account. If you don't have one, sign up here.
- A private API key. There are 2 options to obtain it:
- Either generate it in the Voximplant Control panel
- Or call the CreateKey HTTP API method with the specified authentication parameters. You'll receive a response with the result field in it. Save the result value in a file (since we don't store the keys, save it securely on your side).
- Node.js >=10
Go to your project folder and install the SDK using npm
:
npm i --save @voximplant/apiclient-nodejs
Then import the SDK in your script
const VoximplantApiClient = require("@voximplant/apiclient-nodejs").default;
Next, specify the path to the file with the result value either in the constructor or using the environment.
constructor:
const client = new VoximplantApiClient("/path/to/credentials.json");
env:
export VOXIMPLANT_CREDENTIALS=/path/to/credentials.json
const VoximplantApiClient = require("@voximplant/apiclient-nodejs").default;
const client = new VoximplantApiClient();
client.onReady = function(){
// Start the scripts from the account.
client.Scenarios.startScenarios({ruleId: '1',
scriptCustomData: 'mystr'})
.then(ev=>console.log(ev))
.catch(err=>console.error(err));
};
const VoximplantApiClient = require("@voximplant/apiclient-nodejs").default;
const client = new VoximplantApiClient();
client.onReady = function(){
// Send the SMS message with text "Test message" from the phone number 447443332211 to the phone number 447443332212.
client.SMS.sendSmsMessage({source: '447443332211',
destination: '447443332212',
smsBody: 'Test message'})
.then(ev=>console.log(ev))
.catch(err=>console.error(err));
};
const VoximplantApiClient = require("@voximplant/apiclient-nodejs").default;
const client = new VoximplantApiClient();
client.onReady = function(){
// Get the first call session history record from the 2012-01-01 00:00:00 UTC to the 2014-01-01 00:00:00 UTC
client.History.getCallHistory({fromDate: new Date('2012-01-01 00:00:00 GMT'),
toDate: new Date('2014-01-01 00:00:00 GMT'),
count: '1',
timezone: 'Etc/GMT'})
.then(ev=>console.log(ev))
.catch(err=>console.error(err));
};