All Projects → ipoddubny → ya-node-asterisk

ipoddubny / ya-node-asterisk

Licence: MIT License
node.js client library for Asterisk Manager Interface

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to ya-node-asterisk

Astive
Media controller for Asterisk PBX (FastAGI Server)
Stars: ✭ 37 (+105.56%)
Mutual labels:  ami, asterisk
Pami
PHP Asterisk Manager Interface ( AMI ) supports synchronous command ( action )/ responses and asynchronous events using the pattern observer-listener. Supports commands with responses with multiple events. Very suitable for development of operator consoles and / or asterisk / channels / peers monitoring through SOA, etc
Stars: ✭ 351 (+1850%)
Mutual labels:  ami, asterisk
callme
No description or website provided.
Stars: ✭ 45 (+150%)
Mutual labels:  ami, asterisk
goami
Asterisk Manager Interface (AMI) client in Go
Stars: ✭ 36 (+100%)
Mutual labels:  ami, asterisk
Nami
Asterisk manager interface (ami) client for nodejs
Stars: ✭ 94 (+422.22%)
Mutual labels:  ami, asterisk
Python Ami
Python AMI Client
Stars: ✭ 70 (+288.89%)
Mutual labels:  ami, asterisk
ami
integration asterisk manager interface (AMI) in laravel
Stars: ✭ 25 (+38.89%)
Mutual labels:  ami, asterisk
Starpy
Mirror of Python twisted library for AMI and FastAGI: No pull requests here please. Use Gerrit: https://gerrit.asterisk.org
Stars: ✭ 77 (+327.78%)
Mutual labels:  ami, asterisk
amiws queue
Asterisk Queues Dashboard with amiws
Stars: ✭ 40 (+122.22%)
Mutual labels:  ami, asterisk
amiws
Asterisk Management Interface (AMI) to Web-socket proxy
Stars: ✭ 60 (+233.33%)
Mutual labels:  ami, asterisk
vosk-asterisk
Speech Recognition in Asterisk with Vosk Server
Stars: ✭ 52 (+188.89%)
Mutual labels:  asterisk
nccg
Neural Shift Reduce Parser for CCG Semantic Parsing (Misra and Artzi, EMNLP 2016)
Stars: ✭ 16 (-11.11%)
Mutual labels:  ami
webcdr
☎️ CDR viewer for Asterisk with search, call recording player, bulk downloads, Excel export
Stars: ✭ 54 (+200%)
Mutual labels:  asterisk
caller-lookup
Reverse Caller Id using TrueCaller
Stars: ✭ 55 (+205.56%)
Mutual labels:  asterisk
Core
Free, easy to setup PBX for small business based on Asterisk 16 core
Stars: ✭ 190 (+955.56%)
Mutual labels:  asterisk
panel gen
Auto call generator for telephone switches at Connections Museum, Seattle.
Stars: ✭ 13 (-27.78%)
Mutual labels:  asterisk
aws-utils
This repository provides utilities which are used at MiQ.
Stars: ✭ 20 (+11.11%)
Mutual labels:  ami
amictl
Because you need to control your AMIs
Stars: ✭ 37 (+105.56%)
Mutual labels:  ami
astlinux
AstLinux is a "Network Appliance for Communications" x86_64 Linux distribution
Stars: ✭ 23 (+27.78%)
Mutual labels:  asterisk
magnusbilling7
MagnusBilling is a fast, secure, efficient, high availability, VOIP Billing.
Stars: ✭ 136 (+655.56%)
Mutual labels:  asterisk

js-semistandard-style Node.js CI

Yana

Yana is yet another node.js library for Asterisk Manager Interface.

Supported Asterisk versions: all (tested mostly with Asterisk 11, 13 and 16).

Supported node.js versions: 12+.

  • small (~350 lines of code)
  • no dependencies
  • low-level (AMI events and actions are processed as plain JavaScript objects)
  • supports Promises/async-await
  • supports AMI actions returning event lists

Installation

$ npm install yana

API

Connecting

const AMI = require('yana');

