wechat-relay
0.0.2
See the version list below for details.
dotnet tool install --global wechat-relay --version 0.0.2
dotnet new tool-manifest
dotnet tool install --local wechat-relay --version 0.0.2
#tool dotnet:?package=wechat-relay&version=0.0.2
nuke :add-package wechat-relay --version 0.0.2
wechat-relay
Bridge WeChat personal account messages to any webhook, script, or pipeline.
Zero dependencies beyond .NET 10. Native AOT binaries for Linux, macOS & Windows.
Features
| π QR Login | Scan once, credentials saved in a local JSON session file. No expiry until the server invalidates the session. |
| π‘ Persistent Listener | Long-poll WeChat messages. Survives restarts via disk-backed queue. |
| π Configurable Hooks | Every inbound message triggers your command (default: echo). Passes JSON metadata. |
| π€ Send Messages | Reply to any user via CLI. Context tokens cached automatically. |
| ποΈ Native AOT | Single-file, self-contained binaries β no runtime needed. |
| π§ Cross-platform | linux-x64, win-x64, osx-arm64. |
Install
As a .NET global tool
As an npm package
npm install -g @slaveoftime/wechat-relay
wechat-relay # runs the bundled native binary
dotnet tool install -g wechat-relay
wechat-relay # prints usage
Or grab a native binary
Download from Releases:
| Platform | Asset |
|---|---|
| Linux x64 | wechat-relay-v{version}-linux-x64.tar.gz |
| Windows x64 | wechat-relay-v{version}-win-x64.zip |
| macOS ARM64 | wechat-relay-v{version}-osx-arm64.tar.gz |
Extract and run β no .NET SDK required.
Quick Start
# 1. Login β scan QR with WeChat on your phone
wechat-relay login
# 2. Start listening β messages print to console + trigger your hook
wechat-relay listen
# 3. Send a message
wechat-relay send --text "Hello from CLI!"
Commands
login
QR code login. Credentials and reply-session tokens are saved in a local JSON session file under your application data directory. They stay available until the server-side session actually expires.
wechat-relay login # use cached or start QR flow
wechat-relay login --force # force new QR login
No browser auto-open β the QR URL is printed directly in your terminal for easy copy/paste.
listen
Runs until Ctrl+C. Logs each inbound message to console and fires your configured hook command asynchronously (non-blocking).
wechat-relay listen
Output:
=== Listening for WeChat Messages ===
Press Ctrl+C to stop.
[14:23:01] seq=42 from=o9cq8...@im.wechat type=1 text="δ½ ε₯½"
[14:23:15] seq=43 from=o9cq8...@im.wechat type=1 text="ε¨εοΌ"
Hook payload (JSON passed to your command):
{
"seq": 42,
"message_id": 7447467781622590088,
"from_user_id": "<user-id>@im.wechat",
"to_user_id": "<bot-id>@im.bot",
"create_time_ms": 1775614686361,
"session_id": "",
"message_type": 1,
"text": "δ½ ε₯½",
"context_token": "AARzJWAFAAABAAAA..."
}
Persistent queue: Messages are written to ~/.wechat-relay/pending-messages.jsonl before hook execution. If the process crashes, pending messages are replayed on next listen.
list-send-to
Show all users you can send messages to.
Currently, it only support to send to itself.
wechat-relay list-send-to
send
Send a text message to a WeChat user.
# Send to default channel (logged-in user)
wechat-relay send --text "Hello!"
# Send to a specific user
wechat-relay send user@im.wechat --text "Hi there"
# Pipe from stdin
echo "piped message" | wechat-relay send
Note: The WeChat ilink API requires a
context_tokenfrom a prior inbound message. Runlistenfirst and have the user message you, thensendwill use the cached token automatically.
Configuration
Edit appsettings.json:
{
"AppSettings": {
"LogPath": "logs/wechat-relay.log",
"Verbose": false
},
"WeChat": {
"BaseUrl": "https://ilinkai.weixin.qq.com/",
"BotType": "3",
"UserId": "your-user@im.wechat",
"ToUsers": "user1@im.wechat,user2@im.wechat"
},
"Hook": {
"Command": "node /path/to/your/hook.js {payload}",
"WorkingDirectory": "/path/to/your/project"
}
}
Hook Examples
Echo (default):
{ "Command": "echo" }
Call a Node.js script:
{ "Command": "node /opt/hooks/wechat.js {payload}" }
Curl to a webhook:
{ "Command": "curl -X POST https://hooks.example.com/wechat -H Content-Type:application/json -d '{payload}'" }
Run a Python script:
{ "Command": "python3 /opt/hooks/handler.py" }
The {payload} placeholder is replaced with the raw JSON. Omit it to pass the JSON as a quoted argument.
Architecture
βββββββββββββββββββββββββββββββββββββββββββββββ
β wechat-relay β
β β
β βββββββββββββ ββββββββββββββββββββββ β
β β listen βββββΆβ Inbound Messages β β
β β (long- β β β β
β β poll) β β ββββ ββββ ββββ β β
β βββββββββββββ β βM1β βM2β βM3β ... β β
β β ββ¬ββ ββ¬ββ ββ¬ββ β β
β βββββΌβββββΌβββββΌβββββββββ β
β β β β β
β βββββββββ β βββββββ β
β βΌ βΌ βΌ β
β ββββββββββββββββββββββββββββββββββββββββ β
β β Persistent Queue (JSONL) β β
β ββββββββββββββββββββ¬ββββββββββββββββββββ β
β β β
β ββββββββΌββββββββ β
β β Hook Runner β β
β βββββββββββΆ β (async) ββββββββββββ β
β β ββββββββββββββββ β β
β β β β
β β cmd: echo / node / curl / python β β
β ββββββββββββββββββββββββββββββββββββββββ β
β β
β ββββββββββββββββββββββββββββββββββββββββ β
β β Local Session Store β β
β β (%APPDATA%/wechat-relay) β β
β β - login credentials β β
β β - reply context tokens β β
β β - session-state.json β β
β ββββββββββββββββββββββββββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββ
Build from Source
git clone https://github.com/slaveoftime/wechat-relay.git
cd wechat-relay/WeChatRelay
# Debug build
dotnet build
# Release build
dotnet build -c Release
# Pack as NuGet tool
dotnet pack -c Release
# Install from local package
dotnet tool install -g --source ./bin/Release/ wechat-relay
# Native AOT (single file, no runtime needed)
dotnet publish -c Release -r win-x64 --self-contained -p:PublishAot=true
dotnet publish -c Release -r linux-x64 --self-contained -p:PublishAot=true
dotnet publish -c Release -r osx-arm64 --self-contained -p:PublishAot=true
License
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
This package has no dependencies.