This is a production‑ready, autonomous Telegram bot and its real‑time analytics dashboard.
The bot handles ≥100 concurrent updates, includes rate limiting, reminders, trades, temporary invites, auto‑moderation, and continuous fuzzing.
The dashboard provides live command heatmaps, charts, moderation rule editor, trade viewer, invite manager, user management, and WebSocket‑based real‑time events.
Both components share the same PostgreSQL database and communicate via Redis pub/sub for real‑time events.
The bot can be deployed locally (long polling) or on Kubernetes (minikube) with SealedSecrets for encrypted credentials.
The dashboard runs on Laravel 12 + Vue 3 + Inertia + Reverb.
- Bot: https://github.com/lelextb/telegram-aiogram-bot
- Dashboard: https://github.com/lelextb/telegram-bot-analytics
- Python 3.11+
- PostgreSQL 14+
- Redis 7+
- (Optional) Docker / minikube for Kubernetes deployment
git clone https://github.com/lelextb/telegram-aiogram-bot.git
cd telegram-aiogram-bot
python -m venv venv
source venv/bin/activate
pip install -r requirements.txt
cp .env.example .envEdit .env:
BOT_TOKEN=your_bot_token_from_botfather
DATABASE_URL=postgresql+asyncpg://user:pass@localhost:5432/telegram_db
REDIS_URL=redis://localhost:6379/0
USE_WEBHOOK=false # long polling modeCreate the database:
sudo -u postgres psql -c "CREATE USER dashboard WITH PASSWORD 'secret';"
sudo -u postgres psql -c "CREATE DATABASE telegram_db OWNER dashboard;"Run migrations (automatically created on first start):
python -m bot.main # will create tablesRun the bot:
python -m bot.main- Set
USE_WEBHOOK=truein.env. - Build Docker image and push to your registry (or use minikube’s Docker daemon).
- Install SealedSecrets controller in your cluster.
- Create sealed secret (see README).
- Apply all manifests in
k8s/usingkubectl apply -k k8s/. - Set the webhook URL via
curlor use@BotFatherwith your domain.
- PHP 8.2+ (8.5 supported)
- Composer
- Node.js 20+ & npm
- PostgreSQL 14+
- Redis 7+
git clone https://github.com/lelextb/telegram-bot-analytics.git
cd telegram-bot-analytics
composer install
npm install --legacy-peer-deps
cp .env.example .envEdit .env:
APP_URL=http://localhost
DB_CONNECTION=pgsql
DB_HOST=127.0.0.1
DB_PORT=5432
DB_DATABASE=telegram_db
DB_USERNAME=dashboard
DB_PASSWORD=secret
BROADCAST_DRIVER=reverb
REVERB_APP_ID=123456
REVERB_APP_KEY=your-reverb-key
REVERB_APP_SECRET=your-reverb-secret
REVERB_HOST=localhost
REVERB_PORT=8080
REVERB_SCHEME=http
REDIS_HOST=127.0.0.1
REDIS_PORT=6379
TELEGRAM_BOT_TOKEN=your_bot_token
TELEGRAM_BOT_USERNAME=your_bot_username
TELEGRAM_ADMIN_IDS=7916393260 # your Telegram user IDRun migrations and seed admin:
php artisan key:generate
php artisan migrate --seedBuild frontend:
npm run buildStart the services (three terminals):
# Terminal 1
php artisan serve --host=0.0.0.0 --port=8000
# Terminal 2
php artisan reverb:start
# Terminal 3
php artisan redis:subscribeVisit http://localhost:8000 and log in with Telegram.
docker-compose up -dThe dashboard will be available at http://localhost:8000.
- Database: Both use the same PostgreSQL instance. The bot writes to
command_logs,trades,temp_invites,moderation_logs; the dashboard reads these tables. - Real‑time events: The bot publishes Redis messages on channel
bot_events. The dashboard runsphp artisan redis:subscribeto listen and broadcasts them via WebSocket (Reverb) to the Vue frontend. - Moderation rules: The dashboard CRUD operations modify the
moderation_rulestable. The bot reads this table to enforce rules. - No extra APIs – all communication is through the shared database and Redis.
cd fuzzing
pytest test_fuzz.py --hypothesis-show-statisticsvalgrind --tool=massif python -m bot.main
ms_print massif.out.*py-spy record -o profile.svg -- python -m bot.mainModuleNotFoundError: No module named 'bot'– ensure you are in the correct directory and have__init__.pyfiles.- Redis connection error – verify Redis is running (
redis-cli ping) andREDIS_URLis correct. - Database column missing – run migrations (
python -c "from bot.models.sqlalchemy_models import init_db; import asyncio; asyncio.run(init_db())"). - Webhook not working – check your domain is set with
@BotFatherand the webhook URL is public.
Driver [telegram] not supported– installsocialiteproviders/telegramand add the event listener inEventServiceProvider.- Real‑time events not showing – ensure
php artisan redis:subscribeis running and Redis is reachable. - Mixed content / HTTPS – set
APP_URLto your HTTPS domain and force HTTPS inAppServiceProvider. - Telegram login “Page Expired” – exclude
/auth/telegram/callbackfrom CSRF inbootstrap/app.php.
- Never commit
.envfiles – use.env.exampleas a template. - Use SealedSecrets in Kubernetes to encrypt
BOT_TOKENand database passwords. - Rate limiting prevents command spam.
- Auto‑moderation filters bad words.
- Webhook secret token verifies incoming requests (if using webhook mode).
- Regularly update dependencies to patch vulnerabilities.
Both repositories are open for contributions. Please:
- Fork the repository.
- Create a feature branch.
- Submit a pull request with a clear description.
MIT – free to use, modify, and distribute.
No warranty, use at your own risk.
--
This project was conceived, architected, and brought to life by LelexTB.
It represents a complete, production‑ready ecosystem for a high‑performance Telegram bot and its real‑time analytics dashboard – built with attention to concurrency, security, observability, and developer experience.
Credits & Thanks
- aiogram and Telethon communities for the excellent async Telegram libraries.
- Laravel, Vue, Inertia, Reverb – the backbone of the modern dashboard.
- PostgreSQL & Redis – reliable data and messaging backbone.
- Hypothesis & AFL – for making fuzzing accessible.
- Bitnami SealedSecrets – for Kubernetes secret encryption.
- All open‑source contributors whose packages made this possible.
Special thanks to early testers, issue reporters, and anyone who takes the time to understand, use, or improve this project.
If you find this project useful, consider giving it a ⭐ on GitHub, sharing feedback, or contributing.
For questions or collaborations, reach out via GitHub Issues or Discussions.
— LelexTB
Agentic Architect • Multi‑Stack Engineer • Systems Architect