| By Ben Forta | Article Rating: |
|
| May 7, 2008 01:45 PM EDT | Reads: |
35,737 |
<!--- Gateway id --->
<cfset gateway_id="jabber cfdocs">
<!--- Status options
Bit off a hack needed because the
strings returned by getStatusAsString()
are not the same as the ones passed to
setStatus().
--->
<cfset status_options="ONLINE,AWAY,DND,NA,FREE_TO_CHAT">
<cfset status_display="ONLINE,AWAY,DO NOT DISTURB,NOT AVAILABLE,FREE TO CHAT">
<!--- Get the GatewayHelper --->
<cfset helper=getGatewayHelper(gateway_id)>
<!--- If form post is present --->
<cfif IsDefined("FORM.status_new")>
<cfset helper.setStatus(ListGetAt(status_options, status_new), "")>
</cfif>
<!--- Get current status --->
<cfset status=helper.getStatusAsString()>
<cfoutput>
<!--- Display current status --->
<h3>Status: #status#</h3>
<!--- Form to change status --->
<form action="#CGI.SCRIPT_NAME#" method="post">
<!--- Loop through status options --->
<cfloop index="o" from="1" to="#ListLen(status_options)#">
<input type="radio" name="status_new" value="#o#"
<cfif ListGetAt(status_display, o) is status>checked</cfif>
onChange="submit()">#ListGetAt(status_display, o)#<br>
</cfloop>
</form>
</cfoutput>
This is a pretty simple example. The gateway id is defined, as are lists containing the status values returned by and passed to the GatewayHelper methods. Next, GetGatewayHelper() is used to obtain a GatewayHelper object. The form in this little app is self-posting, and if a new status has been specified, helper.setStatus() is used to set the status (which will immediately be reflected in relevant buddy lists). The code then uses helper.getStatusAsString() to obtain the current status, and then displays a form used to change the status.
This is just a simple example, and there are lots of other GatewayHelper methods, too. Some are informational, like numberOfMessagesReceived() which returns the number of received inbound messages, and isOnline() which indicates whether or not the gateway is online and connected. Others are used to control buddy lists, including getBuddyList() which returns the buddy list, getBuddyInfo() which returns information about a buddy, and addBuddy() and removeBuddy() which do exactly what their names suggest. The full list of GatewayHelper methods for IM gateway types is included in the ColdFusion documentation (in the ColdFusion MX Event Gateway Reference section). Other gateway types may have other helper methods, consult the relevant gateway documentation to determine which methods are available to you.
Managing Session State
The last topic to discuss is session state management. Fortunately, there is not much to discuss. If ColdFusion session state management is enabled then you can use the SESSION scope in your bot code as you would in any other applications.
It is worth noting that although you may use SESSION just as you would in a web application, ColdFusion uses a different mechanism to identify sessions. In web applications ColdFusion uses a jsessionid or a cfid/cftoken pair (in cookies or URL parameters) to identify sessions, and these are passed back and forth with each request. There are no cookies or URL parameters to be passed back and forth when using IM, and so ColdFusion uses a combination of gateway id, gateway type, and the originator id (sender's buddy name) to identify sessions. And this is all handled internally by ColdFusion, you can just use sessions as you usually would, and it'll just work.
Summary
And there you have it, all you need to know to create your own IM bots, one example of the type of integration made possible but event gateways in ColdFusion MX 7 Enterprise. Have fun with this one, and if you do bring a public bot online, be sure to let me know about it.
Published May 7, 2008 Reads 35,737
Copyright © 2008 SYS-CON Media, Inc. — All Rights Reserved.
Syndicated stories and blog feeds, all rights reserved by the author.
More Stories By Ben Forta
Ben Forta is Adobe's Senior Technical Evangelist. In that capacity he spends a considerable amount of time talking and writing about Adobe products (with an emphasis on ColdFusion and Flex), and providing feedback to help shape the future direction of the products. By the way, if you are not yet a ColdFusion user, you should be. It is an incredible product, and is truly deserving of all the praise it has been receiving. In a prior life he was a ColdFusion customer (he wrote one of the first large high visibility web sites using the product) and was so impressed he ended up working for the company that created it (Allaire). Ben is also the author of books on ColdFusion, SQL, Windows 2000, JSP, WAP, Regular Expressions, and more. Before joining Adobe (well, Allaire actually, and then Macromedia and Allaire merged, and then Adobe bought Macromedia) he helped found a company called Car.com which provides automotive services (buy a car, sell a car, etc) over the Web. Car.com (including Stoneage) is one of the largest automotive web sites out there, was written entirely in ColdFusion, and is now owned by Auto-By-Tel.
![]() |
Randy Smith 05/07/08 02:00:43 PM EDT | |||
Got it working - remember to remove the pound sign from in front of each of the options! I assumed that if they said there was a "default" version that you didn't need to specify the parameters. Wrong! |
||||
![]() |
Randy Smith 05/07/08 01:16:24 PM EDT | |||
This was written in 2005. Here it is 2008 and I'm trying to apply this using Cold Fusion 2008 Enterprise, but I can't get the instance to start. The log files are basically saying that talk.google.com won't let me connect. Is there now a different IP I should connect to, or did Google shut down this "portal"? |
||||
![]() |
emanuel 10/22/05 09:43:27 PM EDT | |||
Where can i download this bot? Thanks. |
||||
![]() |
Mark Holton 10/16/05 09:35:23 AM EDT | |||
This is an awesome overview - Thanks for taking the time to supply this great info, Ben! |
||||
- Adobe’s Aiming ColdFusion at Multiple Clouds
- Cloud Computing Journal: Adobe to Deliver ColdFusion in the Cloud
- Adobe May Cooperate with Apple to Transplant Flash Player to iPhone
- Adobe Flex Developer Earns $100K in New York City
- Adobe LiveCycle Enterprise Suite 2 for Cloud Computing
- Adobe Betas Target RIAs and Cloud Computing
- Adobe Cans Another 9% of its Workforce
- Moyea DVD4Web Converter V2.0 Converts DVD to FLV Fast and Synchronously with Watermarks
- Adobe Fiddles with its Web Apps
- Adobe & Salesforce Cut Cloud Deal
- Hosting.com Launches ColdFusion 9 in the Cloud
- The Real Time Infrastructure Ultimatum
- Adobe’s Aiming ColdFusion at Multiple Clouds
- Eval JavaScript in a Global Context
- Fig Leaf Software to Exhibit at Government IT Conference & Expo
- Cloud Computing Journal: Adobe to Deliver ColdFusion in the Cloud
- Is Microsoft as Free as Open Source?
- Adobe Reader Sued
- The Planet Named “Bronze Sponsor” of Cloud Computing Expo
- Microsoft Expression Web Has Got Game
- Adobe May Cooperate with Apple to Transplant Flash Player to iPhone
- Adobe Flex Developer Earns $100K in New York City
- Bruce Chizen Joins Voyager Capital as Venture Partner
- My Top Seven Wishes From Adobe MAX 2009
- The Next Programming Models, RIAs and Composite Applications
- Where Are RIA Technologies Headed in 2008?
- Constructing an Application with Flash Forms from the Ground Up
- AJAX World RIA Conference & Expo Kicks Off in New York City
- CFEclipse: The Developer's IDE, Eclipse For ColdFusion
- Personal Branding Checklist
- Adobe Flex 2: Advanced DataGrid
- Has the Technology Bounceback Begun?
- Building a Zip Code Proximity Search with ColdFusion
- i-Technology Viewpoint: We Need Not More Frameworks, But Better Programmers
- The Asynchronous CFML Gateway
- Web Services Using ColdFusion and Apache CXF



























