Google Wave Robot Development Sample

Download Sample Robot Project

In this post I will discuss development of a Google Wave robot using .Net API. This sample is a port of java sample Debuggy provided by google. I have leveraged that sample to build a simple robot that performs following things:

  • Provides debugging messages to understand life cycle of a wave
  • Dumps details about the whole wave

Some of the key concepts demonstrated in this sample are:

  • How to handle various events in a wave?
  • How to extract contents of a wave/blip?
  • How to add new blip to a wave?
  • How to modify content of an existing blip?
  • How to format content of blip?

Steps to develop a google wave robot

In my previous post, I talked about how to go about developing a wave robot using .Net. I will list those points quickly here.

  • Create a google app engine account. If you already have one then you do not need one. Create an application for your robot in app engine dashboard.
  • Modify proxy.py file to point to URL where you will be hosting your .Net ASHX handler to listen on wave events
  • Upload this python application to app engine
  • Create an ASP.Net Web Application project and add an ASHX handler that will provide implementation for all the robot events that you want to handle.

I will pick OnBlipSubmitted implementation from the sample project and discuss it line by line. And following image shows how this robot is interacting in wave client.

google wave robot

protected override void OnBlipSubmitted(IEvent e)
{
 base.OnBlipSubmitted(e);
 IBlip blip = e.Wavelet.AppendBlip();
 TextView textView = blip.Document;
 textView.Append(string.Format("WaBo - Blip submitted [{0}][{1}]", 
  e.Blip.BlipId, e.Blip.Document.Text));
 if (e.Blip.Document.Text.IndexOf("_dumpit_") != -1)
 {
  try
  {
   var cacheKey = string.Format("DumpTrack_{0}", e.Wavelet.WaveId);
   if (HttpContext.Current.Cache[cacheKey] == null)
   {
     e.Wavelet.AppendBlip().Document.Append("Dumping Wave - " + e.Blip.Document.Text);
     ViewUtil.DumpWave(e);
   }
  }
  catch (Exception ex)
  {
   ViewUtil.DumpException(e, ex);
  }
 }
}

All the steps in this method are very intuitive and self explanatory.

  • Each event handler is provided with parsed request data in IEvent parameter. Different properties and methods provide you with access each component of a wave.
  • Method calls base class implementation of the event handler, just in case there is some. Currently base class implementation is empty.
  • To add a new blip, you will call AppendBlip method on Wavelet. If you do not want to add a new blip and want to act on existing blip itself then you can access the blip via e.Blip property.
  • Each blip has an associated document which is view to content of that blip. To access that document of blip, you will access Document property of the blip.
  • To access content of the blip that triggered the event, you can look at Text property of Document object. For example in my sample, I want to check if the content contains the word _dumpit_. I access it via e.Blip.Document.Tex and then look for presence of that text string in there.
  • To add content to your blip, you can utilize following methods on Document object.
    • Append
    • AppendElement
    • AppendInlineBlip
    • AppendMarkup
    • AppendStyledText

    All these methods are very self explanatory. Simplest of all these methods is Append. If you want to insert some simple text you can use this method. For more formatted and styled text you can utilize other methods. Following example shows implementation from method where I am displaying wave creator's name in red color and other participant names are displayed in blue.

    
    foreach (var participant in e.Wavelet.Participants)
    {
     var color = (string.Compare(participant, creator, true) == 0) ? "red" : "blue";
     var txt = string.Format("<span style=\"color:{0};font-weight:bold;\">{1}</span>", 
      color, participant);
     textView.AppendMarkup(txt);
     textView.Append(ViewUtil.CreateNewLine());
    }
    
    

Following image shows how this debug helper robot helps in dumping exception details when somethings goes wrong in robot event handlers.

wave debug

I hope this sample will provide you enough information and details to get started with Google Wave robot development using .Net. I will post some more samples to demonstrate more advanced features of this framework.

Search

Social

Weather

-1.8 °C / 28.8 °F

weather conditions Clouds

Monthly Posts

Blog Tags