wechat-cli-0.1.0 is not a library.
wechat-cli
wechat-cli is a command-line client for the WeChat iLink Bot API.
It supports:
- QR code login
- Listing local accounts
- Waiting for the next incoming message to print
context_token - Sending text, images, and files
Requirements
- Rust
- Access to
https://ilinkai.weixin.qq.com - A WeChat client that can scan the login QR code
Build
Binary:
target/debug/wechat-cli
Quick Start
Login:
List local accounts:
Wait for the next incoming user message and print context_token:
Send a text message:
Send a file:
Send an image:
Send an image or file with a caption:
Commands
login
Default base_url:
https://ilinkai.weixin.qq.com
account list
get-context-token
send
|
Options:
--account <INDEX>--user-id <USER_ID>--token <TOKEN>--base-url <BASE_URL>optional in explicit credential mode--route-tag <ROUTE_TAG>--context-token <CONTEXT_TOKEN>required--text <TEXT>--file <FILE>--caption <CAPTION>
Rules:
--account <index>selects a saved account- if
--accountand--user-idare both omitted, saved account index0is used --tokenswitchessendinto explicit credential mode- in explicit credential mode,
--user-idis required and--base-urldefaults tohttps://ilinkai.weixin.qq.com --textand--fileare mutually exclusive--captioncan only be used with--file- Image files are sent as image messages automatically
- Other files are sent as file messages
Workflow
Recommended flow:
- Run
login - Run
get-context-token --user-id <user_id> - Send one message from the bound WeChat user to the bot
- Copy the printed token
- Run
send --context-token <token>
Example:
IDs
user_idends with@im.wechatbot_idends with@im.bot- Re-login for the same
user_idchanges the boundbot_id - The bot can only send messages to its currently bound
user_id
Message direction:
- user -> bot:
from_user_id = user_id,to_user_id = bot_id - bot -> user:
to_user_id = user_id
Storage
Local files are stored under:
~/.config/wechat-cli/
Main files:
~/.config/wechat-cli/accounts.json
Notes:
accounts.jsonstores all accountscontext_tokenis not stored locallyget_updates_bufis not stored locally- Old storage layouts are not read for compatibility
Limitations
- Sending requires explicitly passing a valid
--context-token - If the server returns
Session expired, you must log in again - The bot cannot proactively message arbitrary users
- Voice and video sending are not supported yet
Help