Giter Club home page Giter Club logo

apiclient-nodejs's Introduction

Voximplant API client library

Version 2.10.0

Prerequisites

In order to use Voximplant Node.js SDK, you need the following:

  1. A developer account. If you don't have one, sign up here.
  2. A private API key. There are 2 options to obtain it:
    1. Generate it in the Voximplant Control panel
    2. 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).
  3. Node.js >= 11

How to use

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

Examples

Start a scenario

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));
};

Send an SMS

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));
};

Get a call history item

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));
};

apiclient-nodejs's People

Contributors

irbisadm avatar nikolasmelui avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

apiclient-nodejs's Issues

ApiClient instance not connecting in nodejs

const client = new VoximplantApiClient('credentials.json'); ==> this seems to not work
how do i export and import the credentials..
i renamed the file... i hope that's not the issue

downloadHistoryReport doesn't work

Hi,
I'm trying to retrieve the logs with the method downloadHistoryReport.

const client = new VoximplantApiClient();

client.onReady = function () {
      client.History.downloadHistoryReport({
        historyReportId: 123456789 // Here I pass the callSessionHistoryId obtained from client.History.getCallHistory
      })
        .then(ev => resolve(ev))
        .catch(err => reject(err));
};

Then the API returns:

[ { msg: 'Invalid report ID.', code: 355, field_name: 'history_report_id' } ]

What's going wrong?

ClientAPI not working with create-react-app

In React app with the node version 10.15.1, fs module does not work.
I got the following error in the browser when running react-scripts start.

Error

ร—
TypeError: fs.readFile is not a function
new VoximplantApiClient
node_modules/@voximplant/apiclient-nodejs/dist/index.js:6192
  6189 |   }
  6190 | };
  6191 | const path = process.env.VOXIMPLANT_CREDENTIALS || pathToCredentials;
> 6192 | fs.readFile(path, 'utf8', (err, data) => {
       | ^  6193 |   if (err) throw err;
  6194 |   this.key = JSON.parse(data);
  6195 |   if (this.onReady) this.onReady(this);

Suggestion
Instead of using the path and fs, have a user import the credentials file.

Front-end

import credentials from "path/to/credentials.json";

const VoximplantApiClient = require("@voximplant/apiclient-nodejs").default;
const client = new VoximplantApiClient(credentials); // Here we had a TypeError

Line 14- in src/index.tsx (apiclient-nodejs)

  constructor(credentials?: VoximplantApiClient["key"],private host?:string){
    this.key = credentials
    if(this.onReady)
      this.onReady(this)
  }

Authorization failed (Node js)

I keep getting Authorization Failed when trying using client.Users.addUser({}).then(ev=>console.log(ev))

//code below
const VoximplantApiClient = require('@voximplant/apiclient-nodejs').default;
const client = new VoximplantApiClient();
client.onReady = function () {
client.Users.addUser({
userName: 'GordonFreeman',
userDisplayName: 'GordonFreeman',
userPassword: '1234567',
applicationId: '10519832',
})
.then(ev => console.log(ev))
.catch(err => console.error(err));
};

Login fails with error 401: invalid token

When trying to log in with the proper username and password specified, I get the following object:

{
   name: "AuthResult",
   code: 401,
   result: false
}

I have added the scenario, this user exists and is active in the app, and the Client instance is initialized.

According to the document, 401 means "invalid token" although I'm not using token for this.
https://voximplant.com/docs/references/websdk/voximplant/eventhandlers/authresult#code

It was working normally before, and I'm curious what caused this issue.

reading the `pathToCredentials` with readFile instead of readFileSync

when creating a VoximplantApiClient in the constructor you are initializing this.key object of the json by reading from the pathToCredentials with the following line

  fs.readFile(path, 'utf8', (err, data) => {
      if (err)
          throw err;
      this.key = JSON.parse(data);
      if (this.onReady)
          this.onReady(this);
  });

This creates a promise inside a constructor that takes time and in a scenario where you create the credentials file right before creating the VoximplantApiClient and then right after that try to use the client you get the following error:

@voximplant/apiclient-nodejs/dist/index.js:2354
        const tokenData = { iss: this.key.account_id, iat: nowTS, exp: nowTS + 64 };
                                          ^
TypeError: Cannot read properties of undefined (reading 'account_id')

you can solve that by using readFileSync instead.

  try {
    const data = fs.readFileSync(path, 'utf8')
    this.key = JSON.parse(data);
  } catch (err) {
    throw err
  }

vulnerability in jsonwebtoken 8.5.1

Hi, there's a vulnerability in a library you're using jsonwebtoken version 8.5.1
It is recommended to use version 9.0.0

This affects our readiness to a certain mandatory steps in our development, which we can't do at the moment.
can you upgrade this dependency?

Screen Shot 2023-01-15 at 16 41 13

clientapi not working

client = new VoximplantApiClient("./credentials.json"); // this line not working.
client has nothing. 
client.onReady = function () {
// Add a new user.

client.Users.addUser({
    userName: req.query.phoneNumber,
    userDisplayName: req.query.displayName,
    userPassword: req.query.password,
    mobileNumber: req.query.phoneNumber,
    applicationId: voximplant_cred.application_id,
    applicationName: "abc"
})
    .then(ev => console.log(ev))
    .catch(err => console.error(err));

}

CreateCallList method

Hi,

Are there any plans to add CreateCallList method as part of the API client? I would like to be able to start outbound calls from __start_execution_time included as part of the input CSV.

Thanks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.