OneBot 风格消息载荷与消息段模型
Project description
onebot-protocol
OneBot 通信协议,定义消息收发的公共数据结构。基于 OneBot 11 标准,使用 Pydantic 提供类型安全的模型定义。
MessagePayload(OneBot 11 字段名)
| 字段 | 说明 |
|---|---|
post_type |
事件类型,如 message(可选) |
message_type |
group 或 private |
self_id |
机器人 QQ 号(可选) |
message_id |
消息 ID;空时自动生成 UUID |
user_id |
发送方 QQ;私聊时亦为会话对端 |
group_id |
群号;群聊会话标识 |
message |
消息段列表 |
解析时仍接受旧名别名:source_type→message_type、bot_id→self_id、messages→message、session_id→group_id/user_id。
特性
- 完整的消息段(Message Segment)类型:文本、提及、图片、语音、视频、文件、位置、回复等
- 图片、语音、音频、视频、文件段共用
FileData(name、content、mime_type、size) - 支持 discriminated union,根据
type字段自动解析消息类型
文件载荷 FileData
| 字段 | 说明 |
|---|---|
name |
显示用文件名(可选) |
content |
内容引用,如 URL、平台资源标识或 Base64 等(可选,编码由实现方约定) |
mime_type |
MIME 类型(可选) |
size |
字节大小(可选) |
image / voice / audio / video / file 各段类型的 data 均为对应子类,字段与 FileData 相同。
支持的消息类型
| 类型 | 说明 |
|---|---|
text |
纯文本 |
mention |
@某人 |
mention_all |
@所有人 |
image |
图片 |
voice |
语音 |
audio |
音频 |
video |
视频 |
file |
文件 |
location |
位置 |
reply |
回复 |
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file python_library_onebot_protocol-0.2.0.tar.gz.
File metadata
- Download URL: python_library_onebot_protocol-0.2.0.tar.gz
- Upload date:
- Size: 4.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
243e0caaca4368c570dd322c624c55429942bce90a119c2fbc29af4cb9492695
|
|
| MD5 |
ce0c727fae2f34f0a8d01d682e146a61
|
|
| BLAKE2b-256 |
7f1edd908bdbcd8e966a66b64acd75af9e5aa45f435b7d7b19ccc1f95ec69a76
|
File details
Details for the file python_library_onebot_protocol-0.2.0-py3-none-any.whl.
File metadata
- Download URL: python_library_onebot_protocol-0.2.0-py3-none-any.whl
- Upload date:
- Size: 4.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
beb09c2c22138272f81ad80b9d274228113ab84c587d155ec9a0a74331a03aea
|
|
| MD5 |
34b9993e002484549b3d8b2815898403
|
|
| BLAKE2b-256 |
44734efda93d314217d4843fcaac675d986e3745a8723d7fa0729ff1054919fc
|