Skip to content

systemxlabs/wechat-cli

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

69 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

wechat-cli

License Crates.io

A CLI tool to interact with a Wechat iLink bot.

Features

  • Interactive QR code login for human
  • Non-interactive QR code retrieval and status polling for agents
  • Manage multi accounts
  • Get context_token
  • Send text, images, and files to WeChat users

Installation

cargo install wechat-cli

Usage

Usage: wechat-cli <COMMAND>

Commands:
  login              Log in with a QR code and save the account locally
  qrcode             Request a login QR code and print it as JSON without saving anything locally
  qrcode-status      Query a login QR code status and print it as JSON without saving anything locally
  account            Inspect saved accounts
  get-context-token  Wait for the next inbound message and print its context token
  send               Send a text, image, or file message
  help               Print this message or the help of the given subcommand(s)

Options:
  -h, --help  Print helpt-cli [COMMAND]

Login

Interactive QR code login:

wechat-cli login

Non-interactive QR code workflow for agents:

# Request a QR code
wechat-cli qrcode

# Poll QR code status
wechat-cli qrcode-status --qrcode-id <qrcode_id>

Account

List saved accounts:

wechat-cli account list

Add a new account:

wechat-cli account add \
  --user-id <user_id> \
  --bot-token <bot_token> \
  [--route-tag <route_tag>]

Delete an account by index:

wechat-cli account delete --account <index>

Get Context Token

Wait for the next incoming message and print the context_token.

Using a saved account:

wechat-cli get-context-token --account <index>

Using explicit credentials:

wechat-cli get-context-token \
  --bot-token <bot_token> \
  --user-id <user_id> \
  [--route-tag <route_tag>]

Send

Send a text message using a saved account:

wechat-cli send \
  --account <index> \
  --context-token <token> \
  --text "hello"

Send text from stdin (pipe):

echo "hello from pipe" | wechat-cli send \
  --account <index> \
  --context-token <token>

Send text from a file via stdin redirection:

wechat-cli send \
  --account <index> \
  --context-token <token> \
  < message.txt

Send an image using a saved account:

wechat-cli send \
  --account <index> \
  --context-token <token> \
  --file ./image.png

Send a file with caption using a saved account:

wechat-cli send \
  --account <index> \
  --context-token <token> \
  --file ./image.png \
  --caption "this is an image"

Use explicit credentials (without saved account):

wechat-cli send \
  --bot-token <bot_token> \
  --user-id <user_id> \
  --context-token <token> \
  [--route-tag <route_tag>] \
  --text "hello"

Message Source Priority

When sending, the CLI resolves the message source in this order:

  1. If --text is provided, it is used regardless of stdin.
  2. If --file is provided, it is used regardless of stdin.
  3. If neither --text nor --file is provided, stdin is read when it is a pipe or redirected file.
  4. If stdin is an interactive terminal and neither --text nor --file is provided, an error is returned.

Storage

Local files are stored under:

~/.config/wechat-cli/

Main file:

~/.config/wechat-cli/accounts.json

About

A CLI tool to interact with a Wechat iLink bot.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages