Giter VIP home page Giter VIP logo

astproxy's Introduction

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

astproxy's People

Contributors

alepolidori avatar

Watchers

 avatar

Forkers

thutex

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.