I am using Telegram bot API with AWS Lambda and Zappa.
Everything was working fine. Until I realised that bot’s webhook is being called everytime whenever a message is sent by anyone in the group.
I want to limit this webhook requests, as Lambda allows for only 1 million calls which is sufficient if bot is invoked, but only when /commands
are called.
As I have to pin and edit messages using bot, that’s why administrator permission is must.
I just want my bot to respond only to /commands
along with administrator rights.
Please help me in tackling this issue.
2
Answers
I am assuming you added your bot to a Telegram group. In this case, the first thing that you need is group id. This should help: https://github.com/GabrielRF/telegram-id#web-group-id
And then you need to write a function that identifies the status of a chat member. You can do this using getChatMember method in Telegram Bots API.
If the chat member’s status is "creator" or "administrator" then the response is sent to that user.
There are 2 things you need to do.
setPrivacy
for your bot – go toBotFather
chat and use the/setPrivacy
command which gives you the ability to set:BotCommandScopeAllChatAdministrators
scope which should limit the use of the command only to the admins of the chat.