FmylifeBOT – A Google Wave Robot Example

FmylifeBOT is a robot for Google Wave. When added to a wave it will introduce itself and then waits for a blip (message) starting with FML. Once found it will replace the text FML with a random entry on the popular website fmylife.com. This robot was created for educational purposes and for my entertainment more then anything.

Live Demo

For a live demo you must have a wave account. Add fmylifebot@appspot.com to a wave and type FML. It will replace FML with a random entry. That’s all the setup you need!

Screenshot of FmylifeBot

Screenshot of FmylifeBot

Source Code

There isn’t much to it although it might help :)

from waveapi import events
from waveapi import model
from waveapi import robot
import urllib2
from xml.dom import minidom 
 
def OnRobotAdded(properties, context):
    root_wavelet = context.GetRootWavelet()
    root_wavelet.CreateBlip().GetDocument().SetText("FmyLife bot Added \n Usage: Type FML to retreive random FML")
 
def OnBlipSubmitted(properties,context):
    # Grabs contents of the Wave
    blip = context.GetBlipById(properties['blipId'])
    contents = blip.GetDocument().GetText()
    # If Contents contains FML
    if contents[:3].upper() == "FML":
        #Grabs the XML feed from FML
        url = "http://api.betacie.com/view/random/nocomment?key=readonly&language=en"
        req = urllib2.Request(url)
        response = urllib2.urlopen(req)
        result = response.read()
        #Parses the XML Feed
        dom = minidom.parseString(result)
        loclist = dom.getElementsByTagName('text')
        output = loclist[0].childNodes[0].nodeValue
        #Changes the Blip to equal the output text
        blip.GetDocument().SetText(output)
 
if __name__ == '__main__':
    myRobot = robot.Robot('FMLbot',
        image_url='http://corythompson.net/wp-content/uploads/icon.png',
        version='1',
        profile_url='')
    myRobot.RegisterHandler(events.BLIP_SUBMITTED, OnBlipSubmitted)
    myRobot.RegisterHandler(events.WAVELET_SELF_ADDED, OnRobotAdded)
    myRobot.Run()

For an explanation of the code stick around. I should be posting soon. That wraps up my first completed Google Wave Robot. Any questions or comments can be left bellow and thanks for reading.

3 Responses to “FmylifeBOT – A Google Wave Robot Example”

  1. Brown says:

    Interesting and informative. But will you write about this one more?

  2. Fantabulous transmit Jon! I possess been following the #p2 effort since you started it, and although I be suffering with covenanted its plan this dispatch does a positively titanic procedure solidifying the full rationale.
    http://www.corythompson.net – go to my favorites!!!

  3. CaxEvally says:

    This is an excellent review.

Leave a Reply