Getting Started
An implementation of Asterisk Async AGI targeted for typescript. This project is derived from agi-node.
Tested on Asterisk 11.6 & 14.4
This module leverage asterisk-manager
1. Installation
npm install garronej/ts-async-agi
2.Usage
AsyncAGIServer
receives two parameters: ascript
and an AMI connection (established throughasterisk-manager
)- the
script
function must return a void promise, all the channel methods return promises that must complete before the main promise resolve.
Channel method return a Resp object as a promise:
The type T of relevantResult vary for each method. failure tell if the method failed agiReply represent the parsed result of the AGI command.
If you don't want to bother dealing with exceptions caused by remote end hangup use the "relax" methods that only return the relevant result. ( see example)
The API itself is described in index.d.ts
Refer to https://www.voip-info.org/wiki-Asterisk+AGI for specific details on method behavior.
2.Example
;; /* Dialplan example: [from-sip]exten = _[+0-9].,1,AGI(agi:async)*/ console; async { console; console; /* The "relax" set of methods will only return relevant response, if a method fail due to remote hangup the script will just stop it's execution without throwing error, if a method fail but the remote hasn't hangup it will throw an error that can be caught. */ let _= channelrelax; //Dialplan function: compute: MD5 of "foobar" console; await _; console; console; let timeout digits = await _; console; console; await <void> ; await _; await _; console; console; let recordResult = await _; console; console; await _; console; let digit = await _; console; /* To continue script execution after remote hangup and manually handle exceptions use the core methods of the channel object */ console; let failure relevantResult = await channel; //If streamFile failed for an other reason than the caller hanging up throw and exception. if failure && !channelisHangup throw "streamFile error"; console; console; await _; //Hangup, if not called the execution will continue in dialplan. console; await _; } 5038 "127.0.0.1" "admin" "password";