Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

1 Commit
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ“± Telegram Logger

Automatic message backup system for Telegram with web interface. Works as UserBot to track all messages including deleted and edited ones, and media files.

✨ Features

  • βœ… 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

πŸ“‹ Requirements

  • Python 3.8+
  • Telegram API credentials (API_ID, API_HASH)

πŸš€ Quick Start

1. Clone & Install

git clone <url>
cd tg_logger
./setup.sh

2. Get Telegram API Credentials

  1. Go to https://my.telegram.org
  2. Login to your account
  3. Navigate to "API development tools"
  4. Create new application
  5. Copy api_id and api_hash

3. Configure

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=en

4. Run

source venv/bin/activate
python run.py

Open browser: http://127.0.0.1:5000

Login with credentials from .env

πŸ“ Project Structure

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

πŸ” Authentication

Web interface requires login:

  • Username and password from .env
  • Session-based authentication
  • Auto-logout after inactivity

🌐 Language Support

Switch between English and Ukrainian:

  • Login page: language selector at bottom
  • Main interface: flag icon in header
  • Automatic persistence via session

🎯 Usage

Run UserBot

Monitors all messages in real-time:

python bot.py

First run requires authorization:

  1. Enter phone number
  2. Enter verification code from Telegram
  3. If 2FA enabled - enter password

Note: Session is saved, authorization needed only once.

Run Web Interface

View collected data:

python web_server.py

Run Both

python run.py

Or separately in tmux:

tmux new -d -s tg_bot "python bot.py"
python web_server.py

πŸ“Š Web Interface Features

  • πŸ“ˆ 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

πŸ–₯️ Systemd Service

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.service

Details: SYSTEMD.md

πŸ› οΈ Configuration

config.py

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'

πŸ”§ Utilities

# 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

⚠️ Important Notes

  1. UserBot vs Bot: This is a UserBot (uses your account), not a regular @BotFather bot
  2. Telegram ToS: Use at your own risk, comply with Telegram rules
  3. Privacy: Do not share database, media files, and sessions
  4. Security: Keep sessions/ folder and .env file private
  5. Storage: Large media files can consume significant space

πŸ› Troubleshooting

Authorization Error

# Remove old session files
rm -rf sessions/*
# Run bot.py again
python bot.py

Database Locked

# Close all processes
pkill -f "python bot.py"
pkill -f "python web_server.py"
# Restart

FloodWaitError

Telegram limits requests. Bot automatically waits, but if error persists:

  • Reduce simultaneous media downloads
  • Wait before next run

πŸ“ TODO / Future Features

  • 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)

πŸ“„ License

This project is for educational purposes. Use responsibly.

🀝 Contributing

Pull requests are welcome! For major changes, please open an issue first.

βš–οΈ Legal

  • Use only for personal purposes
  • Respect privacy of other users
  • Comply with Telegram Terms of Service
  • Do not use for spam or abuse

πŸ“§ Support

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.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages