$ show offu/WeRoBot
WeRoBot is a Python library for building WeChat Official Account (ε ¬δΌε·) robots. It provides a high-level framework that handles message parsing, event routing, signature verification, session management (with multiple backends like SQLite, Redis, MongoDB), message encryption/decryption (AES), and a full client for the WeChat Corporate API (menu management, user management, template messages, mass messaging, etc.). The library can run as a standalone WSGI application (via Bottle) or be integrated into Django, Flask, Bottle, and Tornado. The core robot class (WeRoBot) allows developers to register handlers via decorators for specific message types (text, image, location) and events (subscribe, click, scan). It is a mature, well-documented project with comprehensive test coverage and CI/CD. The codebase is generally well-structured but shows signs of technical drift in dependency versions and Python version support (officially tested up to Python 3.9, some pinned libraries are outdated).
The LLM identified 3 files worth highlighting for reuse:
This module defines descriptor classes (IntEntry, FloatEntry, StringEntry) that automate the mapping of XML fields to Python types with default handling. The pattern uses Python descriptors to declaratively extract and coerce values from a dictionary (populated from XML parsing). It includes a `get_value` helper that supports nested key paths (e.g., 'ScanCodeInfo.ScanType'). This is a reusable, clean approach for mapping incoming structured data to typed object attributes, and could be extracted and applied to any scenario where XML or JSON data needs type-safe attribute access.
Implements the WeChat message encryption/decryption protocol (AES-256-CBC with PKCS7 padding, Base64 encoding, and signature verification). The `PrpCrypto` class handles low-level AES operations, while `MessageCrypt` provides a higher-level interface (`encrypt_message`/`decrypt_message`) that manages XML wrapping, signature generation, and nonce handling. The implementation correctly follows the WeChat spec (random prefix, length encoding, app_id validation). This module is self-contained and could be reused in any Python project needing WeChat-compatible encryption, or adapted for similar XML-wrapped AES encryption workflows.
Defines the abstract base class `SessionStorage` with a simple dictionary-like interface (`get`, `set`, `delete`, `__getitem__`, `__setitem__`, `__delitem__`). This clean interface enables interchangeable session backends (SQLite, Redis, MongoDB, MySQL, PostgreSQL, File, SAE). The pattern is a textbook example of the strategy pattern for storage backends and is easily reusable for any application that needs pluggable key-value storage with a minimal API.