Getting Started
This fork of agi-node replace fiber by Promises to make the module consistent with the async/await design pattern. Also defines typescript's types.
1. Usage
npm install --save voxo-agi
var AGIServer = AGIServer;//var AsyncAGIServer = require('agi-node').AsyncAGIServer;//var conn = new require('asterisk-manager')(5038, 'localhost', 'asterisk', 'astpass', true);{console;var answerReply = await channel;console;console;console;console;console;await ;await channel;console;console;}/* Async AGI Server */// conn is an asterisk-manager connection//var server = new AsyncAGIServer(script, conn);/* AGI Server */var server = testScript 4573;
AGIServer
constructor receives two parameters: amapper
and aport
. If the mapper is a function it will execute that as an AGI script. If it is an object it maps script names from AGI URL to generator functions. Example:{hello: helloScript}
will mapagi://agi_host/hello
tohelloScript
. Theport
is the AGI standard listening port (default4573
)AsyncAGIServer
receives two parameters: amapper
and an AMI connection (established throughasterisk-manager
)- Mapper function must return a void promise, all the channel methods return promise that must complete before the Mapper promise resolve.
2. Channel API
2.1 Channel.request
This property is an object that maps all the AGI initialization variable without the agi_ prefix (e.g. agi_calleridname
becomes channel.request.calleridname
). Here's a list of all of these variables:
agi_request
- The filename of your scriptagi_channel
- The originating channel (your phone)agi_language
- The language code (e.g. "en")agi_type
- The originating channel type (e.g. "SIP" or "ZAP")agi_uniqueid
- A unique ID for the callagi_version
- The version of Asterisk (since Asterisk 1.6)agi_callerid
- The caller ID number (or "unknown")agi_calleridname
- The caller ID name (or "unknown")agi_callingpres
- The presentation for the callerid in a ZAP channelagi_callingani2
- The number which is defined in ANI2 see Asterisk Detailed Variable List (only for PRI Channels)agi_callington
- The type of number used in PRI Channels see Asterisk Detailed Variable Listagi_callingtns
- An optional 4 digit number (Transit Network Selector) used in PRI Channels see Asterisk Detailed Variable Listagi_dnid
- The dialed number id (or "unknown")agi_rdnis
- The referring DNIS number (or "unknown")agi_context
- Origin context in extensions.confagi_extension
- The called numberagi_priority
- The priority it was executed as in the dial planagi_enhanced
- The flag value is 1.0 if started as an EAGI script, 0.0 otherwiseagi_accountcode
- Account code of the origin channelagi_threadid
- Thread ID of the AGI script (since Asterisk 1.6)
2.2 Channel methods
All those methods returns promises.
answer()
Answers the channel
channelStatus()
Returns the current channel status (see http://www.voip-info.org/wiki/view/channel+status)
continueAt(context, extension, priority)
Sets the point in the dialplan to continue the call after the AGI script is done. extension
is optional and, if missing, is set the current channel extension. priority
is optional and, if missing, is set to 1
.
exec(applicationName, applicationParameters)
Executes the requested dialplan application with parameters
getData(file, timeout, maxDigits)
Reads DTMF input from user. Plays the file
prompt. Times out at timeout
milliseconds and allows
up to maxDigits
to be read. It can be ended with #
.
getVariable(variableName)
Reads the specified variable value on the current channel. Returns null
if variable does not exist.
noop()
Does nothing.
recordFile(file, format, escapeDigits, timeout, silenceSeconds, beep)
Records the current channel in file
using format
. Recording can be stopped using one
of the escapeDigits
or after silenceSeconds
. If beep
is true, a beep sound is played
before recording is started.
setContext(context)
Sets the context to continue at after leaving the script.
setExtension(extension)
Sets the extension to continue at after leaving the script.
setPriority(priority)
Sets the priority to continue at after leaving the script.
setVariable(variable, value)
Sets the specified variable
to the desired value
.
streamFile(file, escapeDigits)
Plays the specified file
. Playback can be stopped using one of the (optional) escapeDigits
.
hangup()
Hangs up the current channel.
;;;const port host user secret = AmiCredential; console; async { console; } port host user secret; : Promise<void> { let _= channelrelax; console; console; await _; console; let activeDongle = "id": await _ "provider": await _ "imei": await _ "imsi": await _ "number": await _ ; console; await _; let dongleStatus = as DongleStatus; console; let timeout digits = await _; console; console; console; await <void> ; await _; let LE_HIP_HOP= "la_coupole"; await _; console; console; let recordResult= await _; console; console; let digit = await _; console; let failure relevantResult = await channel; if failure && !channelisHangup throw "streamFile error"; console; /* console.log("manually hangup"); await _.hangup(); */ } : Promise<void> { console; console; }
LICENSE
Copyright (c) 2015 Alexandru Pirvulescu alex@tcnbroadcasting.com
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.