google wave OnBlipSubmitted

时间:2009-10-18 08:53:42

标签: python google-app-engine google-wave

我正在尝试创建一个波浪机器人,我有基本的东西在工作。我正在尝试使用帮助文本创建一个新的blip,当有人键入@help但由于某种原因它不会创建它。我在日志控制台中没有出错,我在@log'

中看到了信息日志
def OnBlipSubmitted(properties, context):
  # Get the blip that was just submitted.
  blip = context.GetBlipById(properties['blipId'])
  text = blip.GetDocument().GetText()
  if text.startswith('@help') == True:
    logging.info('in @help')
    blip.CreateChild().GetDocument().SetText('help text')

3 个答案:

答案 0 :(得分:1)

如果刚开始工作,我有两个建议......

- >您是否在构造函数中更新了Robot版本?您应该在更新更改时更改值,以便可以更新缓存。

if __name__ == '__main__':                                          
    myRobot = robot.Robot('waverobotdev',
                           image_url = baseurl + 'assets/wave_robot_icon.png',
                           version = '61',  # <-------------HERE
                           profile_url = baseurl)

- &gt; Wave和AppSpot之间的服务器连接最近变化很大。有时,AppSpot服务器需要10多分钟才能收到我的活动,其他时间需要几秒钟。确认您收到了预期的活动。

编辑: 你提供的代码看起来不错,所以我不希望你在这方面做错什么。

答案 1 :(得分:0)

您是否尝试过使用Append()代替SetText()?这就是我在C#API中所做的 - 我没有使用过Python API,但我认为它类似。以下是我的演示机器人的示例:

protected override void OnBlipSubmitted(IEvent e)
{
    if (e.Blip.Document.Text.Contains("robot"))
    {
        IBlip blip = e.Blip.CreateChild();
        ITextView textView = blip.Document;
        textView.Append("Are you talking to me?");
    }
}

工作正常。

编辑:这是上面代码中生成的JSON:

{
  "javaClass": "com.google.wave.api.impl.OperationMessageBundle",
  "version": "173784133",
  "operations": {
    "javaClass": "java.util.ArrayList",
    "list": [
      {
        "javaClass": "com.google.wave.api.impl.OperationImpl",
        "type": "BLIP_CREATE_CHILD",
        "waveId": "googlewave.com!w+PHAstGbKC",
        "waveletId": "googlewave.com!conv+root",
        "blipId": "b+Iw_Xw7FCC",
        "index": -1,
        "property": {
          "javaClass": "com.google.wave.api.impl.BlipData",
          "annotations": {
            "javaClass": "java.util.ArrayList",
            "list": []
          },
          "lastModifiedTime": -1,
          "contributors": {
            "javaClass": "java.util.ArrayList",
            "list": []
          },
          "waveId": "googlewave.com!w+PHAstGbKC",
          "waveletId": "googlewave.com!conv+root",
          "version": -1,
          "parentBlipId": null,
          "creator": null,
          "content": "\nAre you talking to me?",
          "blipId": "410621dc-d7a1-4be5-876c-0a9d313858bb",
          "elements": {
            "map": {},
            "javaClass": "java.util.HashMap"
          },
          "childBlipIds": {
            "javaClass": "java.util.ArrayList",
            "list": []
          }
        }
      },
      {
        "javaClass": "com.google.wave.api.impl.OperationImpl",
        "type": "DOCUMENT_APPEND",
        "waveId": "googlewave.com!w+PHAstGbKC",
        "waveletId": "googlewave.com!conv+root",
        "blipId": "410621dc-d7a1-4be5-876c-0a9d313858bb",
        "index": 0,
        "property": "Are you talking to me?"
      }
    ]
  }
}

与机器人出来的JSON相比如何?

答案 2 :(得分:0)

由于某种原因,它刚刚开始工作。我认为谷歌浪潮不稳定。