Amar
Amar

Reputation: 420

Make Telegram bot to read only /commands as administrator

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.

Upvotes: 2

Views: 5023

Answers (2)

Privorka
Privorka

Reputation: 31

There are 2 things you need to do.

  1. setPrivacy for your bot - go to BotFather chat and use the /setPrivacy command which gives you the ability to set:

'Enable' - your bot will only receive messages that either start with the '/' symbol or mention the bot by username. (Should be default)

'Disable' - your bot will receive all messages that people send to groups. Current status is: DISABLED.

  1. When setting the commands for the bot, set the BotCommandScopeAllChatAdministrators scope which should limit the use of the command only to the admins of the chat.

Upvotes: 0

Brian B
Brian B

Reputation: 80

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.

Upvotes: 1

Related Questions