node package manager
It’s your turn. Help us improve JavaScript. Take the 2017 JavaScript Ecosystem Survey »




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


$ npm install yana



var AMI = require('yana');
var ami = new AMI({
  port: 5038,
  host: '',
  login: 'login',
  password: 'secret',
  events: true,
  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: true): set to false to not receive AMI events
  • reconnect (optional, default: false): automatically reconnect on connection errors


Starts 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.


ami.send(action, [callback])


  • action: an object specifying AMI action to send to Asterisk. Keys are case insensitive.

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 AMI action

Action: Originate
Variable: var1=1
Variable: var2=2
  • callback (optional): a handler for the response and the following related events, if there are any.

Callback takes one argument that is message received from Asterisk. Callback is called once for each received message. The only argument is an object representing the message body.




  • callback (optional)


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 specivied in UserEvent header of AMI message

For thorough documentation on available AMI commands see Asterisk Wiki.

Example usage

var util = require('util');
var AMI = require('yana');
var ami = new AMI({
  login: 'login',
  password: 'secret'
ami.connect(function () {
ami.on('error', function (err) {
  console.log('An error occured: ' + err);
ami.on('FullyBooted', function (event) {
  ami.send({Action: 'ListCommands'}, function (res) {
  setTimeout(function () {
    ami.disconnect(function () {
  }, 5000);

Look at example.js for more examples.