The `ari-client` package provides a JavaScript client library for interacting with the Asterisk REST Interface (ARI). It offers a higher-level, Asterisk-specific API built upon the underlying `swagger-js` library, simplifying interaction with Asterisk resources such as bridges, channels, endpoints, and playback objects. The library supports both callback-based and Promise-based asynchronous operations for connecting to ARI, listing resources, performing actions (like adding channels to bridges), and creating new resource instances (e.g., `ari.Bridge()`, `ari.Channel()`). It is currently at version 2.2.0, indicating a stable release. While a strict release cadence isn't explicitly stated, its active development suggests ongoing maintenance. Its key differentiator is abstracting the raw Swagger API into an intuitive, resource-oriented interface tailored specifically for Asterisk development.
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslnode 18–226 runs
build_error
glibcnode 18–226 runs
build_error
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
The library primarily uses CommonJS `require` syntax as demonstrated in its documentation and targets Node.js environments. Direct ESM `import` is not officially documented or supported for the main entry point in this version.
const client = require('ari-client');
`connect` is a method exposed by the default export `client`. It is not a named export. Ensure the `client` object is correctly obtained first.
client.connect(url, username, password)
Resource managers like `bridges`, `channels`, etc., are properties of the `ari` object returned by the `connect` function. They are not directly importable from the `ari-client` package itself.
const ari = await client.connect(url, username, password); ari.bridges.list();
Demonstrates connecting to Asterisk ARI, listing bridges, creating a new channel, and handling Stasis events using Promises.
const client = require('ari-client');
const url = process.env.ARI_URL ?? 'http://localhost:8088/ari';
const username = process.env.ARI_USERNAME ?? 'asterisk';
const password = process.env.ARI_PASSWORD ?? 'asterisk';
async function main() {
try {
console.log(`Connecting to ARI at ${url}...`);
const ari = await client.connect(url, username, password);
console.log('Successfully connected to ARI.');
// List all active bridges
console.log('Listing existing bridges...');
const bridges = await ari.bridges.list();
console.log(`Found ${bridges.length} bridge(s).`);
bridges.forEach(b => console.log(` Bridge ID: ${b.id}, Type: ${b.bridge_type}`));
// Create a new channel and listen for events
const channel = ari.Channel();
channel.on('StasisStart', (event, channelInstance) => {
console.log(`Channel ${channelInstance.id} entered Stasis application.`);
// Perform actions with the channel, e.g., answer, play media
channelInstance.answer()
.then(() => channelInstance.play({media: 'sound:hello-world'}))
.then(playback => console.log(`Playing sound: ${playback.id}`))
.catch(err => console.error(`Error playing sound: ${err.message}`));
});
channel.on('ChannelDtmfReceived', (event, channelInstance) => {
console.log(`DTMF received on channel ${channelInstance.id}: ${event.digit}`);
});
channel.on('StasisEnd', (event, channelInstance) => {
console.log(`Channel ${channelInstance.id} left Stasis application.`);
});
console.log('Originating a new channel...');
const originatedChannel = await channel.originate({
endpoint: 'PJSIP/1000',
app: 'my-stasis-app',
appArgs: 'dialed'
});
console.log(`Channel ${originatedChannel.id} originated. Waiting for events...`);
// Keep the process alive to receive events (in a real app, use a proper event loop)
// setTimeout(() => { console.log('Exiting after 60 seconds.'); process.exit(0); }, 60000);
} catch (err) {
console.error(`Failed to connect or interact with ARI: ${err.message}`);
process.exit(1);
}
}
main();
Upgrade
Version history
Breaking-change detection hasn't run for this library yet.
Audit
Security & dependencies
CVE tracking and dependency tree are planned for a later release.