skip to Main Content

I’m building a telegram chatbot in nodejs that will work on webhook. Currently, bot hits my webhook URL with every message in chat. Is it possible to only push payload on command execution for the bot?

So I would like only to get the payload from the chat when the user executes /test command and any other messages in the chat should not git to my URL.

#Edit

Current setup of privacy

‘Enable’ – your bot will only receive messages that either start with the ‘/’ symbol or mention the bot by username.
‘Disable’ – your bot will receive all messages that people send to groups.
Current status is: ENABLED

I want to use bot in groups and in direct chat with bot – me so I can test things.

I created a test group added the bot and whatever I type into the group I can see in logs of the Webhook URL. So no matter if its /test or some text it’s beeing pushed

#Edit 2

This it what I receive in my webhook URL (normal chat text, and bot command)

{
  "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"
      }
    ]
  }
}

2

Answers


  1. Chosen as BEST ANSWER

    Alright, so I found the answer to my problem.

    I was adding a bot as an administrator to the chat that's why he was sending all messages. Admins bot will push all chat messages. Adding a bot like a normal user solved the issue and now I only receive /command updates.

    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


  2. You have to use @BotFather to set your bot privacy:

    1. Send /mybots command to @BotFather
    2. Select your bot by its username
    3. Select Bot Settings
    4. Select Group Privacy
    5. Enable or disable your bot’s privacy

    If Privacy Mode is enabled, your bot only receive messages which are start with slash /

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search