{"id":15817073,"url":"https://github.com/numminorihsf/ami-io-simple","last_synced_at":"2025-04-01T04:32:51.120Z","repository":{"id":31630140,"uuid":"35195288","full_name":"NumminorihSF/ami-io-simple","owner":"NumminorihSF","description":null,"archived":false,"fork":false,"pushed_at":"2015-05-07T08:17:32.000Z","size":144,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-10-06T05:21:52.980Z","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/NumminorihSF.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-05-07T02:52:26.000Z","updated_at":"2016-03-18T16:09:53.000Z","dependencies_parsed_at":"2022-08-24T13:30:47.689Z","dependency_job_id":null,"html_url":"https://github.com/NumminorihSF/ami-io-simple","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NumminorihSF%2Fami-io-simple","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NumminorihSF%2Fami-io-simple/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NumminorihSF%2Fami-io-simple/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NumminorihSF%2Fami-io-simple/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/NumminorihSF","download_url":"https://codeload.github.com/NumminorihSF/ami-io-simple/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246586105,"owners_count":20801026,"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-10-05T05:22:00.804Z","updated_at":"2025-04-01T04:32:51.093Z","avatar_url":"https://github.com/NumminorihSF.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"ami-io-simple - simplifier of ami-io (Asterisk AMI client)\n========================\n\nThis is a AMI client.  List of available commands is below.\n\nInstall with:\n\n    npm install ami-io-simple\n\n\n## Usage\n\nSimple example:\n\n```js\n\n    var AmiIo = require(\"ami-io-simple\"),\n        amiio = AmiIo.createClient(),\n        amiio2 = new AmiIo.Client();\n\n    //Both of this are similar\n\n    amiio.on('incorrectServer', function () {\n        amiio.logger.error(\"Invalid AMI welcome message. Are you sure if this is AMI?\");\n        process.exit();\n    });\n    amiio.on('connectionRefused', function(){\n        amiio.logger.error(\"Connection refused.\");\n        process.exit();\n    });\n    amiio.on('incorrectLogin', function () {\n        amiio.logger.error(\"Incorrect login or password.\");\n        process.exit();\n    });\n    amiio.on('event', function(event){\n        amiio.logger.info('event:', event);\n    });\n    amiio.connect();\n    amiio.on('connected', function(){\n        setTimeout(function(){\n            amiio.disconnect();\n            amiio.on('disconnected', process.exit());\n        },30000);\n    });\n\n```\n\nUsed events you can see below.\n\n\n# API\n\n## Connection Events\n\n`client` will emit some events about the state of the connection to the AMI.\n\n### \"connectionRefused\"\n\n`client` will emit `connectionRefused` if server refused connection.\n\n### \"incorrectServer\"\n\n`client` will emit `incorrectServer` if server, you try connect is not an AMI.\n\n### \"incorrectLogin\"\n\n`client` will emit `incorrectLogin` if login or password aren't valid.\n\n### \"connected\"\n\n`client` will emit `connect` after connect to AMI and success authorize.\n\n### \"disconnected\"\n\n`client` will emit `disconnect` when connection close.\n\n## AMI Events\n\n### \"event\"\n\n`client` will emit `event` when has new event object. All of them should find at\nhttps://wiki.asterisk.org/wiki/display/AST/Asterisk+11+AMI+Events.\n\n### \"responseEvent\"\n\n`client` will emit `responseEvent` when some response has event as part of itself.\n\n### \"rawEvent\"\n\n`client` will emit `rawEvent` when has new event object or a part of response object.\nNote that use event and rawEvent at the same time is not a good idea.\n\n### \"rawEvent.\"+eventName\n\n`client` will emit `rawEvent.`+eventName when has new event object or a part of response object.\nYou can find event names at https://wiki.asterisk.org/wiki/display/AST/Asterisk+11+AMI+Events\n\n### \"ais.\"+eventName\n\nThese events will be emitted, then some raw event was simplified. See below.\n\n\n## AIS Events\n\n### \"ais.CallStart\"\n \nEmitted, then call started. The argument to function is event Object:\n\n* `callId` - String. An UniqueId of call from asterisk.\n* `from` - String. Phone number of person, who try call somewhere.\n* `to` - String. What number somebody try call to.\n* `startAt` - Number. Unix timestamp.\n         \n### \"ais.CallRing\"\n\nEmitted, then call ringed at recipient of it. The argument to function is event Object:\n\n* `callId` - String. An UniqueId of call from asterisk.\n* `from` - String. Phone number of person, who try call somewhere.\n* `ringTo` - String. What number somebody try call to.\n* `ringAt` - Number. Unix timestamp.\n\n**Attention!** If call is in queue, may spawn many times.\n\n### \"ais.CallAddInfo\"\n\nEmitted, then some new data about call created. The argument to function is event Object:\n\n* `callId` - String. An UniqueId of call from Asterisk.\n* `queue` - String. *Optional*. Asterisk's queue name.\n* `ringTo` - String. *Optional*. May spawned many times. What number somebody try call to.\n* `ringAt` - Number. *Optional*. May spawned many times. Unix timestamp.\n* `client` - String. *Optional*. If call to queue - client number.\n* `origPos` - Number. *Optional*. If call to queue - position, that applied to call at join to queue.\n* `route` - Number. *Optional*. `1` if call to queue.\n* `abanPos` - Number. *Optional*. If call to queue and client abandon call - his position in queue at this moment.\n* `context` - Number. *Optional*. May spawned many times. Context of call.\n* `referTo` - String. *Optional*. If Asterisk use `local bridge` (besides `bridge`) - uniqueid of call, that our call bridged with.\n* `callId2` - String. *Optional*. Id of call, that call bridged with.\n\n**Attention!** Spawn many times.\n\n\n### \"ais.CallAnswered\"\n\nEmitted, then call answered. The argument to function is event Object:\n\n* `callId` - String. An UniqueId of call from Asterisk.\n* `channelFrom` - String. *Optional*. Channel name, from there call come.\n* `channelNameFrom` - String. *Optional*. Part of channel name, from there call come.\n* `channelIn` - String. *Optional*. Channel name, from there call come.\n* `channelNameIn` - String. *Optional*. Part of channel name, from there call come.\n* `answerAt` - Number. Unix timestamp.\n\n\n### \"ais.CallEnd\"\n\nEmitted, then call answered. The argument to function is event Object:\n\n* `callId` - String. An UniqueId of call from Asterisk.\n* `cause` - Number. Cause code from Asterisk. See http://www.voip-info.org/wiki/view/Asterisk+variable+hangupcause\n* `endAt` - Number. Unix timestamp.\n\n\n### \"ais.QueueJoin\"\n\nEmitter, then somebody joined to queue (incoming call). The argument to function is event Object:\n                                                       \n* `callId` - String. An UniqueId of call from Asterisk.\n* `queue` - String. Asterisk's queue name.\n* `origPos` - Number. Position, that applied to call at join to queue.\n* `client` - String. Client number.\n* `joinAt` - Number. Unix timestamp.\n                                                       \n\n### \"ais.QueueLeave\"\n\nEmitter, then somebody leaved queue (incoming call). The argument to function is event Object:\n                                                       \n* `callId` - String. An UniqueId of call from Asterisk.\n* `queue` - String. Asterisk's queue name.\n* `position` - Number. Position of call in queue, at the moment, then call leave queue.\n\n\n### \"ais.QueueMemberStatus\"\n\nEmitted, then some queue member changed status. If queue member is in more then one queue, spawn event to every queue.\nThe argument to function is event Object:\n\n* `queue` - String. Asterisk's queue name.\n* `device` - String. Phone number, user use.\n* `user` - String. User name. Try parse it from Asterisk's `membername` field.\n If `membername` include `'$'` symbol - part of string before it. Else - whole field.\n* `appId` - Number. Try parse it from Asterisk's `membername` field.\n If `membername` include `'$'` symbol - part of string after it. Default `0`.\n* `penalty` - Number. Asterisk's queue member's penalty.\n* `paused` - Number. Pause status of this device at this queue. \n`0` - unpaused, `1` - paused manualy, `2` - auto-pause, `3` - scenario-pause, `4` - service-pause.\nAll values bigger than 1 - create `reason` field based.\n* `status` - Number. Status of device at queue. See https://wiki.asterisk.org/wiki/display/AST/Asterisk+11+ManagerEvent_QueueMemberStatus\n* `extenState` - Object. Status of devices at all queues, there it is.\n* `reason` - String|`null`. If set pause to true - say why.\n\n### \"ais.QueueMemberAdded\"\n\nEmitted, then somebody adds to queue. If queue member is in more then one queue, spawn event to every queue.\nThe argument to function is event Object:\n\n* `queue` - String. Asterisk's queue name.\n* `device` - String. Phone number, user use.\n* `user` - String. User name. Try parse it from Asterisk's `membername` field.\n If `membername` include `'$'` symbol - part of string before it. Else - whole field.\n* `appId` - Number. Try parse it from Asterisk's `membername` field.\n If `membername` include `'$'` symbol - part of string after it. Default `0`.\n* `penalty` - Number. Asterisk's queue member's penalty.\n* `paused` - Number. Pause status of this device at this queue. \n`0` - unpaused, `1` - paused manualy, `2` - auto-pause, `3` - scenario-pause, `4` - service-pause.\nAll values bigger than 1 - create `reason` field based.\n* `status` - Number. Status of device at queue. See https://wiki.asterisk.org/wiki/display/AST/Asterisk+11+ManagerEvent_QueueMemberStatus\n* `extenState` - Object. Status of devices at all queues, there it is.\n\n### \"ais.QueueMemberRemoved\"\n\nEmitted, then somebody adds to queue. If queue member is in more then one queue, spawn event to every queue.\nThe argument to function is event Object:\n\n* `queue` - String. Asterisk's queue name.\n* `device` - String. Phone number, user use.\n* `user` - String. User name. Try parse it from Asterisk's `membername` field.\n If `membername` include `'$'` symbol - part of string before it. Else - whole field.\n* `appId` - Number. Try parse it from Asterisk's `membername` field.\n If `membername` include `'$'` symbol - part of string after it. Default `0`.\n\n\n# Methods\n\n## amiio.createClient()\n\n* `amiio.createClient() = amiio.createClient({port:5038, host:'127.0.0.1', login:'admin', password:'admin'})`\n\nIf some of object key are undefined - will use default value.\n\n* `host`: which host amiio should use. Defaults to `127.0.0.1`.\n* `port`: which port amiio should use. Defaults to `5038`.\n* `login`: Default to `admin`.\n* `password`: Default to `admin`.\n\n\n## client.connect([shouldReconnect[, reconnectTimeout]])\n\nWhen connecting to AMI servers you can use: `client.connect(true)` to create connection with auto-reconnect.\nAuto-reconnect works only if auth was success. If you use `client.disconnect()` connection will close and\nshouldn't be any reconnect.\nIf use `client.connect()` reconnect will not work.\n\nDefault reconnect timeout is 5000ms.\n\nAlso you may want to set timeout of reconnecting. Then use `client.connect(true, timeoutInMs)`.\nYou don't need to set up timeout for every time you connect (in one client object). After `client.disconnect()`\ntimeout will not be set to default, so you can use `client.connect(true)` to connect again with similar timeout.\n\n\n## client.disconnect()\n\nForcibly close the connection to the AMI server.  Also stop reconnecting.\n\n\n```js\n    var amiio = require(\"ami-io\"),\n        client = amiio.createClient();\n\n    client.connect();\n    //Some code here\n    client.disconnect();\n```\n\n\n## client.unref()\n\nCall `unref()` on the underlying socket connection to the AMI server,\nallowing the program to exit once no more commands are pending.\n\n```js\nvar AmiIo = require(\"ami-io\");\nvar client = AmiIo.createClient();\n\n/*\n    Calling unref() will allow this program to exit immediately after the get command finishes.\n    Otherwise the client would hang as long as the client-server connection is alive.\n*/\nclient.unref();\n//will close process if only AmiIo is in it.\nclient.connect();\n```\n\n## client.ref()\n\nCall `ref()` will cancel `unref()` effect.\n\n## client.useLogger\n\nUse `client.useLogger(LoggerObject)` if you want to use some another logger.\nBy default use console and ignore any logging levels.\n\n```js\nvar AmiIo = require(\"ami-io\");\nvar client = AmiIo.createClient();\nvar client.useLogger(logger);\n```\n\nlogger should has `trace`,`debug`,`info`,`warn`,`error`,`fatal` methods.\nOf course you can emulate them if some lib has not it.\n\n\n# Extras\n\nSome other things you might like to know about.\n\n## client.connected\n\n`true` if client is connected of `false` if it is not.\n\n## client.reconnectionTimeout\n\nTimeout for reconnect. If you didn't want reconnect ever, `client.reconnectionTimeout == undefined`.\n\n## client.shouldReconnect\n\n`true` if will be reconnect, or `false` if will not.\n\n# Send action to AMI\n\nAvailable actions:\n\n* AGI\n* AbsoluteTimeout\n* AgentLogoff\n* Agents\n* AttendedTransfer\n* BlindTransfer\n* Bridge\n* ChangeMonitor\n* Command\n* ConfbridgeKick\n* ConfbridgeList\n* ConfbridgeListRooms\n* ConfbridgeLock\n* ConfbridgeMute\n* ConfbridgeUnlock\n* ConfbridgeUnmute\n* CoreSettings\n* CoreShowChannels\n* CoreStatus\n* CreateConfig\n* DahdiDialOffHook\n* DahdiDndOff\n* DahdiDndOn\n* DahdiHangup\n* DahdiRestart\n* DahdiShowChannels\n* DbDel\n* DbDeltree\n* DbGet\n* DbPut\n* ExtensionState\n* GetConfig\n* GetConfigJson\n* GetVar\n* Hangup\n* JabberSend\n* ListCategories\n* ListCommands\n* LocalOptimizeAway\n* Login\n* Logoff\n* MailboxCount\n* MailboxStatus\n* MeetmeList\n* MeetmeMute\n* MeetmeUnmute\n* ModuleCheck\n* ModuleLoad\n* ModuleReload\n* ModuleUnload\n* Monitor\n* Originate\n* Park\n* ParkedCalls\n* PauseMonitor\n* Ping\n* PlayDtmf\n* QueueAdd\n* QueueLog\n* QueuePause\n* QueueRemove\n* QueueRule\n* QueueStatus\n* QueueSummary\n* QueueUnpause\n* Queues\n* Redirect\n* Reload\n* SendText\n* SetVar\n* ShowDialPlan\n* SipPeers\n* SipQualifyPeer\n* SipShowPeer\n* SipShowRegistry\n* Status\n* StopMonitor\n* UnpauseMonitor\n* VoicemailUsersList\n\nDescription of all commands and variables they need, you can find at\nhttps://wiki.asterisk.org/wiki/display/AST/Asterisk+11+AMI+Actions\nAll values, needed in commands, should passed like this:\n\n```js\n    var action = new amiio.Action.QueueSummary();\n    action.queue = \"some queue's name\";\n    amiioClient.send(action, function(err, data){\n        if (err){\n            //in current time - may be without error. need test\n            //err === null if ami response match(/success/i), else response will pass as error\n        }\n    });\n```\n\n\n\n## LICENSE - \"MIT License\"\n\nCopyright (c) 2015 Konstantine Petryaev\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnumminorihsf%2Fami-io-simple","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnumminorihsf%2Fami-io-simple","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnumminorihsf%2Fami-io-simple/lists"}