BotTest
BotTest is a full featured example Open AIM Java Bot program with menus capable of communicating with LDAP, MySql, Oracle and Google SOAP API. It has a configuration file to manage menus and connections to back-end systems. BotTest is also able to handle a level of authorization based on a Screenname being present in LDAP.
I have provided two versions of the program, one which includes access to Google SOAP API for search and spell capabilities and the other which does not include that because apparently if you don't have an API key now, you may not be able to get one (Google SOAP API). We may add other interfaces (think SOA ;-))in a future version, but for now this should serve as a good example of how to write Bots that communicate with back-end systems to provide value.
The main menu shows selections 0 thru 6. A user would access the Bot menu by sending anything to the Bot via an AIM message. Below shows the main menu for the version with Google SOAP API capabilities.

To select a menu item, the user would just enter the number for the item that they would like to view within the menu. For example, selecting LDAP Status is shown below:

A user must always return to the main menu to select another menu item by sending a 0 via an AIM message. Below shows the user selecting LDAP Search after returning to the main menu.
The MySQL capabilities are configurable via the BotTest.conf file. Below shows a search of the MySQL database.
To add items to the database the user would first send a 3 and then send a 1 as shown below:
The Oracle capabilities are the same as the MySQL capabilities and are also configured in the BotTest.conf file. Below is shows a search and add operation against the Oracle database:
The Google SOAP API provides for search and spelling features. Search results are returned as hyperlinks to allow the user to simply click on the links to open a browser window to the results as shown below.
The Google Spelling capability checks your spelling and returns the results as shown below:
From an Administrators perspective, the Bot logs all conversations to stdout. By starting the bot on Linux using nohup, the logs can be save to a nohup.out file. The following shows a sample of a nohup.out file.
Additionally, the bot uses java.util.logging and logs communications to the BotTest.log file in xml format as shown below:
Ok, enough of the functionality, now lets talk about the code :-)
We use hashtables to keep track of where a particular Screen Name is within the menus. That allows for the required level of session management. The interesting part of this is that the screen name never looses its place in the menus as long as the Bot is running. It might be nice to add the ability to remove screen names after a certain amount of time, using an additional hashtable with the screen name and initial start time and a timer thread to remove screen names from the other hashtables. I'll leave that up to you :-)
Configuration of the menu and setting up back-end connectivity is accomplish by editing the BotTest.conf file. There are two config files provided and you'll just need to select either the Google SOAP config or the one without Google SOAP, if you don't have a key. Most of the items that need to be set are self explanatory. Which ever config you choose, you need to copy that to a file named BotTest.conf before starting the Bot.
Within the config file, each menu item has a menu, an action and an auth flag. The menu is what the user will see and is just html. The action is the method within the BotTest class that will be called. The auth value, if set to true will mean that the Screen Name must exist in ldap in order for the user to be able to use the method.
There is also a mainAuth flag which, if set to true, will cause the checking ldap to see if the user is even allowed to use the Bot. The field items for ldap, mysql and oracle are used to select which fields should be added or returned in searches. Up to 10 fields per database are available in this example. All items in the config file are referenced in the Env.java program, so if you need to add additional items to be configured from the config file, you'll need to add them there.
The directory in which the Bot will run will need to have the required jar files for oracle, mysql and ldap. Additionally the Open AIM libraries must be there. If you are going to be running the Google SOAP API, you'll also need the apache.jar for SOAP and the google_soap.jar. The directory that I ran BotTest in is shown below:
This being java could also be run on other platforms as long as the appropriate DLLs or whatever are in the run directory.
I also provided a build.xml file to allow for building the BotTest using ant. Prior to building, make sure that the pathelements are set correctly. I also provided shell scripts to show how to start the Bot.
All the code can be downloaded in a tar file or viewed individually from here.
