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

Related posts:

  1. Gadget and Robots interaction In some instances you want to have the robots...
  2. Add-Robot     A robot which can stores user favorite robots using...
  3. Capabilities.xml As I was creating my first robot, I wasn’t...
  4. Google Wave Robot and gadget interaction With the new Robot API version 2 is it...
  5. Wordpress publisher bot Inspired by offlineblog’s blog about Live blogging and the...

Related posts brought to you by Yet Another Related Posts Plugin.

0 comments ↓

There are no comments yet...Kick things off by filling out the form below.

Leave a Comment

Powered by WP Hashcash