This section gives details on the AMI_Client component.

Description

The AMI_Client component is the central component of the AMIgo suite. This component creates a new thread and manage the communication with the AMI server and parse all of the received message. It maintains a complete state of the PBX, accessible as read only properties and offers several methods and events that can be used by the application to monitor, control / interact or configure an Asterisk PBX system through a Manager Interface connection.

Using the AMI_Client

The simplest way to use the AMI_Client component is to drop a AMI_Client component in a Windows Form Application, created with Visual Studio.

AMI_Client State

The AMI_Client can be in one of these state:

  • IDLE: Initial state after creation or the application is run.
  • RUNNING: After Start(Control) has been called.
  • CONNECTING: After Connect() has been called.
  • CONNECTED: After successfull connection has been established
  • LOGGING: After connection and Login() method called.
  • LOGGED: After successfull Login. Commands can be sent.
  • READY: After successfull AutoStartAutoLogin. 'One shot' event to signal ready state revert to LOGGED.
  • LOGGING_OFF: After Logoff() has been called.
  • DISCONNECTING: After Logoff and Disconnect() has been called
  • STOPPING: After Stop() has been called.

The state of the AMI_Client can be accessed with the AMI_Client State()()()() property or by setting up an event handler for the StateChangeEvent()()()()

AutoStart / AutoLogin / AutoGetConfig

The behavior on startup vary according to how these public properties are set. The default is true.

  • AutoStart: Auto Start the AMI_Client thread after object creation. If set to false you must explicitly call the Start()()()() method.
  • AutoLogin: Call the Connect()()()() and Login()()()() method on startup. If set to false you must call these function explicitly. The Host Port UserName and Password properties must be setup for the AutoLogin to be attempted.
  • AutoGetConfig: Auto get the system configuration on startup after a successfull connect and login. If set to false methods to get the extensions / trunks, channels, queues, agents etc must be called explicitly or by calling the DoAutoGetConfig()()()() method.

Example

This example show how to use AMI_Client StateChangeEvent()()()() to wait for the READY state and then send an Originate command from an extension to an external phone number.

CopyC#
 1private void StateChangeEventHandler(object Sender, AMIgo.StateChangeEventArgs ev)
 2{
 3  // If auto login just wait for the READY state
 4  if (AMI_Client1.AutoLogin == true)
 5  {
 6    if (ev.state == AMI_Client.AMI_ClientState.READY)
 7      AMI_Client1.OriginateExtension("SIP/200", "DLPN_DialPlan1", "95555551212, "1", "");
 8  }
 9  else // else call Start and do things 'manually'
10  {
11    if (ev.state == AMI_Client.AMI_ClientState.RUNNING)
12      AMI_Client1.Connect();
13    else if (ev.state == AMI_Client.AMI_ClientState.CONNECTED)
14      AMI_Client1.Login();
15    else if (ev.state == AMI_Client.AMI_ClientState.READY)
16      AMI_Client1.OriginateExtension("SIP/200", "DLPN_DialPlan1", "95555551212, "1", "");
17  }
18}