【问题标题】:Receive messages from Telegram Bot to Google App Engine via Cloud Endpoint通过 Cloud Endpoint 从 Telegram Bot 接收消息到 Google App Engine
【发布时间】:2016-08-24 00:43:13
【问题描述】:

我有一个 python Google App Engine 应用程序,它通过 webhook 从 Telegram Bot 接收传入消息。我使用 Cloud Endpoint 来接收请求,因此我使用 Google 协议 RPC 来管理请求和响应。

来自 Telegram 的包含消息的 json 传入更新有一个名为 from 的字段。问题是当我编写 RPC 类来处理消息时,我不能使用名称 from 作为变量,因为它是一个保留关键字:

class TelegramMessage(messages.Message):
    message_id = messages.IntegerField(1, required = True)
    from = messages.MessageField(User, 2)

我无法更改变量的名称,否则传入 json 中的 from 字段会丢失,我在控制台中收到此警告:未找到未识别字段的变体:来自。

我该如何解决?

【问题讨论】:

    标签: python google-app-engine telegram-bot


    【解决方案1】:

    我建议使用像python-telegram-bot 这样的python 库。库 renamed 的作者将 Python 不兼容的 from 属性设置为 from_user。所以就这样做吧:

    user = bot.getUpdates()[-1].from_user
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-06-22
      • 1970-01-01
      • 2015-09-15
      • 1970-01-01
      • 2016-05-09
      • 1970-01-01
      • 2016-11-02
      • 1970-01-01
      相关资源
      最近更新 更多