RkTaggy - example Google Wave robot
RkTaggy is an example Google Wave robot written in Python. Get the source code, and read how RkTaggy is built.Making robots for Google Wave is bit hard at the moment as there isn't much tutorials, examples and most of robots with public code is written in nasty Java... To make a Wave robot in Python you need:
- Googl App Engine account. A robot must be (for now) hosted on GAE, as an GAE application. You don't have to know datastore or webapp to start with making a robot (but you have to know how to deploy you application to GAE servers)
- The official robot Python Tutorial is a good start to get to know how to make a robot skeleton.
- And when creating new code the API Documentation will be our friend
- Robots can be tested only from GAE, so you will need to deploy them often and debug a lot (objects, data) with logging.debug(). The logged data will be available in the application admin panel:
RkTaggy - example robotThe firstname.lastname@example.org robot is an simple example robot that will (currently) insert image with charts based on data you enter in a blip (wave message). Just add him to a wave. This robot parse new messages (blips) using the BLIP_SUBMITTED event that is handled by OnBlipSubmitted function. This function has two arguments: properties and context. When you debugg them you will notice that properties has "blipId" with the ID of blip that have been added. So if we have the ID we can get the whole object of the blip using context.GetBlipById(ID) (you can look also on waveapi/model.py, Context class). We will get a OpBasedBlip object (check the API docs about it) for which we can get OpBasedDocument object using GetDocument method. The document object contains all data of a blip - text and other add-ons (attachments for example). We use GetText method to get the text of the message and pass it to make_barcharts function (described later), that extracts the data needed for charts and returns URL to charts on Google Charts (the charts are images). To add those charts to a Blip we add them as Elements using the document.Image class, which wants a URL to image as argument (which we already have).
The make_barcharts function looks like this: The function looks for tags of this structure:
And then it extracts labels, values and title and makes a chart using pygooglechart module. The pygooglechart will return a URL for the chart (which we later insert to the blip).
[barchart]Chart Title label,int_value label,int_value label,int_value [/barchart]
Currently you can't add HTML to a blip using the API (like with SetText) in an easy way. The problem is known, and the Wave Team is working on it ;) Currently some developers suggest using SetAnnotation to add some HTML markup to the blip text. In our case we use the "easy" way of inserting an image.