{"id":22369229,"url":"https://github.com/tcncloud/agi-node","last_synced_at":"2025-07-30T19:30:47.326Z","repository":{"id":29944470,"uuid":"33490915","full_name":"tcncloud/agi-node","owner":"tcncloud","description":"Asterisk FastAGI and AsyncAGI server for Node.js","archived":false,"fork":false,"pushed_at":"2019-01-11T16:44:34.000Z","size":17,"stargazers_count":42,"open_issues_count":1,"forks_count":25,"subscribers_count":9,"default_branch":"master","last_synced_at":"2024-11-22T19:42:51.250Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tcncloud.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-04-06T16:02:47.000Z","updated_at":"2024-08-12T15:02:13.000Z","dependencies_parsed_at":"2022-08-28T21:00:22.321Z","dependency_job_id":null,"html_url":"https://github.com/tcncloud/agi-node","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tcncloud%2Fagi-node","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tcncloud%2Fagi-node/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tcncloud%2Fagi-node/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tcncloud%2Fagi-node/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tcncloud","download_url":"https://codeload.github.com/tcncloud/agi-node/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":227877491,"owners_count":17833473,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-04T19:18:38.897Z","updated_at":"2024-12-04T19:18:39.475Z","avatar_url":"https://github.com/tcncloud.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Getting Started\n\n### 1. Usage\n\n``` bash\nnpm install --save agi-node\n```\n\n``` javascript\n\nvar AGIServer = require('agi-node').AGIServer;\n//var AsyncAGIServer = require('agi-node').AsyncAGIServer;\n//var conn = new require('asterisk-manager')(5038, 'localhost', 'asterisk', 'astpass', true);\n\nfunction fakeCallback(param, callback) {\n  setTimeout(function () {\n    callback(null, param);\n  }, 2000);\n}\n\nfunction testScript(channel) {\n  console.log('Script got call %s -\u003e %s', channel.request.callerid, channel.request.extension);\n\n  var answerReply = channel.answer();\n  console.log('ANSWER', answerReply);\n\n  console.log('CHANNEL STATUS', channel.channelStatus());\n  console.log('GET UNIQUEID', channel.getVariable('UNIQUEID'));\n  console.log('GET JUNK', channel.getVariable('JUNK'));\n\n  console.log('beeping in 2 seconds');\n  channel.streamFile(fakeCallback.sync(null, 'beep'));\n\n\n  console.log('PLAYBACK', channel.streamFile('conf-adminmenu'));\n  console.log('PLAYBACK', channel.streamFile('conf-adminmenu'));\n}\n\n/* Async AGI Server */\n// conn is an asterisk-manager connection\n//var server = new AsyncAGIServer(script, conn);\n\n/* AGI Server */\nvar server = new AGIServer(testScript, 4573);\n\n```\n\n\n* `AGIServer` constructor receives two parameters: a `mapper` and a `port`. 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 map `agi://agi_host/hello` to `helloScript`. The `port` is the AGI standard listening port (default `4573`)\n* `AsyncAGIServer` receives two parameters: a `mapper` and an AMI connection (established through `asterisk-manager`)\n* The script should exit at the very end. That means that all async operations (e.g. database lookups) need to be done using `sync` library. This is a dependency of `agi-node` and the script is executed inside a fiber, so callbacks can be put in \"sync\" mode (see `fakeCallback` example above and `sync` library itself at https://www.npmjs.com/package/sync).\n\n### 2. Channel API\n\n#### 2.1 Channel.request\n\nThis 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:\n\n\n* `agi_request` - The filename of your script\n* `agi_channel` - The originating channel (your phone)\n* `agi_language` - The language code (e.g. \"en\")\n* `agi_type` - The originating channel type (e.g. \"SIP\" or \"ZAP\")\n* `agi_uniqueid` - A unique ID for the call\n* `agi_version` - The version of Asterisk (since Asterisk 1.6)\n* `agi_callerid` - The caller ID number (or \"unknown\")\n* `agi_calleridname` - The caller ID name (or \"unknown\")\n* `agi_callingpres` - The presentation for the callerid in a ZAP channel\n* `agi_callingani2` - The number which is defined in ANI2 see Asterisk Detailed Variable List (only for PRI Channels)\n* `agi_callington` - The type of number used in PRI Channels see Asterisk Detailed Variable List\n* `agi_callingtns` - An optional 4 digit number (Transit Network Selector) used in PRI Channels see Asterisk Detailed Variable List\n* `agi_dnid` - The dialed number id (or \"unknown\")\n* `agi_rdnis` - The referring DNIS number (or \"unknown\")\n* `agi_context` - Origin context in extensions.conf\n* `agi_extension` - The called number\n* `agi_priority` - The priority it was executed as in the dial plan\n* `agi_enhanced` - The flag value is 1.0 if started as an EAGI script, 0.0 otherwise\n* `agi_accountcode` - Account code of the origin channel\n* `agi_threadid` - Thread ID of the AGI script (since Asterisk 1.6)\n\n#### 2.2 Channel methods\n\n\n* `answer()`\n\nAnswers the channel\n\n* `channelStatus()`\n\nReturns the current channel status (see http://www.voip-info.org/wiki/view/channel+status)\n\n* `continueAt(context, extension, priority)`\n\nSets 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`.\n\n* `exec(applicationName, applicationParameters)`\n\nExecutes the requested dialplan application with parameters\n\n* `getData(file, timeout, maxDigits)`\n\nReads DTMF input from user. Plays the `file` prompt. Times out at `timeout` milliseconds and allows\nup to `maxDigits` to be read. It can be ended with `#`.\n\n* `getVariable(variableName)`\n\nReads the specified variable value on the current channel. Returns `null` if variable does not exist.\n\n* `noop()`\n\nDoes nothing.\n\n* `recordFile(file, format, escapeDigits, timeout, silenceSeconds, beep)`\n\nRecords the current channel in `file` using `format`. Recording can be stopped using one\nof the `escapeDigits` or after `silenceSeconds`. If `beep` is true, a beep sound is played\nbefore recording is started.\n\n* `setContext(context)`\n\nSets the context to continue at after leaving the script.\n\n* `setExtension(extension)`\n\nSets the extension to continue at after leaving the script.\n\n* `setPriority(priority)`\n\nSets the priority to continue at after leaving the script.\n\n* `setVariable(variable, value)`\n\nSets the specified `variable` to the desired `value`.\n\n* `streamFile(file, escapeDigits)`\n\nPlays the specified `file`. Playback can be stopped using one of the (optional) `escapeDigits`.\n\n* `hangup()`\n\nHangs up the current channel.\n\n\n## LICENSE\n\n\nCopyright (c) 2015 Alexandru Pirvulescu \u003calex@tcnbroadcasting.com\u003e\n\n\nPermission 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:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE 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.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftcncloud%2Fagi-node","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftcncloud%2Fagi-node","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftcncloud%2Fagi-node/lists"}