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
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.
Docs
You have to use @BotFather to set your bot privacy:
/mybots
command to @BotFatherIf Privacy Mode is enabled, your bot only receive messages which are start with slash
/