const ami = new AMI({
  port: 5038,
  host: 'example.com',
  login: 'login',
  password: 'secret',
  events: 'on',
  reconnect: true
});

ami.connect(function () {
  console.log('Connected to AMI');
});

Constructor parameters:

  • host (optional, default: 'localhost'): host the client connects to
  • port (optional, default: 5038): port the client connects to
  • login: AMI user login
  • password: AMI user password
  • events (optional, default: 'on'): string specifying which AMI event classes to receive, all by default (see Asterisk Wiki)
  • reconnect (optional, default: false): automatically reconnect on connection errors

ami.connect([callback])

Initiates a connection. When the connection is established, the 'connect' event will be emitted. The callback parameter will be added as an once-listener for the 'connect' event.

Returns: Promise.

Actions

ami.send(action, [callback])

Parameters:

  • action: an object specifying AMI action to send to Asterisk. Keys are expected to be in lower case.

Returns: Promise.

To specify multiple keys with the same name use an array as the value, for example:

{
  action: 'Originate',
  ...,
  variable: ['var1=1', 'var2=2']
}

will be transformed into an AMI action

action: Originate
...
variable: var1=1
variable: var2=2
  • callback (optional)

callback takes 2 arguments (err, res):

  • err indicates only connection or protocol errors. If an AMI action fails, but returns a valid response, it is not considered an error.
  • res is an object representing the message received from Asterisk (keys and values depend on Asterisk). Keys are always converted to lower case. Actions returning results in multiple AMI events are collected as an eventlist key in res. AMI results containing multiple keys of the same name are converted to objects containing one key with values collected in an array.

Disconnecting

ami.disconnect([callback]);

Parameters:

  • callback (optional)

Returns: Promise.

Promises

connect, send and disconnect return Promises and can be used with async/await without callbacks.

Events

AMI is an EventEmitter with the following events:

  • 'connect' emitted when the client has successfully logged in
  • 'error' emitted on unrecoverable errors (connection errors with reconnect turned off, unknown protocol, incorrect login)
  • 'disconnect' is only emitted in reconnection mode when the client loses connection
  • 'reconnect' is emitted on successful reconnection
  • 'event' fires on every event sent by Asterisk
  • all events received from Asterisk are passed trasparently, you can subsribe to events by their names, eg. 'FullyBooted' or 'PeerStatus'
  • UserEvents also trigger events like 'UserEvent-EventName', where EventName is specified in the UserEvent header of AMI message

For thorough documentation on AMI events see Asterisk Wiki.

Example usage

const AMI = require('yana');

const ami = new AMI({
  login: 'login',
  password: 'secret'
});

ami.connect(function () {
  console.log('Connected');
});

ami.on('error', function (err) {
  console.log('An error occured: ' + err);
});

ami.once('FullyBooted', function (event) {
  console.log('Ready');
  ami.send({action: 'CoreSettings'}, function (err, res) {
    console.log('CoreSettings result:', res);

    console.log('Waiting 5 seconds...');
    setTimeout(function () {
      console.log('Disconnecting...');
      ami.disconnect(function () {
        console.log('Disconnected');
      });
    }, 5000);
  });
});

Using Promises and async/await:

const AMI = require('yana');

async function main() {
  const ami = new AMI({
    login: 'login',
    password: 'secret'
  });

  try {
    await ami.connect();
  } catch (e) {
    console.error('Failed to connect');
    process.exit(1);
  }

  console.log('Connected');

  ami.on('error', function (err) {
    console.log('An error occured: ' + err);
  });

  ami.once('FullyBooted', async function (event) {
    console.log('Ready');

    try {
      const res = ami.send({action: 'CoreSettings'});
      console.log('CoreSettings result:', res);
    } catch (e) {
      console.log('Failed to send CoreSettings');
    }

    console.log('Waiting 5 seconds...');
    await new Promise((resolve, reject) => setTimout(resolve, 5000));

    console.log('Disconnecting...');

    await ami.disconnect();

    console.log('Disconnected');
  });
}

main();

Look at example.js for more examples.

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].