Coder Social home page Coder Social logo

node-asterisk-ami's Introduction

asterisk-ami

An extremely lightweight Asterisk AMI connector

Build Status

Install

Try out the beta for version 0.2.0 and let us know what you think!

npm install [email protected]

Or stick with stable

npm install asterisk-ami

##Beta

Try out the beta, the docs can be found in the branch beta - Docs

Build Status

Usage

var AsteriskAmi = require('asterisk-ami');
var ami = new AsteriskAmi( { host: 'hostname', username: 'username', password: 'secret' } );

ami.on('ami_data', function(data){
	console.log('AMI DATA', data);
	//decide between Events and non events here and what to do with them, maybe run an event emitter for the ones you care about
});

ami.connect(function(){
	ami.send({action: 'Ping'});//run a callback event when we have connected to the socket
});//connect creates a socket connection and sends the login action

ami.send({action: 'Ping'});

##Events

(AMI Data) These give you AMI specific information

  • ami_login Called when logging into the ami, no data passed back
  • ami_data Called for each event we get back from the AMI, with an object being returned

(net socket events) Use these events to determine the status of the socket connection, as if the socket is disconnected, you would need to add your .on('close') events again, this was a bug in the previous version of asterisk-ami, use these new events instead which will always be called, even if the connection has died and been reconnected.

  • ami_socket_drain
  • ami_socket_error
  • ami_socket_timeout
  • ami_socket_end
  • ami_socket_close
  • ami_socket_unwritable

##methods

.connect(function(){
  console.log('connection to AMI socket successful');
}, function(raw_data){
  console.log('every time data comes back in the socket, this callback is called, useful for recording stats on data', raw_data);
})

.disconnect() //logs out of the AMI and then closes the connection, sets reconnect to false so that it wont try and reconnect

.send({action: 'Ping'}) //send an ami call, pass in a javascript object with the params you want to send the ami

.destroy() //terminates the connection to the ami socket if say disconnect fails, or you've lost connection to the ami and you're not using reconnect: true as a param

Configuration options

AsteriskAmi has preset/configurable options, you can set these via an object passed in to AsteriskAmi

  • 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
  • debug: Do you want debugging output to the screen, default: false
  • 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
  • events Do we want to recieve AMI events, default: true

NPM Maintainers

The npm module for this library is maintained by:

License

asterisk-ami is licensed under the MIT license.

node-asterisk-ami's People

Contributors

danielburhans avatar danjenkins avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

node-asterisk-ami's Issues

Action: Queues failed in 0.2.0, and can't be catched in 0.1.0

When sending action 'Queues' on server, result are not comming because parsing are failed

Code:
ami.send({action: 'Ping'}, function(err, event){
if (err) {
console.log("ERROR ", err);
return;
}
console.log("Pinged. Answer - ", err, JSON.stringify(event));
});

Server answer:
QUEUE_NAME1 has 0 calls (max unlimited) in 'ringall' strategy (2s holdtime, 4s talktime), W:0, C:2, A:3, SL:100.0% within 60s
Members:
111 (Local/111@from-internal/n from Local/111@from-internal/n) with penalty 2 (ringinuse disabled) (realtime) (paused) (Not in use) has taken no calls yet
222 (Local/222@from-internal/n from Local/222@from-internal/n) with penalty 3 (ringinuse disabled) (realtime) (Not in use) has taken 2 calls (last was 10 secs ago)
No Callers

QUEUE_NAME2 has 0 calls (max unlimited) in 'ringall' strategy (0s holdtime, 0s talktime), W:0, C:0, A:0, SL:0.0% within 0s
No Members
No Callers

.disconnect() should provide a callback

when calling .disconnect(), you're performing a socket.end() but providing no callback for when the socket is completely closed. You could do this by listening to the 'close' event, i.e.

AsteriskAmi.prototype.disconnect = function(callback){
  this.reconnect = false;
  this.socket.on('close', function () {
    callback();
  });
  this.socket.end(this.generateSocketData({Action: 'Logoff'}));
}

You shouldn't need to remove the close listener on the socket because the socket should be destroyed when the connection is closed.

Sorry I'm lazy and didn't do a PR because this was just a tangential thought while reviewing someone's code.

Parse the environment variables in Async AGI responses

Currenrty gives you

{ event: 'AsyncAGI',
privilege: 'agi,all',
subevent: 'Start',
channel: 'SIP/1000-00000005',
env: 'agi_request%3A%20async%0Aagi_channel%3A%20SIP%2F1000-00000005%0Aagi_language%3A%20en%0Aagi_type%3A%20SIP%0Aagi_uniqueid%3A%201351659241.5%0Aagi_version%3A%2011.0.0%0Aagi_callerid%3A%201000%0Aagi_calleridname%3A%201000%0Aagi_callingpres%3A%200%0Aagi_callingani2%3A%200%0Aagi_callington%3A%200%0Aagi_callingtns%3A%200%0Aagi_dnid%3A%20500%0Aagi_rdnis%3A%20unknown%0Aagi_context%3A%20default%0Aagi_extension%3A%20500%0Aagi_priority%3A%203%0Aagi_enhanced%3A%200.0%0Aagi_accountcode%3A%20%0Aagi_threadid%3A%20140372307134208%0A%0A' }

Should be able to parse these vars out

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.