使用Google Wave机器人做简单的事情

yee*_*een 13 python google-wave

我想从这里的教程中为机器人添加3个功能:http: //code.google.com/apis/wave/extensions/robots/python-tutorial.html

在添加所有这些功能之前,我的机器人正在按预期工作.现在奇怪的功能仍然出现(在blip内容的bck处有"v2"),但是没有新功能出现!我已经尝试了不同的方法,仍然无法正常工作.下面是我认为更符合逻辑的代码.有人能告诉我为什么似乎没有工作?

功能1 - 想尝试AppendText
功能2 - 希望机器人检测到blip已提交
功能3 - 希望机器人添加一个blip,删除旧blip的内容.

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()
Run Code Online (Sandbox Code Playgroud)

编辑(重要)

我只是注意到它在正常模式和沙盒模式下似乎有不同的行为.在正常模式下,我看到两个片段"我还活着!v2"和"大家好!v2",但在沙盒模式下我只能看到第一个.在这两种情况下,我都看不到附加文字.

我之所以评论此部分"""myRobot.RegisterHandler(events.BLIP_SUMBITTED,OnBlipSubmitted)myRobot.RegisterHandler(events.BLIP_DELETED,OnBlipDeleted)""是因为没有评论它,机器人根本不做任何事情!

Bog*_*utu 1

events.BLIP_SUMBITTED应该events.BLIP_SUBMITTED