Wiki

« Back to SimpleIpPhoneExecute

SimpleIpPhoneExecute-Designer

Designer implementation of SimpleIpPhoneExecute. The application triggers on http got request, queries the CUCM for the Ip address of the Iphone using device name. Create and send a command to be executed by the Ip phone. The command Dial:<phonenumber> i.e. "Dial:101064" when executed by the Ip phone makes a call to the Ip phone with phone number <phonenumber> i.e. 101064 mentioned in the command.

Note: The Ip phone that executes the command has to be associated with an end user in the call manager. The UserName and Password used in SendExecute are that of the end user.

Build the Project#

Create the Project#

1. Open CUAD designer. Goto File->New Project

2. Create a project called SimpleIpPhoneExecute_CUAD.

3. When creating a new project, the Designer will prompt you to name first script and to select a triggering event for that script. For this example we will just go ahead and keep the default script name 'script1', but we are going to select a specific triggering event. For this application select the 'Metreos.CallControl.Http.GotRequest' event:

Add the Installer#

1. An installer lets you add configuration items to your application. The values for these variables can be set in the CUAE without having to redeploy the application. To add one, r-click on the project 'SimpleIpPhoneExecute_CUAD'. Select Add Installer-> New Installer.

2. To specify the configuration items for the installer, click on the Installer in the Explorer toolbox. R-Click on the canvas and select Add. Add the variables DeviceName, URL1, UserName, and Password. Enter the name and display name for each of the item, as shown below. We will use the default format of String.

Add the Global Variables#

1. Global variables are accessible by any function in the application. We will be capturing the configuration items in global variables. To do this, click on script1 in the Explorer window. A tree structure with 'Events and Functions' and 'Variables' can be seen. R-Click on the Variables folder and select Add New Item.

We will be following the convention of naming global variables with the prefix 'g_'. Add the variables g_DeviceName, g_URL1, g_UserName, and g_Password. You will see them added into the tree structure.

4. These items will be initialized by the configuration items added in Installer. Highlight the variable you wish to set. Goto the Properties Toolbox, which is (by default) at the bottom right-hand corner of the Designer.

These are the basic properties of the variable. Click in the empty box adjacent to InitializeWith. Choose from the drop down the corresponding configuration item to initialize the variable. Do this for all four variables.

Add a Local Variable#

1. The designer canvas has a local variables tray, which is hidden by default. You can toggle the the tray on and off hidden by either selecting View > Variables Tray or R-clicking on canvas and clicking Variable Tray. Click on the OnGotRequest tab and perform one of these two actions. A tray appears in the bottom of OnGotRequest canvas with the message "(tray empty)".

2. To add a variable, R-click on the variable tray and select Add New Item. Call the new item resultsFromQuery. This variable will store the results returned by the action QueryByDeviceName we will be adding later. Click on the newly created variable and go to its Properties Toolbox. Set the type to DataTable.

Add QueryByDeviceName #

1. Goto Toolbox on the top right hand side. Click on Cisco DeviceListX and find QueryByDeviceName.

2. Drag and drop QueryByDeviceName Icon to the OnGotRequest Canvas. Since this is the first action on the OnGotRequest canvas, it will automatically connect it to the Start icon. Select QueryByDeviceName by clicking on it. It will highlight the action with a green border.

3. Go to the Properties toolbox for QueryByDeviceName. R-Click on STR box of the DeviceName action parameter and select Variable and select g_DeviceName from the dropdown list. You will also need to enter a value for CallManagerIP. Then under Result Data, set ResultData to resultsFromQuery.

Add CustomCode#

1. Goto the toolbox on the top right hand side and click on Application Components. Find CustomCode and drag and drop it onto the OnGotRequest canvas. Hover your mouse over the QueryByDeviceName icon until it becomes a hand. Click and drag your mouse towards the CustomCode icon and an arrow will connect the two. Click on the text 'default' and change it to 'Success' from the drop down menu. Now the CustomCode will only be executed if QueryByDeviceName is successful.

2. Select the CustomCode icon and go to the Properties toolbox. Highlight the line that says 'Code' and then click on the '...' button and an editor will pop up.

Our custom code will get the ip address of the device from the result data table returned by QueryByDeviceName. If there are more than one device with same name it will return the ip address of the first device i.e. the device in row 0. Copy the following code into the editor and select Ok.

public static string Execute(DataTable resultsFromQuery, ref string phoneIp)
{
    if(resultsFromQuery != null && resultsFromQuery.Rows.Count == 1)
    {
        phoneIp = resultsFromQuery.Rows[0]["IP"] as string;
    }
    else
    {
        //Choose the first phone (phone row zero)
        phoneIp = resultsFromQuery.Rows[0]["IP"] as string;
    }

    return phoneIp;
}

3. Create a local variable called phoneIp to store the IP address of phone that was returned by the CustomCode parsing QueryByDeviceName. Display the Variables Tray and R-click and select Add New Item. We can accept the default settings for this variable:

Parameter Value
Reference Type reference
Type String
Variable Name phoneIp

Add SendResponse#

1. If QueryByDeviceName fails, we want to send a response to the browser and exit. First, create a local variable called remoteHost. Goto the Properties and set the following items:

Parameter Value
InitializeWith RemoteHost
Reference Type reference
Type String
Variable name remoteHost

