User Guide

Table Of Contents
1056 Chapter 43: Using the Instant Messaging Event Gateways
Status and request-handling CFC
The following CFC handles all IM events, except onIncomingMessage. It maintains an
Application scope buddyStatus structure that contains information on the gateway buddies. This
structure limits the interactions that are needed with the IM server to get buddy and status
information. The application also logs significant events, such as requests to add buddies and
error messages from the IM server. In particular, it does the following:
The onBuddyStatus function updates the Application scope buddy status structure when the
gateway gets an event message indicating that a buddys status has changed.
The onAddBuddyRequest function searches for the requested buddys name in a data source. If
it finds a single instance of the name, it adds the buddy and updates the status in the
Application scope buddyStatus structure. If it doesnt find name, it declines the buddy request.
If it finds multiple instances of the name, it tells the gateway to take no action. It also logs all
actions.
The onAddBuddyResponse function adds the buddy to the Application scope buddy status
structure if the buddy request is accepted, and sets the current status. It logs all responses.
The onIMServerMessage function logs all messages that it receives.
This example uses the IM_ID column of the Employees database of the cfdocexamples database
that is included with ColdFusion MX 7. The entries in this column assume that you use an
XMPP server “company.” To run this example you must configure an XMPP server with this
name and with clients with names in this database, or you must change the database entries to
match IM server clients. You must also configure a gateway instance in the ColdFusion MX
Administrator that uses this server.
The following listing shows the CFC code:
<cfcomponent>
<cffunction name="onBuddyStatus">
<cfargument name="CFEvent" type="struct" required="YES">
<cflock scope="APPLICATION" timeout="10" type="EXCLUSIVE">
<cfscript>
// Create the status structures if they don’t exist.
if (NOT StructKeyExists(Application, "buddyStatus")) {
Application.buddyStatus=StructNew();
}
if (NOT StructKeyExists(Application.buddyStatus,
CFEvent.Data.BUDDYNAME)) {
Application.buddyStatus[#CFEvent.Data.BUDDYNAME#]=StructNew();
}
// Save the buddy status and timestamp.
Application.buddyStatus[#CFEvent.Data.BUDDYNAME#].status=CFEvent.Data.BUDDY
STATUS;
Application.buddyStatus[#CFEvent.Data.BUDDYNAME#].timeStamp=CFEvent.Data.TI
MESTAMP;
</cfscript>
</cflock>
</cffunction>