Logging the CSTA message
I was faced with several problems while developing my outbound application. The outbound samples were not very informative in my book. The code seemed confusing and overly complex. But, the biggest issue I faced was how to determine what was happening when I placed a call and what type of response I was getting back from the TAS/TIM combination. I was also faced with the fact that the call results were not documented anywhere. I didn’t know if the call was answered by a person or by an answering machine and to make matters worse I didn’t know what was returned from the TIM for those cases. Using TASIM was no help as it turns out because the call answer types there are limited and don’t reflect real world responses from a TIM. In fact, the format of the CSTA message differs significantly from a real world TIM (but I’ll blog on that later). The information I needed is in the .etl files but placing a call, answering it, hanging up then importing the .etl files and using CallViewer to get to the data was too time consuming.
What I ended up doing as outlined in the code examples below is to create my own routines for logging the CSTA message returned from the TIM then looking at that to determine the call results. The CSTA message is in XML format so it was easy to pull it up in IE (a great little XML viewer) and see the results. I simply made calls to myself then checked the XML based off of the way I had answered the call. This allowed me to document the different return statuses.
To do this I grab the CSTA message contents and place it in a semanticitem . You will need to do this in both the OnClientConnect and the OnClientFailed event handlers as shown below. I’ve over simplified the code shown here to remove things that I do that aren’t related to the logging of the CSTA message.
function MainMakeCall_OnClientConnected(sender, number, cstaMsg)
{
// Save the csta for logging
siCSTA.value = cstaMsg.xml;
}
function MainMakeCall_OnClientFailed(sender, cstaMsg)
{
siCSTA.value = cstaMsg.xml;
SpeechCommon.Submit();
window.close();
}
I wanted the ability to turn logging on and off so I store a logging flag in the Web.config along with the logging path. The relevant part of the Web.config looks like this:
<add key="cstaLogging" value="true"/>
<add key="cstaLoggingPath" value="\BCOAlertsLogs"/>
In my Page_Load() method on the server I simply check the flag’s value to determine if I need to log the CSTA Naturally you only want to do this on post back.
// IF logging is turned on then do it.
if(ConfigurationSettings.AppSettings["cstaLogging"] == "true")
{
LogCSTA();
}
On the server side I have a method that writes the CSTA (found in the semanticitem) to a file. I build the filename based off of the current time, the number dialed and the MakeCall.CurrentCallID. The CALLID ensures that I get a unique filename even if more than one call to the same number is attempted at the same time. The code to log the data is really very simple. I don’t worry about doing anything significant in the catch as this is only a debugging tool. If it fails I don’t want it blowing up my application (hence the try) but I’m really not too concerned.
private void LogCSTA()
{
try
{
string fileName = ConfigurationSettings.AppSettings["cstaLoggingPath"] + String.Format ("\\{0:MMddyyyyHHmmss}_{1}_{2}.xml", DateTime.Now, MainMakeCall.CurrentCall.CalledDevice, MainMakeCall.CurrentCall.CallID);
StreamWriter sw = File.CreateText(fileName);
sw.Write(siCSTA.Text);
sw.Close();
}
Catch // do nothing
{
}
}
I hope this gives you some insight into how I log the CSTA message and gets you thinking about how you can add logging into your application. If you have any comments on this approach or suggestions for improving it then please leave a comment. I’m anxious to know if you have a better way of doing this.