npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@zhin.js/adapter-onebot12

v0.0.9

Published

Zhin.js adapter for OneBot 12 protocol

Readme

@zhin.js/adapter-onebot12

Zhin.js OneBot 12 协议适配器,一个适配器支持正向 WebSocket、HTTP Webhook、反向 WebSocket 三种连接方式,由配置项 connection 区分。

功能特性

  • 🔌 OneBot 12 标准 兼容(OneBot Connect + 接口定义)
  • 📦 单一适配器context: onebot12,通过 connection 选择连接方式
  • 🌐 正向 WebSocketconnection: ws):应用连 OneBot 实现的 WS 服务器
  • 📮 HTTP Webhookconnection: webhook):OneBot 实现 POST 事件到应用提供的 path,可选 api_url 用于发消息/撤回
  • 🔄 反向 WebSocketconnection: wss):应用开 WS 服务端,OneBot 实现连上来
  • 🔐 access_token 鉴权(Bearer)
  • 📨 私聊 / 群聊 / 频道消息收发,消息段与 OneBot 12 标准一致

安装

pnpm add @zhin.js/adapter-onebot12 ws

Webhook / 反向 WS 需启用 @zhin.js/http

pnpm add @zhin.js/http

配置

所有 Bot 使用 同一 context:onebot12,通过 connection 区分连接方式。

正向 WebSocket

plugins:
  - "@zhin.js/adapter-onebot12"

bots:
  - context: onebot12
    connection: ws
    name: ob12-bot
    url: "ws://127.0.0.1:6700"
    access_token: "${ONEBOT12_ACCESS_TOKEN}"
    reconnect_interval: 5000
    heartbeat_interval: 30000

HTTP Webhook

OneBot 实现会向你的 path 发送 POST 事件;若需发消息/撤回,请配置实现提供的 HTTP 端点 api_url

plugins:
  - "@zhin.js/http"
  - "@zhin.js/adapter-onebot12"

bots:
  - context: onebot12
    connection: webhook
    name: ob12-webhook-bot
    path: "/onebot12/webhook"
    api_url: "http://127.0.0.1:6700"   # 可选,用于 send_message / delete_message
    access_token: "${ONEBOT12_ACCESS_TOKEN}"

反向 WebSocket

plugins:
  - "@zhin.js/http"
  - "@zhin.js/adapter-onebot12"

bots:
  - context: onebot12
    connection: wss
    name: ob12-wss-bot
    path: "/onebot12/event"
    access_token: "${ONEBOT12_ACCESS_TOKEN}"
    heartbeat_interval: 30000

鉴权

  • Bearer:请求头 Authorization: Bearer <access_token>
  • 正向 WS 在建立连接时通过 HTTP Upgrade 头鉴权;Webhook / 反向 WS 同上

配置 access_token 并与 OneBot 实现端一致即可。

连接方式对比

| connection | 说明 | |------------|------| | ws | 应用连实现的 WebSocket 服务器 | | webhook | 实现 POST 事件到应用 path;发消息需配置 api_url | | wss | 应用开 WS 服务端,实现连上来 |

动作与事件

  • 事件:type(meta/message/notice/request)、detail_typemessage(消息段数组)等,见 事件
  • 动作:send_message(params: detail_type, user_id/group_id/channel_id, message)、delete_message 等,见 动作请求

协议文档