Capture Deleted WeChat Messages with Python: A Step‑by‑Step Guide

This article explains how to use Python and the wxpy library to detect and forward WeChat messages that have been revoked, detailing the underlying message format, the retrieval logic, and the code needed to automatically forward the original content to your file helper.

Python Crawling & Data Mining
Python Crawling & Data Mining
Python Crawling & Data Mining
Capture Deleted WeChat Messages with Python: A Step‑by‑Step Guide

Background

WeChat, launched by Tencent in 2011, now has over a billion daily active users and many features such as Moments, Mini Programs, and more. In 2014 it introduced the 撤回消息 (message revocation) feature, which replaces a withdrawn message with a system notice.

Design

The goal is to capture a revoked message as soon as it occurs and forward the original content and sender information to the file helper (or optionally back to the sender), making it easy to review.

Implementation

1. How WeChat Revokes Messages

When a user clicks revoke, the client sends a system message like "xxx撤回了一条消息". The receiving client parses this message and replaces the original display.

"xxx撤回了一条消息" is a system notification that contains the original message ID and replacement text.

2. Finding the Revoked Message

By comparing the msgid in the revocation notice with the IDs of recent messages cached by the wxpy library (default cache of the last 200 messages), we can locate the original message. If the message volume exceeds 200 within two minutes, increase the max_history parameter.

3. Forwarding the Revoked Message

Once the original message is identified, forwarding is a single line of code using wxpy:

msg.forward(bot.file_helper)

4. Full Code Example

The complete script (with detailed comments) is provided below. It sets up the bot, listens for system messages of type revokemsg, extracts the original msgid, retrieves the matching message from the cache, and forwards it.

# Example code (simplified)
from wxpy import Bot
bot = Bot()
@bot.register(msg_types=NOTE)
def on_revoke(msg):
    # parse XML, get original msgid, find in cache, forward
    pass
bot.join()

Verification

Running the script shows that when a friend revokes a message, the original text appears in the file helper, confirming the detection works.

Conclusion

The WeChat anti‑revoke feature is simple yet useful. Current limitations include the need to run the script on a continuously active machine. Future improvements could involve deploying the bot on a cloud server or packaging it as an APK for easier use.

Project repository: https://github.com/pig6/wxrobot

Documentation for wxpy: https://wxpy.readthedocs.io/zh/latest

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

PythonBotwxpyMessage Revocation
Python Crawling & Data Mining
Written by

Python Crawling & Data Mining

Life's short, I code in Python. This channel shares Python web crawling, data mining, analysis, processing, visualization, automated testing, DevOps, big data, AI, cloud computing, machine learning tools, resources, news, technical articles, tutorial videos and learning materials. Join us!

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.