This demonstrates the use of the AMI_Client component in an ASP.NET Web Application

Using the AMI_Client in a Web Application

Note

The source code for this example can be found in the Examples\ASP_NET_Demo.Zip directory.

Caution

If you build this example from the given source code, you will need to change the reference to the AMIgo dll. Click on the project reference directory and delete the reference to AMIgo.dll and then click on Browse and select the AMIgo.dll file from the installation directory.

The AMI_Client can be used in an ASP.NET Web Application / WebSite to provide an interface to an Asterix PBX system.

This demo application features an Asterisk Status display, a simple 'Directory' with 'click to call' functionality and a call Database Lookup.

The demo application uses the 'Northwind' database provided by Visual Studio. The 'Employees' table is used in the directory and the 'Customer' table for call lookup.

Building the ASP.NET Demo

  • Create a new Web Application and keep the default name: WebApplication1
    • In visual studio, select File / New Project
    • Select the 'Web' tab and select 'ASP.NET Web Application'
    • Choose a location and leave the default name (Application1) and click the 'OK' button
  • Extract the content of the ASP_NET_Demo.zip files found into the [Install]\Examples directory into the new application main directory. (where the default.aspx ) replacing all existing files. Getting back to Visual Studio, say yes to reload changed files.
  • Right click on the 'Application1' directory and select 'Add Reference'. Browse and select the AMIgo.dll file from the AMIgo installation directory.
  • Open the Global.asax.cs file from the Solution Explorer and edit it to specify the Asterisk Host / Port / UserName / Password to connect to your target asterisk system. For example:
    CopyC#
    1AMI_Client1.AstMngrSiteName = "MySite"; // Properties.Settings.Default.SiteName;
    2AMI_Client1.AstMngrHost = "192.168.1.10"; // Properties.Settings.Default.AMI_Host; 
    3AMI_Client1.AstMngrPort = 5038; //  Convert.ToInt32(Properties.Settings.Default.AMI_Port);
    4AMI_Client1.AstMngrUserName = "admin"; // Properties.Settings.Default.AMI_UserName; //  
    5AMI_Client1.AstMngrPassword = "mypwd"; //  Properties.Settings.Default.AMI_Password;
    Note
    A better approch would be to use application settings to store the Site definition values. These application settings can be created trough the Solution Explorer and retreived using Properties.Settings.Default.[Setting Name] (commented out above)
  • In Solution Explorer, right click on Application1 and select 'Add' / 'Existing Items ...'. and select the 'CallsLookup.aspx' page.
  • Repeat the operation and select the 'Directory.aspx' page.
  • Build and run the application.
Note

You need to check the Connections strings for the CallsLookup and Directory pages so that it can connect to the 'Northwind' database on your development system.

  • In Solution Explorer, double click on the Directory.asax page to open it for edition.
  • Select the SqlDataSource object and modify the connection string to connect to the Northwind database.
  • Repeat the same operation for the CallsLookup.asax page.

The WebApplication's AMI_Client should connect on the target system when the site is first accessed and you should see a connection status string displayed on the Master page:

Status: LOGGED Site: AMI Site (192.168.1.10@5038) Version: 1.4.21.2

The first page should display the Lines, Channels, Queues, Agents information receveid from the target Asterisk system

If the login information is incorrect you will get something like:

Status: LOGGING Site: AMI Site (192.168.1.1@5038) Version:

If the Host / Port information is incorrect, (or the trial license has expired), you will get:

Status: IDLE Site: AMI Site (192.168.1.5@5038) Version: or 'NOT CONNECTED"

Loging In with Extension as User Name

To keep this example simple, we use the extension number as User Name when loggin in. The user name / extension is then used as the extension number for the click to call and database lookup functions.

Click on the Login link and create a new account with an existing extensions as the user name. Ex: 6000. The login display should display the login status: Loged in: 6000

Directory / Click to call feature

Once logged in you can now use the Directory features. Select an entry and click on the Call button to originate a call to the logged extension and then dial the external phone number. Make sure you have set the 'DialPlan' in the settings (or settings.settings file in the properties directory) to the context for outbound calls used on your system. If not sure, try 'default'. System using the Asterisk GUI use 'DLPN_DialPlan1'.

Note

To test this demo you can edit the Northwind Database's 'Employees' table and change their phone number to some known number you can call.

Database Lookup feature

The demo also features a database lookup example that display a detailed database record based on the phone number of inbound and outband calls. It will display a detailed record from the 'Customer' database for the last call received or placed by the currently logged UserName / Extension.

Note

To test this feature you can edit the Northwind Database's 'Customers' table and change their phone number to some known phone number used to call in or called out.

See Also