Asterisk provides a rich collection of features by default, the standard set of which are described here.
All of the following objects should be accessed as part of the ami.core namespace, regardless of the modules in which they are defined.
Uses MD5 authentication when logging into AMI
Turns on all events with the ami.core.Events action
Turns off all events with the ami.core.Events action
Turns on call events with the ami.core.Events action
Turns on log events with the ami.core.Events action
Turns on system events with the ami.core.Events action
Selects the sln audio format
Selects the g723 audio format
Selects the g729 audio format
Selects the gsm audio format
Selects the alaw audio format
Selects the ulaw audio format
Selects the vox audio format
Selects the wav audio format
Remote extension rejected (hung up) without answering
Local extension rang, but didn’t answer
Remote extension rang, but didn’t answer
Remote extension answered
Remote extension was busy
Remote extension was unreachable
Remote extension could not be identified
Bases: ami.ami._Request
Causes Asterisk to hang up a channel after a given number of seconds.
Requires call
Causes the call on channel to be hung up after seconds have elapsed, defaulting to disabling auto-hangup.
Bases: ami.ami._Request
Causes Asterisk to execute an arbitrary AGI application in a call.
Upon successful execution, an ‘AsyncAGI’ event is generated.
Requires call
channel is the call in which to execute command, the value passed to the AGI dialplan application. command_id is an optional value that will be present in the resulting event, and can reasonably be set to a sequential digit or UUID in your application for tracking purposes.
Bases: ami.ami._Request
Bridges two channels already connected to Asterisk.
Requires call
channel_1 is the channel to which channel_2 will be connected. tone, if True, will cause a sound to be played on channel_2.
Bases: ami.ami._Request
Asks the AMI server for a challenge token to be used to hash the login secret.
The value provided under the returned response’s ‘Challenge’ key must be passed as the ‘challenge’ parameter of the Login object’s constructor:
login = Login(username='me', secret='password', challenge=response.get('Challenge'))
authtype is used to specify the authentication type to be used.
Bases: ami.ami._Request
Changes the filename associated with the recording of a monitored channel. The channel must have previously been selected by the Monitor action.
Requires call
channel is the channel to be affected and filename is the new target filename, without extension, as either an auto-resolved or absolute path.
Bases: ami.ami._Request
Sends an arbitrary shell command to Asterisk, returning its response as a series of lines in the ‘data’ attribute.
Requires command
command is the command to be executed.
Bases: ami.ami._Request
Asks Asterisk to list all active channels.
Any number of ‘CoreShowChannel’ events may be generated in response to this request, followed by one ‘CoreShowChannelsComplete’.
Requires system
Bases: ami.ami._Request
Creates an empty configuration file, intended for use before UpdateConfig().
Requires config
filename is the name of the file, with extension, to be created.
Bases: ami.ami._Request
Deletes a database value from Asterisk.
Requires system
family and key are specifiers to select the value to remove.
Bases: ami.ami._Request
Deletes a database tree from Asterisk.
Requires system
family and key (optional) are specifiers to select the values to remove.
Bases: ami.ami._Request
Requests a database value from Asterisk.
A ‘DBGetResponse’ event will be generated upon success.
Requires system
family and key are specifiers to select the value to retrieve.
Bases: ami.ami._Request
Stores a database value in Asterisk.
Requires system
family and key are specifiers for where to place value.
Bases: ami.ami._Request
Changes the types of unsolicited events Asterisk sends to this manager connection.
Mask is one of the following...
...or an iterable, like a tuple, with any combination of the following...
If an empty value is provided, EVENTMASK_NONE is assumed.
Bases: ami.ami._Request
Provides the state of an extension.
If successful, a ‘Status’ key will be present, with one of the following values as a string:
If non-negative, a ‘Hint’ key will be present, too, containing string data that can be helpful in discerning the current activity of the device.
Requires call
extension is the extension to be checked and context is the container in which it resides.
Bases: ami.ami._Request
Gets the contents of an Asterisk configuration file.
The result is recturned as a series of ‘Line-XXXXXX-XXXXXX’ keys that increment from 0 sequentially, starting with ‘Line-000000-000000’.
A sequential generator is provided by the ‘get_lines()’ function on the response.
Requires config
Provides a generator that yields every line in order.
filename is the name of the config file to be read, including extension.
Bases: ami.ami._Request
Gets the value of a channel or global variable from Asterisk, returning the result under the ‘Value’ key.
Requires call
variable is the name of the variable to retrieve. channel is optional; if not specified, a global variable is retrieved.
Bases: ami.ami._Request
Hangs up a channel.
On success, a ‘Hangup’ event is generated.
Requires call
channel is the ID of the channel to be hung up.
Bases: ami.ami._Request
Provides a list of every command exposed by the Asterisk Management Interface, with synopsis, as a series of lines in the response’s ‘data’ attribute.
Bases: ami.ami._Request
Provides a list of every category in an Asterisk configuration file, as a series of lines in the response’s ‘data’ attribute.
Requires config
filename is the name of the file, with extension, to be read.
Bases: ami.ami._Request
Allows a bridged channel to be optimised in Asterisk’s processing logic. This function should only be invoked after explicitly bridging.
Requires call
channel is the channel to be optimised.
Bases: ami.ami._Request
Authenticates to the AMI server.
username and secret are the credentials used to authenticate.
events may be set to False to prevent unsolicited events from being received. This is normally not desireable, so leaving it True is usually a good idea.
If given, challenge is a challenge string provided by Asterisk after sending a Challenge action, used with authtype to determine how to authenticate. authtype is ignored if the challenge parameter is unset.
Bases: ami.ami._Request
Logs out of the current manager session, permitting reauthentication.
Bases: ami.ami._Request
Loads, unloads, or reloads modules.
Requires system
load_type is one of the following:
module is optionally the name of the module, with extension, or one of the following for a built-in subsystem:
Bases: ami.ami._Request
Starts monitoring (recording) a channel.
Requires call
channel is the channel to be affected and filename is the new target filename, without extension, as either an auto-resolved or absolute path.
format may be any format Asterisk understands, defaulting to FORMAT_WAV:
mix, defaulting to True, muxes both audio streams associated with the channel after recording is complete, with the alternative leaving the two streams separate.
Bases: ami.ami._Request
Starts or stops muting audio on a channel.
Either (or both) directions can be silenced.
Requires system
channel is the channel to be affected and muted indicates whether audio is being turned on or off. input (from the channel) and output (to the channel) indicate the subchannels to be adjusted.
Bases: ami.core._Originate
Initiates a call that answers, executes an arbitrary dialplan application, and hangs up.
Requires call
channel is the destination to be called, expressed as a fully qualified Asterisk channel, like “SIP/test-account@example.org”.
application is the name of the application to be executed, and data is optionally any parameters to pass to the application, as an ordered sequence (list or tuple) of strings, escaped as necessary (the ‘,’ character is special).
timeout, if given, is the number of milliseconds to wait before dropping an unanwsered call. If set, the request’s timeout value will be set to this number + 2 seconds, removing the need to set both variables. If not set, the request’s timeout value will be set to ten minutes.
callerid is an optinal string of the form “name”<number>, where ‘name’ is the name to be displayed (on supporting channels) and ‘number’ is the source identifier, typically a string of digits on most channels that may interact with the PSTN.
variables is an oprional dictionary of key-value variable pairs to be set as part of the channel’s namespace.
account is an optional account code to be associated with the channel, useful for tracking billing information.
async should always be True. If not, only one unanswered call can be active at a time.
Bases: ami.core._Originate
Initiates a call with instructions derived from an arbitrary context/extension/priority.
Requires call
channel is the destination to be called, expressed as a fully qualified Asterisk channel, like “SIP/test-account@example.org”.
context, extension, and priority, must match a triple known to Asterisk internally. No validation is performed, so specifying an invalid target will terminate the call immediately.
timeout, if given, is the number of milliseconds to wait before dropping an unanwsered call. If set, the request’s timeout value will be set to this number + 2 seconds, removing the need to set both variables. If not set, the request’s timeout value will be set to ten minutes.
callerid is an optinal string of the form “name”<number>, where ‘name’ is the name to be displayed (on supporting channels) and ‘number’ is the source identifier, typically a string of digits on most channels that may interact with the PSTN.
variables is an oprional dictionary of key-value variable pairs to be set as part of the channel’s namespace.
account is an optional account code to be associated with the channel, useful for tracking billing information.
async should always be True. If not, only one unanswered call can be active at a time.
Bases: ami.ami._Request
Parks a call for later retrieval.
Requires call
channel is the channel to be parked and channel_callback is the channel to which parking information is announced.
If timeout, a number of milliseconds, is given, then channel_callback is given channel if the call was not previously retrieved.
Bases: ami.ami._Request
Lists all parked calls.
Any number of ‘ParkedCall’ events may be generated in response to this request, followed by one ‘ParkedCallsComplete’.
Bases: ami.ami._Request
Pauses the recording of a monitored channel. The channel must have previously been selected by the Monitor action.
Requires call
channel is the channel to be affected.
Bases: ami.ami._Request
Pings the AMI server. The response value has a ‘RTT’ attribute, which is the number of seconds the trip took, as a floating-point number, or -1 in case of failure.
Bases: ami.ami._Request
Plays a DTMF tone on a channel.
Requires call
channel is the channel to be affected, and digit is the tone to play.
Bases: ami.ami._Request
Adds a member to a queue.
Upon success, a ‘QueueMemberAdded’ event will be generated.
Requires agent
Adds the device identified by interface to the given queue.
membername optionally provides a friendly name for logging purposes, penalty establishes a priority structure (lower priorities first, defaulintg to 0) for call escalation, and paused optinally allows the interface to start in a disabled state.
Bases: ami.ami._Request
Adds an arbitrary record to the queue log.
Requires agent
queue is the queue to which the event is to be attached.
interface optionally allows the event to be associated with a specific queue member.
uniqueid‘s purpose is presently unknown.
message‘s purpose is presently unknown.
Bases: ami.ami._Request
Pauses or unpauses a member in one or all queues.
Upon success, a ‘QueueMemberPaused’ event will be generated for all affected queues.
Requires agent
interface is the device to be affected, and queue optionally limits the scope to a single queue. paused must be True or False, to control the action being taken.
Bases: ami.ami._Request
Changes the penalty value associated with a queue member, in one or all queues.
Requires agent
Changes the penalty value associated with interface in all queues, unless queue is defined, limiting it to one.
Bases: ami.ami._Request
Reloads properties from config files for one or all queues.
Requires agent
Reloads parameters for all queues, unless queue is defined, limiting it to one.
members is ‘yes’ (default) or ‘no’, indicating whether the member-list should be reloaded.
rules is ‘yes’ (default) or ‘no’, indicating whether the rule-list should be reloaded.
parameters is ‘yes’ (default) or ‘no’, indicating whether the parameter-list should be reloaded.
Bases: ami.ami._Request
Removes a member from a queue.
Upon success, a ‘QueueMemberRemoved’ event will be generated.
Requires agent
Removes the device identified by interface from the given queue.
Bases: ami.ami._Request
Describes the status of one (or all) queues.
Upon success, ‘QueueParams’, ‘QueueMember’, and ‘QueueEntry’ events will be generated, ending with ‘QueueStatusComplete’.
Describes all queues in the system, unless queue is given, which limits the scope to one.
Bases: ami.ami._Request
Redirects a call to an arbitrary context/extension/priority.
Requires call
channel is the destination to be redirected.
context, extension, and priority, must match a triple known to Asterisk internally. No validation is performed, so specifying an invalid target will terminate the call immediately.
Bases: ami.ami._Request
Reloads Asterisk’s configuration globally or for a specific module.
Requires call
If given, module limits the scope of the reload to a specific module, named without extension.
Bases: ami.ami._Request
Sends text along a supporting channel.
Requires call
channel is the channel along which to send message.
Bases: ami.ami._Request
Sets the user-field attribute for the CDR associated with a channel.
Requires call
channel is the channel to be affected, and user_field is the value to set.
Bases: ami.ami._Request
Sets a channel-level or global variable.
Requires call
value is the value to be set under variable.
channel is the channel to be affected, or None, the default, if the variable is global.
Bases: ami.ami._Request
Sends a SIP NOTIFY to the remote party on a channel.
Requires call
channel is the channel along which to send the NOTIFY.
headers is a dictionary of key-value pairs to be inserted as SIP headers.
Bases: ami.ami._Request
Lists all SIP peers.
Any number of ‘PeerEntry’ events may be generated in response to this request, followed by one ‘PeerlistComplete’.
Requires system
Bases: ami.ami._Request
Sends a SIP OPTIONS to the specified peer, mostly to ensure its presence.
Some events are likely raised by this, but they’re unknown at the moment.
Requires system
peer is the peer to ping.
Bases: ami.ami._Request
Provides detailed information about a SIP peer.
The response has the following key-value pairs:
- ‘CodecOrder’: The order in which codecs are tried
- ‘Codecs’: A list of supported codecs
Requires system
peer is the identifier of the peer for which information is to be retrieved.
Bases: ami.ami._Request
Lists all SIP registrations.
Any number of ‘RegistryEntry’ events may be generated in response to this request, followed by one ‘RegistrationsComplete’.
Requires system
Bases: ami.ami._Request
Lists the status of an active channel.
Zero or one ‘Status’ events are generated, followed by a ‘StatusComplete’ event.
Requires call
channel is the channel for which status information is to be retrieved.
Bases: ami.ami._Request
Stops recording a monitored channel. The channel must have previously been selected by the Monitor action.
Requires call
channel is the channel to be affected.
Bases: ami.ami._Request
Unpauses recording on a monitored channel. The channel must have previously been selected by the Monitor action.
Requires call
channel is the channel to be affected.
Bases: ami.ami._Request
Updates any number of values in an Asterisk configuration file.
Requires config
Reads from src_filename, performing all changes, and writing to dst_filename.
If reload is True, the changes take effect immediately. If reload is the name of a module, that module is reloaded.
changes may be any iterable object countaining quintuples with the following items:
- ‘NewCat’: creates a new category
- ‘RenameCat’: renames a category
- ‘DelCat’: deletes a category
- ‘Update’: changes a value
- ‘Delete’: removes a value
- ‘Append’: adds a value
Bases: ami.ami._Request
Causes a ‘UserEvent’ event to be generated.
Requires user
Any keyword-arguments passed will be present in the generated event, making this usable as a crude form of message-passing between AMI clients.
Bases: ami.ami._Request
Lists all voicemail information.
Any number of ‘VoicemailUserEntry’ events may be generated in response to this request, followed by one ‘VoicemailUserEntryComplete’.
Requires system (probably)