Skip to Content
NNadirv1.0.0

生态框架接入指南

在 NoneBot2、Koishi、反向 WebSocket 与 HTTP Webhook 中接入 Nadir。

你可以先在 Nadir 的 Web Dashboard(http://127.0.0.1:3020/)中创建或启用对应协议适配器,再从面板直接复制自动填好端口与 Token 的配置片段,也可参考下方标准配置。

NoneBot2 接入

1. OneBot v11(推荐反向或正向 WebSocket)

在 NoneBot2 项目的 .env 中配置 nonebot-adapter-onebot:

DRIVER=~fastapi+~websockets

# 若使用 Nadir 正向 WS Server(默认 3001)
ONEBOT_WS_URLS=["ws://127.0.0.1:3001/"]
ONEBOT_ACCESS_TOKEN=你的适配器Token

# 或使用 Nadir Reverse WS Client 主动连入 NoneBot2
# ONEBOT_ACCESS_TOKEN=你的适配器Token

若使用 OneBot v11 HTTP 模式:

ONEBOT_API_ROOTS={"<BotQQ号>": "http://127.0.0.1:3000/"}
ONEBOT_ACCESS_TOKEN=你的适配器Token

2. Milky(nonebot-adapter-milky)

在 Nadir Dashboard 启用 Milky 适配器(默认端口 3002)并配置 token 后,在 .env 中填入:

DRIVER=~fastapi+~httpx+~websockets
MILKY_CLIENTS=[
  {
    "host": "127.0.0.1",
    "port": 3002,
    "use_tls": false,
    "access_token": "你的适配器Token"
  }
]

Koishi 接入

安装 @koishijs/plugin-adapter-onebot,在配置文件 koishi.yml 中选择 ws(正向 WS) 或 ws-reverse(反向 WS):

plugins:
  adapter-onebot:
    protocol: ws
    endpoint: ws://127.0.0.1:3001/
    token: 你的适配器Token

如果使用 ws-reverse,则在 Nadir Dashboard 添加一条类型为 ws_client 的 OneBot 适配器,将目标 URL 设为 Koishi 暴露的 ws://127.0.0.1:5140/onebot 即可。

HTTP Webhook 与 HMAC-SHA1 签名校验

当你创建一个类型为 http_client 的适配器并填入了 secret 时,Nadir 每次 POST 推送事件都会附加以下请求头:

  • Content-Type: application/json; charset=utf-8
  • User-Agent: Nadir/1.0
  • X-Self-ID: <当前BotQQ号>
  • Authorization: Bearer <adapter.token>(若配置了 token)
  • X-Signature: sha1=<hmac_sha1_hex>(若配置了 secret)

Node.js 接收端验证签名示例:

import crypto from 'node:crypto';

export function verifyNadirSignature(rawBody, signatureHeader, secret) {
  if (!secret || !signatureHeader) return false;
  const expected = 'sha1=' + crypto.createHmac('sha1', secret).update(rawBody).digest('hex');
  const a = Buffer.from(expected, 'utf8');
  const b = Buffer.from(String(signatureHeader), 'utf8');
  return a.length === b.length && crypto.timingSafeEqual(a, b);
}

On this page