My First Wave Robot ::

Filed under: Google, Technology, Wave — Tags: , , , , , , , — Developer42 @ 00:34 first demo


<?xml version="1.0" encoding="utf-8"?>
<appengine-web-app xmlns="">


<?xml version="1.0" encoding="utf-8"?>
 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
<web-app xmlns="" version="2.5">


<?xml version="1.0" encoding="utf-8"?>
<w:robot xmlns:w="">
    <w:capability name="blip_submitted" content="true" />
    <w:capability name="wavelet_self_added" content="true" />

import java.util.*;
//FIX FOR ISSUE 354 is used where the robot suffers from the bug mentioned in the below links
public class SmileyServlet extends AbstractRobotServlet {
	 * Robot's version id & usage info
	private static final long serialVersionUID = 1L;
	private static final long serialSubVersionUID = 2L; //this is to help me prove that my latest changes 
                                                            //have been uploaded correctly
	private static final String serialVersionID = "Version #" + new Long(serialVersionUID).toString() + "." + 
                                                      new Long(serialSubVersionUID).toString();
	private static final String helpInfo = "\nThis robot is my learning tool for wave development, " +
                                               "so may occasionally break!  Apologies if you're one of " +
                                               "the people for whom it doesn't work!";
	private static HashMap dictionary = null;
	 * Creates the images & registers them against their invoking smileys 
	 * */	
	static {
		final int width = 24;
		final int height = 24;
		dictionary = new HashMap();
		dictionary.put(":)",new Image("",width,height,":)"));
		dictionary.put(":(",new Image("",width,height,":("));
		dictionary.put(";)",new Image("",width,height,";)"));
		dictionary.put(":D",new Image("",width,height,":D"));
     * Handles changes to the wave 
	public void processEvents(RobotMessageBundle bundle) {		
		if (bundle.wasSelfAdded()) {
			final Blip blip = bundle.getWavelet().appendBlip();
			blip.getDocument().delete(); //FIX FOR ISSUE 354
			final TextView textView = blip.getDocument();
			textView.append( serialVersionID );
			textView.append( helpInfo );
		for (Event e: bundle.getEvents()) {
			if ((e.getType() == EventType.BLIP_SUBMITTED) || (e.getType() == EventType.WAVELET_SELF_ADDED)) {
				final Blip blip = e.getBlip();
	private void smile(TextView textView){
		final String text = textView.getText();
		Iterator<Map.Entry> i = dictionary.entrySet().iterator();
			Map.Entry pic =;
			String key = pic.getKey();
			int pos = -1;
			while((pos = text.indexOf(key,++pos))>-1){
				textView.delete(new Range(pos, pos + key.length()));



  1. One of the guys in Facebook’s Google Wave Developers Group kindly pointed out that I’ve not used serialVersionUID correctly in the above code, and has provided information on its correct usage (here). Before my next revision I’ll read up a bit more on what this field’s for and either correct or remove it; initially I’d only added this to prevent a warning from popping up in Eclipse, so skimmed the documentation, saw it was some form of version id, and ignored the rest of the explanation.
    Thanks to Ugljesa for pointing this out to me.

    Comment by Developer42 — 2009-11-10 @ 22:44

  2. If you make a smiley robot that you can customize (Put images you want) that will be used by me 😀

    Comment by Janko — 2009-12-01 @ 15:28

    • Hey Janko,

      good shout. . . I’ll need to figure out how to keep session data per user, but am pretty sure that’s possible, so should have something here soon. I’ll drop you an email when available :). In the meantime, there are other emoticon bots which you may wish to try (I haven’t tested these out, so not sure if they allow you to add your own images, or what emoticons they support). . . a list of these is available in the See Also section at the bottom of this linked page.

      It may also be good to allow community suggested features to bubble into use somehow (though putting in some kind of peer review ability to avoid bloating the library of emoticons / using copyrighted images). . . if anyone has any suggestions on a good way to incorporate those features, I’d welcome your thoughts.

      Comment by Developer42 — 2009-12-01 @ 20:35

      • Actually I was going to copy your code and put my own smileys, but I thought it would be interesting to make a customizable bot 🙂

        Comment by Janko — 2009-12-02 @ 16:04

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at

%d bloggers like this: