@nimvelo/phone-api-client
Official Nimvelo Phone API client
Last updated 2 months ago by nimvelo .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @nimvelo/phone-api-client 
SYNC missed versions from official npm registry.

⚠️ ⚠️ ⚠️ Deprecated Package ⚠️ ⚠️ ⚠️

This package has been renamed, and so this version has been deprecated.

Development is continuing under the name @sipcentric/pbx-client, please use that instead.


Nimvelo Node.js Client

Node.js client for the Nimvelo/Sipcentric API.

Usage

npm install @nimvelo/phone-api-client
const Nimvelo = require("@nimvelo/phone-api-client");

// ...

Getting started

Examples

The techniques shown in these examples work in the same way across the majority of resources. Refer to the API documentation for more information on those specific resources.

The examples below use Promises with async/await, however the library also supports callbacks. To use callbacks, simply pass a callback as the final parameter.

// Using async/await
const customers = await nimvelo.customers.get();
doStuffWith(customers);

// Using callbacks
nimvelo.customers.get((err, customers) => {
  doStuffWith(customers);
});

There are further examples in the examples/ directory. To try them, just clone the project, run an install in the project root, then again in the directory of the example you want to run. Finally, run npm start and the example will run.

Get all customers a user has access to

const Nimvelo = require("@nimvelo/phone-api-client");

(async () => {
  const nimvelo = new Nimvelo({
    username: "myusername",
    password: "mypassword"
  });

  const customers = await nimvelo.customers.get();
  console.log(customers);
})();

Get a specific customer

const Nimvelo = require("@nimvelo/phone-api-client");

(async () => {
  const nimvelo = new Nimvelo({
    username: "myusername",
    password: "mypassword"
  });

  const customerId = 1234;

  const customer = await nimvelo.customers.get(customerId);
  console.log(customer);
})();

Get a customer's phone book

const Nimvelo = require("@nimvelo/phone-api-client");

(async () => {
  const nimvelo = new Nimvelo({
    username: "myusername",
    password: "mypassword"
  });

  const customerId = 1234;

  const customer = await nimvelo.customers.get(customerId);
  const phonebook = await customer.phonebook.get();

  console.log(phonebook);
})();

Create phone book entry

const Nimvelo = require("@nimvelo/phone-api-client");

(async () => {
  const nimvelo = new Nimvelo({
    username: "myusername",
    password: "mypassword"
  });

  const customerId = 1234;

  const customer = await nimvelo.customers.get(customerId);
  const phonebookentry = {
    name: "Nimvelo",
    phoneNumber: "03301200030",
    email: "hello@nimvelo.com"
  };

  const createdEntry = await customer.phonebook.create(phonebookentry).save();

  console.log(createdEntry);
})();

Update phone book entry

const Nimvelo = require("@nimvelo/phone-api-client");

(async () => {
  const nimvelo = new Nimvelo({
    username: "myusername",
    password: "mypassword"
  });

  const customerId = 1234;
  const phonebookentryId = 5678;

  const customer = await nimvelo.customers.get(customerId);
  const phonebookentry = await customer.phonebook.get(phonebookentryId);

  phonebookentry.name = "Updated name";

  const savedEntry = await phonebookentry.save();

  console.log(savedEntry);
})();

Delete phone book entry

const Nimvelo = require("@nimvelo/phone-api-client");

(async () => {
  const nimvelo = new Nimvelo({
    username: "myusername",
    password: "mypassword"
  });

  const customerId = 1234;
  const phonebookentryId = 5678;

  const customer = await nimvelo.customers.get(customerId);
  const phonebookentry = await customer.phonebook.get(phonebookentryId);

  await phonebookentry.delete();
})();

Subscribe to incoming call events

const Nimvelo = require("@nimvelo/phone-api-client");

const nimvelo = new Nimvelo({
  username: "myusername",
  password: "mypassword"
});

nimvelo.stream.subscribe("incomingcall", function(call) {
  console.log(call);
});

Monitor presence of an extension

const Nimvelo = require("@nimvelo/phone-api-client");

const nimvelo = new Nimvelo({
  username: "myusername",
  password: "mypassword"
});

const myCustomerId = 1; // Change this to your customer ID

// Returns an array of subscriptions
const subscriptions = await nimvelo.presenceWatcher.subscribe({
  customerId: myCustomerId,
  targets: ["012345"], // The extensions you'd like to monitor
  onStateChange: (extension, newState) => {
    console.log(extension); // 012345
    console.log(newState); // AVAILABLE, BUSY, or RINGING
  }
});

Monitor presence of all extensions on an account

const Nimvelo = require("@nimvelo/phone-api-client");

const nimvelo = new Nimvelo({
  username: "myusername",
  password: "mypassword"
});

const subscribeToAll = async () => {
  const myCustomerId = 1; // Change this to your customer ID
  // Get your customer
  const customer = await nimvelo.customers.get(myCustomerId);
  // Get a list of all regular extensions
  const phones = await customer.phones.get();

  // Get the ids of each extension
  const extensionIds = phones.items.map(x => x.id);

  // Subscribe to each extension
  const subscriptions = await nimvelo.presenceWatcher.subscribe({
    customerId: myCustomerId,
    targets: extensionIds,
    onStateChange: (extension, newState) => {
      console.log(extension);
      console.log(newState);
    }
  });
};

try {
  subscribeToAll();
} catch (err) {
  console.error("Error: ", err);
}

Current Tags

  • 1.6.3                                ...           latest (2 months ago)

6 Versions

  • 1.6.3                                ...           2 months ago
  • 1.6.2                                ...           a year ago
  • 1.6.1                                ...           a year ago
  • 1.6.0                                ...           a year ago
  • 1.5.3                                ...           a year ago
  • 1.5.2                                ...           a year ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (5)
Dev Dependencies (5)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |