npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@gibme/asterisk-gateway-interface

v22.0.0

Published

Asterisk Gateway Interface Server

Readme

Asterisk Gateway Interface Server

A TypeScript implementation of an Asterisk Gateway Interface (AGI) server for building voice applications with Asterisk.

Requirements

  • Node.js >= 22

Installation

npm install @gibme/asterisk-gateway-interface
yarn add @gibme/asterisk-gateway-interface

Documentation

Full API documentation is available at https://gibme-npm.github.io/asterisk-gateway-interface/

Quick Start

import AGI, { Channel } from '@gibme/asterisk-gateway-interface';

const agi = new AGI(3000, '0.0.0.0');

agi.on('channel', async (channel: Channel) => {
    await channel.answer();
    await channel.sayNumber(12345);
    await channel.hangup();
});

await agi.start();

Then configure your Asterisk dialplan to route calls to the AGI server:

exten => 100,1,AGI(agi://127.0.0.1:3000)

Usage

Creating a Server

import AGI from '@gibme/asterisk-gateway-interface';

// new AGI(port, ip, maximumListeners)
const agi = new AGI(3000, '0.0.0.0', 20);

agi.on('channel', async (channel) => {
    // Handle incoming AGI channels
});

agi.on('error', (error) => {
    console.error('Server error:', error);
});

agi.on('close', () => {
    console.log('Server closed');
});

await agi.start();

// Later, to stop the server:
await agi.stop();

Working with Channels

Each incoming AGI connection emits a channel event with a Channel instance that provides the full AGI command set:

Call Control

agi.on('channel', async (channel) => {
    // Answer the channel
    await channel.answer();

    // Hang up when done
    await channel.hangup();
});

Playing Audio

// Play a sound file (allow caller to interrupt with '#')
await channel.streamFile('welcome', '#');

// Play with finer control over playback position
await channel.controlStreamFile('instructions', '#', 3000, '*', '#', '#');

// Say things
await channel.sayNumber(42);
await channel.sayDigits(12345, '#');
await channel.sayAlpha('hello', '#');
await channel.sayPhonetic('world', '#');
await channel.sayDate(Math.floor(Date.now() / 1000));
await channel.sayTime(Math.floor(Date.now() / 1000));

Collecting Input

// Get digits from the caller
const response = await channel.getData('enter-account-number', 5000, 10);

// Wait for a single digit
const digit = await channel.waitForDigit(5000);

// Get a single key during audio playback
const option = await channel.getOption('press-one-for-sales', '#', 5000);

// Receive text (for text-capable channels)
const text = await channel.receiveText(5000);

Dialing

import { Channel, Driver } from '@gibme/asterisk-gateway-interface';

const result = await channel.dial(
    Driver.PJSIP,   // Channel driver
    '1001',          // Destination
    30,              // Timeout in seconds
    'tT'             // Dial options
);

if (result.status === Channel.Dial.Status.ANSWER) {
    console.log('Call was answered');
}

Database Operations

// Asterisk DB operations
await channel.databasePut('family', 'key', 'value');
const value = await channel.databaseGet('family', 'key');
await channel.databaseDel('family', 'key');
await channel.databaseDelTree('family');

Channel Variables

// Set and get channel variables
await channel.setVariable('MY_VAR', 'some_value');
const value = await channel.getVariable('MY_VAR');
const fullValue = await channel.getFullVariable('${CALLERID(num)}');

Recording

// Record audio to a file
await channel.recordFile(
    '/tmp/recording',  // Filename (without extension)
    'wav',             // Format
    '#',               // Escape digits
    30000,             // Max duration (ms)
    undefined,         // Offset
    true,              // Beep before recording
    undefined          // Silence threshold
);

SIP/PJSIP Headers

// Add, get, and remove SIP headers (works with SIP, PJSIP, and IAX2 channels)
await channel.addHeader('X-Custom-Header', 'my-value');
const header = await channel.getHeader('X-Custom-Header');
await channel.removeHeader('X-Custom-Header');

Channel Properties

The Channel object exposes Asterisk AGI environment variables as properties:

agi.on('channel', async (channel) => {
    console.log(channel.callerid);       // Caller ID number
    console.log(channel.calleridname);   // Caller ID name
    console.log(channel.callingpres);    // Calling presentation
    console.log(channel.channel);        // Channel name (e.g., "PJSIP/1000-00000001")
    console.log(channel.context);        // Dialplan context
    console.log(channel.extension);      // Dialplan extension
    console.log(channel.priority);       // Dialplan priority
    console.log(channel.uniqueid);       // Unique channel ID
    console.log(channel.accountcode);    // Account code
    console.log(channel.language);       // Channel language
    console.log(channel.channelType);    // Channel driver type (Driver enum)
    console.log(channel.network);        // Whether this is a network AGI request
    console.log(channel.network_script); // Network script path
});

Exports

import AGI, {
    AsteriskGatewayInterface, // AGI server class (same as default export)
    Channel,                  // Channel class with full AGI command set
    Driver,                   // Channel driver enum (PJSIP, SIP, IAX2, etc.)
    ContextState,             // Channel context state enum
    ResponseArguments         // Parsed AGI response arguments
} from '@gibme/asterisk-gateway-interface';

License

MIT