It turned out that I'm managing a Telegram group in a new residential complex.
Due to the large number of spammers in Telegram, access had to be granted based on requests.
Initially, there were a few requests per week, which I handled manually. However, recently, the spammers have become very active. There can be up to 20-30 requests per day.
I have to go into the profile of each applicant, ask them control questions. It doesn't seem like much time, but it's still a lot :)
So, I had to vibecode a bot :)
It took about 5 hours of pure time. Most of that was spent on testing :)
The configuration file allows you to define lists of control questions. For example, I ask for the apartment number and the floor it's located on.
The bot checks the correctness of the apartment number and its location on the floor.
Excerpts from README.md
Why Chur-Bot?
Mythology: Slavic.
Legend: Chur is an ancient deity of boundaries, borders, and the protection of property. Just as Chur protected the borders of our ancestors, this bot protects the borders of your Telegram group.
Description
Chur-Bot allows you to automate the process of admitting new members to a Telegram group based on their answers to questions.
Functionality
- Guardian: Intercepts requests to join the chat (
chat_join_request). - Interrogation: Asks configured questions in private messages.
- Court: Approves the request if the answers are correct; otherwise, rejects it.
- Timeout: Automatically rejects requests if the user remains silent for too long.
Installation and Update (Linux)
-
Run the installation script:
bashchmod +x setup.sh ./setup.shThe script will perform all the necessary actions:
- Creates the user
chur_bot. - Creates a virtual environment and installs dependencies.
- Configures and starts the systemd service.
- Creates the user
-
Configuration:
- Copy
config.yaml.exampletoconfig.yaml. - Edit
config.yaml: specify the token, admin IDs, and questions. - Restart the service to apply the settings:
sudo systemctl restart chur_bot
- Copy
-
Configuration in Telegram:
- Go to group settings -> Group Type / Members.
- Enable "Approve New Members".
- Add the bot to the group and make it an Administrator with the permission "Invitation Links".
Update
To update the bot code and dependencies:
chmod +x update.sh
./update.sh
Service Management
- Status:
sudo systemctl status chur_bot - Logs:
journalctl -u chur_bot -f - Restart:
sudo systemctl restart chur_bot
Administrator Commands
/stats: Shows statistics of requests (pending, approved, rejected)./logs: Shows the last 10 log entries directly in Telegram.- Important: These commands only work for users specified in
admin_idsinconfig.yaml.
Utility Commands
/id: Sends the current chat ID and user ID. Use this to fill inconfig.yaml.
Viewing Logs
The bot writes logs to the console and to the file bot.log.
- Console: Just look at the terminal where the bot is running.
- File:
tail -f bot.logor openbot.login an editor. - Telegram command: Send
/logsto the bot in a private message (only for Admins).
