Posts Tagged ‘Wave Sandbox’

Google Wave Robots: A Pictured Java Tutorial

September 24th, 2009

This post is a reference to Google’s own Java Tutorial for Google Wave Robots with an example of robot code that performs word replacement.

In my previous post, I have also briefly explained what Google Wave is about.

What you need to run a simple Java Wave Robot.

1) Eclipse IDE + JDK 6
2) Google Wave Java Client libraries
3) Google App Engine Account

Yes, you only require 3 items but most importantly, to access Google Wave, you need a Google Wave Id.

1) Eclipse IDE + JDK 6

Download Eclipse IDE here :


Download JDK 6 here :


Install the Google Plugin and the App Engine SDK:


Depending on the version of Eclipse IDE you downloaded, you will need to follow Google Wave’s guide to update using either one of the following URL:


2) Google Wave Java Client libraries
Download the Java client libraries from
Jar files required are :

  • wave-robot-api-.jar
  • json.jar
  • jsonrpc.jar

Save those files to your project library under \WEB-INF\lib


3) Code your Wave Robot

You can use Google Wave Java Tutorial source code directly if you want to, but I figure that I need to make some difference and hence thought of a simple words replacement robot.



My customization is highlighted in bold, you would want to change it with your own code.

Following is my source code of MarvyServlet (pardon me for the profanity in the source code, but this is a profanity filter robot afterall 🙂 )

package net.marvinlee.marvy;


public class MarvyServlet extends AbstractRobotServlet {

      public void processEvents(RobotMessageBundle bundle) {
        Wavelet wavelet = bundle.getWavelet();

        if (bundle.wasSelfAdded()) {
          Blip blip = wavelet.appendBlip();
          TextView textView = blip.getDocument();
          textView.append("I'm here to ensure you have a nice and polite wave.");

        for (Event e: bundle.getEvents()) {

          if (e.getType() == EventType.WAVELET_PARTICIPANTS_CHANGED) {
            Blip blip = wavelet.appendBlip();
            TextView textView = blip.getDocument();
            textView.append("Hi, everybody! I will be censoring profanities in your conversation.");

          if (e.getType() == EventType.BLIP_SUBMITTED) {
            Blip blip = e.getBlip();
            TextView textView = blip.getDocument();
            String blipText = textView.getText();

        private static String replaceProfanity(String text)
            String[] vulgars = {"shit", "damn", "fark"};
            String[] vulgarReplacement = {"sh#t", "darn", "f##k"};
            String niceText = "";

            System.out.println("Input:" + text);
            for (int i=0; i< vulgars.length; i++)
                String key = vulgars[i];
                if (text.indexOf(key) > 0)
                    text = text.replaceAll(vulgars[i], vulgarReplacement[i]);
                    System.out.println(vulgars[i] + " replaced with " + vulgarReplacement[i] );

                niceText = text;

            System.out.println("Output:" + niceText);
            return niceText;


capabilities.xml file under _wave

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

web.xml under WEB-INF

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

<web-app xmlns="" version="2.5">

appengine-web.xml – marvinleebot is my application name, and is unique in Google App Engine.
If you do not have a Google App Engine yet, follow step 4) below and come back again.

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

    <!-- Configure java.util.logging -->
        <property name="java.util.logging.config.file" value="WEB-INF/"/>


You can make other changes by viewing the Wave JavaDoc.

4) Deploy to Google App Engine
You will need to create an application in your Google App Engine first if you have not.


You might also need to verify your account with a mobile number, just follow through the steps.
Create your app here :
Your app name has to be unique so take some time to figure one or if you’re like me, just a lame bot name like marvinleebot might do the trick.

Once you’re done with your app name and created successfully, make sure that your appengine-web.xml file contains your own app name.


When you’re ready, just hit the Deploy App Engine Project button.


Submit your App Engine Account Email and Password.


5) Test your Wave Robot

As I’ve mentioned earlier, the single most important thing for it to work is to have a Google Wave Id.

If you have one, you can login Wave Sandbox at


If you do not have a Google Wave Id yet, request one here.

Create a new wave, and then add the bot you have created by adding a participant : <your_app_name>

This is how the bot looks like and how my marvinleebot worked (click to enlarge). I was using a test Wave Id from Nazroll.


You can also monitor your bot/app from your App Engine dashboard.

Google, Java, Open Source , , , , ,