npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@nethesis/astproxy

v0.0.27

Published

Node.js proxy for Asterisk PBX

Downloads

135

Readme

Node.js Proxy for Asterisk PBX

Astproxy is a proxy between Asterisk PBX system and your application. It provides the possibility to send commands and to receive events from Asterisk offering an abstraction layer of data to always remain independent from the specific version of the PBX and to offer the possibiity to extend its functionalities to even support other type of PBX systems.

Requirements

Node.js v10 LTS (10.19.0) or later.

Asterisk versions supported

Asterisk v13.

Installation

This is a Node.js module available through the npm registry.

Before installing, download and install Node.js.

Install with npm:

npm i astproxy --save

Quick start

  1. Install the executable:
npm install astproxy
  1. Include the library:
const astproxy = require('astproxy');
  1. Configure astproxy

astproxy uses Asterisk AMI to communicate with Asterisk, so it needs some information to connect to it:

astproxy.config({
  port: 5038,
  host: 'localhost',
  username: '<USERNAME>',
  password: '<PASSWORD>',
  reconnect: true,
  reconnect_after: 3000
});

The credentials are usually present into /etc/asterisk/manager.conf.

  1. Register for the event ready

The event ready is emmited when the connection with Asterisk has been successfully established. Before using the astproxy you always have to register for this event:

let ready = () => {
  // astproxy is ready to be used
  // your code here
};
astproxy.on('ready', ready);
  1. Start the module:
astproxy.start();

Features

  • Configuration by JSON files
  • Send command to Asterisk
  • Receive events from Asterisk
  • Provides all the JSON data about:
    • extensions
    • queues
    • parkings
    • call conversations
  • Runtime reloading

Use Cases

An example of use cases could be:

  • originate a new call, answer to an incoming call, hangup a call
  • obtain all the extensions status: online, busy, ringing, offline, dnd, ...
  • obtain information about all phone conversations

Configuration

These are the configuration options used by astproxy to connect to Asterisk AMI:

  • port: port number for Asterisk AMI (default 5038)
  • host: host of Asterisk (default localhost)
  • username: username of Asterisk AMI user (default username)
  • password: password of Asterisk AMI user (default password)
  • reconnect: do you want the ami to reconnect if the connection is dropped (default false)
  • reconnect_after: how long to wait to reconnect, in miliseconds (default 3000)
  • prefix: a prefix number to be used for all phone calls (optional)

Example:

const astproxy = require('astproxy');
astproxy.config({
  port: 5038,
  host: 'localhost',
  username: 'admin',
  password: '0123456789',
  reconnect: true,
  reconnect_after: 3000
});

The credentials are usually contained into /etc/asterisk/manager.conf.

Events

You can obtain the events list with astproxy.EVENTS.

  • ready: is emitted once the asterisk connection has been established. You always have to register for this event before doing any operation.
const astproxy = require('astproxy');
astproxy.config({
  port: 5038,
  host: 'localhost',
  username: '<USERNAME>',
  password: '<PASSWORD>',
  reconnect: true,
  reconnect_after: 3000
});
astproxy.on('ready', () => {});  // or astproxy.on(asproxy.EVENTS.EVT_READY, () => {});
astproxy.start();
  • extenHangup
  • extenDialing

Get Extensions list

Data about all the extensions:

let extensions = astproxy.getExtensions();

Example of returned data:

{
  "2001": {                 // extension identifier
    "ip": "192.168.5.163",  // the ip address of the phone registered with this extension
    "cf": "221",            // the call forward status. If it's disabled, it is an empty string
    "cfb": "221",           // the call forward on busy status. If it's disabled, it is an empty string
    "cfu": "221",           // the call forward on unavailable status. If it's disabled, it is an empty string
    "dnd": false,           // it's true if the don't disturb is active
    "cfVm": "",             // the call forward to voicemail status. If it's disabled, it is an empty string
    "cfbVm": "",            // the call forward on busy to voicemail status. If it's disabled, it is an empty string
    "cfuVm": "",            // the call forward on unavailable to voicemail status. If it's disabled, it is an empty string
    "port": "5062",
    "name": "Alessandro",
    "exten": "214",
    "status": "online",              // the status can be: "dnd", "busy", "online", "onhold", "offline", "ringing", "busy_ringing"
    "context": "from-internal",      // the context
    "useWebsocket": false,           // if the extension use websocket
    "sipuseragent": "Twinkle/1.4.2",
    "conversations": {               // the keys are the conversation identifiers
      "SIP/214-000002f4>SIP/209-000002f5": {
        "id": "SIP/214-000002f4>SIP/209-000002f5",
        "owner": "214",
        "chDest": { ... },           // the source channel of the call
        "queueId": "401",            // the queue identifier if the conversation has gone through a queue
        "chSource": { ... },         // the destination channel of the call
        "duration": 26,
        "recording": "false",        // it's "true" or "mute" if the conversation is recording, "false" otherwise
        "direction": "in",
        "inConference": true,        // if the conversation involves a meetme conference
        "throughQueue": true,        // if the call has gone through a queue
        "counterpartNum": "209",
        "counterpartName": "user"
      }
    }
  },
  ...
}

Make a phone call

let callCb = (err, resp) => {
  // callback function
};
astproxy.call({
  endpointId: '2001', // the extension identifier: the caller
  to: '2002',         // the destination number of the call
  cb: callCb          // the callback function
});