A simple yet powerful Telegram bot built with Go that receives files from users and stores them locally. Perfect for creating a personal file storage system accessible through Telegram.
- 📁 Multiple File Types Support: Documents, photos, videos, audio, voice messages, video notes, and stickers
- 📁 Simple Storage: All files stored in a single directory with timestamp naming
- 🔒 Access Control: Restrict bot access to authorized users only
- 👨💼 Admin Features: Admin commands for user management
- 🔐 Security: Files are stored securely with proper permissions
- 📦 Docker Support: Easy deployment with Docker and Docker Compose
- 🚀 Lightweight: Minimal resource usage with Alpine Linux base
- 📝 Detailed Logging: Comprehensive logging for monitoring and debugging
- 💾 Size Limits: Configurable file size limits (default: 50MB)
- 📊 Synology Status Monitoring: Monitor download tasks and receive notifications for status changes
- Documents: PDF, DOC, TXT, ZIP, etc.
- Photos: JPG, PNG, GIF, etc.
- Videos: MP4, AVI, MOV, etc.
- Audio: MP3, WAV, FLAC, etc.
- Voice Messages: OGG format
- Video Notes: Circular videos from Telegram
- Stickers: WEBP format
- Go 1.21 or higher (for local development)
- Docker and Docker Compose (for containerized deployment)
- A Telegram Bot Token (obtain from @BotFather)
- Open Telegram and search for @BotFather
- Send
/newbotcommand - Follow the instructions to create your bot
- Save the token provided by BotFather
-
Clone the repository:
git clone <repository-url> cd tg-fsyn
-
Set up environment variables:
cp .env.example .env nano .env # Edit with your bot token -
Build and run with Docker Compose:
docker-compose up -d
-
Check logs:
docker-compose logs -f
For Synology NAS users, use the automated setup script:
-
Quick Setup:
./setup-synology.sh --token YOUR_BOT_TOKEN --user YOUR_USER_ID
-
Or step-by-step:
# Fix permissions for Synology (UID 1026) make fix-permissions # Deploy with Synology-specific settings make synology-deploy # Check status make synology-status
-
Alternative (if permissions are problematic):
# Use root mode (less secure but simpler) ./setup-synology.sh --root-mode
-
Clone and setup:
git clone <repository-url> cd tg-fsyn go mod tidy
-
Set environment variables:
export TELEGRAM_BOT_TOKEN="your_bot_token_here" export STORAGE_PATH="./files"
-
Run the bot:
go run main.go
| Variable | Description | Default | Required |
|---|---|---|---|
TELEGRAM_BOT_TOKEN |
Your Telegram bot token | - | ✅ |
ALLOWED_USERS |
Comma-separated list of allowed user IDs | - | ❌ |
ADMIN_USERS |
Comma-separated list of admin user IDs | - | ❌ |
STORAGE_PATH |
Directory to store files | ./files |
❌ |
LOG_LEVEL |
Logging level | info |
❌ |
MAX_FILE_SIZE |
Maximum file size in bytes | 52428800 (50MB) |
❌ |
BOT_DEBUG |
Enable debug mode | false |
❌ |
SYNOLOGY_HOST |
Synology DSM IP address | 127.0.0.1 |
❌ |
SYNOLOGY_PORT |
Synology DSM port | 5000 |
❌ |
SYNOLOGY_USERNAME |
Synology username | (empty) | ❌ |
SYNOLOGY_PASSWORD |
Synology password | (empty) | ❌ |
Note for Synology Users: The bot uses UID 1026 and GID 100 by default, which matches standard Synology user permissions.
Files are stored directly in the storage directory:
files/
├── document_1641234567_ABC123.pdf
├── photo_1641234568_DEF456.jpg
├── video_1641234569_GHI789.mp4
└── audio_1641234570_JKL012.mp3
Files are named with timestamps and file IDs for easy identification.
docker build -t tg-file-bot .docker run -d \
--name tg-file-bot \
-e TELEGRAM_BOT_TOKEN="your_token_here" \
-v $(pwd)/files:/app/files \
tg-file-bot# Start the bot
docker-compose up -d
# View logs
docker-compose logs -f
# Stop the bot
docker-compose down
# Rebuild and restart
docker-compose up -d --build- Synology NAS with DSM 6.0 or higher
- Docker package installed from Package Center
- SSH access enabled (for advanced setup)
# Automated setup script
./setup-synology.sh --token YOUR_BOT_TOKEN --user YOUR_USER_ID
# Or interactive setup
./setup-synology.sh-
Create storage directory:
mkdir -p ./files sudo chown 1026:100 ./files chmod 755 ./files
-
Use Synology-specific compose file:
# Copy environment template cp .env.example .env # Edit with your settings nano .env # Deploy with Synology settings docker-compose -f docker-compose.synology.yml up -d --build
-
Alternative - Root mode (if permissions fail):
docker-compose --profile root-mode up -d --build
Permission denied errors:
# Fix permissions automatically
make fix-permissions
# Or manually
sudo chown -R 1026:100 ./files
chmod -R 755 ./filesContainer won't start:
# Check logs
make synology-logs
# Try root mode
make setup-synology-rootThe bot supports user access control to restrict usage to authorized users only:
-
Get your Telegram User ID:
- Send
/idcommand to the bot - The bot will reply with your user ID
- Send
-
Configure allowed users:
# In .env file ALLOWED_USERS=123456789,987654321,555666777 # Or as environment variable export ALLOWED_USERS="123456789,987654321,555666777"
-
Configure admin users (optional):
# In .env file ADMIN_USERS=123456789 # Or as environment variable export ADMIN_USERS="123456789"
Admins have additional capabilities:
- Add/remove users from the allowed list
- View bot statistics
- List all authorized users
/start- Show welcome message and bot capabilities/help- Display help information and supported file types/id- Get your Telegram user ID (useful for access control setup)/status- Show current download status from Synology
/admin list- List all allowed users/admin add <user_id>- Add user to allowed list/admin remove <user_id>- Remove user from allowed list/admin status- Show bot statistics
- Get your bot token from @BotFather
- Find your Telegram user ID:
- Start a chat with your bot
- Send
/idcommand - Save the user ID for configuration
# Add your user ID to allowed users
export ALLOWED_USERS="your_user_id_here"
# Optionally, make yourself an admin
export ADMIN_USERS="your_user_id_here"- Start a chat with your bot
- Send
/startto see the welcome message - Send any supported file type
- The bot will confirm successful storage
- Files are saved to the configured storage path
- Users should send
/idto the bot to get their user ID - Admins can add them using
/admin add <user_id> - Or add their ID to the
ALLOWED_USERSenvironment variable
tg-fsyn/
├── main.go # Main application file
├── go.mod # Go module dependencies
├── go.sum # Dependency checksums
├── Dockerfile # Docker build instructions
├── docker-compose.yml # Docker Compose configuration
├── .env.example # Environment variables template
├── .dockerignore # Docker ignore patterns
└── README.md # This file
The bot is structured with clear separation of concerns:
Botstruct handles the main bot logic- Individual handler functions for each file type
- Utility functions for file operations
- Environment-based configuration
To add support for new file types, create a new handler function following the existing pattern.
- Access Control: Configurable user authorization prevents unauthorized access
- Simple Structure: All files stored in a single directory with clear naming convention
- Admin Controls: Admin users can manage access without server access
- Secure Container: The application runs as a non-root user in Docker
- File Limits: File size limits prevent abuse
- Input Validation: Proper validation on all file operations
- Privacy: No sensitive information is logged
- User ID Logging: Unauthorized access attempts are logged for security monitoring
-
Bot not responding:
- Check if the bot token is correct
- Verify the bot is not blocked by Telegram
- Check if your user ID is in the allowed users list
- Check application logs for errors
-
Access Denied error:
- Get your user ID with
/idcommand - Ask an admin to add you with
/admin add <your_user_id> - Or add your user ID to
ALLOWED_USERSenvironment variable
- Get your user ID with
-
Files not saving:
- Verify storage directory permissions
- Check available disk space
- Review file size limits
-
Docker issues:
- Ensure Docker daemon is running
- Check port conflicts
- Verify volume mounts
Check application logs for debugging:
# Docker Compose
docker-compose logs -f tg-bot
# Docker
docker logs tg-file-bot
# Local development
# Logs are printed to stdout- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
If you encounter any issues or have questions:
- Check the troubleshooting section
- Review the logs for error messages
- Open an issue on GitHub
- Join our community discussions
- User access control and authorization
- Admin commands for user management
- Synology status monitoring with notifications
- Web interface for file management
- Database integration for metadata
- Role-based permissions (viewer, uploader, admin)
- User quotas and storage limits
- File compression options
- Multi-language support
- File encryption
- File sharing capabilities
- Audit logs and activity tracking
Made with ❤️ using Go and the Telegram Bot API