Telegram group ban/boot/kick user - telegram

I need to create a Telegram bot to moderate a group and be able to ban/boot/kick users from the group.
I could not find anything in the Telegram API to boot a user from a group, how can a bot do this through the API?

You can use banChatMember to remove a user from a group.
The bot must be an administrator in the chat for this to work and must have the appropriate admin rights.

To remove a user without banning them, use unbanChatMember.
this method guarantees that after the call the user is not a member of the chat, but will be able to join it. So if the user is a member of the chat they will also be removed from the chat.

Related

Telegram BOT - How to get chat ID of users in my group?

I've been using a Telegram BOT to send notifications for a group, and for users.
I already know i can get Chat ID by receiving a message from the user on my bot, using getUpdates.
I also know i can get Group ID using the same method...
But what i really need is:
There is three users in my group.
My bot.
Me.
Another user that didn't sent any messages to my bot so it does not appear on getUpdates
Is it possible to get this third user his ID?
PS: I am the group owner, and also added my bot as Admin...
The third user is a normal user.
Can someone help me?
Thanks!
That's not possible with the offical Telegram Bot API
Possible Workarounds:
Hold a list of your own. If a user is joining (new_chat_member), lefting (left_chat_member), somebody is sending a message in the group, and so on. Check Message for more information.
Check if a user is a member of the group with getChatMember.
Also may be helpful: getChatMembersCount and getChatAdministrators

Can another telegram user make me access his bot?

My friend has a tranding bot made with BotFather.
Is there a way to make the bot shared betweeen our account in a way we can use it together?
Bot usernames are unique to each Telegram account and only that account is able to change the settings of the bot.
But you can make use of a bot through its API_TOKEN which you can get from botfather.
It looks like this:
300123900:BARsAbMYBJv5wFhzNJ-Gbx678qpln7IgvzI
If you share the token with anyone, they can use your bot. They will receive an error if they try to use it at the same time (calling getUpdates method from more than one instance would reject the caller except for the first one).
If by sharing you meant using the bot (not developing it), you can't do that unless the bot's developer designs it in a way that multiple Telegram accounts messaging the bot are considered one account.

How do I make the bot not leave a telegram group?

I created a new Telegram group, and my problem is that I cannot add any bot to it, knowing that I have created a channel and have linked it to the group and the bot is added to the channel with no problems. Please help me in adding the bot
bot exit messages from My group
I think you are anonymous in group and it looks like the bot you are trying to add doesn't supports anonymous admins.

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.
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 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.
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.

How can a telegram get a list of all chats he participates in?

Relates to Retrieve all chat ids using Telegram bot but 3 years later.
My use case is a bot that notifies chat participants of home automation events. Any user might create his own chat and receive events or send commands.
Currently, it seems that the bot has no option to find the chats that it participates in. Even a potential workaround like using GetUpdates(0) seems to retrieve only new message ids which makes it impossible to get a complete list of chats from looking at the received messages.
Is there a stable solution for doing this?
This is not possible from Telegram's API. Howerver,
A bot will receive a new_chat_members which could be the bot 'joining another group':
new_chat_members -- Array of User -- Optional.
New members that were added to the group or supergroup and information about them (the bot itself may be one of these members)
To remember each user/group, you'll have to save each chat/user_id into a database.
The bot will also receive the opposite left_chat_member so you'll know when to delete a database entry.

Resources