views:

74

answers:

0

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 alr, still doesn't work. So frustrating... Below is the code tt i think looks more logically. Can someone tell me why none seems to work? Thanks...

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 hv 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. Werid... 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 cos without commenting it, the robot doesn't do anything at all!