MessageContext API
MessageContext 用于 handler 回调中的上下文操作。
常用方法:
replyreply_imagereply_videoreply_filesend_typingdownload_media
wechat_bot.context.MessageContext
Convenience wrapper provided to every handler callback.
属性:
| 名称 | 类型 | 描述 |
|---|---|---|
message |
The raw :class: |
|
from_user |
str
|
Sender user ID. |
text |
str
|
Extracted text body (from TEXT or voice-to-text items). |
items |
list[MessageItem]
|
Shortcut for |
account_id |
Bot account ID processing this message. |
context_token: str | None
property
The context_token for this conversation, looked up from storage.
download_media(save_dir: str) -> str | None
async
Download the first media item to save_dir. Returns saved path or None.
reply(text: str) -> None
async
Reply with a text message.
reply_file(file_path: str, caption: str = '') -> None
async
Reply with a file attachment.
reply_image(file_path: str, caption: str = '') -> None
async
Reply with an image (optionally with a text caption).
reply_video(file_path: str, caption: str = '') -> None
async
Reply with a video.
send_typing() -> None
async
Send a typing indicator to the conversation partner.
The underlying get_config lookup is short-lived cached by client,
so repeated calls in one conversation avoid redundant network fetches.