Telegram File Server is a powerful, self-hosted media server application that integrates with Telegram bots to provide file storage, organization, and streaming capabilities through a web interface. It now supports multi-user access with per-file ownership and access control.
- Telegram Integration: Uses Pyrogram to connect with Telegram bots for file management
- Web Interface: Modern React frontend with TypeScript and TailwindCSS
- File Management: Organize files in folders, search, and filter by type
- Media Streaming: Built-in support for streaming videos, images, documents, and audio
- Authentication: Secure login with local accounts or Google OAuth
- Multi-User Support: Per-file ownership and access control
- Database Storage: MongoDB integration for storing file metadata
- Auto Updates: GitHub webhook support for automatic deployment updates
- Multi-Bot Support: Manage multiple Telegram bots from a single interface
The application consists of three main components:
-
Backend Server (FastAPI):
- REST API for file operations
- Telegram bot management
- Authentication system
- MongoDB integration
-
Frontend Interface (React/Vite):
- File explorer UI with grid/list views
- Folder navigation and breadcrumb support
- File operations (copy, move, delete, rename)
- Responsive design with dark/light mode
-
Telegram Bots (Pyrogram):
- File upload/download from Telegram
- Media organization and categorization
- User interaction through commands
The frontend is maintained as a separate repository and included in this project as a git submodule:
- Repository: https://github.com/pamod-madubashana/FileServerApp
- Location:
src/frontend
To initialize the submodule, run:
git submodule update --init --recursiveA Windows desktop application is available, built with Tauri:
- Version: v1.0.1
- Features:
- Cross-platform file downloads (browser and desktop)
- Advanced download management with progress tracking
- File browsing and organization
- User authentication and profile management
- Multi-user file access control
- Settings customization
Desktop applications are also available for Linux and macOS, built with Tauri:
- Python 3.12+
- Node.js 16+
- MongoDB
- Telegram API credentials
-
Clone the repository with submodules:
git clone --recurse-submodules <repository-url> cd fileServer
-
If you've already cloned the repository without submodules, initialize them:
git submodule update --init --recursive
-
Install Python dependencies:
pip install -r requirements.txt
-
Install frontend dependencies:
cd src/frontend npm install -
Set up environment variables: Copy
.env.exampleto.envand configure your settings:API_ID=your_telegram_api_id API_HASH=your_telegram_api_hash TOKEN0=your_bot_token DATABASE_URL=your_mongodb_connection_string -
Run the application:
python __main__.py
Run the installation script to set up a systemd service:
chmod +x install.sh
./install.shThis creates a service named telegram-file-server that can be managed with:
tgserver start # Start the service
tgserver stop # Stop the service
tgserver restart # Restart the service
tgserver status # Check service status
tgserver logs # View live logsBuild and run with Docker:
docker build -t telegram-file-server .
docker run -p 8000:8000 telegram-file-serverThe application supports Heroku deployment through the provided app.json and heroku.yml.
The Telegram File Server now supports multiple users with per-file ownership and access control:
- Each file and folder is associated with an owner (user ID)
- Users can only access files they own
- Files uploaded via Telegram are associated with the Telegram account owner
- All file operations (view, move, copy, delete, rename) are restricted to owners
- Admin users can access all files
| Variable | Description | Required |
|---|---|---|
API_ID |
Telegram API ID | Yes |
API_HASH |
Telegram API Hash | Yes |
TOKEN0 |
Primary bot token | Yes |
DATABASE_URL |
MongoDB connection string | Yes |
OWNER |
Owner user ID | No |
PORT |
Web server port (default: 8000) | No |
GOOGLE_CLIENT_ID |
For Google OAuth | No |
GOOGLE_CLIENT_SECRET |
For Google OAuth | No |
Additional bot tokens can be added as TOKEN1, TOKEN2, etc.
After starting the server, access the web interface at http://localhost:8000 (or your configured port).
Features include:
- File browsing with folder navigation
- Virtual folders for media types (Images, Videos, Documents, Audio)
- Search functionality
- File operations (create folder, copy, move, etc.)
The bot supports various commands for file management:
/start- Welcome message- File upload/download through Telegram
GET /- Application informationPOST /api/auth/login- User authenticationGET /api/files- List files in a path (filtered by owner)POST /api/folders/create- Create a new folder (assigned to current user)GET /api/bots/info- Get bot information
All file operations are restricted to the owner of the files. Full API documentation is available at /docs when the server is running.
The backend is written in Python using FastAPI. Key directories:
src/Backend/- Web server implementationsrc/Database/- MongoDB models and connectionssrc/Telegram/- Bot implementationssrc/Config/- Configuration files
The frontend uses React with Vite and is located in the src/frontend directory:
cd src/frontend
npm run dev # Start development server
npm run build # Build for productionKey directories:
src/frontend/src/components/- React componentssrc/frontend/src/hooks/- Custom React hookssrc/frontend/src/pages/- Page componentssrc/frontend/src/lib/- Utility functions
The frontend is a submodule repository hosted at https://github.com/pamod-madubashana/FileServerApp
To build the Windows desktop application using Tauri:
-
Navigate to the frontend directory:
cd src/frontend -
Install dependencies:
npm install
-
Install Tauri CLI globally:
npm install -g @tauri-apps/cli
-
Build the desktop app:
npm run tauri build
The built application will be available in src/frontend/src-tauri/target/release/bundle/ with installers for Windows.
- Session-based authentication with secure middleware
- CORS protection
- Protected API endpoints
- Secure handling of Telegram credentials
- Fork the repository
- Create a feature branch
- Commit your changes
- Push to the branch
- Create a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
For support, please open an issue on the GitHub repository or contact the maintainers.