Alita is a powerful, modern Telegram group management bot built with Go and the Gotgbot library. Designed for speed, reliability, and extensive customization, Alita provides comprehensive moderation tools for Telegram communities of any size.
- Parallel Bulk Processing: High-performance batch operations for filters, blacklists, and warnings
- Worker Pool Architecture: Efficient concurrent task processing with rate limiting
- Smart Caching: Two-tier caching with stampede protection and TTL management
- Batch Prefetching: Optimized data loading for reduced database queries
- Resource Monitoring: Automatic detection and alerting for memory/goroutine issues
- Performance Analytics: Built-in statistics collection and performance tracking
- User Management: Ban, mute, kick, and warn users with customizable actions
- Permission System: Granular permission control for admins
- Anti-Spam: Configurable flood control and spam detection
- Blacklist: Word and sticker filtering with pattern matching
- Welcome/Goodbye: Customizable greeting messages with variables
- Filters: Keyword-triggered auto-responses with regex support
- Notes: Save and retrieve formatted messages
- Pins: Manage pinned messages with anti-spam protection
- Locks: Control message types (links, forwards, media, etc.)
- Performance: Built with Go for blazing-fast response times
- Dual-Layer Cache: Redis + Ristretto for optimal performance
- Database: PostgreSQL with connection pooling and batch operations
- Deployment Modes: Support for both polling and webhook modes
- Multi-Language: i18n support with YAML locale files
- Monitoring: Built-in resource monitoring and health checks
- Fully Asynchronous: Non-blocking operations throughout
- Repository Pattern: Clean separation of concerns
- Middleware System: Extensible command decorators
- Graceful Shutdown: Proper cleanup and connection handling
- Docker Ready: Multi-architecture images for easy deployment
- Worker Pools: Concurrent processing with configurable worker pools
- Batch Operations: Optimized bulk database operations with parallel processing
- Performance Monitoring: Built-in metrics collection and analysis
Get Alita running in under 5 minutes!
- Docker and Docker Compose installed
- PostgreSQL database (or use the included one)
- Redis instance (or use the included one)
- Telegram Bot Token from @BotFather
git clone https://github.com/divkix/Alita_Robot.git
cd Alita_Robot
cp sample.env .env
# Edit .env with your configuration
nano .env
Required variables:
BOT_TOKEN=your_bot_token_from_botfather
OWNER_ID=your_telegram_user_id
MESSAGE_DUMP=-100xxxxxxxxx # Your log channel
DATABASE_URL=postgres://postgres:password@postgres:5432/alita_robot
REDIS_ADDRESS=redis:6379
docker-compose up -d
That's it! Your bot should now be running. Check the logs:
docker-compose logs -f alita
Open Telegram and search for your bot username to start using it!
We provide official Docker images at ghcr.io/divkix/alita_robot
for easy
deployment.
This includes PostgreSQL, Redis, and the bot:
# Clone the repository
git clone https://github.com/divkix/Alita_Robot.git
cd Alita_Robot
# Configure environment
cp sample.env .env
# Edit .env with your settings
# Start all services
docker-compose up -d
# View logs
docker-compose logs -f alita
# Stop services
docker-compose down
Note: Database migrations run automatically in Docker (AUTO_MIGRATE=true).
Optional: To run a local Telegram Bot API server for faster file handling, use
the compose profile and set API_SERVER in your .env
:
# .env
API_SERVER=http://telegram-bot-api:8081
TELEGRAM_API_ID=your_api_id
TELEGRAM_API_HASH=your_api_hash
# Start with profile
docker compose --profile local-bot-api up -d
If you have existing PostgreSQL and Redis instances:
docker run -d \
--name alita-bot \
--restart unless-stopped \
-e BOT_TOKEN="your_bot_token" \
-e DATABASE_URL="your_postgres_url" \
-e REDIS_ADDRESS="your_redis_address" \
-e OWNER_ID="your_telegram_id" \
-e MESSAGE_DUMP="-100xxxxxxxxx" \
ghcr.io/divkix/alita_robot:latest
Download pre-built binaries for your platform:
-
Visit the Releases page
-
Download the appropriate binary for your OS/architecture:
- Linux:
alita_robot_*_linux_amd64.tar.gz
or_arm64
- macOS:
alita_robot_*_darwin_amd64.tar.gz
or_arm64
- Windows:
alita_robot_*_windows_amd64.zip
- Linux:
-
Extract and run:
# Linux/macOS
tar -xzf alita_robot_*.tar.gz
chmod +x alita_robot
./alita_robot
# Windows
# Extract the zip file and run alita_robot.exe
- Go 1.21 or higher
- PostgreSQL 14+
- Redis 6+
- Make (optional)
# Clone the repository
git clone https://github.com/divkix/Alita_Robot.git
cd Alita_Robot
# Install dependencies
go mod download
# Build the binary
go build -o alita_robot .
# Or use make
make build
# Run the bot
./alita_robot
# (Recommended) Run database migrations before the first run
# Provide your Postgres connection via env vars:
# PSQL_DB_HOST, PSQL_DB_NAME, PSQL_DB_USER, PSQL_DB_PASSWORD
# Optional: PSQL_DB_PORT (default 5432), PSQL_DB_SSLMODE (default require)
make psql-migrate
# Run with hot reload (requires air)
go install github.com/cosmtrek/air@latest
air
# Or use make
make run
Alita uses environment variables for configuration. Create a .env
file in the
project root:
Variable | Description | Example |
---|---|---|
BOT_TOKEN |
Telegram Bot Token from @BotFather | 123456:ABC-DEF... |
DATABASE_URL |
PostgreSQL connection string | postgres://user:pass@host/db |
REDIS_ADDRESS |
Redis server address | redis:6379 |
OWNER_ID |
Your Telegram user ID | 123456789 |
MESSAGE_DUMP |
Log channel ID (must start with -100) | -100123456789 |
Variable | Description | Default |
---|---|---|
REDIS_PASSWORD |
Redis password | (empty) |
ENABLED_LOCALES |
Comma-separated locale codes | en |
USE_WEBHOOKS |
Enable webhook mode | false |
WEBHOOK_DOMAIN |
Webhook domain (if enabled) | - |
WEBHOOK_SECRET |
Webhook security token | - |
WEBHOOK_PORT |
Webhook server port | 8080 |
MAX_DB_POOL_SIZE |
Database connection pool size | (calculated) |
CACHE_TTL |
Cache time-to-live (seconds) | 300 |
CACHE_SIZE |
In-memory cache size (MB) | 100 |
WORKER_POOL_SIZE |
Concurrent worker pool size | 10 |
QUERY_TIMEOUT |
Database query timeout (seconds) | 30 |
See sample.env
for a complete list of configuration options.
For production deployments, webhook mode provides better performance and lower resource usage than polling. Alita supports webhooks with Cloudflare Tunnel for easy setup behind firewalls.
- Cloudflare account with a domain added to Cloudflare
- Docker and Docker Compose installed
- Go to Cloudflare Zero Trust Dashboard
- Navigate to Networks > Tunnels
- Click Create a tunnel β Choose Cloudflared
- Name your tunnel (e.g.,
alita-telegram-bot
) - Copy the tunnel token from the command shown (the long string after
--token
)
- In your tunnel dashboard, go to Public Hostnames tab
- Click Add a public hostname
- Configure:
- Subdomain:
alita-bot
(or your preference) - Domain: Select your domain
- Service:
http://alita:8080
- Path:
/webhook/your-secret
(replace with your actualWEBHOOK_SECRET
)
- Subdomain:
Create your .env
file with webhook settings:
# Bot Configuration
BOT_TOKEN=your_bot_token_here
OWNER_ID=your_telegram_user_id
MESSAGE_DUMP=-100xxxxxxxxx
# Database Configuration
DATABASE_URL=postgres://postgres:password@postgres:5432/alita_robot?sslmode=disable
REDIS_ADDRESS=redis:6379
REDIS_PASSWORD=your_redis_password
# Webhook Configuration
USE_WEBHOOKS=true
WEBHOOK_DOMAIN=https://alita-bot.yourdomain.com
WEBHOOK_SECRET=your-random-secret-string-here
WEBHOOK_PORT=8080
# Cloudflare Tunnel
CLOUDFLARE_TUNNEL_TOKEN=eyJhIjoiNzU1...your-tunnel-token-here
Uncomment the cloudflared
service in your docker-compose.yml
:
# Uncomment this section for webhook mode
cloudflared:
image: cloudflare/cloudflared:latest
container_name: alita-cloudflared
environment:
- TUNNEL_TOKEN=${CLOUDFLARE_TUNNEL_TOKEN}
command: tunnel --no-autoupdate run
restart: unless-stopped
depends_on:
- alita
deploy:
resources:
limits:
memory: 128M
cpus: "0.1"
After your bot is running, register the webhook URL with Telegram:
# Replace YOUR_BOT_TOKEN with your actual bot token
# Replace the URL with your actual webhook URL
curl -X POST "https://api.telegram.org/botYOUR_BOT_TOKEN/setWebhook" \
-H "Content-Type: application/json" \
-d '{
"url": "https://alita-bot.yourdomain.com/webhook/your-secret",
"secret_token": "your-secret"
}'
docker-compose up -d
Check webhook status:
curl "https://api.telegram.org/botYOUR_BOT_TOKEN/getWebhookInfo"
To disable webhooks and return to polling mode:
# Clear webhook
curl -X POST "https://api.telegram.org/botYOUR_BOT_TOKEN/setWebhook" -d "url="
# Update environment
USE_WEBHOOKS=false
Feature | Webhook Mode | Polling Mode |
---|---|---|
Performance | β‘ Real-time updates | π 1-3 second delay |
Resource Usage | π Lower CPU/bandwidth | π‘ Higher CPU/bandwidth |
Setup Complexity | π§ Requires domain setup | β Simple, works anywhere |
Production Ready | β Recommended | |
Firewall Friendly | β Works behind NAT | β Needs outbound access |
/promote
- Promote user to admin/demote
- Demote admin to user/ban
- Ban a user/unban
- Unban a user/mute
- Mute a user/unmute
- Unmute a user/kick
- Kick a user/warn
- Warn a user/unwarn
- Remove warnings/setwarnlimit
- Set warning limit/lock
- Lock message types/unlock
- Unlock message types
/start
- Start the bot/help
- Get help/info
- User information/id
- Get IDs/ping
- Check bot response
/filter
- Add keyword filter/filters
- List filters/stop
- Remove filter/save
- Save a note/get
- Get a note/notes
- List notes/clear
- Delete a note
/setwelcome
- Set welcome message/setgoodbye
- Set goodbye message/resetwelcome
- Reset welcome/resetgoodbye
- Reset goodbye/cleanwelcome
- Auto-delete welcomes/cleanservice
- Auto-delete service messages/setflood
- Configure antiflood/blacklist
- Add blacklisted words
- Comprehensive Code Documentation: All 774+ functions across 83 Go files are fully documented
- GoDoc Compatible: Documentation follows Go standards for automatic documentation generation
- Developer Guide: See CLAUDE.md for detailed architecture and development guidelines
- API Reference: Run
go doc
or visit pkg.go.dev for API documentation
Alita_Robot/
βββ alita/ # Core bot code
β βββ config/ # Configuration management
β βββ db/ # Database layer
β βββ modules/ # Command handlers
β βββ utils/ # Utility packages
β βββ i18n/ # Internationalization
βββ cmd/ # Executables
β βββ alita/ # Main bot
β βββ migrate/ # Migration tool
βββ locales/ # Language files
βββ supabase/ # Database migrations
βββ docker/ # Docker configurations
-
Install Go 1.21+
# macOS brew install go # Linux wget https://go.dev/dl/go1.21.0.linux-amd64.tar.gz sudo tar -C /usr/local -xzf go1.21.0.linux-amd64.tar.gz
-
Setup PostgreSQL and Redis
# Using Docker docker run -d --name postgres -e POSTGRES_PASSWORD=password -p 5432:5432 postgres:14 docker run -d --name redis -p 6379:6379 redis:7-alpine
-
Clone and Build
git clone https://github.com/divkix/Alita_Robot.git cd Alita_Robot go mod download make build
-
Install Pre-commit Hooks (Optional but recommended)
pip install pre-commit pre-commit install
This will run automatic checks before each commit:
- Code formatting (gofmt)
- Linting (golangci-lint)
- Security checks
- File cleanup (trailing whitespace, EOF)
-
Run Database Migrations
Supabase is the source of truth for schema files (
supabase/migrations
). Migrations are applied to any PostgreSQL by auto-cleaning Supabase-specific statements at runtime.- Required environment variables for migrations:
PSQL_DB_HOST
,PSQL_DB_NAME
,PSQL_DB_USER
,PSQL_DB_PASSWORD
- Optional:
PSQL_DB_PORT
(default: 5432),PSQL_DB_SSLMODE
(default: require)
# Example: local Postgres export PSQL_DB_HOST="localhost" export PSQL_DB_NAME="alita_robot" export PSQL_DB_USER="postgres" export PSQL_DB_PASSWORD="password" # export PSQL_DB_PORT="5432" # optional # export PSQL_DB_SSLMODE="require" # optional # Apply migrations (auto-cleans Supabase SQL for generic Postgres) make psql-migrate
Optional: generate cleaned SQL for inspection (not required to run migrations):
make psql-prepare PSQL_MIGRATIONS_DIR=tmp/migrations_cleaned ls -1 tmp/migrations_cleaned
- Required environment variables for migrations:
-
Start Development
make run
make run # Run bot locally
make build # Build release binaries
make lint # Run linters
make tidy # Clean dependencies
make vendor # Vendor dependencies
make psql-migrate # Run migrations
make psql-prepare # Generate cleaned SQL into tmp/migrations_cleaned
make psql-status # Check migration status
make psql-reset # Reset database (DANGEROUS)
- Database Model - Add to
alita/db/
- Repository - Implement in
alita/db/repositories/
- Handler - Create in
alita/modules/
- Register - Add to module's init function
- Localize - Add strings to
locales/
# Run linters
make lint
# Format code
gofmt -w .
# Run tests (when available)
go test ./...
All releases are cryptographically attested using GitHub's attestation feature for supply chain security. To verify:
# Using GitHub CLI (gh)
gh attestation verify alita_robot_*.tar.gz \
--owner divkix \
--repo Alita_Robot
This verification ensures:
- The artifact was built by our official GitHub Actions workflow
- The binary hasn't been tampered with since build
- Full build provenance and supply chain integrity
We welcome contributions! Here's how to get started:
- Fork the repository and create your branch from
main
- Write clean code that follows Go best practices
- Test your changes thoroughly
- Update documentation if needed
- Submit a Pull Request with a clear description
# Fork and clone
git clone https://github.com/YOUR_USERNAME/Alita_Robot.git
cd Alita_Robot
# Create feature branch
git checkout -b feature/amazing-feature
# Make changes and test
make run
make lint
# Commit with conventional commits
git commit -m "feat: add amazing feature"
# Push and create PR
git push origin feature/amazing-feature
We use Conventional Commits:
feat:
New featurefix:
Bug fixdocs:
Documentationrefactor:
Code refactoringtest:
Testingchore:
Maintenance
- Join our Support Group
- Check existing issues
- Read the CLAUDE.md for codebase details
- Paul Larsen - For the amazing Gotgbot library and inspiration from Marie
- ΓΓΓΓHΓLΓ TΓR SPΓRK - Continuous motivation and contributions
- jayantkageri - Support and encouragement
- Anony - Bug fixes and improvements
- All Contributors - Everyone who has helped improve this project!
This project is licensed under the MIT License - see the LICENSE file for details.
Copyright (C) 2020-2025 Divkix
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
Made with β€οΈ by Divkix and contributors
Try Alita β’ Support Group β’ Updates Channel