A Guided Tour: AgentX Controls

An AgentX control is a thin wrapper around a Conversation object. It provides a convenient way of making connections and it is the only means that programs have for receiving the Connected, Disconnected, and Changed events outside of the VBVoice environment.

Read comprehensive details about AgentX control's properties, events, and methods.

How to initiate a connection using an AgentX control:

VB

Dim Talker as Conversation
Set Talker = AgentX1.Connect("TESTMACHINE")

C#

CONVERSATIONOCXLib.Conversation talker;
talker = (CONVERSATIONOCXLib.Conversation)agentX1.Connect("TESTMACHINE");

Events

AgentX controls provide three events:

Connected Event

The Connected event fires every time an inbound connection is detected. It provides two parameters: the Conversation object being used for the connection and a Connect flag determining whether the default response is to connect or not. The flag's initial value is set to the value of the AutoConnect property of the AgentX control. It can be overridden depending upon application requirements.

The Connected event is seldom used. Typically either all incoming connections for a given AppID are accepted (AutoConnect set to True) or they are all rejected (AutoConnect set to False). The Connected event is only useful for screening connections to specific subsets of behaviour. A logging application, for instance, may only be interested in connections that have the key Fatal Error set to True.

Typical code for a Connected event could look like this:

VB

Private Sub TestAgentX_Connected(ByVal Conversation As Object, Connect As Long)

Dim Inbound as Conversation
Dim Fatal as Boolean
' Check if this is a fatal error being reported.

Set Inbound = Conversation
Fatal = Inbound.GetData("Fatal Error")
' Connect for further processing if and only if Fatal is True.

Connect = Fatal

End Sub

C#

private void testAgentX1_Connected(object sender, AxCONVERSATIONOCXLib._DAgentXEvents_ConnectedEvent e)
{

CONVERSATIONOCXLib.Conversation inbound;
inbound = (CONVERSATIONOCXLib.Conversation)e.conversation;
int fatal = (int)inbound.GetData("Fatal Error");
e.connect = fatal;

}

Changed Event

The Changed event is the most often used event in AgentX controls. It provides a single parameter: the Conversation object reporting the change.

A typical Changed handler could look like this:

VB

Private Sub TestAgentX_Changed(ByVal Conversation As Object)

Dim Inbound as Conversation
Dim CallerID as String
Dim CallerName as String
' Get the data we need.

Set Inbound = Conversation
CallerID = Inbound.GetData("Caller ID")
CallerName = Inbound.GetData("Caller Name")
' Do whatever handling we need.

End Sub

C#

private void testAgentX1_Changed(object sender, AxCONVERSATIONOCXLib._DAgentXEvents_ChangedEvent e)
{

CONVERSATIONOCXLib.Conversation Inbound;
Inbound = (CONVERSATIONOCXLib.Conversation)e.conversation;

String caller_ID = (String)Inbound.GetData("Caller ID");
String caller_ID = (String)Inbound.GetData("Caller Name");

}

It is also possible to iterate over all the keys supplied in a Conversation object - they do not have to be known in advance. See GetData for an example.

Disconnected Event

The Disconnected event is rarely used. It is fired when a connection has been dismantled and it is provided as a convenience for cleaning up any objects used in association with a Conversation.

Blocking in Events

One important point to note is that all three AgentX control events are non-blocking on the receiving side. If an application blocks in the Changed or Connected event, the sending application will be able to continue processing.