Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do simple things with a Google Wave robot

I wanted to add 3 features to the robot from the tutorial here: http://code.google.com/apis/wave/extensions/robots/python-tutorial.html

Before adding all these features, my robot is working as intended. Now the odd features still shows up (with "v2" at the bck of the blip content), but neither of the new features shows up! I tried different ways already, still doesn't work. Below is the code I think looks more logically. Can someone tell me why none seems to work?

Feature 1 -- wanted to try out AppendText
Feature 2 -- wanted the robot to detect a blip is submitted
Feature 3 -- wanted the robot to add a blip with the content of the old blip deleted.

from waveapi import events
from waveapi import model
from waveapi import robot

def OnParticipantsChanged(properties, context):
  """Invoked when any participants have been added/removed."""
  added = properties['participantsAdded']
  for p in added:
    Notify(context)

def OnRobotAdded(properties, context):
  """Invoked when the robot has been added."""
  root_wavelet = context.GetRootWavelet()
  """feature 1"""
  root_wavelet.CreateBlip().GetDocument().SetText("I'm alive! v2").GetDocument().AppendText("xxx")

def Notify(context):
  root_wavelet = context.GetRootWavelet()
  root_wavelet.CreateBlip().GetDocument().SetText("Hi everybody! v2")

  """feature 2"""
def OnBlipSubmitted(properties, context):
  blip = context.GetBlipById(properties['blipId'])
  blip.GetDocument().AppendText("xxx")

  """feature 3"""
def OnBlipDeleted(properties, context):
  blip = context.GetBlipById(properties['blipId'])
  contents = blip.GetDocument().GetText()  
  root_wavelet = context.GetRootWavelet()
  root_wavelet.CreateBlip().GetDocument().SetText(contents)

if __name__ == '__main__':
  myRobot = robot.Robot('appName', 
      image_url='http://appName.appspot.com/icon.png',
      version='1',
      profile_url='http://appName.appspot.com/') 
  myRobot.RegisterHandler(events.WAVELET_PARTICIPANTS_CHANGED, OnParticipantsChanged)
  myRobot.RegisterHandler(events.WAVELET_SELF_ADDED, OnRobotAdded)   
  """myRobot.RegisterHandler(events.BLIP_SUMBITTED, OnBlipSubmitted)
  myRobot.RegisterHandler(events.BLIP_DELETED, OnBlipDeleted)"""
  myRobot.Run()

Edit (Important)

I just noticed that it seems to have different behaviour on normal mode vs sandbox mode. In normal mode I see both blips "I'm alive! v2" and "Hi everybody! v2", but in sandbox mode I can only see the 1st one. In neither case I see the appended text.

The reason why I commented this part """myRobot.RegisterHandler(events.BLIP_SUMBITTED, OnBlipSubmitted) myRobot.RegisterHandler(events.BLIP_DELETED, OnBlipDeleted)""" is because without commenting it, the robot doesn't do anything at all!

like image 303
yeeen Avatar asked Feb 19 '10 15:02

yeeen


People also ask

What does Google Wave do?

Google Wave, later known as Apache Wave, was a software framework for real-time collaborative editing online. Originally developed by Google and announced on May 28, 2009, it was renamed to Apache Wave when the project was adopted by the Apache Software Foundation as an incubator project in 2010.


1 Answers

events.BLIP_SUMBITTED should be events.BLIP_SUBMITTED

like image 65
Bogdacutu Avatar answered Oct 12 '22 23:10

Bogdacutu