Skip to content

lelextb/telegram-bot-analytics

Repository files navigation

📊 Telegram Bot Analytics – Real‑time Dashboard

Laravel Vue Inertia Reverb

Production‑ready real‑time analytics dashboard for the Telegram AIogram Bot.
Displays command heatmap, hourly charts, auto‑moderation rules, trade history, temporary invites, user management, and live event stream via WebSocket.


✨ Features

  • 🔥 Real‑time event stream – Redis pub/sub → WebSocket (Laravel Reverb)
  • 📊 Command heatmap – GitHub‑style, 365 days
  • 📈 Hourly command charts – ApexCharts
  • ⚖️ Auto‑moderation CRUD – Create/edit/delete rules (bot enforces)
  • 🤝 Trade history – Pending & confirmed trades
  • 🔗 Temporary invites – List invites generated by bot
  • 👤 User management – View users, ban (simulated)
  • 🔐 Telegram OAuth login – No passwords, secure
  • 🐳 Docker Compose – Full stack (Laravel + Reverb + PostgreSQL + Redis)
  • 🧪 Testing – PHPUnit, Pest (optional)

🚀 Quick Start (Local)

Prerequisites

  • PHP 8.2+ (8.5 supported)
  • Composer 2.x
  • Node.js 20+ & npm
  • PostgreSQL 14+
  • Redis 7+

Installation

git clone https://github.com/lelextb/telegram-bot-analytics.git
cd telegram-bot-analytics
composer install
npm install --legacy-peer-deps
cp .env.example .env

Environment Configuration

Edit .env with your settings:

APP_NAME="Telegram Bot Analytics"
APP_ENV=local
APP_DEBUG=true
APP_URL=http://localhost

DB_CONNECTION=pgsql
DB_HOST=127.0.0.1
DB_PORT=5432
DB_DATABASE=telegram_analytics
DB_USERNAME=your_db_user
DB_PASSWORD=your_db_password

BROADCAST_DRIVER=reverb
REVERB_APP_ID=123456
REVERB_APP_KEY=your-key
REVERB_APP_SECRET=your-secret
REVERB_HOST=localhost
REVERB_PORT=8080
REVERB_SCHEME=http

REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379

# Telegram OAuth
TELEGRAM_BOT_TOKEN=your_bot_token
TELEGRAM_BOT_USERNAME=your_bot_username
TELEGRAM_ADMIN_IDS=123456789   # comma‑separated Telegram user IDs

Database Setup

php artisan key:generate
php artisan migrate --seed

The seeder creates an admin user (for password login) – but you will use Telegram OAuth.
Admin access is granted based on TELEGRAM_ADMIN_IDS.

Frontend Build

npm run build

Run the Dashboard

php artisan serve --host=0.0.0.0 --port=8000

In separate terminals, start the WebSocket server and Redis subscriber:

php artisan reverb:start
php artisan redis:subscribe

Now visit http://localhost:8000 and log in with Telegram.


🐳 Docker Compose (All Services)

The repository includes a docker-compose.yml that starts:

  • PostgreSQL
  • Redis
  • Laravel (PHP-FPM + Nginx)
  • Reverb (WebSocket)
  • Redis subscriber
docker-compose up -d

Access the dashboard at http://localhost:8000.


🔗 Integration with Telegram Bot

This dashboard is designed to work with the Telegram AIogram Bot.
Requirements:

  • Both bot and dashboard share the same PostgreSQL database.
  • The bot must write to these tables:
    • command_logs – for heatmap and charts
    • trades – for trade history
    • temp_invites – for invite list
    • moderation_logs – for audit (optional)
    • moderation_rules – dashboard writes, bot reads
  • The bot must publish events to Redis channel bot_events (the dashboard subscribes).

No API calls needed – only shared database and Redis.


🧪 Testing

php artisan test

For frontend, open browser developer tools – no unit tests for Vue provided.


📁 Project Structure (Key Folders)

app/
├── Http/Controllers/         # Analytics, Moderation, Trades, Invites, Users
├── Models/                   # CommandLog, Trade, TempInvite, ModerationRule, User
├── Events/                   # BotEvent (broadcastable)
├── Console/Commands/         # SubscribeRedis
database/
├── migrations/               # All required tables
├── seeders/                  # AdminUserSeeder
resources/
├── js/
│   ├── Pages/                # Dashboard, Analytics, Moderation, Trades, Invites, Users
│   ├── Components/           # Heatmap, CommandChart, RealTimeLog, ModerationRuleForm
│   ├── Layouts/              # AppLayout
│   ├── store/                # Pinia store for real‑time events
│   └── app.js
routes/
├── web.php                   # Inertia pages + API endpoints
└── channels.php              # Reverb channel authorization

🛠️ Troubleshooting

“Driver [telegram] not supported”

  • Ensure socialiteproviders/telegram is installed and EventServiceProvider has the listener.
  • Clear config: php artisan config:clear.

Real‑time events not showing

  • Verify Redis is running: redis-cli ping
  • Check that php artisan redis:subscribe is running.
  • Send a test message: redis-cli publish bot_events '{"event":"test"}' – should appear in subscriber.

Mixed content / HTTPS errors

  • Set APP_URL to your HTTPS domain.
  • Add URL::forceScheme('https') in AppServiceProvider::boot() for production.

“Page Expired” on Telegram callback

  • Exclude /auth/telegram/callback from CSRF in bootstrap/app.php.

📝 License

MIT – free to use and modify.


🤝 Credits

Coded & Developed by LelexTB

Built with Laravel, Vue 3, Inertia, and Reverb.
Uses socialiteproviders/telegram for OAuth.

About

Real‑time analytics dashboard for Telegram bot (Laravel + Vue + Inertia + Reverb)

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages