From time to time the owners of Telegram groups are faced with the fact that malicious citizens begin to behave not particularly culturally and pour thousands of bots into your group.
In addition to the fact that it leads to paralysis of any communication in the group due to spam messages "So-and-so joined the group
" and messages from the bots themselves, and it can also end rather sadly if the bots "trained" to leave the group by pressing the "complain" button. If you complain enough, you can lose your Telegram chat! 😱
So what to do if one "beautiful" day you see that you began to add to your group packs of unknown users?
Our defense tactics will consist of three things:
- Adding to a group admin botwhich will automatically ban all new users
- Clearing all those who have already managed to join, before the time when the bot-administrator was added
- Creating difficulties for repeated attacks
Let's go!
Adding an admin bot
If you have a big enough telegram chat and still do not have a bot with which it can be administered and moderate users, it's a big mistake!
There are a dozen solutions to this problem on the market, I personally chose for myself ChatKeeper bot. Bot quite handy, a lot of settings, there is a web interface, in short - I recommend it.
After you add him to your group and make him an administrator, you can send commands to the bot. Just write them in the chat, the bot responds to them. With the full list you you can check it out herebut we are only interested in one at the moment: /kickall
. See the description👇
So, after turning on "attack mode", your newfound admin will ban all the bots that keep pouring into your group. Great, we've stopped the influx of new bots, but what about those who have already joined us?
Cleaning up the bots that entered
First of all, take note of the time when you translated admin bot into attack mode. Let's say it was 12:15. Next, scroll through your group and look for the moment when inarticulate users began to be added to it. Let's say it was at 10:42.
Any new users added between 10:42 and 12:15 must be removed. How do I get a list of these users?
To solve this problem, Telegram provides us with a full log of the actions that took place in the channel. It is called "Recent Actions
"and is available in the group menu.
If you go into this log, there is a button at the top right that allows you to filter the log by different types of actions. We are interested in the action "New members
«.
After applying the filter, we will see a log of all new users added to our group. But what if several thousand bots have managed to get to you? We won't search for them all in the log and delete them by ourselves, will we?
Of course not. Especially for this task I had to write a small console application that runs on both Windows and MacOs. It does exactly what I wrote above: it reads the log of the group's actions over a specified period of time and deletes new users.
WARNING: The group's log is stored on Telegram's servers for 48 hours, after which it is deleted, so start clearing it as soon as possible!
The app lives here and this is how to work with it:
- Download all the code from the GitHub repository as a zip-archive and unzip it into some folder
- Open the Program.cs file in any text editor and edit the settings. This is what the settings👇 block looks like
You need to change everything and everything and everything here. Let's start in order:
- Your phone number - everything is quite obvious here.
- The name of your telegram chat. Without a dog!
- The initial date from which the software will purge users. The format is as follows: year, month, day, hours, minutes, seconds. WARNING: the time zone here is UTC+0!!! So if you have, for example, +3, you have to subtract 3 hours to get the right date.
- End date, format is the same as the initial date
- apiId and apiHash - the number and hash for accessing the Telegram API on your behalf. They need to be take it from here.
After you have changed and saved everything, you need to compile and run the software. To do this:
- You set yourself the last one. .NET SDK from the Microsoft site
- Launch the console/terminal and with the command
cd
Go to the folder where you unzipped the code - Write
dotnet run
and press Enter
After you run the program, it will ask you for an access code, which will come to you in Telegram. Enter it in the console.
Then the software starts cleaning all users in a given period of time, and it looks something like this👇
The cleanup rate is 300 users in 13 minutes, which is about 1,500 users per hour. Unfortunately, you won't be able to do it any faster, because Telegram restricts repetitive API requests. So just run the program in the background and let it run.
Note: If you are a programmer, you can speed up the program by adding more admins to the group, then get apiId and apiHash for them, then clean up the group with all the admin accounts you have.
After the software finishes removing bots, go to the third part of the Marlesonian ballet.
Making it more difficult to carry out subsequent attacks on your group
Unless you have non-professionals working against you, the most effective way to limit the inflow of bots to your group is to set some kind of check for new users.
Checks can be varied: pressing the "Login" button, solving a simple math problem, captcha, etc. We'll focus on the simplest one: the "Login" button.
To implement it, we need the same ChatKeeper bot administrator. Go to the web interface of the bot, select "Settings" - "Greeting"
and put everything approximately as in the screenshot below:
Then save the settings. All, now all users who do not pass the test (ie, do not press the button) will be deleted!
Congratulations! You've just done everything necessary to secure your Telegram group. To add a math problem instead of a button, for example - read the help ChatKeeper-And I, for my part, wish your group prosperity and health, success!