我想3个功能从这里教程添加到机器人: http://code.google.com/apis/wave/extensions/robots/python-tutorial.html做简单的事情与谷歌Wave机器人
之前将所有这些功能,我的机器人是否按预期运行。 现在仍然显示出奇怪的特征(在blip内容的bck处显示“v2”),但是没有任何新功能出现! 我尝试了不同的方式alr,仍然不起作用。令人沮丧...下面是我认为看起来更逻辑的代码。 有人可以告诉我为什么没有人似乎工作?谢谢...
特点1 - 想尝试AppendText通过
特点2 - 希望机器人能够检测昙花一现提交
特点3 - 希望机器人添加昙花一现用的内容旧的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()
编辑:(重要!) 我只注意到它似乎在正常模式VS沙盒模式HV不同的行为。在正常模式下,我看到两个闪烁“我还活着!v2”和“大家好!v2”,但在沙箱模式下,我只能看到第一个。 Werid ......在两种情况下我看到了附加文本...
为什么我评论这一部分 “”“myRobot.RegisterHandler(events.BLIP_SUMBITTED,OnBlipSubmitted) myRobot.RegisterHandler(events.BLIP_DELETED,OnBlipDeleted原因)“”“” 是因为没有评论它,机器人根本没有做任何事情!
'events.BLIP_SUMBITTED'看起来拼错了我。 – 2011-07-06 21:07:46