Losing years of Telegram history by mistake felt like a nightmare. Here’s how I reverse-engineered Telegram’s Admin Log to bring it all back. Losing years of Telegram history by mistake felt like a nightmare. Here’s how I reverse-engineered Telegram’s Admin Log to bring it all back. ⚠️ Heads-up: This method only works for group chats and channels — not for one-on-one private conversations. ⚠️ Heads-up: This method only works for group chats and channels — not for one-on-one private conversations. Heads-up The Accident That Started It All On September 23, 2024, I made a catastrophic mistake. September 23, 2024 I accidentally deleted all messages and media from a Telegram group chat with my close friends — a conversation that had spanned over three years, included thousands of files, and over 350,000 messages. all messages and media three years thousands of files 350,000 messages Telegram gives you just five seconds to undo a deletion. I missed the window. five seconds Panic. Regret. Despair. Who Am I? Hi, I’m Dmitrii Gusev, a Frontend Developer on the Bricks team at Avito. This isn’t a post about my job — this is about a very personal technical challenge that turned into a mini-investigation, a code project, and ultimately… a successful recovery. Dmitrii Gusev a Frontend Developer Bricks Avito Is Recovery Even Possible? Telegram doesn’t offer any official method to restore deleted group messages or media. Their export tool only works with existing data — not deleted content. existing But I found a clue: Recent Actions. Recent Actions If you’re an admin of a group or channel, you can see deleted messages there — but only for 48 hours, and there’s no “Restore” button. only for 48 hours Still, I thought: If Telegram shows deleted messages there… they must be stored somewhere. Maybe I can get them out. If Telegram shows deleted messages there… they must be stored somewhere. Maybe I can get them out. If Telegram shows deleted messages there… they must be stored somewhere. Maybe I can get them out. Enter: MTProto Telegram has two main APIs: Bot API — simplified, safe, limited MTProto API — complex, powerful, and undocumented in parts Bot API — simplified, safe, limited Bot API MTProto API — complex, powerful, and undocumented in parts MTProto API I realized the only way to access deleted content was through MTProto, specifically the GetAdminLogRequest method. MTProto MTProto MTProt GetAdminLogRequest I found an old, buggy script on GitHub Gist that tried this. It didn’t fully work, but it gave me a starting point. GitHub Gist GitHub Gist Building the Recovery Tool I rewrote and extended the script. Here’s what my tool can now do: [x]Extract deleted text messages [x]Download deleted media files [x]Export data into a clean dump.json [x](Optionally) Resend messages/media to a Telegram group or chat [x]Extract deleted text messages [x] text messages [x]Download deleted media files [x] media files [x]Export data into a clean dump.json [x] dump.json [x](Optionally) Resend messages/media to a Telegram group or chat [x] Resend I used Telethon, a Python library for interacting with Telegram’s MTProto API. Telethon Telethon Telethon My friends and I decided to recover only media files — dumping 350k messages would’ve taken days. My friends and I decided to recover only media files — dumping 350k messages would’ve taken days. The script ran for ~8 hours. It successfully downloaded every media file deleted in that accidental wipe. Crisis averted. every media file 📦 How to Use the Tool You can try this too. Here’s the full guide. 1. Install Python3 Mac users: Install Homebrew first, then Python 3. Homebrew Homebrew Windows/Linux: Use the official site. official site official site Install VSCode or another IDE and set up Python. VSCode VSCode 2. Clone the Repo Install Git and clone the project: git clone https://github.com/sw1tch3roo/tg-message-lifeguard.git cd tg-message-lifeguard git clone https://github.com/sw1tch3roo/tg-message-lifeguard.git cd tg-message-lifeguard 3. (Optional) Create a Virtual Environment python3 -m venv venv source venv/bin/activate # macOS/Linux .\venv\Scripts\activate # Windows python3 -m venv venv source venv/bin/activate # macOS/Linux .\venv\Scripts\activate # Windows 4. Install Dependencies pip install -r requirements.txt pip install -r requirements.txt 5. Get Telegram Credentials Go to https://my.telegram.org Log in with your phone Navigate to API Development Tools Save your api_id and api_hash Go to https://my.telegram.org https://my.telegram.org https://my.telegram.org Log in with your phone Navigate to API Development Tools API Development Tools Save your api_id and api_hash api_id api_hash You’ll also need your group or channel’s internal ID — follow the script instructions to get it. the script instructions the script instructions 6. Run the Backup Script python3 -m src.backup python3 -m src.backup You’ll be prompted for: api_id api_hash Your phone number Your group’s chat ID api_id api_id api_hash api_hash Your phone number Your group’s chat ID ❗ Note: You must use your personal Telegram account, not a bot — bots don’t have access to admin logs. Note You can choose to export: Text only Media only Both text and media Text only Media only Both text and media You can also specify: A message range (min_message_id, max_message_id) Your group or channel ID (group_chat_id) A message range (min_message_id, max_message_id) min_message_id max_message_id Your group or channel ID (group_chat_id) group_chat_id 🔢 How min_message_id and max_message_id work: This defines the range of messages to export: min_message_id = 0 → start from the very first message in the chat max_message_id = 0 → export all available messages min_message_id = 0 → start from the very first message in the chat min_message_id = 0 max_message_id = 0 → export all available messages max_message_id = 0 For example: min_message_id = 23456 max_message_id = 25673 min_message_id = 23456 max_message_id = 25673 This will export only messages within that range, including media. 8. Let It Run Files and metadata will be saved in a folder called backup_will_be_inside_me. You can interrupt and resume anytime — the script supports resuming via message ID. backup_will_be_inside_me ⚠️ Each media file is saved with its corresponding message ID as the file name. This is extremely helpful if the script stops and you need to resume. Just restart the script and set min_message_id to the last downloaded ID — the export will pick up from there. ⚠️ Each media file is saved with its corresponding message ID as the file name. This is extremely helpful if the script stops and you need to resume. Just restart the script and set min_message_id to the last downloaded ID — the export will pick up from there. ⚠️ Each media file is saved with its corresponding message ID as the file name. This is extremely helpful if the script stops and you need to resume. Just restart the script and set min_message_id to the last downloaded ID — the export will pick up from there. What It Looks Like What It Looks Like .json file with message metadata and IDs Downloaded media: photos, videos, documents Easy mapping between message ID and file .json file with message metadata and IDs .json Downloaded media: photos, videos, documents Easy mapping between message ID and file You can also use a companion resender.py script to re-post content into Telegram. resender.py Lessons Learned Telegram does temporarily store deleted content for group chats You can access this data via MTProto, if you act within 48 hours Scripts using Telethon and GetAdminLogRequest can download it Private chats? Unfortunately, there’s no way to recover those once deleted Telegram does temporarily store deleted content for group chats temporarily store deleted content You can access this data via MTProto, if you act within 48 hours can Scripts using Telethon and GetAdminLogRequest can download it GetAdminLogRequest Private chats? Unfortunately, there’s no way to recover those once deleted The Repo 🛠 Check out the tool here. here here Open to contributions, suggestions, or bug reports! Final Thoughts What started as a dumb mistake turned into a deep technical dive — and a surprising success. I hope this tool helps you if you ever find yourself in a similar situation. Got questions? DM me or leave a comment — happy to help. me me And hey — maybe go back up your favourite chats today, just in case. today