WeChatAuto.SDK
repository·master·Indexed 42 days ago
https://github.com/scottfly189/wechatauto.sdkA modern RPA framework for WeChat automation optimized for AI/LLM integration. It supports .NET and Python, offering automation strategies like UI Tree and Hybrid OCR (via RapidOCRCSharp) for WeChat versions 4.1.xx and 3.9.12.xx. Features include message listening, social capabilities, group management, and a WebSocket server to bridge .NET functionality to other languages. Includes a Python community edition package (wechat-auto4x-sdk v1.0.0).
What's inside WeChatAuto.SDK
- The WebSocket Server provides a way to access the full range of Wechatauto.SDK's native .NET API functionality from other programming languages such as Python, JavaScript/Node.js, and Java. It acts as a bridge, allowing non-.NET environments to control WeChat via the SDK's core capabilities through WebSocket communication.
Overview of WeChatAuto.SDK
masterWeChatAuto.SDK is a modern WeChat RPA (Robotic Process Automation) framework designed for AI integration (e.g., LLM context interaction). It is built on .NET and UI automation technologies. The SDK supports both .NET and Python, allowing developers to integrate WeChat automation into existing systems. It offers features like message listening, social capabilities (sending text, emojis, files, @mentions), group management, and support for multiple WeChat instances via local execution or WebSocket long connections.Overview of WebChatAuto.SDK Web Support
masterWebChatAuto.SDK Web Support extends the core SDK by providing a Visual UI and a REST API service. This allows developers to control the WeChat client via HTTP requests.
To mitigate WeChat risk control (anti-spam) measures, the system implements a "pooling" mechanism for outgoing messages. This means messages are queued and sent at a controlled rate, making it suitable for high-volume batch messaging without the risk of being logged out due to high frequency.
Overview of WeChatAuto.SDK Python SDK Community Edition
masterThe
wechat-auto4x-sdkis the Python community edition of the WeChatAuto.SDK. It is designed for modern AI-oriented WeChat RPA (Robotic Process Automation) and supports the latest WeChat versions, including4.1.10.xxand4.1.11.xxseries.For core framework details and full documentation, refer to the main WeChatAuto.SDK repository.
Compare WeChat 4.1.xx and 3.9.12.xx automation solutions
masterThe SDK provides two distinct automation paths depending on the WeChat version:
WeChat 4.1.xx (Latest Version)
- Solution: Hybrid UI Tree + OCR automation.
- OCR Engine: Uses local
onnx-runtimemodels viaRapidOCRCSharp. - Platforms: Supports both .NET and Python.
- Open Source: Core code and documentation are 100% open source; business code is 80% open source (20% of APIs are VIP-exclusive).
WeChat 3.9.12.xx (Legacy Version)
- Solution: Pure UI Tree automation.
- Platforms: Supports .NET only.
- Open Source: 100% open source.
System Requirements and Risk Mitigation
masterSystem Requirements
- OS: Windows (Linux and MacOS are not supported).
- Runtime: .NET 6.0 or higher (Note: Python SDK does not require .NET).
Risk Management (Anti-Detection)
Frequent automated operations may trigger WeChat's risk control mechanisms. To mitigate this:
- Use Hardware Keyboard/Mouse Simulators: Instead of software-based API injection (like
PostMessage), use hardware simulators to mimic real human input. This is highly recommended for high-sensitivity operations like adding friends. - Control Frequency: Avoid performing large volumes of actions in a short period.
- Simulate Human Behavior: Use the simulator to provide more natural input patterns.
Setup and use WeChatAuto.SDK for .NET (WeChat 4.x)
masterTo use the latest WeChat 4.x automation in a .NET project:
- Create a project: Create a .NET console project.
- Configure Target Framework: Ensure your
.csprojtargets a Windows-specific framework (e.g.,net10.0-windows,net6.0-windows, ornet7.0-windows). - Install Dependencies:
dotnet add package Microsoft.Extensions.DependencyInjection dotnet add package WeChatAuto4x.SDK - Add OCR Models: Download the OCR model files and place the
modelsfolder in your project root. - Initialize and Run:
Use
WeAutomation.InitializewithEnableOCR = trueto start the service.
using WeChatAuto.Services; using WeChatAuto.Components; using Microsoft.Extensions.DependencyInjection; var serviceProvider = WeAutomation.Initialize(options => { options.DebugMode = false; // Optional options.EnableOCR = true; // Required for 4.x }); using var clientFactory = serviceProvider.GetRequiredService<WeChatClientFactory>(); // Check available WeChat clients var wechat_list = clientFactory.GetWeChatClientNames(); Console.WriteLine($"Open WeChat clients: {string.Join(',', wechat_list)}"); // Open the first client and send a message var client = clientFactory.GetWeChatClient(wechat_list.First()); await client.SendMessage("AI.Net_test", "hello world!!");Set up and use WebChatAuto.SDK Web Support
masterFollow these steps to integrate WeChat automation via REST API:
- Prepare WeChat: Ensure your WeChat client is version
3.9.12.xx. This specific release is built for this version. - Start the Service: Run the application and click the 【运行】 (Run) button in the UI. This starts the local Web API service.
- Access API Documentation: Once running, the service defaults to
http://localhost:5000. You can access the Swagger UI athttp://localhost:5000/swaggerto view available endpoints and test them manually. - Integrate: Use any language that supports HTTP (e.g., Python, Node.js) to send requests to the local API endpoints.
http://localhost:5000/swagger- Prepare WeChat: Ensure your WeChat client is version
Choose a WebSocket Server implementation
masterThe repository provides two versions of the WebSocket Server depending on your deployment needs:
- Server: A console-based (CLI) WebSocket Server, ideal for headless environments, servers, or automated deployments.
- Server_UI: A WebSocket Server with a graphical user interface (UI), useful for manual control and visual monitoring.
Setup and use WeChatAuto.SDK for Python (WeChat 4.x)
masterThe Python SDK communicates with a WebSocket Server and does not require .NET installed on the client machine.
- Start the WebSocket Server:
- Download the
WeChatAuto4x.SDK WebSocket Server. - Run
Server.exe. It typically listens onhttp://localhost:5000.
- Download the
- Initialize Python Project:
uv init demo-python cd demo-python uv add wechat-auto4x-sdk
3. **Implement Automation**: Connect to the server using `WechatFactory.create_factory` with a WebSocket URI (e.g., `ws://localhost:5000/ws`). ```python import asyncio from wechat_auto_sdk import WeChatClient from wechat_auto_sdk import WeChatConfig from wechat_auto_sdk import WechatFactory DEFAULT_URI = "ws://localhost:5000/ws" async def wechat_automation(): async with WechatFactory.create_factory(DEFAULT_URI, WeChatConfig()) as factory: await factory.initialize() wechat_list = factory.client_list print(f"Connected to {len(wechat_list)} clients: {list(wechat_list.keys())}") # Access a specific client by name client: WeChatClient = wechat_list["Alex"] # Send message with @mentions await client.send_message( "DroidMirror官方技术支持", "hello world!", at_user=["AI.Net_test", "智影工坊"] ) if __name__ == "__main__": asyncio.run(wechat_automation())- Start the WebSocket Server:
Access WeChatAuto.SDK 3.9.12.xx Documentation
masterFor detailed documentation, API references, and comprehensive guides regarding WeChatAuto.SDK version 3.9.12.xx, please refer to the official documentation website.
https://scottfly189.github.io/WeChatAuto.SDK/Troubleshoot WeChat automation failures
masterIf the example automation fails to control the WeChat client, perform the following checks:
- Taskbar Placement: Ensure the WeChat window is dragged to the taskbar.
- OS Compatibility: Verify you are using Windows 10 or Windows 11.
- UI Tree Availability: If using WeChat version 4.1.xx, check if a UI Tree is available. You can verify this using tools like
inspect.exeorFlaUInspect(available in the project'sToolsdirectory).- If no UI Tree is detected, refer to the specific issue documentation for handling missing UI Trees.
If these steps do not resolve the issue, contact the author with your code for assistance.