Google Wave Python API and Annotations

I spent a considerable amount of time this weekend hacking away at my Google Wave robot, Wave Toolkit. It’s a lot of fun and I’ve managed to write something that allows for quick implementation of ‘commands’ from initial idea to ‘live’.

One of the frustrating things about developing Google Wave extensions is the poor documentation. It starts out great: lovely overview documentation and tutorial, with plenty of insight and step-by-step instructions; and then nothing. It stops there. Apart from reading the API documentation which can be cumbersome, you’re left alone in the dark, weeping like a sad puppy after meeting its new owners.

An example of this is using Annotations within Google Wave; formatting text for bold or italics,  providing nicely worded hyperlinks or embedding images is governed by inserting annotations that ‘explain’ how the text should look. If you try to find out how to use these objects within the Python API you’ll see it’s nearly impossible. I got my answer only from guessing and scouring the Google Group and reading and example in Java, then posting when that didn’t work and finally getting some helpful advice. Please Google, document this protocol more!

So, to save an further frustration, here’s how to use Annotations in the Google Wave python API for robots:
doc = wavelet.CreateBlip().GetDocument()
doc.SetText("THIS IS ANNOTATED TEXT")
doc.SetAnnotation(Range(2, 12), "link/manual", "http://www.google.com")

I hope to hell that helps someone and saves the pain I underwent to work it out! Buggered if I know how to bold text though…Happy hacking!

2 Comments

  1. Posted October 20, 2009 at 08:17 | Permalink

    Thanks!

    Ive done the same hunt last weekend. I got it almost working, my fail was that i specified Range(0, 20), where 0 didnt work.. Range(1,20) does seem to work, but it doesnt start with the first character :( So it needs more work :)

    Your post showed me I was on the correct path!

    I found the other annotation types here:
    http://groups.google.com/group/google-wave-api/browse_thread/thread/ba08146d448658a6?pli=1

  2. Posted October 20, 2009 at 19:22 | Permalink

    Thanks maurice, very helpful.

    One thing: annotations start at the original index you require plus two (presumably for the annotation characters).

Post a Comment

Your email is never published nor shared. Required fields are marked *
*
*