To How to receive messages in group chats using telegram bot api, I find 2 solutions:
- Make the bot admin of the group
- Disable privacy
Unfortunately, if I do any of those, the Telegram bot will receive ALL messages sent to the group (according to my tests).
However, according with what I read, it should be possible to send to the bot messages only if I mention the bot eg @my-bot-name-bot
How to restrict the bot to receive messages only if I mention it?
Some screenshots:
2
Answers
Short answer
Keep privacy enabled, add the bot as member to the group (no admin). Follow the following structure:
Long answer
Actually the reply was in the other post I mentioned, but I didn't understand it well. So I'm going to explain again with my words trying to help to whoever comes next trying to find a more privacy-happy solution.
It is possible to restrict the bot to receive messages only if we mention it.
Firstly, remember:
Then, you just have to m̶e̶n̶t̶i̶o̶n̶ write a message following the following structure:
The following worked in my tests:
The following didn't work in my test (do NOT include a space before the @):
As you already know, if your bot is admin of the chat all messages are received to the bot. There’s no way to alter this behavior.
The best way to only listen to messages that mentions bot by its username, you may edit your code and explicitly look if the message contains bot’s username.
Here’s a simple JavaScript example:
Hope this helps 🙂