Quick Start¶
Login¶
A QR code URL will be printed. Scan it with WeChat to authorize.
Credentials are saved to ~/.weilink/token.json and reused on next run.
Receive Messages¶
recv() blocks for up to 35 seconds (long-polling).
Callback Mode¶
Instead of a manual recv() loop, you can register handlers and let the SDK poll for you:
@wl.on_message
def handle(msg):
print(f"{msg.from_user}: {msg.text}")
wl.send(msg.from_user, "Got it!")
wl.run_forever() # blocks until Ctrl+C
Use run_background() if you need the main thread for other work:
Send Messages¶
send() returns False if no context_token is available for the user.
Send Media¶
The unified send() method supports text, images, voice, files, and video:
# Image
wl.send(user, image=img_data)
# Voice
wl.send(user, voice=audio_data)
# File (with filename)
wl.send(user, file=pdf_data, file_name="report.pdf")
# Video
wl.send(user, video=vid_data)
# Text + multiple images
wl.send(user, "Check these photos", image=[img1, img2])
Quoted Messages¶
When a user replies to a previous message, msg.ref_msg contains the quoted content:
for msg in wl.recv():
if msg.ref_msg:
print(f"Replying to: {msg.ref_msg.text}")
print(f"Message: {msg.text}")