92 lines
2.8 KiB
Markdown
92 lines
2.8 KiB
Markdown
# Marzban Telegram Bot
|
|
|
|
A powerful Telegram Bot with a built-in Web App (Mini App) for managing [Marzban](https://github.com/Gozargah/Marzban) VPN subscriptions.
|
|
|
|
## Features
|
|
|
|
- **📱 Interactive Web App**: A beautiful Material 3 Expressive UI for users to manage their VPN.
|
|
- **🌍 Localization**: Fully localized in English and Russian.
|
|
- **📊 User Dashboard**: Real-time traffic usage, expiration date, and subscription status.
|
|
- **🛍️ Shop**: Integrated store to purchase VPN plans (Lite, Medium, Heavy, Unlimited) using Telegram Stars.
|
|
- **🎟️ Promo Codes**: Advanced promo code system (discounts, bonus days, unlimited usage).
|
|
- **🔧 Configuration**: Easy setup for users with QR codes and subscription links (VLESS/VMess/Trojan).
|
|
- **🛡️ Admin Panel**: comprehensive admin tools directly in the Web App:
|
|
- View bot and server statistics (CPU, RAM, Revenue).
|
|
- Manage users (add days, reset traffic, ban/unban, delete).
|
|
- Create and manage promo codes.
|
|
- Broadcast messages to all users.
|
|
|
|
## Tech Stack
|
|
|
|
- **Backend**: Python 3.11, [Aiogram 3.x](https://github.com/aiogram/aiogram), [FastAPI](https://fastapi.tiangolo.com/)
|
|
- **Database**: SQLite (default) or PostgreSQL (via asyncpg)
|
|
- **Frontend**: HTML5, CSS3 (Material 3 Expressive Design), Vanilla JS
|
|
- **Integration**: Marzban API
|
|
|
|
## Prerequisites
|
|
|
|
- A running [Marzban](https://github.com/Gozargah/Marzban) instance.
|
|
- Telegram Bot Token (from [@BotFather](https://t.me/BotFather)).
|
|
- Python 3.11+ (for local run) or Docker.
|
|
|
|
## Setup & Configuration
|
|
|
|
1. **Clone the repository:**
|
|
```bash
|
|
git clone <your-repo-url>
|
|
cd marzban_tg_bot
|
|
```
|
|
|
|
2. **Create config file:**
|
|
Rename `.env.example` to `.env` and fill in the values:
|
|
```ini
|
|
BOT_TOKEN=your_bot_token_here
|
|
ADMIN_IDS=12345678,87654321
|
|
|
|
# Marzban Credentials
|
|
MARZBAN_URL=https://your-marzban-domain.com
|
|
MARZBAN_USERNAME=admin
|
|
MARZBAN_PASSWORD=admin_password
|
|
|
|
# Web App Settings
|
|
BASE_URL=https://your-marzban-domain.com
|
|
WEB_APP_URL=https://your-bot-domain.com # URL where this bot is hosted
|
|
WEB_APP_PORT=8888
|
|
|
|
# Database (leave empty for SQLite)
|
|
DATABASE_URL=
|
|
```
|
|
|
|
## Running with Docker (Recommended)
|
|
|
|
1. **Build and Run:**
|
|
```bash
|
|
docker-compose -f docker/docker-compose.yml up -d --build
|
|
```
|
|
|
|
2. **Check Logs:**
|
|
```bash
|
|
docker-compose -f docker/docker-compose.yml logs -f
|
|
```
|
|
|
|
The Web App will be available at `http://your-server-ip:8888`. Ensure you have set up a reverse proxy (Nginx/Caddy) with SSL pointing to this port, as Telegram Web Apps require HTTPS.
|
|
|
|
## Running Locally
|
|
|
|
1. **Create Virtual Environment:**
|
|
```bash
|
|
python -m venv .venv
|
|
source .venv/bin/activate # Linux/Mac
|
|
.venv\Scripts\activate # Windows
|
|
```
|
|
|
|
2. **Install Dependencies:**
|
|
```bash
|
|
pip install -r requirements.txt
|
|
```
|
|
|
|
3. **Run:**
|
|
```bash
|
|
python main.py
|
|
```
|