【问题标题】:Telegram bot sends "my_chat_member" object instead of "message" object on start via webhookTelegram 机器人在启动时通过 webhook 发送 \"my_chat_member\" 对象而不是 \"message\" 对象
【发布时间】:2022-12-09 01:44:34
【问题描述】:

我有一个电报机器人,用户可以在其中发送 /start 命令,我将通过网络挂钩在我的服务器上接收此命令。在 99% 的情况下,来自电报的请求如下所示:

{
   "update_id":99999999,
   "message":{
      "message_id":9999,
      "from":{
         "id":999999999,
         "is_bot":false,
         "first_name":"first_name",
         "last_name":"last_name",
         "language_code":"code"
      },
      "chat":{
         "id":99999999,
         "first_name":"first_name",
         "last_name":"last_name",
         "type":"private"
      },
      "date":1665383118,
      "text":"/start",
      "entities":[
         {
            "offset":0,
            "length":6,
            "type":"bot_command"
         }
      ]
   }
}

对象是“消息”,我在那里有一个文本“/start”。

但有时一些新用户之前没有使用过这个机器人,当他们从电报发送开始请求时,看起来像这样:

{
   "update_id":999999999,
   "my_chat_member":{
      "chat":{
         "id":999999999,
         "first_name":"first_name",
         "type":"private"
      },
      "from":{
         "id":999999999,
         "is_bot":false,
         "first_name":"first_name",
         "language_code":"code"
      },
      "date":1665381194,
      "old_chat_member":{
         "user":{
            "id":8888888888,
            "is_bot":true,
            "first_name":"bot_name",
            "username":"bot_name"
         },
         "status":"member"
      },
      "new_chat_member":{
         "user":{
            "id":8888888888,
            "is_bot":true,
            "first_name":"bot_name",
            "username":"bot_name"
         },
         "status":"kicked",
         "until_date":0
      }
   }
}

未从该用户收到对象“my_chat_member”和“开始”命令。

iPhone、Android、PC、Web 上的用户都会出现这种情况。 我不明白为什么会发生以及如何解决。

【问题讨论】:

  • 第二个请求是状态更新,表示您的机器人被踢出群组或在私人聊天中被用户阻止。你确定不是这样吗?
  • @Cem 是的,用户只是向机器人发送 /start 命令,但我没有收到消息,而是在我的服务器上收到了 new_chat_member 。这只是有时发生。在大多数情况下,我收到“消息”。

标签: telegram telegram-bot


【解决方案1】:

问题出在我的服务器端。我将 int32 用于用户和聊天的 ID,但它们可以更大。使用正确的类型解决了这个问题。

【讨论】:

    【解决方案2】:

    消息类型“my_chat_member”表示被描述为“from”的人想要取消订阅 bot。 "status":"kicked" 表示相同。在这里https://core.telegram.org/bots/api你可以阅读获取更新主题

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-20
      • 2021-08-02
      • 1970-01-01
      • 2021-02-02
      • 2012-06-19
      • 2015-10-04
      相关资源
      最近更新 更多