WaveCalender 3: RatingBot

Rating Bot is a simpel robot which helps with creating voting in best Web 2.0 style where you can vote on each blip. The robot is made by Przemysław Gajda.

You can add the robot using the address: rating-bot@appspot.com

An example on where the robot has been used is on the picture bellow.


The idea of being able to rate each blip is rather smart. It will make it to vote for ideas described in a full blip. So this links a lot to the polling gadget from yesterday. It does thou vote for different blips. So this will be use full when you have more to choose from.

It is possible for a person only to cast one vote for each blip. The way this has been implemented is by using annotation to store each persons vote. I have always used the Cache storage for handling metadata and then linked it to the wave or blip. But using annotations can make it easier to persist data. Then everything is stored in just one place. It would also be possible for other robots to interact with the data created.

You can have a look at the Java code behind the gadget at code.google.com. I could learn a little from the way this code is structured.

Bookmark and Share

Blip debug robot

In the last post I created a screencast of how a debug session, which showed which annotations is created.

Now I have posted the robot so it is possible for others to start using the robot. This will allow all users to investigate how the annotations work. I hope it will help you to gain some more knowledge on how annotations work.

Simply add the robot with the name BlipDebug@appspot.com to you wave, and start modify your application. Just be careful and not add the robot to any large waves. This robot is quite disturbing and should only be used for testing purposes.

The Java code to the robot is in the code.google.com repository.

The robot is now approved in the sample gallery.

Bookmark and Share

Google Wave annotations

Annotations (com.google.wave.api.Annotation) is a key concept to understand, when you are developing robots, how should understand the content of a robot.

I have created a screencast, where I show how the annotations are changed because of the editing.

I have found the following types of annotations.

  • user/d/key identifies that the user is on the blib and is in edit mode
  • user/e/key identifies where the users cursor is only the from selection counts.
  • user/r/key identifies the selection the user has created with start and end. The user will still have his curser at a place in the blip.
  • style/fontWeight identify if the selection is bold
  • style/textDecoration can be used to add line through
  • style/color is the color of the selected text
  • lang identifies the language of a region. There can be multiply different languages in a blip.

There are probably a number of different style markings, which you will have to find your self.

Key is probably a hash of the user address.

Bookmark and Share

Gadget and Robots interaction

In some instances you want to have the robots and gadgets to interact. A scenario where it could make sense is, when the user wants information about a site. The page which could be showed could be the sales report of the customer or some other information which is of interest to the participants.

This tutorial has basis in the Creating A Simple Inline Gadget To Show External Web Applications, which shows how to inline a page into the a wave using a gadget. There is a robot which creates a form for entering the url of the page. When the user press submit the robot adds a gadget which inline the specified url.

First the robot which inserts the gadget.

public class EmbedUrlRobotServlet extends AbstractRobotServlet {
    public final String URLFIELD = "URL_FIELD";
    public void processEvents(RobotMessageBundle bundle) {
        Wavelet wavelet = bundle.getWavelet();
        String creator = wavelet.getCreator();
        if (bundle.wasSelfAdded()) {
            Blip blip = wavelet.appendBlip();
            TextView textView = blip.getDocument();
            textView.appendMarkup("<p><b>Inline the url</b></p>\n");
            FormView form = textView.getFormView();
            form.append(new FormElement(ElementType.INPUT, URLFIELD,"http://"));
            form.append(new FormElement(ElementType.BUTTON, "submit", "INSERT"));

        for (Event e : bundle.getEvents()) {
            if (e.getType() == EventType.FORM_BUTTON_CLICKED) {
                Blip blip = e.getBlip();
                FormView form = blip.getDocument().getFormView();
                FormElement urlElement = form.getFormElement(URLFIELD);
                GadgetView gadgetView= blip.getDocument().getGadgetView();
                gadgetView.append(new Gadget("http://pollenvarsel.appspot.com/gadget?url="+urlElement.getValue()));


The robots listens for two event. First the SELF_ADDED which creates the URL form with a text box and a submit button. When the button is pressed a gadget is inserted in to the Blip, with the url of the gadget + the target URL. Probably something should be performed to ensure that the submitted URL is valid and can be sent as a query parameter. Probably a URL encoding should be performed or save the data in the datastorage.

    public void doGet(HttpServletRequest req, HttpServletResponse resp)
            throws IOException {
        PrintWriter out= resp.getWriter();
        out.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
      +"<ModulePrefs title=\"inline_external_page\" height=\"400\" width=\"800\"/>"
      +"<Content type=\"html\">"
      +"<![CDATA[ "
      +" <div id=\"main\"><!--Main container for the iframe-->"
      +" <iframe name=\"check\" id=\"check\" height=\"100%\" src =\""+(String)req.getParameter("url")+"\" width=\"100%\" frameborder=\"0\">"
        +"<p>Your browser does not support iframes .</p>"
        +"</iframe> <!-- this is where contents of the links are displayed -->"

The code is the same in the original blog it has just been placed into a servlet, to make it possible to have parameters inside. It just inserts the query parameter into the gadget XML.

The code can be found at code.google.com.

Bookmark and Share


When I was just starting to learn Google Wave Robots, I decided to create a robot that replaces the “at” phrase to “@” since Google does not allow Danish users to create an “@” in the current wave implementation. I’ll give you a walk-through on how I managed to create the “at-buddy.”

I started this robot using the wave robot tutorial which can be found here.

What we need to do is to replace the blip’s text while the user is typing so we need to register the event “DOCUMENT_CHANGED” in the capabilities.xml. For more information regarding capabilities.xml, you can refer to this post.

Once the capabilities are updated, we can now catch the event in our servlet. Let’s insert this in our “Process Events” method.

for (Event e : bundle.getEvents()) {
if (e.getType() == EventType.DOCUMENT_CHANGED) {


// get event blip
Blip blip = e.getBlip();
TextView textView = blip.getDocument();
// get blip text and replace (at) to @
String strBlip = e.getBlip().getDocument().getText().toLowerCase();

//check if text has an "(at)"

//get the index of the first "(at)"
int index = strBlip.indexOf("(at)");

//replace "(at)" to @
textView.replace(new Range(index, index+4), "@");


That’s it! now you can deploy your robot and try it out.

Bookmark and Share