数据模型¶
weilink.MessageType
¶
Bases: IntEnum
iLink message content types.
weilink.Message
dataclass
¶
A received WeChat message.
Attributes:
| Name | Type | Description |
|---|---|---|
from_user |
str
|
Sender identifier (xxx@im.wechat). |
msg_type |
MessageType
|
Content type (TEXT, IMAGE, VOICE, FILE, VIDEO). |
text |
str | None
|
Text content, if any. |
image |
ImageInfo | None
|
Image metadata, if msg_type is IMAGE. |
voice |
VoiceInfo | None
|
Voice metadata, if msg_type is VOICE. |
file |
FileInfo | None
|
File metadata, if msg_type is FILE. |
video |
VideoInfo | None
|
Video metadata, if msg_type is VIDEO. |
timestamp |
int
|
Creation time in milliseconds. |
message_id |
int | None
|
Unique message identifier. |
context_token |
str
|
Opaque token required for replying (managed internally). |
ref_msg |
RefMessage | None
|
Quoted/referenced message, if this is a reply. |
to_dict()
¶
Convert to a JSON-friendly dict.
weilink.RefMessage
dataclass
¶
A quoted / referenced message embedded in a received message.
When a WeChat user replies to (quotes) a previous message, the quoted content is available here. Only content fields are present — the protocol does not expose sender, timestamp, or message-id for the referenced message.
Attributes:
| Name | Type | Description |
|---|---|---|
msg_type |
MessageType
|
Content type of the referenced message. |
text |
str | None
|
Text content, if msg_type is TEXT. |
image |
ImageInfo | None
|
Image metadata, if msg_type is IMAGE. |
voice |
VoiceInfo | None
|
Voice metadata, if msg_type is VOICE. |
file |
FileInfo | None
|
File metadata, if msg_type is FILE. |
video |
VideoInfo | None
|
Video metadata, if msg_type is VIDEO. |
to_dict()
¶
Convert to a JSON-friendly dict.
weilink.BotInfo
dataclass
¶
Bot credentials obtained after QR code login.
Attributes:
| Name | Type | Description |
|---|---|---|
bot_id |
str
|
Bot identifier (xxx@im.bot). |
base_url |
str
|
iLink API base URL. |
token |
str
|
Bearer token for authentication. |
user_id |
str
|
WeChat user ID that authorized the bot (xxx@im.wechat). |
weilink.MediaInfo
dataclass
¶
CDN media reference for encrypted files.
Attributes:
| Name | Type | Description |
|---|---|---|
encrypt_query_param |
str
|
CDN download query parameter. |
aes_key |
str
|
AES-128-ECB key (hex or base64 encoded). |
encrypt_type |
int
|
Encryption type identifier (typically 1). |
full_url |
str
|
Direct CDN URL (when provided by server, bypasses URL construction from encrypt_query_param). |
weilink.ImageInfo
dataclass
¶
Image metadata from a received message.
Attributes:
| Name | Type | Description |
|---|---|---|
media |
MediaInfo
|
CDN media reference for the full-size image. |
url |
str
|
Direct image URL (may be empty). |
thumb_width |
int
|
Thumbnail width in pixels. |
thumb_height |
int
|
Thumbnail height in pixels. |
mid_size |
int
|
Medium-quality image size in bytes. |
thumb_size |
int
|
Thumbnail image size in bytes. |
hd_size |
int
|
HD image cipher size in bytes. |
weilink.VoiceInfo
dataclass
¶
Voice message metadata from a received message.
Attributes:
| Name | Type | Description |
|---|---|---|
media |
MediaInfo
|
CDN media reference for the voice file. |
playtime |
int
|
Duration in milliseconds. |
text |
str
|
Voice-to-text transcription (may be empty). |
encode_type |
int
|
Audio codec (1=pcm, 2=adpcm, 4=speex, 5=amr, 6=silk, 7=mp3). |
bits_per_sample |
int
|
Bit depth. |
sample_rate |
int
|
Sample rate in Hz. |
weilink.VideoInfo
dataclass
¶
Video metadata from a received message.
Attributes:
| Name | Type | Description |
|---|---|---|
media |
MediaInfo
|
CDN media reference for the video. |
play_length |
int
|
Duration in seconds. |
video_md5 |
str
|
Video file MD5 checksum. |
thumb_width |
int
|
Thumbnail width in pixels. |
thumb_height |
int
|
Thumbnail height in pixels. |
thumb_media |
MediaInfo | None
|
CDN media reference for the video thumbnail. |
video_size |
int
|
Video file size in bytes. |
thumb_size |
int
|
Thumbnail image size in bytes. |
weilink.FileInfo
dataclass
¶
File attachment metadata from a received message.
Attributes:
| Name | Type | Description |
|---|---|---|
media |
MediaInfo
|
CDN media reference for the file. |
file_name |
str
|
Original file name. |
file_size |
str
|
File size as string. |
md5 |
str
|
File MD5 checksum. |
weilink.MediaContent = Union[bytes, UploadedMedia, list[Union[bytes, UploadedMedia]]]
module-attribute
¶
weilink.UploadedMedia
dataclass
¶
Result of a CDN media pre-upload via WeiLink.upload().
Pass this object to WeiLink.send() instead of raw bytes to reuse
a previously uploaded file without re-uploading.
Attributes:
| Name | Type | Description |
|---|---|---|
media_type |
UploadMediaType
|
The media type used for this upload. |
filekey |
str
|
Random hex filekey used for this upload. |
download_param |
str
|
CDN download parameter (x-encrypted-param header). |
aes_key_hex |
str
|
Hex-encoded AES key used for encryption. |
file_size |
int
|
Original plaintext file size. |
cipher_size |
int
|
Encrypted file size. |
file_name |
str
|
Original file name (for files only). |
weilink.SendResult
dataclass
¶
Result of a WeiLink.send() call.
Evaluates to True / False based on :attr:success, so
if wl.send(...) continues to work as before.
Attributes:
| Name | Type | Description |
|---|---|---|
success |
bool
|
Whether all sends succeeded. |
messages |
list[Message]
|
Messages received during auto-recv (empty when
|
remaining |
int | None
|
Number of outbound messages still available on the
current context_token (out of 10). |