2. Goto Toolbox and expand the HTTP tab. Drag and drop SendResponse onto the OnGotRequest Canvas and connect it to QueryByDeviceName. Check that the connecting link is set to "default", so SendResponse will execute if QueryByDeviceName is anything but successful.

3. Set the following parameters in the SendResponse Properties toolbox:

Action Parameter Type Value
Body String Query by device name failed
Content-Type String text/plain
RemoteHost Variable remoteHost
ResponseCode String 200

Add EndScript#

1. Goto Toolbox on the top right hand side and expand Application Components. Drag and drop EndScript onto the OnGotRequest Canvas. Connect it to SendResponse.

2. Now, when QueryByDeviceName fails the application will send an http response with an error message 'Query by device name failed' and exit.

Add CreateExecute#

1. R-click on the Variables Tray and select Add New Item. Call this new local variable createExeObject . This variable will store the result from createExecute. Go to the Properties toolbox and set the parameters as follows:

Parameter Value
Reference Type reference
Type Execute
Variable name createExeObject

2. Goto the Toolbox and expand Cisco IP Phone. Drag and drop CreateExecute onto the OnGotRequest canvas and connect it to QueryByDeviceName.

Create execute creates an object that stores the command to be executed by the IP Phone.

Action Parameter Type Value
URL1 variable g_URL1
ResultData createExeObject

Add SendResponse#

1. Goto the Toolbox and expand HTTP. Drag and drop SendResponse onto the OnGotRequest canvas and connect it to CustomCode.

2. Set the following parameters in the Properties toolbox for SendResponse:

Parameter Type Value
Body String Create execute Failed.
Content-Type String text/plain
RemoteHost Variable remoteHost
ResponseCode String 200

2. Connect this SendResponse node to the already existing EndScript node. When CreateExecute fails the application sends an http response with an error message 'Create execute Failed' and exits.

Add SendExecute #

1. Now that we have created the object to send to the phone in CreateExecute, we must use a SendExecute to actually get the message to the phone. Goto the Toolbox and expand Cisco Ip Phone. Drag and drop SendExecute onto the OnGotRequest canvas. Connect it to CreateExecute and change the connecting link to 'Success'. If CreateExecute is successful, the SendExecute is executed, otherwise a SendResponse is executed to send a response with error message to the browser.

2. Set the following parameters for SendExecute:

Parameter Type Value
Message C# createExeObject.ToString()
Password Variable g_Password
PhoneIp Variable phoneIp
UserName Variable g_UserName

Add Default SendResponse#

1. Goto the Toolbox and expand HTTP. Drag and drop SendResponse onto the OnGotRequest canvas. Connect it to SendExecute and ensure that the connecting link is set to 'default'. Then connect SendResponse to EndScript and ensure that the connecting link is set to 'default'. Now when SendExecute fails the application sends an http response with an error message 'Send Execute Failed' and exits.

2. Set the following parameters for SendResponse:

Parameter Type Value
Body String Send Execute Failed.
Content-Type String text/plain
RemoteHost Variable remoteHost
ResponseCode String 200

Add Success SendResponse#

1. Goto the Toolbox and expand HTTP. Drag and drop SendResponse onto the OnGotRequest canvas. Connect it to SendExecute and ensure that the connecting link is set to 'Success'. Now if SendExecute is successful then the message 'Done.' will be sent to the web browser.

2. Set the following parameters for SendResponse:

Parameter Type Value
Body String Done.
Content-Type String text/plain
RemoteHost Variable remoteHost
ResponseCode String 200

Add EndScript#

1. Goto the Toolbox and expand Application Components. Drag and drop EndScript onto the OnGotRequest canvas. Connect it to SendExecute and ensure that the connecting link is set to 'default'.

Build and Deploy Application#

1. In the Designer, Goto Tools-> Options...

2. Select Connectivity from the menu on the left. Check that the Framework Directory and Version is correct, and set the IP address for your server with the matching username and password. Click Ok.

Build Project#

Goto Build-> Build Project to build the project. You will see the following output in the Remote Console:

    ---- Build Started ----

Building ... Preparing to build 'script1' ... Building 'script1' ... Build succeeded for 'script1' Packaging ... Assembling ...

Build successful }}}

Install Project#

Goto Build-> Deploy to build the project. You will see the following output in the Remote Console:

   Deploying ...
Package deployed}}}

Running the Application#

1. Login into the CUAE Admin console. Goto Applications-> List Applications. Click on the application SimpleIpPhoneExecute_CUAD.

Under 'Extended Configuration', enter the DeviceName (including the prefix 'SEP') and URL1 (Dial:######) . Enter the UserName and Password of the end user associated with the IP phone.

The device mentioned in device name should be associated to this application user in CUCM (Cisco Unified Call Manger). Click Apply and then Done.

2. Goto Applications-> List Triggers. Click on the application SimpleIpPhoneExecute_CUAD. To add a trigger, enter the trigger name in the text box and trigger value in the second text box. Here we are using "url" and "/SimpleIpPhoneExecute_CUAD". Click Add Parameter and then Done.

3. Open a browser and type

http://<IPaddress_of_the_application_server>:8000/<your_trigger_value>
. This will send an http request to the application server that will trigger the application.

0 Attachments
372 Views
Average (0 Votes)
The average rating is 0.0 stars out of 5.
Comments
No comments yet. Be the first.