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

@imhelper/onebot-v11

v1.0.0

Published

OneBot V11 协议客户端 SDK

Readme

@imhelper/onebot-v11

OneBot V11 协议客户端 SDK,提供快速连接和消息收发功能。

功能特性

  • ✅ HTTP API 调用(发送消息、获取信息等)
  • ✅ WebSocket 事件接收
  • ✅ Webhook 事件接收
  • ✅ SSE 事件接收(浏览器环境)
  • ✅ 自动重连机制
  • ✅ TypeScript 支持

安装

npm install @imhelper/onebot-v11
# 或
pnpm add @imhelper/onebot-v11

使用示例

WebSocket 模式(推荐)

import { OneBotV11Client } from '@imhelper/onebot-v11';

const client = new OneBotV11Client({
  baseUrl: 'http://localhost:6727',
  platform: 'kook',
  accountId: 'zhin',
  accessToken: 'your_token',
  receiveMode: 'websocket', // 默认
});

// 监听事件
client.onEvent((event) => {
  if (event.post_type === 'message') {
    console.log('收到消息:', event);
  }
});

// 连接
await client.connect();

// 发送私聊消息
await client.sendPrivateMsg(123456, 'Hello!');

// 发送群消息
await client.sendGroupMsg(789012, 'Hello Group!');

Webhook 模式

const client = new OneBotV11Client({
  baseUrl: 'http://localhost:6727',
  platform: 'kook',
  accountId: 'zhin',
  receiveMode: 'webhook',
  webhookPort: 8080, // Webhook 服务器端口
});

await client.connect();
// 现在客户端会在 http://localhost:8080/onebot/v11 接收事件

SSE 模式(浏览器环境)

const client = new OneBotV11Client({
  baseUrl: 'http://localhost:6727',
  platform: 'kook',
  accountId: 'zhin',
  receiveMode: 'sse',
});

await client.connect();

API

构造函数

new OneBotV11Client(config: OneBotV11ClientConfig)

配置选项

  • baseUrl: 服务器地址(必需)
  • platform: 平台标识(必需)
  • accountId: 账号ID(必需)
  • accessToken: 访问令牌(可选)
  • receiveMode: 接收方式,可选值:'websocket' | 'webhook' | 'sse'(默认:'websocket'
  • webhookUrl: Webhook 接收地址(webhook 模式)
  • webhookPort: Webhook 端口(webhook 模式,默认:8080)

方法

连接和断开

  • connect(): 连接并开始接收事件
  • disconnect(): 断开连接
  • onEvent(handler): 监听事件

消息 API

  • sendPrivateMsg(userId, message): 发送私聊消息
  • sendGroupMsg(groupId, message): 发送群消息
  • deleteMsg(messageId): 撤回消息
  • getMsg(messageId): 获取消息

用户和群组 API

  • getLoginInfo(): 获取登录信息
  • getUserInfo(userId, noCache?): 获取用户信息
  • getFriendList(): 获取好友列表
  • getGroupInfo(groupId, noCache?): 获取群信息
  • getGroupList(): 获取群列表
  • getGroupMemberInfo(groupId, userId, noCache?): 获取群成员信息
  • getGroupMemberList(groupId): 获取群成员列表

自定义 API

  • call(action, params?): 调用自定义 API

事件类型

事件对象遵循 OneBot V11 标准:

interface OneBotV11Event {
  post_type: 'message' | 'notice' | 'request' | 'meta_event';
  message_type?: 'private' | 'group';
  time: number;
  self_id: number;
  // ... 其他字段
}

License

MIT