Adobe COLDFUSION 9 Manual page 1287

Developing applications
Hide thumbs Also See for COLDFUSION 9:
Table of Contents

Advertisement

DEVELOPING COLDFUSION 9 APPLICATIONS
Using External Resources
The
CFML function can send any command, and can be used to send an accept or decline
SendGatewayMessage
message. One possible use is in an application where someone must review all buddy requests before they are added.
In this case, the
onAddBuddyRequest
the request information in a database. Administrators could use a separate ColdFusion application to review the
request information. This application could use the
command to act on the request and inform the requestor.
The following example
onIncomingMessage
originator:
<cffunction name="onIncomingMessage" output="no">
<cfargument name="CFEvent" type="struct" required="yes">
<cfset retValue.MESSAGE = "echoing: " & CFEvent.DATA.message>
<cfset retValue.BuddyID = arguments.CFEVENT.DATA.SENDER>
<cfreturn retValue>
</cffunction>
Sample IM message handling application
The application described here consists of two CFCs: an employee phone directory lookup CFC that responds to an
onIncomingMessage event, and a Gateway management CFC that responds to all other events. This example shows
how an application can respond to events and send outgoing messages.
You can configure a gateway to use both CFCs by entering the paths to the two CFCs, separated by a comma, in the
CFC Path field of the Add/Edit ColdFusion Event Gateways form on the Gateway Instances page in the ColdFusion
Administrator.
Phone directory lookup CFC
The following CFC implements a simple employee phone directory lookup application. The user sends an instant
message containing some part of the name to looked up (a space requests all names). The
response depends on the number matches.
• If there is no match, the
onIncomingMessage
• If there is one match, the function returns the name, department, and phone number.
• If there are up to ten matches, the function returns a list of the names preceded by a number that the user can enter
to get the detailed information.
• If there are over ten matches, the function returns a list of only the first ten names. A more complex application can
let the user get multiple lists of messages to provide access to all names.
• If the user enters a number, and previously got a multiple-match list, the application returns the information for
the name that corresponds to the number.
The following listing shows the CFC code:
CFC method could initially send a noact command in its return value, and save
SendGatewayMessage
method of a listener CFC echoes incoming IM messages to the message
function returns a message indicating that there are no matches.
Last updated 8/5/2010
function with an accept or decline
onIncomingMessage
1282

Advertisement

Table of Contents
loading

Table of Contents