onebot-protocol
OneBot 通信协议,定义消息收发的公共数据结构。基于 OneBot 11 标准,使用 Pydantic 提供类型安全的模型定义。
模块职责:models.py 定义全部公共消息模型与兼容归一化;__init__.py 只导出稳定名称。
MessagePayload(OneBot 11 字段名)
| 字段 | 说明 |
|---|---|
post_type |
事件类型,如 message(可选) |
message_type |
group 或 private |
self_id |
机器人 QQ 号(可选) |
message_id |
消息 ID;空时自动生成 UUID |
user_id |
发送方 QQ;私聊时亦为会话对端 |
sender_name |
发送方显示名;群聊优先使用群名片(可选) |
timestamp |
平台消息 Unix 时间戳(可选) |
mentioned_self |
群消息是否明确 @ 当前机器人;null 表示旧 Adapter 未提供 |
group_id |
群号;群聊会话标识 |
message |
消息段列表 |
解析时仍接受旧名别名:source_type→message_type、bot_id→self_id、messages→message、session_id→group_id/user_id。
Adapter 应无损上报消息,并用 mentioned_self 传递寻址事实;是否触发回复由宿主业务层决定,不属于协议模型的过滤职责。
特性
- 消息段类型包含文本、提及、图片、语音、视频、文件、位置、回复和合并转发
- 图片、语音、音频、视频、文件段共用
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 |
回复 |
forward |
合并转发;节点可包含嵌套消息段 |
合并转发
forward.data 包含 message_id 和 content。content 中每个节点可带 user_id、nickname、time 与 message;message 使用相同的消息段模型,因此可以继续包含 forward。
Metadata
Release files for python-library-onebot-protocol 0.4.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| python_library_onebot_protocol-0.4.0.tar.gz | 5.3 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| python_library_onebot_protocol-0.4.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 10.6 kB
Release files / python_library_onebot_protocol-0.4.0.tar.gz
| Download URL | python_library_onebot_protocol-0.4.0.tar.gz |
|---|---|
| Size | 5.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
17d9b580adedb0465c797597896e5164db7a63e6df43910e05609c8087bb4f4c
|
|
BLAKE2b-256 checksum How to use checksums |
98b06c05cee1e87b07bdd162018158cf2b66ec77450944a68e3a6ffd575328bc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.6
|
Release files / python_library_onebot_protocol-0.4.0-py3-none-any.whl
| Download URL | python_library_onebot_protocol-0.4.0-py3-none-any.whl |
|---|---|
| Size | 5.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5518ce3efc6525e1937d97a7cead314be91d7e5dcf37bd17d2f31e8efee1d6c0
|
|
BLAKE2b-256 checksum How to use checksums |
42eda566679398b66c80205cbb525a19bba8879edb61f0b959f2dd322601e179
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.6
|
Security for python-library-onebot-protocol 0.4.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.