Skip to Content
NNadirv1.0.0

OneBot v11 协议参考

Nadir 支持的 OneBot v11 传输方式、鉴权规则、事件列表、消息段与全部 Action 清单。

Nadir 原生兼容 OneBot v11 协议规范及常用扩展接口,可在单个适配器内同时提供 HTTP、WebSocket 与 Server-Sent Events(SSE)服务。

传输与路径约定

鉴权方式

当对应适配器配置了独立 token(或启用沿用网关令牌)时,服务端按以下顺序提取凭证:

  1. 请求头 Authorization: Bearer <token>
  2. URL Query 参数 ?access_token=<token>

未通过鉴权时,HTTP 返回 401(retcode: 1403),WebSocket 握手拒绝连接。

HTTP & SSE

  • HTTP API 调用:支持 POST /<action>(请求体为参数 JSON)、POST /(标准 { "action": "...", "params": {...}, "echo": "..." })以及 GET /<action>?key=val。
  • HTTP SSE 事件流:GET /_events(MIME 类型 text/event-stream),建连后立即推送一条 meta_event (lifecycle / connect)。

正向与反向 WebSocket

  • 正向 WebSocket(ws_server):
    • /(Universal):同时收发事件与调用 Action
    • /api:仅调用 Action(不主动广播事件与 lifecycle)
    • /event:仅接收事件推送
  • 反向 WebSocket(ws_client):主动连接至框架端 WS 地址,请求头携带 X-Self-ID、X-Client-Role: Universal 及可选 Authorization: Bearer <token>;建连后推送 lifecycle (connect) 并按 heartbeatMs 周期发送心跳事件,断线自动重连。

私聊发送策略(好友优先 + 临时会话自动降级)

调用 send_private_msg(以及 send_msg 指定 message_type: "private" 或仅传 user_id)时:

  • 默认策略:若目标 user_id 为当前账号好友,走标准好友会话;若未在好友列表但可通过 group_id 或近期临时会话上下文定位群来源,则自动降级为**临时会话(Temp Chat)**投递,无需调用方手动区分底层 chatType。

标准消息段支持

Nadir 统一编解码器支持以下 11 类消息段(OneBot 数组段 / CQ 码与标准化段双向映射):

text · face · image · record · video · at · mention · reply · forward · file · json

事件推送清单

上报大类 (post_type)覆盖事件 (notice_type / request_type / sub_type)
message / message_sent好友私聊、临时会话私聊、群消息(含自身消息回传)
meta_eventlifecycle (connect)、heartbeat
requestfriend(好友申请)、group(入群申请 / 邀请)
noticefriend_add、friend_recall、group_recall、group_upload、group_admin、group_ban、group_increase、group_decrease、group_msg_emoji_like、essence、bot_status、bot_offline
notice (notify)poke(私聊/群戳一戳)、profile_like、input_status、group_name、title

已实现 Action 全表

系统与账号凭证

get_version_info · get_status · get_login_info · get_online_clients · can_send_image · can_send_record · get_cookies · get_clientkey · get_csrf_token · get_credentials · clean_cache

好友、陌生人与资料

get_friend_list · get_friends_with_category · get_stranger_info · get_recent_contact · delete_friend · set_qq_profile · set_self_longnick · set_qq_avatar · set_friend_remark · send_like

群列表与群成员管理

get_group_list · get_group_info · get_group_info_ex · get_group_detail_info · get_group_member_list · get_group_member_info · get_group_shut_list · set_group_name · set_group_card · set_group_admin · set_group_ban · set_group_whole_ban · set_group_kick · set_group_leave · set_group_portrait · set_group_remark · get_group_honor_info · get_group_ignore_add_request · send_group_sign

消息收发、合并转发、回应与媒体资源

send_msg · send_group_msg · send_private_msg · send_custom_face · delete_msg · get_msg · get_group_msg_history · get_friend_msg_history · get_forward_msg · send_group_forward_msg · send_private_forward_msg · forward_group_single_msg · forward_friend_single_msg · mark_msg_as_read · mark_group_msg_as_read · mark_private_msg_as_read · _mark_all_as_read · set_msg_emoji_like · set_group_reaction · fetch_custom_face · ocr_image · get_image · get_record · get_file · download_file

群公告、精华与加好友/加群审核

get_group_notice · _get_group_notice · _send_group_notice · _del_group_notice · get_essence_msg_list · set_essence_msg · delete_essence_msg · get_group_system_msg · set_friend_add_request · set_group_add_request

群文件与私聊文件

get_group_file_system_info · get_group_root_files · get_group_files_by_folder · create_group_file_folder · delete_group_folder · delete_group_file_folder · rename_group_file_folder · rename_group_file · move_group_file · delete_group_file · get_group_file_url · upload_group_file · upload_private_file

QQ 空间与群相册扩展

get_qzone_feeds · get_qzone_msg_list · publish_qzone_post · send_qzone_msg · delete_qzone_post · delete_qzone_msg · get_group_album_list · get_qun_album_list · get_group_album_media · get_group_album_media_list · delete_group_album

On this page