问题
I'm working with a guy who uses telegram app to send bet tips on football matches. He wants the group to be private, right now he is adding and removing all members manually. The group is growing and now has more than 300 members which makes his job harder, what he wants is an automatic way of adding and removing members from the group . Is there any api that let me do this? I'm open to change to another chat app if it's needed.
回答1:
First of all, for inviting new members to the group, your friend can make an invite link for his group and use it because bots cannot automatically add people to groups.
But for removing people there is a method in telegram bot api which is called Kick Chat Member:
await Bot.KickChatMemberAsync(chatId, userId, untilDate);
Of course this method is used in Telegram.Bot API which is made for C#, but you can find its alternative for PHP.
Not that UntilDate is optional and if you do not set it, it means the user will be kicked for ever.
chatId refers to your group's Chat ID and userId refers to the user whom you want to delete.
回答2:
As with the bot API, it is NOT possible to add members directly to the group, you can still kick them out.
However what you are asking is still possible by using a user bot (MTPROTO client). If you are going to use PHP, I suggest you look at MadelineProto. I will list the methods you can use:
- channels.inviteToChannel (Works with supergroups)
- channels.editBanned (Works with supergroups)
Using the two methods you can easily achive your aim.
来源:https://stackoverflow.com/questions/52267617/chat-api-to-add-and-remove-members-automatically