Code Monkey home page Code Monkey logo

node-client's Introduction

⚠️ ⚠️ ⚠️ 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: "[email protected]"
  };

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

node-client's People

Contributors

adambowles avatar dependabot[bot] avatar djm0 avatar joannaaraneta avatar joshfarrant avatar

Watchers

 avatar  avatar

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.