A small Telegram logger I made for my own account. It keeps a local cache of messages and forwards deleted or edited ones into a private log channel. Media can be cached too, so a deleted photo or video is still there when Telegram removes it.
This is mostly a practical tool I wanted to have running in the background: simple Python, SQLite, and one Docker Compose command. It is not a polished Telegram product and it does not try to be one.
Use it only with accounts, chats, and data you are allowed to monitor. The cache contains private message content, so treat the data/ directory like a password manager backup.
- Watches incoming and outgoing messages from the connected Telegram account
- Sends deleted and edited messages to a chosen private log channel
- Downloads photos, videos, and documents before they disappear, with size limits
- Tries to save self-destructing media as soon as it arrives
- Keeps a persistent SQLite cache and cleans up old records once it reaches the configured limit
- Supports phone-number or QR-code login
- Can filter private chats, groups, channels, and specific chat IDs
You need a Telegram API ID and hash from my.telegram.org, plus a private channel where the logs will be sent.
Create the local configuration file and fill in your values:
mkdir -p data
cp config.example.json data/config.jsonThe important fields are:
api_idandapi_hash: Telegram application credentialsphone: your account number, used for phone loginlog_channel_id: numeric ID of the private log channellogin_method:qrorphone
data/config.json, the Telegram session, SQLite cache, and downloaded media are all ignored by Git on purpose.
docker compose up --buildFor QR login, scan the code in Telegram: Settings → Devices → Link Desktop Device. The session is stored in data/, so future starts do not need another login.
To run it in the background:
docker compose up -d --buildpython -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
python logger.pySet mode to whitelist or blacklist to use the matching ID list. ignored_ids is useful for excluding the log channel itself. cache_size is the maximum number of message records retained locally; cached media for trimmed records is removed with them.
The defaults log everything. Before using this on a real account, narrow the chat-type toggles and limits to what you actually need.
- Python 3.14
- Telethon
- SQLite in WAL mode
- Docker Compose
