Automatic message backup system for Telegram with web interface. Works as UserBot to track all messages including deleted and edited ones, and media files.
- β Automatic message saving from all chats
- β Deleted message tracking - everything is saved
- β Edit history - all versions saved
- β Media files - auto-download photos, videos, documents
- β Web interface - beautiful UI with search and authentication
- β Multilingual - English / Ukrainian
- β Export - JSON/CSV format
- β Statistics - per chat analytics
- β Systemd - auto-start on boot
- Python 3.8+
- Telegram API credentials (API_ID, API_HASH)
git clone <url>
cd tg_logger
./setup.sh- Go to https://my.telegram.org
- Login to your account
- Navigate to "API development tools"
- Create new application
- Copy
api_idandapi_hash
Edit .env file:
TG_API_ID=12345678
TG_API_HASH=your_32_character_hash_here
SECRET_KEY=any_random_string
WEB_USERNAME=admin
WEB_PASSWORD=your_secure_password
DEFAULT_LANGUAGE=ensource venv/bin/activate
python run.pyOpen browser: http://127.0.0.1:5000
Login with credentials from .env
tg_logger/
βββ bot.py # Telegram UserBot
βββ web_server.py # Web interface (Flask)
βββ database.py # Database module
βββ config.py # Configuration
βββ logger.py # Logging setup
βββ translations.py # Multilingual support
βββ utils.py # Utilities (export, stats)
βββ run.py # Run both components
βββ setup.sh # Auto-install script
βββ requirements.txt # Dependencies
βββ .env # Environment variables
βββ templates/ # HTML templates
β βββ index.html # Main page
β βββ login.html # Login page
βββ sessions/ # Telegram sessions
βββ media/ # Saved media files
βββ logs/ # Application logs
βββ systemd/ # Systemd service files
βββ telegram_logger.db # SQLite database
Web interface requires login:
- Username and password from
.env - Session-based authentication
- Auto-logout after inactivity
Switch between English and Ukrainian:
- Login page: language selector at bottom
- Main interface: flag icon in header
- Automatic persistence via session
Monitors all messages in real-time:
python bot.pyFirst run requires authorization:
- Enter phone number
- Enter verification code from Telegram
- If 2FA enabled - enter password
Note: Session is saved, authorization needed only once.
View collected data:
python web_server.pypython run.pyOr separately in tmux:
tmux new -d -s tg_bot "python bot.py"
python web_server.py- π Statistics: total chats, messages, deleted, edited
- π¬ Chat list: all monitored chats
- π Messages: view all messages per chat
- ποΈ Deleted: highlighted in red
- βοΈ Edited: view edit history
- π· Media: photos, videos, audio with embedded player
- π Search: search all messages
- π Auto-refresh: updates every 30 seconds
Auto-start on system boot:
# Configure service files in systemd/
# Detailed instructions in SYSTEMD.md
sudo cp systemd/*.service /etc/systemd/system/
sudo systemctl enable tg_logger_bot.service tg_logger_web.service
sudo systemctl start tg_logger_bot.service tg_logger_web.serviceDetails: SYSTEMD.md
Main settings:
# Monitor all chats or selected only
LOG_ALL_CHATS = True
# If LOG_ALL_CHATS = False, specify chat IDs
MONITORED_CHATS = [-1001234567890, -1009876543210]
# Web server
WEB_HOST = '127.0.0.1' # Change to '0.0.0.0' for network access
WEB_PORT = 5000
# Media folder
MEDIA_FOLDER = 'media'# Export chat to JSON
python utils.py export_json <chat_id>
# Export to CSV
python utils.py export_csv <chat_id>
# Export all chats
python utils.py export_all json
# View deleted messages
python utils.py deleted
# View edited messages
python utils.py edited
# Chat statistics
python utils.py stats <chat_id>
# Cleanup old media (30+ days)
python utils.py cleanup 30- UserBot vs Bot: This is a UserBot (uses your account), not a regular @BotFather bot
- Telegram ToS: Use at your own risk, comply with Telegram rules
- Privacy: Do not share database, media files, and sessions
- Security: Keep
sessions/folder and.envfile private - Storage: Large media files can consume significant space
# Remove old session files
rm -rf sessions/*
# Run bot.py again
python bot.py# Close all processes
pkill -f "python bot.py"
pkill -f "python web_server.py"
# RestartTelegram limits requests. Bot automatically waits, but if error persists:
- Reduce simultaneous media downloads
- Wait before next run
- Export to various formats (JSON, CSV, HTML)
- Date and message type filters
- Voice message transcription support
- Telegram bot for remote control
- Docker container for easy deployment
- Database encryption
- Cloud storage support (optional)
This project is for educational purposes. Use responsibly.
Pull requests are welcome! For major changes, please open an issue first.
- Use only for personal purposes
- Respect privacy of other users
- Comply with Telegram Terms of Service
- Do not use for spam or abuse
If you have questions or issues, create an Issue on GitHub.
Note: This is a UserBot running under your account. Be careful and responsible when using it.