<html>
    <head>
        <meta name="viewport" content="width=device-width" />
        <base href="https://wiki.asterisk.org/wiki" />
        <style type="text/css">
    body, #email-content, #email-content-inner { font-family: Arial,FreeSans,Helvetica,sans-serif; }
    body, p, blockquote, pre, code, td, th, li, dt, dd { font-size: 13px; }
    small { font-size: 11px; }

    body { width:100% !important; -webkit-font-smoothing: antialiased; }

    body,
    #email-wrapper { background-color: #f0f0f0; }
    #email-wrapper-inner { padding: 20px; text-align: center; }
    #email-content-inner { background-color: #fff; border: 1px solid #bbb; color: $menuTxtColour; padding:20px; text-align:left; }
    #email-wrapper-inner > table { width: 100%; }
    #email-wrapper-inner.thin > table { margin: 0 auto; width: 50%; }
    #email-footer { padding: 0 16px 32px 16px; margin: 0; }

    .email-indent { margin: 8px 0 16px 0; }
    .email-comment { margin: 0 0 0 56px; }
    .email-comment.removed { background-color: #ffe7e7; border: 1px solid #df9898; padding: 0 8px;}

    #email-title-avatar { text-align: left; vertical-align: top; width: 48px; padding-right: 8px; }
    #email-title-flavor { margin: 0; padding: 0 0 4px 0; }
    #email-title-heading { font-size: 16px; line-height: 20px; min-height: 20px; margin: 0; padding: 0; }
    #email-title .icon { border: 0; padding: 0 5px 0 0; text-align: left; vertical-align: middle; }

    #email-actions { border-top: 1px solid #bbb; color: #505050; margin: 8px 0 0 0; padding: 0; }
    #email-actions td { padding-top: 8px; }
    #email-actions .left { max-width: 45%; text-align: left; }
    #email-actions .right { text-align: right; }
    .email-reply-divider { border-top: 1px solid #bbb; color: #505050; margin: 32px 0 8px 0; padding: 8px 0; }
    .email-section-title { border-bottom: 1px solid #bbb; margin: 8px 0; padding: 8px 0 0 0; }

    .email-metadata { color: #505050; }

    a { color: #326ca6; text-decoration: none; }
    a:hover { color: #336ca6; text-decoration: underline; }
    a:active {color: #326ca6; }

    a.email-footer-link { color: #505050; font-size: 11px; }

    .email-item-list { list-style: none; margin: 4px 0; padding-left: 0; }
    .email-item-list li { list-style: none; margin: 0; padding: 4px 0; }
    .email-list-divider { color: #505050; padding: 0 0.35em; }
    .email-operation-icon { padding-right: 5px; }

    .avatar { -ms-interpolation-mode: bicubic; border-radius: 3px;}
    .avatar-link { margin: 2px; }

    .tableview th { border-bottom: 1px solid #69C; font-weight: bold; text-align: left; }
    .tableview td { border-bottom: 1px solid #bbbbbb; text-align: left; padding: 4px 16px 4px 0; }

    .aui-message {  margin: 1em 0; padding: 8px; }
    .aui-message.info { background-color: #e0f0ff; border: 1px solid #9eb6d4; }
    .aui-message.success { background-color: #ddfade; border: 1px solid #93c49f; }
    .aui-message.error,
    .aui-message.removed { background-color: #ffe7e7; border: 1px solid #df9898; color: #000; }

    .call-to-action-table { margin: 10px 1px 1px 1px;}
    .call-to-cancel-container, .call-to-action-container { padding: 5px 20px; }
    .call-to-cancel-container { border: 1px solid #aaa; background-color: #eee; border-radius: 3px; }
    .call-to-cancel-container a.call-to-cancel-button { background-color: #eee; font-size: 14px; line-height: 1; padding: 0; margin: 0; color: #666; font-family: sans-serif;}
    .call-to-action-container { border: 1px solid #486582;  background-color: #3068A2; border-radius: 3px; padding: 4px 10px; }
    .call-to-action-container a.call-to-action-button { background-color: #3068A2; font-size: 14px; line-height: 1; padding: 0; margin: 0; color: #fff; font-weight: bold; font-family: sans-serif; }

    /** The span around the inline task checkbox image */
    .diff-inline-task-overlay {
        display: inline-block;
        text-align: center;
        height: 1.5em;
        padding: 5px 0px 1px 5px;
        margin-right: 5px;
        /** Unfortunately, the negative margin-left is stripped out in gmail */
        margin-left: -5px;
    }

            @media handheld, only screen and (max-device-width: 480px) {
        div, a, p, td, th, li, dt, dd { -webkit-text-size-adjust: auto; }
        small, small a { -webkit-text-size-adjust: 90%; }

        td[id=email-wrapper-inner] { padding: 2px !important; }
        td[id=email-content-inner] { padding: 8px !important; }
        td[id="email-wrapper-inner"][class="thin"] > table { text-align: left !important; width: 100% !important; }
        td[id=email-footer] { padding: 8px 12px !important; }
        div[class=email-indent] { margin: 8px 0px !important; }
        div[class=email-comment] { margin: 0 !important; }

        p[id=email-title-flavor] a { display: block; } /* puts the username and the action on separate lines */
        p[id=email-permalink] { padding: 4px 0 0 0 !important; }

        table[id=email-actions] td { padding-top: 0 !important; }
        table[id=email-actions] td.right { text-align: right !important; }
        table[id=email-actions] .email-list-item { display: block; margin: 1em 0 !important; word-wrap: normal !important; }
        span[class=email-list-divider] { display: none; }
    }



        </style>
    </head>
    <body style="font-family: Arial, FreeSans, Helvetica, sans-serif; font-size: 13px; width: 100%; -webkit-font-smoothing: antialiased; background-color: #f0f0f0">
        <table id="email-wrapper" width="100%" cellspacing="0" cellpadding="0" border="0" style="background-color: #f0f0f0">
            <tbody>
                <tr valign="middle">
                    <td id="email-wrapper-inner" style="font-size: 13px; padding: 20px; text-align: center">
                        <table id="email-content" cellspacing="0" cellpadding="0" border="0" style="font-family: Arial, FreeSans, Helvetica, sans-serif; width: 100%">
                            <tbody>
                                <tr valign="top">
                                    <td id="email-content-inner" align="left" style="font-family: Arial, FreeSans, Helvetica, sans-serif; font-size: 13px; background-color: #fff; border: 1px solid #bbb; padding: 20px; text-align: left">
                                        <table id="email-title" cellpadding="0" cellspacing="0" border="0" width="100%">
                                            <tbody>
                                                <tr>
                                                    <td id="email-title-avatar" rowspan="2" style="font-size: 13px; text-align: left; vertical-align: top; width: 48px; padding-right: 8px"> <img class="avatar" src="cid:avatar_ce51dcf276530e4a4b00548e2a6d0905" border="0" height="48" width="48" style="-ms-interpolation-mode: bicubic; border-radius: 3px" /> </td>
                                                    <td valign="top" style="font-size: 13px">
                                                        <div id="email-title-flavor" class="email-metadata" style="margin: 0; padding: 0 0 4px 0; color: #505050">
                                                            <a href="    https://wiki.asterisk.org/wiki/display/~mjordan " style="color:#326ca6;text-decoration:none;; color: #326ca6; text-decoration: none">Matt Jordan</a> edited the page:
                                                        </div> </td>
                                                </tr>
                                                <tr>
                                                    <td valign="top" style="font-size: 13px"> <h2 id="email-title-heading" style="font-size: 16px; line-height: 20px; min-height: 20px; margin: 0; padding: 0"> <a href="https://wiki.asterisk.org/wiki/display/AST/AMI+1.4+Specification" style="color: #326ca6; text-decoration: none"> <img class="icon" src="cid:page-icon" alt="" style="border: 0; padding: 0 5px 0 0; text-align: left; vertical-align: middle" /> <strong style="font-size:16px;line-height:20px;vertical-align:top;">AMI 1.4 Specification</strong> </a> </h2> </td>
                                                </tr>
                                            </tbody>
                                        </table>
                                        <div class="email-indent" style="margin: 8px 0 16px 0">
                                            <div class="email-diff">
                                                <div id="page-diffs" class="wiki-content">
                                                    <table class="diff-macro diff-block-target" style="background-color: #f0f0f0;border: 1px solid #dddddd;margin: 10px 1px;padding: 0 2px 2px;width: 100%;">
                                                        <thead>
                                                            <tr>
                                                                <th class="diff-macro-title" style="background-color: transparent; text-align: left; font-weight: normal;padding: 5px;; font-size: 13px"><span class="icon macro-placeholder-icon" style="background-color: ;line-height: 20px;"><img src="https://wiki.asterisk.org/wiki/s/en_GB-1988229788/4109/76e0dbb30bc8580e459c201f3535d84f9283a9ac.25/_/images/icons/macrobrowser/macro-placeholder-default.png" style="padding-right: 5px; vertical-align: text-bottom;" /> </span>Wiki Markup</th>
                                                            </tr>
                                                        </thead>
                                                        <tbody>
                                                            <tr>
                                                                <td class="diff-macro-body" style="background-color: #fff;border: 1px solid #dddddd;padding: 10px;; font-size: 13px"> <pre style="font-size: 13px">{numberedheadings}

{note}
This Specification is still in draft form.
{note}

{toc}

h1. Introduction

This Asterisk Manager Interface (AMI) specification describes the relationship between Asterisk and an external entity wishing to communicate with Asterisk over the AMI protocol.  It describes:
* An overview of the AMI protocol
* The operations AMI provides external entities wishing to control Asterisk
* Basic formatting of AMI message structures
* Guaranteed operations, configuration control, and other information provided by Asterisk in AMI 1.4

h2. Scope

This specification describes AMI version 1.4 for Asterisk 12.  This specification provides details on the functional, operational and design requirements for AMI 1.4. Note that this does not include a comprehensive listing of the AMI configuration file parameters or messages that a system interfacing over AMI in Asterisk 12 will send/receive; however, it does provide a baseline of the supported features and messages provided in AMI 1.4.  This specification should be used in conjunction with the documented AMI actions and events in Asterisk 12 to encompass the full range of functionality provided by AMI in Asterisk 12.

In addition, this specification provides interface requirements levied on AMI by Stasis Core.  It conveys sufficient detail to understand how AMI attaches to Stasis Core and interacts with other entities on the Stasis Core message bus.

This specification is intended for all parties requiring such information, including software developers, system designers and testers responsible for implementing the interface.

h1. Terminology

|| Term || Definition ||
| Action | A command issued to Asterisk from an external entity via AMI |
| Client | An external entity communicating with Asterisk via AMI over some transport mechanism |
| Event | A message sent from Asterisk to an external entity via AMI |
| Field | A key/value pair that exists in either an action or event |
| Stasis-Core | The internal framework that AMI is built on top of |

h1. Protocol Overview

Asterisk provides a number of interfaces that serve different purposes.  Say, for example, we wanted to manipulate a call between Alice and Bob via some external mechanism.  Depending on what we wanted to do with the call, we may use one or more interfaces to manipulate the channels that make up the call between Alice and Bob.

|| Alice calls Bob and... || Interface ||
| ... we want to use a local script to execute some logic on Alice's channel | AGI |
| ... we want to execute a script on a remote machine on Bob's channel | FastAGI |
| ... we want to put Alice into an IVR with fine grained media control, where the IVR is written outside of {{extensions.conf}} | ExternalIVR |
| ... we want to control Alice and Bob's underlying channel objects | AMI (with, possibly, AsyncAGI as well) |

In general, AMI is used to manage Asterisk and its channels.  It does not determine what actions are executed on a particular channel - the dialplan and some AGI interface does that - but it does allow a client to control call generation, aspects of call flow, and other internals of Asterisk.

At its heart, AMI is an asynchronous message bus: it spills *events* that contain information about the Asterisk system over some transport.  In response, clients may request that Asterisk takes some *action*.  These two concepts - actions and events - make up the core of what is AMI.  As AMI is asynchronous, as events occur in Asterisk they are immediately sent to the clients.  This means that actions issued by entities happen without any synchronization with the events being received, even if those events occur in response to an action.  It is the responsibility of entities to associate event responses back to actions.

Clients wishing to use AMI act as clients and connect to Asterisk's AMI server over a supported transport mechanism. Authentication may or may not be enabled, depending on the configuration. Once connected, events can be automatically spilled to the connected clients, or limited in a variety of fashions. A connected client can send an action to the AMI server at any time. Depending on the allowed authorizations, the action may be allowed or disallowed.

More information on the various ways a client can be configured can be seen in [AMI Configuration|#ami_configuration].

{tip:Nomenclature}
Sometimes, the term *command* may be used instead of the term *action*.  With respect to AMI actions, command is synonymous with action, and the two can be treated the same.  For the sake of consistency, we've attempted to use the term *action* where possible.
{tip}

Historically, AMI has existed in Asterisk as its own core component {{manager}}.  AMI events were raised throughout Asterisk encoded in an AMI specific format, and AMI actions were processed and passed to the functions that implemented the logic.  In Asterisk 12, AMI has been refactored to sit on top of Stasis Core, which is a generic, protocol independent message bus internal to Asterisk.  From the perspective of clients wishing to communicate with Asterisk over AMI very little has changed; internally, the Stasis representation affords a much higher degree of flexibility with how messages move through Asterisk.

{section}
{table}
{tr}
{td}
{gliffy:name=AMI High Level Diagram|align=left|size=L|version=1}
{td}
{tr}
{tr}
{td}
Asterisk's Stasis-Core provides a generic publish/subscribe message bus inside of Asterisk. While AMI often directly interacts with constructs in Asterisk through actions, it receives its events through messages published over Stasis-Core. It translates the generic Stasis messages into an AMI event, and sends those to the appropriate AMI clients.
{td}
{tr}
{table}
{section}

h1. Semantics and Syntax

h2. Message Sending and Receiving

By default, AMI is an asynchronous protocol that sends events immediately to clients when those events are available. Likewise, clients are free to send actions to AMI at any time, which may or may not trigger additional events. The exception to this is when the connection is over [HTTP/HTTPS|#transport_http]; in that scenario, events are only transmitted as part of the response to an HTTP POST.

Various options for configuration of clients can control which events are sent to a client. Events can be whitelisted/blacklisted explicitly via event filters, or implicitly by [class authorizations|#class_authorizations].

h2. Message Layout

AMI is an ASCII protocol that provides bidirectional communication with clients. Each field in an AMI message - action or event - is delineated by the '\r\n' characters. An action or event is terminated by an additional '\r\n' character.  Within a message, each field is a key value pair delineated by a ':'. A single space MUST follow the ':' and precede the value.

{section}
{column:width=50%}
{noformat}

Event: Newchannel
Privilege: call,all
Channel: SIP/misspiggy-00000001
Uniqueid: 1368479157.3
ChannelState: 3
ChannelStateDesc: Up
CallerIDNum: 657-5309
CallerIDName: Miss Piggy
ConnectedLineName:
ConnectedLineNum:
AccountCode: Pork
Priority: 1
Exten: 31337
Context: inbound
{noformat}
{column}
{column:width=50%}
This is syntantically equivalent to the following ASCII string:
{noformat}
Event: Newchannel\r\nPrivilege: call,all\r\nChannel: SIP/misspiggy-00000001\r\n
Uniqueid: 1368479157.3\r\nChannelState: 3\r\n
ChannelStateDesc: Up\r\nCallerIDNum: 657-5309\r\n
CallerIDName: Miss Piggy\r\nConnectedLineName:\r\nConnectedLineNum:\r\nAccountCode: Pork\r\n
Priority:\r\nExten: 31337\r\nContext: inbound\r\n\r\n
{noformat}
{column}
{section}

Actions are specified in a similar manner. Note that depending on the message, some keys can be repeated.

{noformat}
Action: Originate
ActionId: SDY4-12837-123878782
Channel: SIP/kermit
Context: outbound
Exten: s
Priority: 1
CallerID: &quot;Kermit the Frog&quot; &lt;123-4567&gt;
Account: FrogLegs
Variable: MY_VAR=frogs
Variable: HIDE_FROM_CHEF=true
{noformat}

In addition, no ordering is implied on message specific keys.  Hence, the following two messages are semantically the same.

{section}
{column:width=50%}
{noformat}
Action: Originate
ActionId: SDY4-12837-123878782
Channel: SIP/kermit
Context: outbound
Exten: s
Priority: 1
CallerID: &quot;Kermit the Frog&quot; &lt;123-4567&gt;
Account: FrogLegs
Variable: MY_VAR=frogs
Variable: HIDE_FROM_CHEF=true
{noformat}
{column}
{column:width=50%}
{noformat}
ActionId: SDY4-12837-123878782
Action: Originate
Variable: HIDE_FROM_CHEF=true
Variable: MY_VAR=frogs
Channel: SIP/kermit
Account: FrogLegs
Context: outbound
Exten: s
CallerID: &quot;Kermit the Frog&quot; &lt;123-4567&gt;
Priority: 1
{noformat}
{column}
{section}

This is also true for events, although by convention, the {{Event}} key is the first key in the event. If an action or event contains duplicate keys, such as {{Variable}}, the order in which Asterisk processes said keys is the order in which they occur within the action or event.

Keys are case insensitive. Hence, the following keys are equivalent:

{section}
{column:width=30%}
{noformat}
Action: Originate
{noformat}
{column}
{column:width=30%}
{noformat}
ACTION: Originate
{noformat}
{column}
{column:width=30%}
{noformat}
action: Originate
{noformat}
{column}
{section}

The case sensitivity for values is left up to the context in which they are interpreted.

h3. Common Fields

h4. Actions

h5. General Fields

This section lists fields that apply generally to all actions.

h6. Action

*Action* specifies the action to execute within Asterisk.  Each value corresponds to a unique action to execute within Asterisk.  The value of the *Action* field determines the allowed fields within the rest of the message.  By convention, the first field in any action is the *Action* field.

{anchor:action_actionid}

h6. ActionId

*ActionId* is a universal unique identifier that can optionally be provided with an action.  If provided in an action, events that are related to that action will contain the same *ActionId* value, allowing a client to associate actions with events that were caused by that action.

It is recommended that clients always provide an *ActionId* for each action they submit.

h5. Channels

This section lists fields that apply generally to all actions that interact upon an Asterisk channel. Note that an Action that interacts with a channel must supply either the *Channel* field or the *Uniqueid* field.

{tip}
In the past, only the *Channel* field could be used. As Asterisk can change the name of a channel, the *Uniqueid* is now the preferred way of initiating an action on a channel.
{tip}

{anchor:action_channel}

h6. Channel

The Asterisk channel name. A channel name is provided by AMI to clients during a *Newchannel* event. A channel name can be used as a handle to a channel, although the *Uniqueid* field is generally preferred.

{tip:title=Why Uniqueid over Channel name?}
In the past, channel masquerades would rename channels and AMI clients would have to track the name changes via a sequence of *Rename* events. While this no longer occurs, it is possible for certain channel drivers and other third party modules to rename a channel. As such, the safest way to handle a channel is to use the *Uniqueid*, which cannot be changed.
{tip}

{anchor:action_uniqueid}

h6. Uniqueid

A universal unique identifier that acts as a handle to the channel. Once a communication path between an endpoint and Asterisk is established, a *Uniqueid* is created as a handle to that communication path.

h4. Events

h5. General Fields

This section lists fields that apply generally to all events.

h6. Event

The unique name of the event being raised. The value of the *Event* field determines the rest of the contents of the message. By convention, the *Event* field is the first field in an AMI message.

h6. ActionId

If present, the Action's corresponding [ActionId|#action_actionid] that caused this event to be created. If an Action contained an *ActionId*, any event relating the success or failure of that action MUST contain an *ActionId* field with the same value.

h6. Privilege

The class authorizations associated with this particular event. The class authorizations for a particular event are in a comma-delineated list. For more information, see [class authorizations|#class_authorizations].

{anchor:event_channels}

h5. Channels

This section lists fields that apply generally to all events that occur due to interactions upon an Asterisk channel.

Events that relate multiple channels will prefix these fields with an event specific role specifier. For example, a *DialBegin* or a *DialEnd* event will prefix the outbound channel's fields with *Dest*. So, the *Channel* field is the *DestChannel* field; the *Uniqueid* field is the *DestUniqueid* field, etc.
h6. Channel

The current Asterisk channel name. This corresponds to the [Channel|#action_channel] field in actions.

h6. Uniqueid

A universal unique identifier that acts as a handle to the channel. This corresponds to the [Uniqueid|#action_uniqueid] field in actions.

{anchor:event_chanvariable}

<span class="diff-html-removed" id="removed-diff-0" style="font-size: 100%; background-color: #ffe7e7; text-decoration: line-through;">
</span>h6. ChanVariable

Channel variables specific to a channel can be conveyed in each AMI event related to that channel. When this occurs, each variable is referenced in a *ChanVariable* field. The value of a *ChanVariable* field will always be of the form {{key=value}}, where {{key}} is the name of the channel variable and {{value}} is its value.

h5. Bridges

h6. BridgeUniqueid

A unique identifier for the bridge, which provides a handle to actions that manipulate bridges.
h6. Bridgetype

The type of the bridge. Bridge types&nbsp;can vary based on the registered bridge technologies; in general, however, this will indicate whether the bridge is a holding bridge, a simple two-party bridge, or a multi-party bridge. The type of a bridge can change during the lifetime of the bridge as channels enter and leave a bridge.
h5. Action Responses

When an Action is submitted to AMI, the success or failure of the action is communicated in subsequent events.

h6. Response

Contains whether or not the action succeeded or failed.  Valid values are &quot;Success&quot; or &quot;Error&quot;.  Events that are in response to an action MUST include this field.

h6. EventList

Some actions will cause a chain of events to be created.  Events that are a response to an action that causes such a sequence will contain the EventList field with a value of &quot;start&quot;.  When all generated events have been sent, a final event will be sent containing the EventList field with the value &quot;complete&quot;.

If, for some reason, an error occurs and the events cannot be sent, an event will be sent with an EventList field that contains the value &quot;cancelled&quot;.

Note that the events that mark the completion or cancellation of an event list are not technically action responses, and have their own specific event types.

h6. Message

An optional text message that provides additional contextual information regarding the success or failure of the action.

h2. Actions

The supported actions for Asterisk 12 are listed here:

[Asterisk 12 AMI Actions|AST:Asterisk 12 AMI Actions]

h2. Events

The supported events for Asterisk 12 are listed here:

[Asterisk 12 AMI Events|AST:Asterisk 12 AMI Events]

h2. Channel Interaction/Lifetime

While channels are independent of AMI, they have a large implication on the events sent out over AMI. Many of the events in AMI correspond to changes in channel state. While AMI is an asynchronous protocol, there is some ordering with respect to the events that are relayed for a particular channel. This section provides the basic event relationships that are guaranteed through AMI.

h3. Basic Channel Lifetime

All channels begin with a *Newchannel* event. A *Newchannel* will always contain the following fields:
* The current [Channel|#action_channel] name
* The [Uniqueid|#action_uniqueid] that acts as a handle to the channel for that channel's lifetime

Changes in the state of the channel, i.e., the [ChannelState|#event_channelstate] field, are conveyed via *Newstate* events.
Notification of a Channel being disposed of occurs via a *Hangup* event. A *Hangup* signals the termination of the channel associated with the Uniqueid. After the *Hangup* event, no further events will be raised in relation to the channel with that Uniqueid, and the communication between the endpoint and Asterisk via that channel is terminated.
h3. Channel Variables

For each channel variable that is changed, a *VarSet* event is sent to the client. The *VarSet* event contains the new value of the appropriate channel variable. Note that channel variables can also be conveyed in [ChanVariable|#event_chanvariable] fields.

h3. DTMF

DTMF is indicated via a *DTMFBegin*/*DTMFEnd* events. A *DTMFEnd* event MUST convey the duration of the DTMF tone in milliseconds.

{<span class="diff-html-removed" id="removed-diff-1" style="font-size: 100%; background-color: #ffe7e7; text-decoration: line-through;">note</span><span class="diff-html-added" id="added-diff-0" style="font-size: 100%; background-color: #ddfade;">warn</span>:title=<span class="diff-html-removed" id="removed-diff-2" style="font-size: 100%; background-color: #ffe7e7; text-decoration: line-through;">Deprecation</span><span class="diff-html-added" id="added-diff-1" style="font-size: 100%; background-color: #ddfade;">Upgrade</span> Warning}
The combination of *DTMFBegin*/*DTMFEnd* events replaces the <span class="diff-html-removed" id="removed-diff-3" style="font-size: 100%; background-color: #ffe7e7; text-decoration: line-through;">deprecated </span>*DTMF* event.
{<span class="diff-html-removed" id="removed-diff-4" style="font-size: 100%; background-color: #ffe7e7; text-decoration: line-through;">note</span><span class="diff-html-added" id="added-diff-2" style="font-size: 100%; background-color: #ddfade;">warn</span>}

h3. Dialplan Execution

As a channel executes operations in the dialplan, those operations are conveyed via a *NewExten* event. Each transition to a new combination of context, extension, and priority will trigger a *NewExten* event.

{panel:title=Example}
{table}{tr}{td}{noformat}
Event: Newexten
Privilege: dialplan,all
Channel: SIP/kermit-00000001
Uniqueid: 550e8400-e29b-41d4-a716-446655440000
...
Context: default
Extension: h
Priority: 1
Application: NoOp
AppData: Ah Snap
{noformat}{td}
{td}
Kermit the Frog's SIP channel has been hung up, and he's been tossed rudely into the _h_ extension. This event informs the clients that Kermit's channel is in context _default_, extension _h_, priority _1_, and is about to execute the _NoOp_ application with application data _&quot;Ah Snap&quot;_.
{td}{tr}{table}
{panel}

h3. Dialing <span class="diff-html-added" id="added-diff-3" style="font-size: 100%; background-color: #ddfade;">and</span> <span class="diff-html-added" id="added-diff-4" style="font-size: 100%; background-color: #ddfade;">Channel Origination

</span>Dial operations always result in two events: a *DialBegin* event that signals the beginning of the dial to a particular destination, and a *DialEnd* event that signals the end of the dialing. In parallel dialing situations, *DialBegin*/*DialEnd* events MUST be sent for each channel dialed. For each *DialBegin* event sent, there MUST be a corresponding *DialEnd* event.

<span class="diff-html-removed" id="removed-diff-5" style="font-size: 100%; background-color: #ffe7e7; text-decoration: line-through;">{note</span><span class="diff-html-added" id="added-diff-5" style="font-size: 100%; background-color: #ddfade;">&nbsp;
A *DialEnd* occurs whenever Asterisk knows the final state of the channel that it was attempting to establish. This is communicated in the DialStatus field.
{warn</span>:title=<span class="diff-html-removed" id="removed-diff-6" style="font-size: 100%; background-color: #ffe7e7; text-decoration: line-through;">Deprecation</span><span class="diff-html-added" id="added-diff-6" style="font-size: 100%; background-color: #ddfade;">Upgrade</span> Warning}
The pair of *DialBegin*/*DialEnd* events replaces the deprecated *Dial* event. Note that the *Dial* event signalling the end of dialing would not normally be sent until after bridging was complete; this operation should now occur when the dial operation has determined the status of a particular called channel.
{<span class="diff-html-removed" id="removed-diff-7" style="font-size: 100%; background-color: #ffe7e7; text-decoration: line-through;">note</span><span class="diff-html-added" id="added-diff-7" style="font-size: 100%; background-color: #ddfade;">warn</span>}

<span class="diff-html-removed" id="removed-diff-8" style="font-size: 100%; background-color: #ffe7e7; text-decoration: line-through;">A *DialEnd* occurs whenever Asterisk knows the final state of the channel that it was attempting to establish. This is communicated in the DialStatus field.

</span><span class="diff-html-added" id="added-diff-8" style="font-size: 100%; background-color: #ddfade;">When Asterisk originates an outbound channel, there is no calling party. *DialBegin* and *DialEnd* events are still sent for the originated channel, where the originated channel is the destination of the dialing attempt.
</span>{panel:title=Simple Successful Dial}
{table}
{tr}
{td}{noformat}
Event: Newchannel
Channel: SIP/animal-00000001
Uniqueid: 550e8400-e29b-41d4-a716-446655440000
...
Event: DialBegin
Channel: SIP/<span class="diff-html-added" id="added-diff-9" style="font-size: 100%; background-color: #ddfade;">kermit-00000000
Uniqueid: 550e8400-e29b-41d4-a716-446655430000
DestChannel: SIP/</span>animal-00000001
<span class="diff-html-removed" id="removed-diff-9" style="font-size: 100%; background-color: #ffe7e7; text-decoration: line-through;">Uniqueid</span><span class="diff-html-added" id="added-diff-10" style="font-size: 100%; background-color: #ddfade;">DestUniqueid</span>: 550e8400-e29b-41d4-a716-446655440000
...
Event: DialEnd
Channel: SIP/<span class="diff-html-added" id="added-diff-11" style="font-size: 100%; background-color: #ddfade;">kermit-00000000
Uniqueid: 550e8400-e29b-41d4-a716-446655430000
DestChannel: SIP/</span>animal-00000001
<span class="diff-html-removed" id="removed-diff-10" style="font-size: 100%; background-color: #ffe7e7; text-decoration: line-through;">Uniqueid</span><span class="diff-html-added" id="added-diff-12" style="font-size: 100%; background-color: #ddfade;">DestUniqueid</span>: 550e8400-e29b-41d4-a716-446655440000
DialStatus: ANSWER
...
{noformat}{td}{td}
In this example, <span class="diff-html-removed" id="removed-diff-11" style="font-size: 100%; background-color: #ffe7e7; text-decoration: line-through;">we</span><span class="diff-html-added" id="added-diff-13" style="font-size: 100%; background-color: #ddfade;">Kermit</span> <span class="diff-html-removed" id="removed-diff-12" style="font-size: 100%; background-color: #ffe7e7; text-decoration: line-through;">decide</span><span class="diff-html-added" id="added-diff-14" style="font-size: 100%; background-color: #ddfade;">decides</span> to dial Animal. We create a new channel to between Asterisk and Animal's SIP device, and begin a dial operation. When Animal eats his handset (causing the device to think he merely took it off the hook), the SIP device answers and the dial operation completes. This indicated by a *DialEnd* event. At this point, the channel is ready for something - it can execute in the dialplan, or be immediately bridged with another channel (which<span class="diff-html-added" id="added-diff-15" style="font-size: 100%; background-color: #ddfade;">,</span> <span class="diff-html-removed" id="removed-diff-13" style="font-size: 100%; background-color: #ffe7e7; text-decoration: line-through;">is</span><span class="diff-html-added" id="added-diff-16" style="font-size: 100%; background-color: #ddfade;">in</span> <span class="diff-html-removed" id="removed-diff-14" style="font-size: 100%; background-color: #ffe7e7; text-decoration: line-through;">usually the channel that initiated the dial operation in the first place.)</span><span class="diff-html-added" id="added-diff-17" style="font-size: 100%; background-color: #ddfade;">this case, would be Kermit.)
&nbsp;
Note that in the *DialBegin* and *DialEnd* events, Animal's channel is prefixed with the role &quot;Dest&quot;, indicating that Animal is the destination of the dial attempt.</span>
{td}{tr}{table}{panel}

{panel:title=Simple Failed Dial}
{table}
{tr}
{td}{noformat}
Event: Newchannel
Channel: SIP/animal-00000002
Uniqueid: 550e8400-e29b-41d4-a716-446655440002
...
Event: DialBegin
Channel: SIP/animal-00000002
Uniqueid: 550e8400-e29b-41d4-a716-446655440002
...
Event: DialEnd
Channel: SIP/animal-00000002
Uniqueid: 550e8400-e29b-41d4-a716-446655440002
DialStatus: TIMEDOUT
...
Event: Hangup
Channel: SIP/animal-00000002
Uniqueid: 550e8400-e29b-41d4-a716-446655440002
...
{noformat}{td}{td}
In this example, we decide to dial Animal again. Unfortunately, Animal ate his handset, so we inevitably time out. When we do, a DialEnd event is received indicating the failure.
{td}{tr}{table}{panel}

{panel:title=Parallel Dial}
{table}
{tr}
{td}{noformat}
Event: Newchannel
Channel: SIP/animal-00000003
Uniqueid: 550e8400-e29b-41d4-a716-446655440003
...
Event: Newchannel
Channel: SIP/drteeth-00000004
Uniqueid: 550e8400-e29b-41d4-a716-446655440004
...
Event: DialBegin
Channel: SIP/animal-00000003
Uniqueid: 550e8400-e29b-41d4-a716-446655440003
...
Event: DialBegin
Channel: SIP/drteeth-00000004
Uniqueid: 550e8400-e29b-41d4-a716-446655440004
...
Event: DialEnd
Channel: SIP/drteeth-00000004
Uniqueid: 550e8400-e29b-41d4-a716-446655440004
DialStatus: ANSWER
...
Event: DialEnd
Channel: SIP/animal-00000003
Uniqueid: 550e8400-e29b-41d4-a716-446655440003
DialStatus: CANCEL
...
{noformat}{td}{td}
In this example, we decide to dial Animal and Dr. Teeth. Dr. Teeth immediately answers, and so we cancel the dial to Animal. We can now do something with Dr. Teeth's channel (such as bridge him with his dentist) - however, Animal's channel is implicitly destroyed, as his device never answered.
{td}{tr}{table}{panel}

h3. Bridging

A bridge contains 0 or more channels. When a channel is in a bridge, it has the potential to communicate with other channels within the bridge. Before channels enter a bridge, a *BridgeCreate*&amp;nbsp;event is sent, indicating that a bridge has been created. When a bridge is destroyed, a *BridgeDestroy*&amp;nbsp;event is sent. All channels within a bridge must leave a bridge prior to the *BridgeDestroy*&amp;nbsp;event being sent.

When a channel enters a bridge, a *BridgeEnter* event is raised. When a channel is put into a bridge, it is implied that the channel can pass media between other channels in the bridge. This is not guaranteed, as other properties on the channel or bridge may restrict media flow. When a channel leaves a bridge, a corresponding *BridgeLeave* event is raised. A *BridgeLeave* event MUST mean that the channel that left the bridge can no longer pass media to other channels still in the bridge. This does not necessarily mean that the channel is being hung up; rather, that it is no longer in a communication path with some other set of channels. In some scenarios, a channel may enter a bridge that has no other channels; this could occur when the channel has been put in some hold state (such as in a parking lot).

In all cases, if a channel has a *BridgeEnter* event, it MUST have a corresponding *BridgeLeave* event. If a channel is hung up and it is in a bridge, a *BridgeLeave* event MUST precede the *Hangup* event.

If a transfer operation begins, a *Transfer* event MUST be raised for the channels involved in the transfer prior to those channels leaving the bridge or entering another bridge. Similarly, if a channel enters a parking lot, a *ParkedCall* event MUST be raised for the channel prior to it entering the bridge that represents the parking lot.

If a property of a bridge is changed, such as the type going from a &quot;native&quot; bridge to a &quot;core&quot; bridge, then the *BridgeUpdate* event is sent with the updated parameters.

h4. Two Party Bridging

Parties are bridged by virtue of them entering a bridge, as indicated by a *BridgeEnter*. When parties are no longer talking, a *BridgeLeave* event is sent for each channel that leaves the bridge.

{panel:title=Example - Two Party Bridge}
{table}
{tr}{td}{noformat}
Event: BridgeCreate
Bridgetype: core
BridgeUniqueid: 1234
...
Event: BridgeEnter
Bridgetype: core
BridgeUniqueid: 1234
Channel: SIP/kermit-00000001
Uniqueid: 550e8400-e29b-41d4-a716-446655440000
...
{noformat}{td}
{td}Kermit the Frog's SIP channel enters into Bridge 1234. As a result, the bridge is first created (denoted by the *BridgeCreate*&amp;nbsp;event), and then Kermit's channel enters the bridge (the *BridgeEnter*&amp;nbsp;event){td}{tr}
{tr}{td}{noformat}
Event: BridgeEnter
Bridgetype: core
BridgeUniqueid: 1234
Channel: SIP/gonzo-00000002
Uniqueid: 550e8400-e29b-41d4-a716-446655440001
...
{noformat}{td}
{td}
Gonzo the Great enters the bridge and talks with Kermit. Note that the bridge Gonzo entered is Bridge 1234; by virtue of this being the same bridge Kermit entered, we know that the two can talk.{td}{tr}
{tr}{td}{noformat}
Event: BridgeLeave
Bridgetype: core
BridgeUniqueid: 1234
Channel: SIP/kermit-00000001
Uniqueid: 550e8400-e29b-41d4-a716-446655440000
...

Event: Hangup
Channel: SIP/kermit-00000001
Uniqueid: 550e8400-e29b-41d4-a716-446655440000
...
{noformat}{td}
{td}Kermit decided he was tired of Gonzo's pontificating, and hung up on Gonzo. We are first alerted that Kermit has left the bridge; quickly thereafter, we receive the *Hangup* event indicating that Kermit's channel is dead.{td}{tr}
{tr}{td}{noformat}
Event: BridgeLeave
Bridgetype: core
BridgeUniqueid: 1234
Channel: SIP/gonzo-00000002
Uniqueid: 550e8400-e29b-41d4-a716-446655440001
...

Event: Hangup
Channel: SIP/gonzo-00000002
Uniqueid: 550e8400-e29b-41d4-a716-446655440001
...

Event: BridgeDestroy
Bridgetype: core
BridgeUniqueid: 1234
...
{noformat}{td}
{td}
Asterisk is configured to not let Gonzo continue on in the dialplan once his bridge is broken. As such, Gonzo is forcibly ejected from the bridge, and is hung up on after. Because no channels are left in the bridge, the bridge is destroyed.
{td}{tr}{table}{panel}

{tip}
In this scenario, it was perfectly acceptable for either Kermit or Gonzo's channels to continue after the bridge was broken. Since this represents the most basic two-party call scenario, once one party decided to hang up, the other party was also hung up on.
{tip}

h4. Transfers

Transfers begin with a *Transfer* event, which indicates information about the transfer that is about to take place. Subsequently, *BridgeLeave*/*BridgeEnter* events are used to indicate which channels are talking at different stages during the transfer.

{panel:title=Example - Blind Transfer}
{table}
{tr}{td}{noformat}
Event: BridgeCreate
Bridgetype: core
BridgeUniqueid: 1234
...
Event: BridgeEnter
Bridgetype: core
BridgeUniqueid: 1234
Channel: SIP/kermit-00000001
Uniqueid: 550e8400-e29b-41d4-a716-446655440000
...
{noformat}{td}
{td}Kermit the Frog's SIP channel enters into Bridge 1234{td}{tr}
{tr}{td}{noformat}
Event: BridgeEnter
Bridgetype: core
BridgeUniqueid: 1234
Channel: SIP/fozzie-00000002
Uniqueid: 550e8400-e29b-41d4-a716-446655440001
...
{noformat}{td}
{td}Fozzie Bear's SIP channel enters into Bridge 1234. At this point, Fozzie and Kermit can talk to each other.{td}{tr}
{tr}{td}{noformat}
Event: Transfer
Privilege: call,all
TransferMethod: Core
TransferType: Blind
Channel: SIP/fozzie-00000002
Uniqueid: 550e8400-e29b-41d4-a716-446655440001
TargetChannel: SIP/kermit-00000001
TargetUniqueid: 550e8400-e29b-41d4-a716-446655440000
TransferExten: call_miss_piggy
TransferContext: default
{noformat}{td}
{td}Fozzie decides he's tired of telling Kermit jokes and blind transfers him off to Miss Piggy via the dialplan extension {{call_miss_piggy}}. The fact that a transfer is occurring starts off with the *Transfer* event.  This tells the user who initiates the transfer, who is being transferred, and where the transfer target is going.{td}{tr}
{tr}{td}{noformat}
Event: BridgeLeave
Bridgetype: core
BridgeUniqueid: 1234
Channel: SIP/kermit-00000001
...
{noformat}{td}
{td}Kermit leaves the bridge with Fozzie.{td}{tr}
{tr}{td:colspan=2}
{note}At this point, the order of the events that affect Fozzie versus Kermit are not defined. Fozzie and Kermit are no longer bridged together, and their respective events may arrive in any order.{note}
{td}{tr}
{tr}{td}{noformat}
Event: BridgeLeave
Bridgetype: core
BridgeUniqueid: 1234
Channel: SIP/fozzie-00000002
...

Event: BridgeDestroy
Bridgetype: core
BridgeUniqueid: 1234
...
{noformat}{td}
{td}Because Fozzie isn't talking to anyone anymore, he leaves the bridge as well. At this point Asterisk could hang up Fozzie's channel, or, if configured, he could continue on in the dialplan (say, perhaps, to talk to his rubber chicken).{td}{tr}
{tr}{td}{noformat}
Event: Newchannel
Channel: SIP/miss_piggy-00000003
Uniqueid: 550e8400-e29b-41d4-a716-446655440002
...
Event: DialBegin
Channel: SIP/miss_piggy-00000003
Uniqueid: 550e8400-e29b-41d4-a716-446655440002
...
Event: DialEnd
Channel: SIP/miss_piggy-00000003
Uniqueid: 550e8400-e29b-41d4-a716-446655440002
DialStatus: ANSWER
...
{noformat}{td}
{td}The act of Kermit entering into extension {{call_miss_piggy}} causes a new channel to be created between Asterisk and Miss Piggy. Asterisk immediately dials Miss Piggy, who answers.{td}{tr}
{tr}{td}{noformat}
Event: BridgeCreate
Bridgetype: core
BridgeUniqueid: 1235
...
Event: BridgeEnter
Bridgetype: core
BridgeUniqueid: 1235
Channel: SIP/kermit-00000001
Uniqueid: 550e8400-e29b-41d4-a716-446655440000
...
{noformat}{td}
{td}Kermit enters into a bridge. Note that the *BridgeUniqueid* is different than the previous bridge's *BridgeUniqueid*.{td}{tr}
{tr}{td}{noformat}
Event: BridgeEnter
Bridgetype: core
BridgeUniqueid: 1235
Channel: SIP/miss_piggy-00000003
Uniqueid: 550e8400-e29b-41d4-a716-446655440002
...
{noformat}{td}
{td}Miss Piggy enters the bridge. At this point, Kermit and Miss Piggy can converse, and the blind transfer is complete.{td}{tr}
{table}
{panel}

h3. Local Channels

Local channels are different than 'normal' channels in Asterisk, in that they have several properties that make them unique:
* A Local channel never has a physical device that it directly communicates with - it exists as a virtual channel within Asterisk.
* A Local channel can communicate with one or more channels, or directly with an Asterisk application.
* Local channels can be optimized out of a communication path, causing the state of bridges and channels to change.
* A Local channel is actually always two separate channels with a special bridge between them.

{gliffy:name=AMI Local Channels Diagram|align=left|size=L|version=1}

While the Local channel exists as a single concept from the perspective of the dialplan, from the perspective of an AMI client, it is always two channels that are tied together by a special bridge. When the bridge between the Local channel halves is formed, a *LocalBridge* event is raised denoting that the two are connected.

h4. Local Channel Creation

When a Local channel is created, a *Newchannel* event is created for each half of the Local channel being created. Each Local channel half has its own Channel field name and its own Uniqueid - for the purposes of an AMI client, they are two separate channels that can be manipulated separately but whose lifetime is tied together. When either Local channel half is hungup, denoted by a *Hangup* event, the other Local channel half will also be hungup automatically.

h4. Local Channel Bridging

Local channels receive bridge events in the same fashion as other channels. Thus, when they join a bridge, they receive a *BridgeEnter* event and when they leave a bridge, a corresponding *BridgeLeave* event. The exception to this is a Local channel bridge, denoted by a *LocalBridge* event. Once a *LocalBridge* event occurs, the two Local channel halves can pass frames back and forth between each other. Because the lifetime of the Local channel halves is the same, there is no event representing a Local channel bridge being broken.

{panel:title=Example - Local Channel between two SIP Channels}
{table}
{tr}{td}{noformat}
Event: Newchannel
Channel: SIP/miss_piggy-00000003
Uniqueid: 550e8400-e29b-41d4-a716-446655440002
...
{noformat}{td}
{td}Miss Piggy decides to call Kermit the Frog, and a channel is created between Asterisk and Miss Piggy's SIP device.{td}
{tr}
{tr}{td}{noformat}
Event: Newchannel
Channel: Local/kermit@default-00000001;1
Uniqueid: 550e8400-e29b-41d4-a716-446655440003
...
Event: Newchannel
Channel: Local/kermit@default-00000001;2
Uniqueid: 550e8400-e29b-41d4-a716-446655440004
...
Event: LocalBridge
Channel1: Local/kermit@default-00000001;1
Channel2: Local/kermit@default-00000001;2
Uniqueid1: 550e8400-e29b-41d4-a716-446655440003
Uniqueid2: 550e8400-e29b-41d4-a716-446655440004
LocalOptimization: No
...Event: DialBegin
Channel: Local/kermit@default-00000001;1
Uniqueid: 550e8400-e29b-41d4-a716-446655440003
...
{noformat}{td}
{td}
Instead of dialing Kermit the Frog directly, a Local channel is created inside Asterisk and Asterisk dials one half of the Local channel. Note that both halves of the Local channel are created first; the Local channel bridges its two halves together;&amp;nbsp;then a *DialBegin* event indicates that Asterisk is attempting to connect to one half of the Local channel, {{Local/kermit@default-00000001;1}}.{td}
{tr}
{tr}{td}{noformat}
Event: DialEnd
Channel: Local/kermit@default-00000001;1
Uniqueid: 550e8400-e29b-41d4-a716-446655440003
DialStatus: ANSWER
...
Event: BridgeCreate
Bridgetype: core
BridgeUniqueid: 1234
...
Event: BridgeEnter
Bridgetype: core
BridgeUniqueid: 1234
Channel: SIP/miss_piggy-00000003
Uniqueid: 550e8400-e29b-41d4-a716-446655440002
...
Event: BridgeEnter
Bridgetype: core
BridgeUniqueid: 1234
Channel: Local/kermit@default-00000001;1
Uniqueid: 550e8400-e29b-41d4-a716-446655440003
...
{noformat}{td}
{td} The dial operation succeeds and Miss Piggy is bridged with one half of the Local channel that will eventually connect her to Kermit. Note that Miss Piggy doesn't realize that any changes have occurred - from her perspective, nothing has really happened, as the Local channel is a virtual channel and we haven't yet dialed Kermit.{td}
{tr}
{tr}
{td}{noformat}
Event: Newchannel
Channel: SIP/kermit-00000002
Uniqueid: 550e8400-e29b-41d4-a716-446655440005
...
Event: DialBegin
Channel: SIP/kermit-00000002
Uniqueid: 550e8400-e29b-41d4-a716-446655440005
...
Event: DialEnd
Channel: SIP/kermit-00000002
Uniqueid: 550e8400-e29b-41d4-a716-446655440005
DialStatus: ANSWER
...
Event: BridgeCreate
Bridgetype: core
BridgeUniqueid: 5678
...
Event: BridgeEnter
Bridgetype: core
BridgeUniqueid: 5678
Channel: Local/kermit@default-00000001;2
Uniqueid: 550e8400-e29b-41d4-a716-446655440004
...
Event: BridgeEnter
Bridgetype: core
BridgeUniqueid: 5678
Channel: SIP/kermit-00000002
Uniqueid: 550e8400-e29b-41d4-a716-446655440005
...
{noformat}{td}{td}
We dial Kermit, and he foolishly answers. He is now bridged with the second half of the Local channel, {{Local/kermit@default-00000001;2}}, as both that channel and the SIP channel communicating with his SIP device have corresponding *BridgeEnter* events.
{tip}
In those situations where both a Local channel half and a SIP channel are bridged, there is no ordering guaranteed on which channel enters the bridge first - however, both a Local channel half and the SIP channel will be bridged in the same bridge.
{tip}
{td}{tr}
{tr}{td}{noformat}
Event: BridgeLeave
Bridgetype: core
BridgeUniqueid: 1234
Channel: SIP/miss_piggy-00000003
Uniqueid: 550e8400-e29b-41d4-a716-446655440002
...
Event: Hangup
Channel: SIP/miss_piggy-00000003
Uniqueid: 550e8400-e29b-41d4-a716-446655440002
...
Event: BridgeLeave
Bridgetype: core
BridgeUniqueid: 1234
Channel: Local/kermit@default-00000001;1
Uniqueid: 550e8400-e29b-41d4-a716-446655440003
...
Event: Hangup
Channel: Local/kermit@default-00000001;1
Uniqueid: 550e8400-e29b-41d4-a716-446655440003
...
Event: BridgeDestroy
Bridgetype: core
BridgeUniqueid: 1234
...
Event: BridgeLeave
Bridgetype: core
BridgeUniqueid: 5678
Channel: Local/kermit@default-00000001;2
Uniqueid: 550e8400-e29b-41d4-a716-446655440004
...
Event: Hangup
Channel: Local/kermit@default-00000001;2
Uniqueid: 550e8400-e29b-41d4-a716-446655440004
...
Event: BridgeLeave
Bridgetype: core
BridgeUniqueid: 5678
Channel: SIP/kermit-00000002
Uniqueid: 550e8400-e29b-41d4-a716-446655440005
...
Event: Hangup
Channel: SIP/kermit-00000002
Uniqueid: 550e8400-e29b-41d4-a716-446655440005
...

Event: BridgeDestroy
Bridgetype: core
BridgeUniqueid: 5678
{noformat}{td}
{td}
Miss Piggy, in a fit of frustrated porkine anger, karate chops her SIP phone, causing it to hangup. She leaves the bridge with the Local channel half, {{Local/kermit@default-00000001;1}}. This causes it to be hungup, as no one else is in the bridge. Because {{Local/kermit@default-00000001;1}} is hungup, its corresponding other Local channel half, {{Local/kermit@default-00000001;2}}, leaves the bridge with Kermit's SIP phone and is also hung up. Kermit's SIP channel realizes it's all by itself (it's not easy being green), leaves the bridge it had with its Local channel half, and hangs up as well.{td}
{tr}
{table}
{panel}

h4. Local Channel Optimization

Local channels have an option wherein they can be optimized away if there are two other channels in the Answered state on either end of the Local channel half. This option is performed on Local channel creation, and is communicated back to the AMI clients in the *LocalBridge* event in the LocalOptimization field. When a Local channel optimization occurs, a *LocalOptimization* event is sent that indicates the channels involved in the optimization and any bridges they happen to be in. If, after the Local channel optimization, either bridges contains only a single channel, then a single channel in that bridge is moved to the bridge that had the other channel half.

{tip}
It is not defined which channel is moved first - in this situation, that is an implementation detail left up to Asterisk. Suffice to say, if a Local channel is optimized away, Asterisk attempts to rebridge the channels left over.
{tip}

{panel:title=Example - Optimizing Local Channel between two SIP Channels}
{table}
{tr}{td}{noformat}
Event: Newchannel
Channel: SIP/gonzo-00000001
Uniqueid: 550e8400-e29b-41d4-a716-446655440000
...
{noformat}{td}
{td}Gonzo decides to call Kermit the Frog, and a channel is created between Asterisk and Gonzo's SIP device.{td}
{tr}
{tr}{td}{noformat}
Event: Newchannel
Channel: Local/kermit@default-00000001;1
Uniqueid: 550e8400-e29b-41d4-a716-446655440001
...
Event: Newchannel
Channel: Local/kermit@default-00000001;2
Uniqueid: 550e8400-e29b-41d4-a716-446655440002
...
Event: DialBegin
Channel: Local/kermit@default-00000001;1
Uniqueid: 550e8400-e29b-41d4-a716-446655440001
...
{noformat}{td}
{td}
Instead of dialing Kermit the Frog directly, a Local channel is created inside Asterisk and Asterisk dials it.{td}
{tr}
{tr}{td}{noformat}
Event: DialEnd
Channel: Local/kermit@default-00000001;1
Uniqueid: 550e8400-e29b-41d4-a716-446655440001
DialStatus: ANSWER
...
Event: BridgeCreate
Bridgetype: core
BridgeUniqueid: 1234
...
Event: BridgeEnter
Bridgetype: core
BridgeUniqueid: 1234
Channel: SIP/gonzo-00000001
Uniqueid: 550e8400-e29b-41d4-a716-446655440000
...
Event: BridgeEnter
Bridgetype: core
BridgeUniqueid: 1234
Channel: Local/kermit@default-00000001;1
Uniqueid: 550e8400-e29b-41d4-a716-446655440001
...
Event: LocalBridge
Channel1: Local/kermit@default-00000001;1
Channel2: Local/kermit@default-00000001;2
Uniqueid1: 550e8400-e29b-41d4-a716-446655440001
Uniqueid2: 550e8400-e29b-41d4-a716-446655440002
LocalOptimization: Yes
...
{noformat}{td}
{td} The dial operation succeeds and Gonzo is bridged with one half of the Local channel that will eventually connect him (it?) to Kermit. The Local channel itself has also decided to go ahead and bridge the two local halves together, since we have one half of the full chain of channels established. Note that we are told at this point that the Local channel will attempt to optimize itself away, if Kermit answers.{td}
{tr}
{tr}
{td}{noformat}
Event: DialBegin
Channel: SIP/kermit-00000002
Uniqueid: 550e8400-e29b-41d4-a716-446655440003
...
Event: DialEnd
Channel: SIP/kermit-00000002
Uniqueid: 550e8400-e29b-41d4-a716-446655440003
DialStatus: ANSWER
...
Event: BridgeCreate
Bridgetype: core
BridgeUniqueid: 5678
...
Event: BridgeEnter
Bridgetype: core
BridgeUniqueid: 5678
Channel: Local/kermit@default-00000001;2
Uniqueid: 550e8400-e29b-41d4-a716-446655440002
...
Event: BridgeEnter
Bridgetype: core
BridgeUniqueid: 5678
Channel: SIP/kermit-00000002
Uniqueid: 550e8400-e29b-41d4-a716-446655440003
...
{noformat}{td}{td}
We dial Kermit and he answers. He is now bridged with the second half of the Local channel, {{Local/kermit@default-00000001;2}}.
{tip}
Note that even in the optimizing case, both the Local channel halves and the other channels involved first enter their respective bridges.
{tip}
{td}{tr}
{tr}{td}{noformat}
Event: LocalOptimization
Channel1: Local/kermit@default-00000001;1
Uniqueid1: 550e8400-e29b-41d4-a716-446655440001
BridgeUniqueid1: 1234
Channel2: Local/kermit@default-00000001;2
Uniqueid2: 550e8400-e29b-41d4-a716-446655440002
BridgeUniqueid2: 5678
...
Event: BridgeLeave
Bridgetype: core
BridgeUniqueid: 5678
Channel: SIP/kermit-00000002
Uniqueid: 550e8400-e29b-41d4-a716-446655440003
...Event: BridgeEnter
Bridgetype: core
BridgeUniqueid: 1234
Channel: SIP/kermit-00000002
Uniqueid: 550e8400-e29b-41d4-a716-446655440003
...
{noformat}{td}
{td}
Asterisk determines that it can optimize away the Local channel. It notifies the AMI client that this is about to occur, which Local channels are involved, and what bridges they are currently in. It starts first by moving Kermit into Gonzo's bridge. From their perspective, nothing has happened - they just now happen to be in the same bridge, instead of having a Local channel pass frames for them.

Note that before this happens, a *LocalOptimization*&amp;nbsp;event is sent indicating that some shenanigans are about to ensue with the Local channels and by extension, the bridges they are in.

{td}{tr}
{tr}{td}{noformat}
Event: BridgeLeave
Bridgetype: core
BridgeUniqueid: 5678
Channel1: Local/kermit@default-00000001;2
Uniqueid1: 550e8400-e29b-41d4-a716-446655440002
...
Event: BridgeLeave
Bridgetype: core
BridgeUniqueid: 1234
Channel1: Local/kermit@default-00000001;1
Uniqueid1: 550e8400-e29b-41d4-a716-446655440001
...
Event: Hangup
Channel1: Local/kermit@default-00000001;1
Uniqueid1: 550e8400-e29b-41d4-a716-446655440001
...
Event: Hangup
Channel1: Local/kermit@default-00000001;2
Uniqueid1: 550e8400-e29b-41d4-a716-446655440002
...Event: BridgeDestroy
Bridgetype: core
BridgeUniqueid: 5678
...
{noformat}{td}
{td}
The Local channels now leave their bridges and are hung up. As a result, the bridge with no channels left in it - Bridge 5678 - is destroyed.

{td}{tr}
{table}
{panel}

{anchor:masquerades}

h3. Masquerades

{note:title=Masquerades have changed}
In the past, masquerades occurred rather frequently - most often in any scenario where a transfer occurred or where a {{pbx_thread}} needed to be associated with a channel. This has now changed. Masquerades now rarely occur, and are never communicated to AMI clients. From the perspective of AMI clients, nothing changes - you still use your handle to a channel to communicate with it, regardless of the presence (or lack thereof) of a masquerade operation.

This note only exists to explicitly call out that fact.
{note}

{anchor:transport_http}

h2. Transports

AMI supports the following transport mechanisms:
* TCP/TLS
* HTTP/HTTPS

When clients connect over HTTP/HTTPS, AMI events are queued up for retrieval. Events queued up for a client are automatically retrieved and sent in the response to any POST operation. The *WaitEvent* action can be used to wait for and retrieve AMI events.

h1. Security Considerations

AMI supports security at the transport level via TLS using OpenSSL.

{anchor:class_authorizations}

h2. Class Authorizations

{warning}
Do not rely on class authorizations for security. While they provide a means to restrict a client's access to sets of functionality, there are often ways of achieving similar functionality through multiple mechanisms. Do *NOT* assume that because a class authorization has not been granted to a client, that they can't find a way around it. In general, view class authorizations as a coarse grained way of providing sets of filters.
{warning}

Events and actions are automatically classified with particular class authorizations. Clients can be configured to support some set of class authorizations, filtering the actions that they can perform and events that they receive. The supported class authorizations are listed below.

|| Class Type || Description ||
| system | The item is associated with something that reports on the status of the system or manipulates the system in some fashion |
| call | The item is associated with calls, i.e., state changes in a call, etc. |
| log | The item is associated with the logging subsystem |
| verbose | The item is associated with verbose messages |
| command | The item is associated with execution of CLI commands through AMI |
| agent | The item is associated with Queue Agent manipulation |
| user | The item is associated with user defined events |
| config | The item is associated with manipulating the configuration of Asterisk |
| dtmf | The item is associated with DTMF manipulation |
| reporting | The item is associated with querying information about the state of the Asterisk system |
| cdr | The item is associated with CDR manipulation |
| dialplan | The item is associated with dialplan execution |
| originate | The item is associated with originating a channel |
| agi | The item is associated with AGI execution |
| cc | The item is associated with call completion |
| aoc | The item is associated with Advice of Charge |
| test | The item is associated with some test action |
| message | The item is associated with out of call messaging |
| all | The item has all class authorizations associated with it |
| none | The item has no class authorization associated with it |

h2. Access Control Lists

Access Control Lists can be used to filter connections based on address. If an attempt to connect from an unauthorized address is detected, the connection attempt will be rejected.

h2. Authorization

Authorization can be provided via the *Login* action. If a client fails to provide a valid username/password, the connection attempt and any subsequent actions will be rejected. Events will not be sent until the client provides authorized credentials.

The actions that are excluded from successful login are:
* *Login*
* *Logout*
* *Challenge*

{note}
The action *Logoff* has been replaced by a corresponding action *Logout*. *Logoff* has been deprecated in favor of *Logout*.
{note}


{anchor:ami_configuration}

h1. AMI Configuration

AMI supports the following configuration options. Note that additional configurations MAY be specified; however, these configuration options are valid for Asterisk 12.

h2. General Settings

|| Option || Type || Description || Default ||
| enabled | Boolean | Enable AMI | no |
| webenabled | Boolean | Enable AMI over HTTP/HTTPS | no |
| port | Integer | The port AMI's TCP server will bind to | 5038 |
| bindaddr | IP Address | The address AMI's TCP server will bind to | 0.0.0.0 |
| tlsenable | Boolean | Enable TLS over TCP | no |
| tlsbindaddr | IP Address | The address AMI's TCP/TLS server will bind to | 0.0.0.0:5039 |
| tlscertfile | String | The full path to the TLS certificate to use | /tmp/asterisk.pem |
| tlsprivatekey | String | The full path to the private key. If no path is specified, _tlscertfile_ will be used for the private key. | /tmp/private.pem |
| tlscipher | String | The string specifying which SSL ciphers to use. Valid SSL ciphers can be found at [http://www.openssl.org/docs/apps/ciphers.html#CIPHER_STRINGS] | |
| allowmultiplelogin | Boolean | Allow multiple logins for the same user. If set to no, multiple logins from the same user will be rejected. | Yes |
| timestampevents | Boolean | Add a Unix epoch *Timestamp* field to all AMI events | No |
| authlimit | Integer | The number of unauthenticated clients that can be connected at any time | |

{anchor:configuration_client}

h2. Client Settings

Note that the name of the client settings context is the username for the client connection.

|| Option || Type || Description || Default ||
| secret | String | The password that must be provided by the client via the *Login* action | |
| deny | ACL | An address/mask to deny in an ACL. This option may be present multiple times. | |
| permit | ACL | An address/mask to allow in an ACL. This option may be present multiple times. | |
| acl | String | A Named ACL to apply to the client. | |
| setvar | String | A channel variable key/value pair (using the nomenclature VARIABLE=value) that will be set on all channels originated from this client | |
| eventfilter | Regular Expression | This option may be present multiple times. This options allows clients to whitelist or blacklist events. A filter is assumed to be a whitelist unless preceeded by a '\!'. Evaluation of the filters is as follows:
* If no filters are configured all events are reported as normal.
* If there are white filters only: implied black all filter processed first, then white filters.
* If there are black filters only: implied white all filter processed first, then black filters.
* If there are both white and black filters: implied black all filter processed first, then white filters, and lastly black filters. | |
| read | String | A comma delineated list of the allowed class authorizations applied to events | all |
| write | String | A comma delineated list of the allowed class authorizations applied to actions | all |
| tag | String | If present, the client will only receive events that are related to channels created in relation to endpoints that are configured with the same tag. See [Publish/Subscribe|#publish_subscribe] for more information.  | |

{numberedheadings}</pre> </td>
                                                            </tr>
                                                        </tbody>
                                                    </table>
                                                </div>
                                            </div>
                                        </div>
                                        <table id="email-actions" class="email-metadata" cellspacing="0" cellpadding="0" border="0" width="100%" style="border-top: 1px solid #bbb; color: #505050; margin: 8px 0 0 0; padding: 0; color: #505050">
                                            <tbody>
                                                <tr>
                                                    <td class="left" valign="top" style="font-size: 13px; padding-top: 8px; max-width: 45%; text-align: left"> <span class="email-list-item"><a href="https://wiki.asterisk.org/wiki/display/AST/AMI+1.4+Specification" style="color: #326ca6; text-decoration: none">View Online</a> </span> <span class="email-list-divider" style="color: #505050; padding: 0 0.350em">&middot;</span> <span class="email-list-item"><a href="https://wiki.asterisk.org/wiki/plugins/likes/like.action?contentId=22086004" style="color: #326ca6; text-decoration: none">Like</a> </span> <span class="email-list-divider" style="color: #505050; padding: 0 0.350em">&middot;</span> <span class="email-list-item"><a href="https://wiki.asterisk.org/wiki/pages/diffpagesbyversion.action?pageId=22086004&amp;revisedVersion=16&amp;originalVersion=15" style="color: #326ca6; text-decoration: none">View Changes</a> </span> <span class="email-list-divider" style="color: #505050; padding: 0 0.350em">&middot;</span> <span class="email-list-item"><a href="https://wiki.asterisk.org/wiki/display/AST/AMI+1.4+Specification?showComments=true&amp;showCommentArea=true#addcomment" style="color: #326ca6; text-decoration: none">Add Comment</a> </span> </td>
                                                    <td class="right" width="50%" valign="top" style="font-size: 13px; padding-top: 8px; text-align: right"> <span class="email-list-item"><a href="https://wiki.asterisk.org/wiki/users/removespacenotification.action?spaceKey=AST" style="color: #326ca6; text-decoration: none">Stop watching space</a> </span> <span class="email-list-divider" style="color: #505050; padding: 0 0.350em">&middot;</span> <span class="email-list-item"><a href="https://wiki.asterisk.org/wiki/users/editmyemailsettings.action" style="color: #326ca6; text-decoration: none">Manage Notifications</a> </span> </td>
                                                </tr>
                                            </tbody>
                                        </table> </td>
                                </tr>
                            </tbody>
                        </table> </td>
                </tr>
                <tr>
                    <td id="email-footer" align="center" style="font-size: 13px; padding: 0 16px 32px 16px; margin: 0"> <small style="font-size: 11px"> This message was sent by <a class="email-footer-link" style="color:#505050;font-size:11px;text-decoration:none;; color: #326ca6; text-decoration: none; color: #505050; font-size: 11px" href="http://www.atlassian.com/software/confluence">Atlassian Confluence</a> 5.0.3, <a class="email-footer-link" style="color:#505050;font-size:11px;text-decoration:none;; color: #326ca6; text-decoration: none; color: #505050; font-size: 11px" href="http://www.atlassian.com/software/confluence/overview/team-collaboration-software?utm_source=email-footer">Team Collaboration Software</a> </small> </td>
                </tr>
            </tbody>
        </table>
    </body>
</html>