wechat-relay 0.0.2

There is a newer version of this package available.
See the version list below for details.
dotnet tool install --global wechat-relay --version 0.0.2
                    
This package contains a .NET tool you can call from the shell/command line.
dotnet new tool-manifest
                    
if you are setting up this repo
dotnet tool install --local wechat-relay --version 0.0.2
                    
This package contains a .NET tool you can call from the shell/command line.
#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.

CI NuGet MIT dotnet tool

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_token from a prior inbound message. Run listen first and have the user message you, then send will 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

MIT

Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

Version Downloads Last Updated
0.1.1 194 7/9/2026
0.1.0 148 4/9/2026
0.0.2 128 4/9/2026