Working with Asterisk and Node.js

Screen Shot 2014-08-13 at 2.21.49 PM Screen Shot 2014-08-13 at 2.22.23 PM

I’ve been working on a very cool project project here at Vale Presente which was able to provide a smooth interface to our call center attendees increasing their productivity and quality of our costumer service. The project was built with HTML5, CSS3, Javascript and Node.js as our backend engine (only cool stuff!). But the main challenge was finding the right tool to get the job done in a fast and consistent manner. I’m not going to talk about how I built the client. My focus here is talk about the tool I used to create a fast and consistent connection between the attendees and Asterisk. That was tough. There are a lot of libraries available over the Internet but most of them aren’t production ready.

Production ready

During my quest I had the pleasure to meet asterisk-manager. A Asterisk Manager Interface created by Philipp Dunkel which is a node.js module for interacting with the Asterisk Manager API. Nowdays I’m helping him as a maintainer of the project, improving, fixing bugs and helping to increase the project’s visibility. Not just because I’m a maintainer but because it works!

Currently the asterisk-manager module/package for node.js is handling incredibly well more than 500,000 asterisk events and ~5,000 voice calls a day. All of those events are being transmitted to our clients through This is a production ready and tested solution.

How to use it

Pretty simple. First you have to install it directly:

npm install asterisk-manager

Or put it inside of your package.json:

"dependencies": {
"asterisk-manager": "0.1.x"

Now you have to create a connection instance with your asterisk server:

var AsteriskManager = require(‘asterisk-manager’)
, ami = new AsteriskManager(config.asterisk.port,, config.asterisk.user, config.asterisk.password, true)

And that’s it! It works! Now you have to take a closer look inside of the available events and actions and have fun!


The list of all available events which is supported by Asterisk Manager API can be found here: How do I listen for any/all AMI events?

ami.on(‘managerevent’, function(evt) {});

How do I listen for specific AMI events?

ami.on(‘hangup’, function(evt) {});
ami.on(‘confbridgejoin’, function(evt) {});

What if my connection dropped? You can listen to the connection events like:

ami.on(‘close’, function(e) {});
ami.on(‘disconnect’, function(e) {});
ami.on(‘connect’, function(e) {});

And make your own decision on what do to next.


The list of all available actions supported by Asterisk Manager API can be found here: How do I call an action?

‘channel’: "SIP/1234",
‘exten’: ‘1143224321’,
‘context’: ‘from-internal’,
‘priority’: ‘1’
}, function(err, res) {});

And that’s it! Have fun!

Github: NPM Repository: Bug Reports:

6 thoughts on “Working with Asterisk and Node.js

  1. Hi,
    I am trying to use asterisk-manager with nodejs. I have a running nodejs server at port 3000. Now I want to connect to my asterisk server and for that I am using asterisk-manager.

    a)In the node_modules folder I have the package ‘asterisk-manager’, and in the main package.json under dependencies I added the line “asterisk-manager”: “0.1.x” and restarted the nodejs server.
    But when I try to connect the AMI using the command
    var AsteriskManager = require(‘asterisk-manager’);
    var ami = new AsteriskManager(‘5038′,’serverip’,’user’,’passwd’, true);
    it throws an error ‘ReferenceError: AsteriskManager is not defined’

    Am I missing anything? Please let me know.



  2. Dear Igor, how to catch error ‘Authentication failed’ from function ManagerLogin in client code without analize raw events ?


  3. Hello,
    I am trying to print the peer statues on browser using node and, Till the data what i understood i think io.emit will help me to print my peers on browser. I get the status of peers on my terminal i want to print it upon browser to please help me for the same.

    Below is my code to fetch peer status on terminal
    console.log(‘connected to the AMI’);
    //ami.send({action: ‘Sippeers’,peer :’7010_rtcbiz’});
    ami.send({action: ‘SIPpeerstatus’});
    // ami.send({action: ‘sip show peer 7010_rtcbiz’});//run a callback event when we have connected to the socket
    }, 6000);


  4. Hello Igor ,

    sorry , but I do not understand how perform a meetme list #room and get the result .
    There i some other site where I’ll find some docs ?

    I coded :

    }, function(err, res) {

    Res = server listening on localhost:8000
    { response: ‘Success’,
    actionid: ‘1467211204530’,
    eventlist: ‘start’,
    message: ‘Meetme user list will follow’ }

    same with :
    ‘conference’: ‘12345’
    }, function(err, res) {

    Many thanks .


Leave a Reply to esraldi Cancel reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: