A Telegram bot that uses AI to detect and remove spam messages, with a focus on filtering out job-related spam messages in group chats.
- AI-powered message moderation using OpenAI's GPT models
- User reputation system that rewards good behavior and penalizes spam
- Automatic message deletion for detected spam
- User banning for repeat offenders
- SQLite storage for persistent data
- Configurable scoring thresholds
- Detailed spam reports with reasons for moderation actions
- Enhanced message handling through optimized Telegram update processing
The bot uses a reputation scoring system:
- New users start with a default score
- Messages from users below the trusted threshold are checked by AI
- Non-spam messages earn users +1 point
- Spam messages result in -1 point, message deletion, and a detailed report
- Once users reach the trusted score, their messages bypass checks
- Go 1.20+
- OpenAI API key
- Telegram Bot API token
The application is configured via environment variables or command line flags:
| Parameter | Flag | Environment Variable | Description |
|---|---|---|---|
| Telegram API Token | --telegram-api-token |
TELEGRAM_API_TOKEN |
Your Telegram Bot API token (required) |
| Workers | --telegram-workers-num |
TELEGRAM_WORKERS_NUM |
Number of Telegram workers (default: 5) |
| Database Path | --db-path |
DB_PATH |
Path to SQLite database (default: ./db/antispam.sqlite) |
| OpenAI API Key | --ai-key |
OPENAI_KEY |
Your OpenAI API key (required) |
- Clone the repository
- Create a database directory:
mkdir -p db - Set up required environment variables or prepare to use command-line flags
Build and run with Make:
make runOr directly with Go:
go run cmd/bot/main.go --telegram-api-token=YOUR_TOKEN --ai-key=YOUR_OPENAI_KEYThe project follows standard Go project layout:
cmd/- Application entrypointsapp/- Application-specific codeservices/- Core business logicstorage/- Data persistencetelegram/- Telegram integration
pkg/- Reusable packagesai/- AI client integrationentities/- Domain entitieslogger/- Logging utilities