At-Buddy

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) {

if(!e.getModifiedBy().equalsIgnoreCase("at-buddy@appspot.com"))
{

// 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)"
if(match(strBlip,".*\\([aA][tT]\\).*").length()>0)
//if(strBlip.indexOf("(at)")>0)
{

//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