logo
0
0
WeChat Login

WeChat

简体中文

OpenClaw's WeChat channel plugin, supporting login authorization via QR code scanning.

Prerequisites

OpenClaw must be installed (the openclaw CLI needs to be available).

Quick Install

npx -y @tencent-weixin/openclaw-weixin-cli install

Manual Installation

If the quick install doesn't work, follow these steps manually:

1. Install the plugin

openclaw plugins install "@tencent-weixin/openclaw-weixin"

2. Enable the plugin

openclaw config set plugins.entries.openclaw-weixin.enabled true

3. QR code login

openclaw channels login --channel openclaw-weixin

A QR code will appear in the terminal. Scan it with your phone and confirm the authorization. Once confirmed, the login credentials will be saved locally automatically — no further action is needed.

4. Restart the gateway

openclaw gateway restart

Adding More WeChat Accounts

openclaw channels login --channel openclaw-weixin

Each QR code login creates a new account entry, supporting multiple WeChat accounts online simultaneously.

Multi-Account Context Isolation

By default, all channels share the same AI conversation context. To isolate conversation context for each WeChat account:

openclaw config set agents.mode per-channel-per-peer

This gives each "WeChat account + message sender" combination its own independent AI memory, preventing context cross-talk between accounts.

Backend API Protocol

This plugin communicates with the backend gateway via HTTP JSON API. Developers integrating with their own backend need to implement the following interfaces.

All endpoints use POST with JSON request and response bodies. Common request headers:

HeaderDescription
Content-Typeapplication/json
AuthorizationTypeFixed value ilink_bot_token
AuthorizationBearer <token> (obtained after login)
X-WECHAT-UINBase64-encoded random uint32

Endpoint List

EndpointPathDescription
getUpdatesgetupdatesLong-poll for new messages
sendMessagesendmessageSend a message (text/image/video/file)
getUploadUrlgetuploadurlGet CDN upload pre-signed URL
getConfiggetconfigGet account config (typing ticket, etc.)
sendTypingsendtypingSend/cancel typing status indicator

getUpdates

Long-polling endpoint. The server responds when new messages arrive or on timeout.

Request body:

{ "get_updates_buf": "" }
FieldTypeDescription
get_updates_bufstringSync cursor from the previous response; empty string for the first request

Response body:

{ "ret": 0, "msgs": [...], "get_updates_buf": "<new cursor>", "longpolling_timeout_ms": 35000 }
FieldTypeDescription
retnumberReturn code, 0 = success
errcodenumber?Error code (e.g., -14 = session timeout)
errmsgstring?Error description
msgsWeixinMessage[]Message list (structure below)
get_updates_bufstringNew sync cursor to pass in the next request
longpolling_timeout_msnumber?Server-suggested long-poll timeout for the next request (ms)

sendMessage

Send a message to a user.

Request body:

{ "msg": { "to_user_id": "<target user ID>", "context_token": "<conversation context token>", "item_list": [ { "type": 1, "text_item": { "text": "Hello" } } ] } }

getUploadUrl

Get CDN upload pre-signed parameters. Call this endpoint before uploading a file to obtain upload_param and thumb_upload_param.

Request body:

{ "filekey": "<file identifier>", "media_type": 1, "to_user_id": "<target user ID>", "rawsize": 12345, "rawfilemd5": "<plaintext MD5>", "filesize": 12352, "thumb_rawsize": 1024, "thumb_rawfilemd5": "<thumbnail plaintext MD5>", "thumb_filesize": 1040 }
FieldTypeDescription
media_typenumber1 = IMAGE, 2 = VIDEO, 3 = FILE
rawsizenumberOriginal file plaintext size
rawfilemd5stringOriginal file plaintext MD5
filesizenumberCiphertext size after AES-128-ECB encryption
thumb_rawsizenumber?Thumbnail plaintext size (required for IMAGE/VIDEO)
thumb_rawfilemd5string?Thumbnail plaintext MD5 (required for IMAGE/VIDEO)
thumb_filesizenumber?Thumbnail ciphertext size (required for IMAGE/VIDEO)

Response body:

{ "upload_param": "<original image upload encrypted parameters>", "thumb_upload_param": "<thumbnail upload encrypted parameters>" }

getConfig

Get account configuration, including the typing ticket.

Request body:

{ "ilink_user_id": "<user ID>", "context_token": "<optional, conversation context token>" }

Response body:

{ "ret": 0, "typing_ticket": "<base64-encoded typing ticket>" }

sendTyping

Send or cancel the typing status indicator.

Request body:

{ "ilink_user_id": "<user ID>", "typing_ticket": "<obtained from getConfig>", "status": 1 }
FieldTypeDescription
statusnumber1 = typing, 2 = cancel typing

Message Structure

WeixinMessage

FieldTypeDescription
seqnumber?Message sequence number
message_idnumber?Unique message ID
from_user_idstring?Sender ID
to_user_idstring?Receiver ID
create_time_msnumber?Creation timestamp (ms)
session_idstring?Session ID
message_typenumber?1 = USER, 2 = BOT
message_statenumber?0 = NEW, 1 = GENERATING, 2 = FINISH
item_listMessageItem[]?Message content list
context_tokenstring?Conversation context token, must be passed back when replying

MessageItem

FieldTypeDescription
typenumber1 TEXT, 2 IMAGE, 3 VOICE, 4 FILE, 5 VIDEO
text_item{ text: string }?Text content
image_itemImageItem?Image (with CDN reference and AES key)
voice_itemVoiceItem?Voice (SILK encoded)
file_itemFileItem?File attachment
video_itemVideoItem?Video
ref_msgRefMessage?Referenced message

CDN Media Reference (CDNMedia)

All media types (image/voice/file/video) are transferred via CDN using AES-128-ECB encryption:

FieldTypeDescription
encrypt_query_paramstring?Encrypted parameters for CDN download/upload
aes_keystring?Base64-encoded AES-128 key

CDN Upload Flow

  1. Calculate the file's plaintext size, MD5, and ciphertext size after AES-128-ECB encryption
  2. If a thumbnail is needed (image/video), calculate the thumbnail's plaintext and ciphertext parameters as well
  3. Call getUploadUrl to get upload_param (and thumb_upload_param)
  4. Encrypt the file content with AES-128-ECB and PUT upload to the CDN URL
  5. Encrypt and upload the thumbnail in the same way
  6. Use the returned encrypt_query_param to construct a CDNMedia reference, include it in the MessageItem, and send

For complete type definitions, see src/api/types.ts. For API call implementations, see src/api/api.ts.