Telegram bot webhook 仅发送命令

Telegram bot webhook send only commands

我正在用 nodejs 构建一个可以在 webhook 上运行的电报聊天机器人。目前,机器人在聊天中的每条消息都会点击我的 webhook URL。是否可以仅在机器人执行命令时推送负载?

所以我只想在用户执行 /test 命令时从聊天中获取有效负载,并且聊天中的任何其他消息不应该 git 到我的 URL.

#编辑

当前的隐私设置

'Enable' - 您的机器人只会接收以“/”符号开头或通过用户名提及机器人的消息。 'Disable' - 您的机器人将接收人们发送给群组的所有消息。 当前状态为:ENABLED

我想在群组中使用 bot 并与 bot - 我直接聊天,这样我就可以测试东西。

我创建了一个测试组,添加了机器人和我在组中输入的任何内容,我都可以在 Webhook 的日志中看到 URL。所以无论它的 /test 还是一些文本都被推送

#编辑 2

这是我在 webhook 中收到的内容 URL(正常聊天文本和机器人命令)

{
  "update_id": 1,
  "channel_post": {
    "message_id": 65,
    "sender_chat": {
      "id": -1,
      "title": "Tssos",
      "type": "channel"
    },
    "chat": {
      "id": -1,
      "title": "Tssos",
      "type": "channel"
    },
    "date": 1,
    "text": "test"
  }
}
{
  "update_id": 1,
  "channel_post": {
    "message_id": 67,
    "sender_chat": {
      "id": -1,
      "title": "Tssos",
      "type": "channel"
    },
    "chat": {
      "id": -1,
      "title": "Tssos",
      "type": "channel"
    },
    "date": 1,
    "text": "/test@TESTss_bot",
    "entities": [
      {
        "offset": 0,
        "length": 23,
        "type": "bot_command"
      }
    ]
  }
}

您必须使用 @BotFather 来设置您的机器人隐私:

  1. 发送/mybots命令给@BotFather
  2. Select 你的机器人的用户名
  3. Select 机器人设置
  4. Select 群组隐私
  5. 启用或禁用您的机器人的隐私

如果启用隐私模式,您的机器人只会收到以斜杠开头的消息/

好的,我找到了问题的答案。

我将一个机器人作为管理员添加到聊天中,这就是他发送所有消息的原因。管理员机器人将推送所有聊天消息。 像普通用户一样添加一个机器人解决了这个问题,现在我只收到 /command 更新。

Privacy mode is enabled by default for all bots, except bots that were added to the group as admins (bot admins always receive all messages). It can be disabled, so that the bot receives all messages like an ordinary user (the bot will need to be re-added to the group for this change to take effect). We only recommend doing this in cases where it is absolutely necessary for your bot to work — users can always see a bot's current privacy setting in the group members list. In most cases, using the force reply option for the bot's messages should be more than enough.

Docs