GithubHelp home page GithubHelp logo

asterisk.io's Introduction

asterisk.io

node.js asterisk pbx io

1. Install

2. How to use

2.1 AMI

2.1.1 Actions

2.1.2 Events

2.2 AGI

3. TODO

1. Install

npm install asterisk.io

2. How to use

var aio = require('asterisk.io'),
    ami = null,   // see ami section
    agi = null;   // see agi section

2.1 AMI

Read more at asterisk wiki for: actions, events.

2.1.1 Actions

A list of actions that can be send to asterisk pbx can be found at asterisk wiki page.

IMPORTANT: The list of actions depends of your asterisk version installed.

Send an action and get the response in a callback function.

var aio = require('asterisk.io'),
    ami = null;

ami = aio.ami(
    'ip_or_hostname',   // Asterisk PBX machine

    5038,               // the default port number setup
                        // in "/etc/asterisk/manager.conf"
                        // in "general" section

    'admin',            // manager username

    'admin'             // manager password
);

ami.on('error', function(err){
    throw err;
});

ami.on('ready', function(){

    // connected && authenticated

    ami.action(
        'Originate',
        {
            Channel: 'SIP/101',
            Context: 'default',
            Priority: 1,
            Async: 'false',     // set Async to 'false' to
                                // get response in the callback function
            Exten: '102'
        },
        function(data){
            if(data.Response == 'Error'){
                console.log('Originate', data.Message);
                return;
            }
            console.log('Originate', data.Message);
        }
    );

});

2.1.2 Events

A list of events from asterisk pbx can be found at asterisk wiki page.

IMPORTANT: The list of events depends of your asterisk version installed.

Catch all events from asterisk ami with eventAny. Example:

var aio = require('asterisk.io'),
    ami = null;

ami = aio.ami(
    'ip_or_hostname',   // Asterisk PBX machine

    5038,               // the default port number setup
                        // in "/etc/asterisk/manager.conf"
                        // in "general" section

    'admin',            // manager username

    'admin'             // manager password
);

ami.on('error', function(err){
    throw err;
});

// this catch any event from asterisk pbx
ami.on('eventAny', function(data){
    console.log(data.Event, data);
});

Catch specific event from asterisk ami with eventXYZ. Example:

var aio = require('asterisk.io'),
    ami = null;

ami = aio.ami(
    'ip_or_hostname',   // Asterisk PBX machine

    5038,               // the default port number setup
                        // in "/etc/asterisk/manager.conf"
                        // in "general" section

    'admin',            // manager username

    'admin'             // manager password
);

ami.on('error', function(err){
    throw err;
});

// Bridge event
ami.on('eventBridge', function(data){
    console.log('eventBridge', data);
});

// Hangup event
ami.on('eventHangup', function(data){
    console.log('eventHangup', data);
});

2.2 AGI

Documetation for agi commands on asterisk wiki page.

var aio = require('asterisk.io'),
    agi = null;

agi = aio.agi(14000); // port and host
                      // if host is missing then
                      // '0.0.0.0' is used as host

agi.on('error', function(err){
    throw err;
});

agi.on('listening', function(){
    console.log('listening on port 14000');
});

agi.on('close', function(){
    console.log('close');
});

agi.on('connection', function(agiHandler){

    // all variables (key, value pairs) are
    // avaiable in agiHandler
    // example: agiHandler.agi_network
    //          agiHandler.agi_network_script
    //          agiHandler.agi_channel
    //          agiHandler.agi_xyz

    agiHandler.on('hangup', function(){
        console.log('hangup');
    });

    agiHandler.on('error', function(err){
        throw err;
    });

    agiHandler.on('close', function(){
        console.log('close');
    });

    // answer the channel
    agiHandler.command('Answer', function(code, result, data){

        // say date with "unix_timestamp" and "" as escape digits
        agiHandler.command('Say Date "1414330073" ""', function(code, result, data){

            // say time with "unix_timestamp" and "" as escape digits
            agiHandler.command('Say Time "1414330073" ""', function(){

                agiHandler.command('HangUp', function(){
                    // hangup the channel, this will raise hangup and close event
                });

            });

        });

    });

});

3. TODO

  • ARI
  • AGI - IVR (Interactive Voice Response) from JSON object
  • UI: real time user interface

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.