Dialogue management KIT bot for Telegram using.
Currently supports:
- Automatic detection and removal of bot-generated messages using machine learning spam detection.
- SQLite logging of all detected bot messages.
- Statistics and recent activity view.
- Commands:
/start- Start the bot/stats- View detection statistics/recent- View recent detections/allow- Allow a chat for moderation/disallow- Remove a chat from moderation/allowed- View allowed chats/del- Admin-only. Reply to a message to delete it manually
- Automatic Bot Detection: Uses a pre-trained FastText model to detect bot-generated messages with >95% accuracy
- Message Deletion: Automatically deletes messages identified as bot-generated
- SQLite Logging: Records all detected bot messages in a local database
- Statistics: View detection statistics and recent activity
- Commands:
/start- Start the bot/stats- View detection statistics/recent- View recent detections/del- Admin-only, reply-based manual deletion
- The bot monitors all text messages in the chat
- Each message is analyzed using a FastText spam detection model
- If the spam probability is >95%, the message is considered bot-generated
- Bot messages are automatically deleted and logged to a SQLite database
- Admins can view statistics and recent activity using bot commands
-
Get a Bot Token:
- Message @BotFather on Telegram
- Create a new bot with
/newbot - Save the token provided
-
Install Dependencies:
pip install uv uv sync
-
Configure Environment:
# Copy the example configuration file cp .env.example .env # Edit .env file and set your bot token # TELEGRAM_BOT_TOKEN=your_bot_token_here
Alternatively, set environment variables directly:
export TELEGRAM_BOT_TOKEN=your_bot_token_here export SPAM_THRESHOLD=0.95
-
Run the Bot:
# Starts the bot by default python main.py
Run the test suite to verify functionality:
python test_bot.pyThe bot requires the following permissions in your Telegram group:
- Delete messages
- Read messages
The bot creates a local SQLite database (bot_messages.db) to store:
- Message ID and chat information
- User details (ID, username)
- Message content
- Spam probability score
- Detection timestamp
- Whether the message was successfully deleted
Uses a pre-trained FastText model for spam detection located at:
dialogue_kitogram/data/antispam.bin
-
Set admin Telegram user IDs via environment variable:
export ADMIN_USER_IDS="123456789,987654321"
Supports comma or space separated integers.
-
Only chats in the allow-list are moderated. Admins can manage it:
- In a group (as admin):
/allowto allow current chat - In a group:
/disallowto remove current chat - In a group: reply to a message with
/delto delete it (admins only) - In a DM with the bot (admin only):
/allow <chat_id> [title]/disallow <chat_id>/allowed— list allowed chats
- In a group (as admin):
Non-admin DMs receive a brief notice to contact an admin.
The model was trained on Russian/English spam detection datasets and achieves high accuracy in distinguishing between human and bot-generated content.