10.07.2015 Views

Lotus Instant Messaging/ Web Conferencing ... - IBM Redbooks

Lotus Instant Messaging/ Web Conferencing ... - IBM Redbooks

Lotus Instant Messaging/ Web Conferencing ... - IBM Redbooks

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

method returns the word the end user is searching for. The bot then calls specificfunctions to determine the meaning of the word, and sends that meaning back tothe end user with the sendText() method of the Im object:public void textReceived(ImEvent e){String dictionaryWord = e.getText();String wordMeaning = botDictionaryLogic(dictionaryWord);e.getIm().sendText(true, wordMeaning);}Tip: The first parameter of the sendText() method is a boolean flag thatdetermines whether or not the text should be sent encrypted.3.3 Bot examplesThis section details three bots developed using the Java Client Toolkit. The first,the Echo Bot, is a Java application that simply echoes back any text that is sentto it. The second is an FAQ Bot, developed as a Java servlet that reads andwrites to a Domino database containing the FAQs. The third is a Translation Botthat uses a <strong>Web</strong> service to convert phrases entered by the user into thelanguage of their choice. All of these bots follow the five essential steps detailedin the previous section.3.3.1 The Echo BotThis first example shows the basic framework of how to construct a bot,incorporating all the stages outlined in the previous section. The Java applicationEchoBot takes three command line parameters:► The Sametime server DNS name or IP address► The user name of the bot as stored in the Sametime directory► The password for that userExample 3-2 shows the EchoBot.java code.Example 3-2 EchoBot.javaimport com.lotus.sametime.community.*;import com.lotus.sametime.core.comparch.*;import com.lotus.sametime.core.constants.*;import com.lotus.sametime.im.*;public class EchoBotimplements Runnable, LoginListener, ImServiceListener, ImListener{56 <strong>Lotus</strong> <strong>Instant</strong> <strong>Messaging</strong>/<strong>Web</strong> <strong>Conferencing</strong> (Sametime): Building Sametime-Enabled Applications

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!