AI-powered spam detection and moderation bot for Telegram groups using Google Gemini.
Filter.AI is an intelligent Telegram bot that helps keep your group chats clean and civilized. Using Google's Gemini AI, it analyzes reported messages to detect spam content, automatically banning offenders and maintaining a detailed log of all actions.
- AI-Powered Analysis: Leverages Google Gemini 2.5 Flash for intelligent message classification
- Automatic Moderation: Bans users and deletes messages identified as spam
- Detailed Logging: Maintains a CSV(for local) and @t.me/filterAiLogs for production log of all banned users with timestamps and reasons
- Simple Commands: Easy-to-use interface with
/startand/reportcommands - Privacy-Focused: Only analyzes messages when explicitly reported by group members
- Python 3.7 or higher
- A Telegram Bot Token (from @BotFather)
- A Google Gemini API Key (from Google AI Studio)
-
Clone the repository
git clone https://github.com/iput-object/Filter.Ai.git cd Filter.Ai -
Install dependencies
pip install -r requirements.txt
-
Configure environment variables
cp .env.example .env
Edit
.envand add your credentials:TELEGRAM_BOT_TOKEN=your_telegram_bot_token_here GEMINI_API_KEY=your_gemini_api_key_here TELEGRAM_LOG_CHANNEL=your_telegram_log_channel_id_here ENVIRONMENT=your_build_environment_here #PRODUCTION OR DEVELOPMENT -
Run the bot
python main.py
docker compose up --build filterai-local- Uses
.envfile for credentials. - Stops and removes safely:
docker compose down filterai-localdocker compose up -d filterai-production- Uses environment variables injected by your hosting platform (e.g., Railway).
.envis ignored in production.- Stop and remove production container safely:
docker compose stop filterai-production
docker compose rm filterai-production| Service | Description | Environment |
|---|---|---|
filterai-local |
Local testing/debugging | .env (local) |
filterai-production |
Production deployment | Hosting platform env vars |
- Add the bot to your Telegram group
- Promote the bot to admin with the following permissions:
- Delete messages
- Ban users
/start- Display help and documentation/report- Report a message (must be used as a reply to the message you want to report)
- A user replies to a suspicious message with
/report - The bot analyzes the message content using Gemini AI
- If classified as "spam":
- The message is deleted
- The user is banned from the group
- The incident is logged to
banned_logs.csvor to @t.me/filterAiLogs
- If the message is safe, the bot notifies that no action is needed
LOCAL: All ban actions are logged to banned_logs.csv with the following information:
- Timestamp
- User ID
- Username
- Reason (spam)
- Message content PRODUCTION: All bans will be logged to @t.me/filterAiLogs (Depends on the CHANNEL_ID)
python-telegram-bot- Telegram Bot API wrappergoogle-generativeai- Google Gemini AI integrationpython-dotenv- Environment variable management
Filter.Ai/
├── main.py # Main bot application
├── requirements.txt # Python dependencies
├── .env.example # Environment variables template
├── .gitignore # Git ignore rules
├── LICENSE # Project license
├── README.md # This file
└── banned_logs.csv # Ban logs (generated at runtime)
Contributions are welcome! Feel free to:
- Report bugs
- Suggest new features
- Submit pull requests
- Improve documentation
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- Currently only analyzes texts & captions messages
- Depends on Gemini AI availability and API limits
- Support for analyzing images and media
- Customizable sensitivity levels
- Dashboard for viewing ban statistics
- Whitelist/blacklist functionality
Considerably give a Star to the Repo and have fun ✨
- python-telegram-bot - Telegram Bot API wrapper
- Google Gemini - AI model for content analysis
Made with ❤️ for safer Telegram communities