ami

1.0.0 • Public • Published

ami NPM Version

Astersik Manager Interface

Install ami

This module requires node.js 14.0.0 or above and ES modules.

npm install ami

class AMISocket

import AMISocket from 'ami';
 
const ami = new AMISocket();

new AMISocket(options)

Construct a new AMI connection instance. Default options:

{
  connect: {
    host: 'localhost',
    port: 5038
  },
  credentials: {
    username: 'local',
    secret: 'local'
  },
  events: true
}

AMISocket#amiVersion

Version string provided by the Asterisk server, example 2.10.5. This property is undefined prior to receiving first line from connected socket.

AMISocket#connected

Boolean value if the socket is connected.

AMISocket#authenticated

Boolean value if the socket is authenticated.

async AMISocket#connect()

Connect to the AMI server for this instance. Promise is resolved once authentication is successful. Rejection occurs if connection or authentication fails.

This function resolves after queued packets are sent but before responses are received.

AMISocket#disconnect()

Disconnect from the AMI server. No attempt is made to wait for responses to requests that are in progress.

async AMISocket#send(object, options)

async AMISocket#getList(object, options)

object is the key/value pairs to send as an AMI request. This must contain an action key. A key can be specified multiple times by providing an array, for example:

ami.send({
  action: 'originate',
  // channel / app / etc
  variable: [
    'CHANVAR1=value',
    'CHANVAR2=value'
  ]
});

options.ignoreResponse can be set to true if you don't care about the result. In this case the promise resolves as soon as the request is written to the socket.

options.responseType controls the information provided when resolving:

  • response: resolves with a single object structured like the input object. This is default for AMISocket#send.
  • responses: resolves with an array of objects. This is default for AMISocket#getList.
  • responsePacket: resolves with a single AMIPacket instance.
  • responsePackets: resolves with an array of AMIPacket instances.

Keys of all responses are normalized to lowercase strings.

AMIPacket#asObject

This is the property which resolve requests that used responseType of response or responses.

AMIPacket#values

An ordered array of name/value pairs, for example:

[
  ['actionid', 'random-generated-id'],
  ['response', 'success']
]

This is only needed to deal with responses which violate the AMI specification. An example of this is the app_queue QueueRule response, see ASTERISK-27072.

AMIPacket#toString()

This is used internally to produce the raw data. It could also be used for debug output. Note that keys are already tranformed to lowercase.

Readme

Keywords

none

Package Sidebar

Install

npm i ami

Weekly Downloads

6

Version

1.0.0

License

MIT

Unpacked Size

16.1 kB

Total Files

13

Last publish

Collaborators

  • coreyfarrell