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.

It is important for our bot to know when a message arrives from an end user. Toaccomplish this, the bot implements the ImServiceListener interface andregisters to listen for events using the addImServiceListener() method of the<strong>Instant</strong><strong>Messaging</strong>Service:m_imService.addImServiceListener(this);The ImServiceListener interface defines the imReceived() method that must beimplemented by the bot. This method is called when a user initiates aconversation with the bot. It is triggered as soon as the user double-clicks on thebot’s name in her buddylist. The bot can use this event to send a greetingmessage to the user, perhaps with instructions on how to use the bot effectivelyor personalized information specific to the user.Important: When a user clicks on a Sametime Link to launch a chat window,the imReceived() method is not called. For a discussion on using bots withSametime Links, see 9.6, “Using Sametime Links with bots” on page 256.3.2.4 Listening for incoming messagesOnce the imReceived() method is triggered, the bot must implement theImListener interface to receive follow-on messages from the user. It uses theaddImListener() method of the Im object to add itself as an ImListener. The botgets a handle on the Im object from the ImEvent object that is passed in to theimReceived() method:public void imReceived(ImEvent e){e.getIm().addImListener(this);}The ImListener interface defines five methods, one of which, textReceived(), iscalled when the user sends a text message to the bot. The actual content of thetext message can be retrieved by calling the getText() method on the ImEventobject that is passed in to the textReceived() method:public void textReceived(ImEvent e){String messageFromUser = e.getText();}3.2.5 Responding with logicOnce the bot has received a text message from the end user, it needs to performany bot-specific logic and respond back. For example, consider a Dictionary Botthat a user sends words to and expects back their meaning. The getText()Chapter 3. Sametime Bots 55

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

Saved successfully!

Ooh no, something went wrong!