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.
The Accident That Started It All
On September 23, 2024, I made a catastrophic mistake.
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.
Telegram gives you just five seconds to undo a deletion. I missed the window.
Panic. Regret. Despair.
Who Am I?
Hi, I’m Dmitrii Gusev,
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.
But I found a clue: 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.
Still, I thought:
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
I realized the only way to access deleted content was through GetAdminLogRequest
method.
I found an old, buggy script on
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
I used
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.
You can try this too. Here’s the full guide.
1. Install Python3
Mac users: Install
Windows/Linux: Use the
Install
2. Clone the Repo
Install Git and clone the project:
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
.venvScriptsactivate # Windows
4. Install Dependencies
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
andapi_hash
You’ll also need your group or channel’s internal ID — follow
6. Run the Backup Script
python3 -m src.backup
You’ll be prompted for:
api_id
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.
You can choose to export:
- 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
)
🔢 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 chatmax_message_id = 0
→ export all available messages
For example:
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.
⚠️ 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
.json
file with message metadata and IDs- 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.
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
The Repo
🛠 Check out the tool
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
And hey — maybe go back up your favourite chats today, just in case.