Skip to main content

onebot-protocol

OneBot 通信协议,定义消息收发的公共数据结构。基于 OneBot 11 标准,使用 Pydantic 提供类型安全的模型定义。

模块职责:models.py 定义全部公共消息模型与兼容归一化;__init__.py 只导出稳定名称。

MessagePayload(OneBot 11 字段名)

字段 说明
post_type 事件类型,如 message(可选)
message_type groupprivate
self_id 机器人 QQ 号(可选)
message_id 消息 ID;空时自动生成 UUID
user_id 发送方 QQ;私聊时亦为会话对端
group_id 群号;群聊会话标识
message 消息段列表

解析时仍接受旧名别名:source_typemessage_typebot_idself_idmessagesmessagesession_idgroup_id/user_id

特性

  • 消息段类型包含文本、提及、图片、语音、视频、文件、位置、回复和合并转发
  • 图片、语音、音频、视频、文件段共用 FileDatanamecontentmime_typesize
  • 支持 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_idcontentcontent 中每个节点可带 user_idnicknametimemessagemessage 使用相同的消息段模型,因此可以继续包含 forward

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

python_library_onebot_protocol-0.3.0.tar.gz (5.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

File details

Details for the file python_library_onebot_protocol-0.3.0.tar.gz.

File metadata

File hashes

Hashes for python_library_onebot_protocol-0.3.0.tar.gz
Algorithm Hash digest
SHA256 e79d4fb150f7ff7b159329b1880af92546ce4fa1e2cbd9298a61fc7fa2a80bec
MD5 c50d5604fd6a6baa63473be72510e572
BLAKE2b-256 9d8e9a6d90fcf9fa3d77a33f9805598790b0c964958ae8ea0b1eee3ae4b6add6

See more details on using hashes here.

File details

Details for the file python_library_onebot_protocol-0.3.0-py3-none-any.whl.

File metadata

File hashes

Hashes for python_library_onebot_protocol-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3fc6f78f25818ec644f72cc1e1c70d7ef569a985c1c41cd5b609677cfe5e1aad
MD5 fed2bc946f1736d6387358859fc21374
BLAKE2b-256 2b2430a71eb4b3edaa4096b36512e2c6eaaa8a839ff916d38c03f02b0277ee66

See more details on using hashes here.

Release history Release notifications | RSS feed

0.4.0

2 files

This release

0.3.0 This release

2 files

0.2.0

2 files

0.1.2

2 files

0.1.1

2 files

0.1.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page