@tencent-connect/qqbot-nodejs 1.0.4 → 1.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. package/CHANGELOG.md +114 -0
  2. package/LICENSE +21 -0
  3. package/README.md +181 -86
  4. package/README.zh-CN.md +293 -0
  5. package/USAGE.md +80 -27
  6. package/assets/docs/feedback.jpg +0 -0
  7. package/assets/docs/qqchannel.jpg +0 -0
  8. package/dist/QQBot.d.ts +66 -3
  9. package/dist/QQBot.d.ts.map +1 -1
  10. package/dist/QQBot.js +144 -33
  11. package/dist/QQBot.js.map +1 -1
  12. package/dist/index.d.ts +4 -1
  13. package/dist/index.d.ts.map +1 -1
  14. package/dist/index.js +2 -0
  15. package/dist/index.js.map +1 -1
  16. package/dist/protocol/api/token.d.ts.map +1 -1
  17. package/dist/protocol/api/token.js +6 -2
  18. package/dist/protocol/api/token.js.map +1 -1
  19. package/dist/protocol/gateway/constants.d.ts +6 -1
  20. package/dist/protocol/gateway/constants.d.ts.map +1 -1
  21. package/dist/protocol/gateway/constants.js +6 -1
  22. package/dist/protocol/gateway/constants.js.map +1 -1
  23. package/dist/protocol/gateway/errors.d.ts +22 -0
  24. package/dist/protocol/gateway/errors.d.ts.map +1 -0
  25. package/dist/protocol/gateway/errors.js +24 -0
  26. package/dist/protocol/gateway/errors.js.map +1 -0
  27. package/dist/protocol/gateway/event-dispatcher.d.ts +22 -0
  28. package/dist/protocol/gateway/event-dispatcher.d.ts.map +1 -1
  29. package/dist/protocol/gateway/event-dispatcher.js +17 -0
  30. package/dist/protocol/gateway/event-dispatcher.js.map +1 -1
  31. package/dist/protocol/gateway/gateway-connection.d.ts +69 -4
  32. package/dist/protocol/gateway/gateway-connection.d.ts.map +1 -1
  33. package/dist/protocol/gateway/gateway-connection.js +349 -146
  34. package/dist/protocol/gateway/gateway-connection.js.map +1 -1
  35. package/dist/protocol/gateway/reconnect.d.ts +24 -1
  36. package/dist/protocol/gateway/reconnect.d.ts.map +1 -1
  37. package/dist/protocol/gateway/reconnect.js +56 -9
  38. package/dist/protocol/gateway/reconnect.js.map +1 -1
  39. package/dist/protocol/index.d.ts +5 -4
  40. package/dist/protocol/index.d.ts.map +1 -1
  41. package/dist/protocol/index.js +3 -2
  42. package/dist/protocol/index.js.map +1 -1
  43. package/dist/protocol/types.d.ts +49 -10
  44. package/dist/protocol/types.d.ts.map +1 -1
  45. package/dist/protocol/types.js.map +1 -1
  46. package/dist/protocol/utils/file-utils.d.ts +2 -2
  47. package/dist/protocol/utils/file-utils.js +2 -2
  48. package/dist/protocol/utils/image-size.d.ts +3 -3
  49. package/dist/protocol/utils/image-size.js +3 -3
  50. package/dist/protocol/utils/ref-index-store.d.ts +1 -1
  51. package/dist/protocol/utils/ref-index-store.js +1 -1
  52. package/package.json +24 -7
  53. package/src/QQBot.ts +173 -36
  54. package/src/index.ts +6 -0
  55. package/src/protocol/api/token.ts +6 -2
  56. package/src/protocol/gateway/constants.ts +6 -1
  57. package/src/protocol/gateway/errors.ts +32 -0
  58. package/src/protocol/gateway/event-dispatcher.ts +41 -0
  59. package/src/protocol/gateway/gateway-connection.ts +389 -160
  60. package/src/protocol/gateway/reconnect.ts +76 -10
  61. package/src/protocol/index.ts +11 -1
  62. package/src/protocol/types.ts +46 -10
  63. package/src/protocol/utils/file-utils.ts +2 -2
  64. package/src/protocol/utils/image-size.ts +3 -3
  65. package/src/protocol/utils/ref-index-store.ts +1 -1
package/CHANGELOG.md ADDED
@@ -0,0 +1,114 @@
1
+ # 1.0.6 (unreleased)
2
+
3
+ ### Features
4
+
5
+ * **sdk:** new `bot.connectionState` and `connection` event — read or watch the connection state without combining individual events
6
+ * **sdk:** new `bot.ping` and `bot.lastHeartbeatAt`
7
+ * **sdk:** message events expose a normalized `msg.author` object with the sender avatar; flat sender fields are deprecated, and unmapped author fields stay readable without `as any`
8
+ * **gateway:** dead connections are detected and reconnected instead of hanging
9
+ * **gateway:** a server-requested reconnect resumes the previous session and replays messages missed while offline
10
+
11
+ ### Bug Fixes
12
+
13
+ * **gateway:** a server-requested reconnect no longer drops the session, which could lose messages received while offline
14
+
15
+ ### Behavior changes
16
+
17
+ * `ConnectionState` gains `resuming` and `QQBotEventMap` gains `connection`; exhaustive switches need updating
18
+
19
+ # 1.0.5 (2026-10-12)
20
+
21
+ ### Features
22
+
23
+ * **gateway:** startup now fails fast with a clear reason when the connection can't be established, instead of waiting forever
24
+ * **gateway:** new `disconnected` event reports why the connection dropped and whether the SDK will recover on its own
25
+ * **gateway:** reconnects are now configurable — cap the attempts and tune the backoff; unrecoverable cases (banned bot, sandbox-only account) are reported once and explicitly
26
+ * **sdk:** `bot.getCredentials()` exposes the configured credentials for calling the lower-level APIs directly
27
+
28
+ ### Bug Fixes
29
+
30
+ * **gateway:** retries are no longer reset by a connection that is accepted then immediately rejected, so a misconfigured bot can't spin in a tight reconnect loop
31
+ * **gateway:** fixed several issues that could stall or misjudge the connection: an exception in your own handler, a silently dropped handshake, and a platform-requested reconnect treated as permanent
32
+ * **token:** restarting the bot no longer cancels the token refresh belonging to the new session
33
+
34
+ ### Behavior changes
35
+
36
+ * The SDK now keeps retrying until the failure is clearly unrecoverable (previously it gave up after 100 attempts). Set `reconnect.maxAttempts` for a hard cap.
37
+
38
+ ## 1.0.4 (2026-07-14)
39
+
40
+ ### Bug Fixes
41
+
42
+ * **token:** fetching an access token now times out, and failures report the HTTP status and server response instead of a generic error
43
+ * **token:** fixed edge cases that could leave token refresh stuck or log a crash that never happened
44
+
45
+ ## 1.0.3 (2026-07-13)
46
+
47
+
48
+ ### Features
49
+
50
+ * **sdk:** add universal send(), API gateway, rawEvent, and P1 messaging capabilities
51
+ * **media:** auto-fill fileName from localPath/URL in uploadMedia
52
+ * **media:** pre-check fileData size before upload
53
+ * **middleware:** concurrency-guard merge support
54
+ * **middleware:** enhance types & buffered reply
55
+ * **concurrency:** add maxProcessingMs timeout with abort
56
+ * **concurrency:** add urgentPredicate for priority flush
57
+ * **quote-ref:** prefer msg_elements over stored entry
58
+ * **quote-ref:** add enrichEntry & extend entry
59
+ * **api:** support data in acknowledge interaction
60
+ * **sanitizer:** support new face tag format
61
+ * **slash:** add per-command authorized check
62
+ * export webhook transport types
63
+ * update mention-gate
64
+
65
+
66
+ ### Bug Fixes
67
+
68
+ * **slash:** check rawEventType for group @bot detection
69
+ * **media:** use raw https for COS chunked upload
70
+ * **media:** pass Uint8Array directly to fetch body
71
+ * **middleware:** refine mention-gate logic
72
+
73
+
74
+ ## 1.0.2 (2026-06-10)
75
+
76
+
77
+ ### Features
78
+
79
+ * **qqbot:** support tokenPrefetch option for sync/async token initialization
80
+
81
+
82
+ ## 1.0.1 (2026-05-20)
83
+
84
+
85
+ ### Features
86
+
87
+ * **middleware:** add concurrencyGuard for per-target serial processing
88
+ * **middleware:** add ctx.abort() and ctx.signal for async cancellation
89
+ * **middleware:** add typing keepalive to typingIndicator
90
+ * **middleware:** add receivedAt to MiddlewareContext for latency measurement
91
+ * **concurrency:** add merge strategy with dependency-inverted dispatch
92
+ * **slash:** add allowFrom option for command access control
93
+ * **event:** expose messageScene on C2C inbound messages
94
+ * **transport:** add webhook example and update readme
95
+ * dataflow middleware pipeline
96
+ * check slash scope
97
+
98
+
99
+ ### Bug Fixes
100
+
101
+ * **webhook:** async dispatch to prevent ACK timeout on long-running handlers
102
+ * **webhook:** log full event payload in dispatch debug output
103
+ * **stream:** ensure DONE frame is sent even when flush is in progress
104
+ * **streaming:** catch throttle flush error to prevent unhandledRejection
105
+ * **streaming:** fix rate-limit retry storm in flush
106
+ * **concurrency-guard:** evict queued waiters on abort to prevent stale replies
107
+
108
+
109
+ # 1.0.0 (2026-04-30)
110
+
111
+
112
+ ### Features
113
+
114
+ * initialize QQ Open Platform Node.js SDK
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Tencent
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,18 +1,46 @@
1
1
  # @tencent-connect/qqbot-nodejs
2
2
 
3
- Tencent QQ Open Platform Node.js SDK。提供与 QQ 机器人开放平台对接所需的全部
4
- 协议层能力:HTTP REST、WebSocket / Webhook 双传输、Koa-style 中间件管线、
5
- 消息收发、媒体上传(含大文件分块)、C2C 流式消息(stream_messages)。
3
+ > **English** (this file) · [简体中文](./README.zh-CN.md)
6
4
 
7
- ## 安装
5
+ [![npm version](https://img.shields.io/npm/v/@tencent-connect/qqbot-nodejs.svg)](https://www.npmjs.com/package/@tencent-connect/qqbot-nodejs)
6
+ [![CI](https://github.com/tencent-connect/qqbot-nodejs/actions/workflows/ci.yml/badge.svg)](https://github.com/tencent-connect/qqbot-nodejs/actions/workflows/ci.yml)
7
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](./LICENSE)
8
+ [![Node.js Version](https://img.shields.io/node/v/@tencent-connect/qqbot-nodejs.svg)](https://nodejs.org)
9
+
10
+ Tencent QQ Open Platform Node.js SDK. Provides every protocol-layer capability
11
+ needed to integrate with the QQ Bot Open Platform: HTTP REST, dual WebSocket /
12
+ Webhook transport, a Koa-style middleware pipeline, messaging, media upload
13
+ (including chunked upload for large files), and C2C streaming messages
14
+ (`stream_messages`).
15
+
16
+ ## Resources & community
17
+
18
+ - **[Official QQ Bot platform docs](https://bot.q.qq.com/wiki/develop/api-v2/)** —
19
+ first-hand API, event and error-code definitions (in Chinese).
20
+
21
+ Scan to add the feedback assistant bot / join the developer channel:
22
+
23
+ <table align="center">
24
+ <tr>
25
+ <td align="center" width="50%"><img src="./assets/docs/feedback.jpg" height="360" alt="Feedback assistant QR code" /><br /><b>Feedback Assistant</b><br /><sub>Official QQ Bot platform assistant · Support hours: weekdays 10:00–20:00</sub></td>
26
+ <td align="center" width="50%"><img src="./assets/docs/qqchannel.jpg" height="360" alt="QQ channel QR code" /><br /><b>QQ Developer Community Channel</b><br /><sub>Channel ID: 20dnumts4z</sub></td>
27
+ </tr>
28
+ </table>
29
+
30
+ ## Requirements
31
+
32
+ - Node.js **>= 20** (uses global `fetch` / `AbortController`)
33
+ - Pure ESM (`"type": "module"`); CJS consumers should use dynamic `import()`
34
+
35
+ ## Install
8
36
 
9
37
  ```bash
10
38
  pnpm add @tencent-connect/qqbot-nodejs
11
- # 或
39
+ # or
12
40
  npm install @tencent-connect/qqbot-nodejs
13
41
  ```
14
42
 
15
- ## 快速开始
43
+ ## Quick Start
16
44
 
17
45
  ```ts
18
46
  import { QQBot } from "@tencent-connect/qqbot-nodejs";
@@ -24,32 +52,36 @@ const bot = new QQBot({
24
52
  });
25
53
 
26
54
  bot.on("message", async (ctx, msg) => {
27
- // ctx — Koa-style MiddlewareContext,携带 middleware 注入的数据
55
+ // ctx — Koa-style MiddlewareContext carrying data injected by middleware
28
56
  await bot.sendText(msg.replyTarget, `Echo: ${msg.content}`);
29
57
  });
30
58
 
31
59
  await bot.start();
32
60
  ```
33
61
 
34
- 参考 [examples/](./examples/) 下的完整示例:
62
+ See the complete examples under [examples/](./examples/):
35
63
 
36
- | 示例 | 说明 |
64
+ | Example | Description |
37
65
  |------|------|
38
- | [playground](./examples/playground/) | 核心能力演示(文本、流式、媒体、命令) |
39
- | [middleware](./examples/middleware/) | 完整 14 层 Koa-style 中间件管线 |
40
- | [webhook](./examples/webhook/) | Webhook(HTTP 回调)传输模式 |
41
- | [send-plain-100](./examples/send-plain-100/) | 普通文本发送对照实验 |
42
- | [send-streaming-100](./examples/send-streaming-100/) | 流式消息发送对照实验 |
66
+ | [playground](./examples/playground/) | Core capabilities demo (text, streaming, media, commands) |
67
+ | [middleware](./examples/middleware/) | Full 13-layer Koa-style middleware pipeline |
68
+ | [webhook](./examples/webhook/) | Webhook (HTTP callback) transport |
69
+ | [send-plain-100](./examples/send-plain-100/) | Plain-text send baseline |
70
+ | [send-streaming-100](./examples/send-streaming-100/) | Streaming-message send baseline |
43
71
 
44
- ## 主要能力
72
+ > Examples read `QQBOT_APP_ID` / `QQBOT_APP_SECRET` from `process.env` **only
73
+ > for demo convenience**. The SDK itself never reads environment variables —
74
+ > credentials are always injected via `new QQBot({ appId, appSecret })`.
45
75
 
46
- ### 1. 双传输模式(WebSocket / Webhook)
76
+ ## Features
77
+
78
+ ### 1. Dual transport (WebSocket / Webhook)
47
79
 
48
80
  ```ts
49
- // WebSocket(默认)— 长连接 + 心跳 + RESUME
81
+ // WebSocket (default) — long-lived connection + heartbeat + RESUME
50
82
  const bot = new QQBot({ appId, appSecret });
51
83
 
52
- // Webhook — HTTP 回调,适合 Serverless / 水平扩展
84
+ // Webhook — HTTP callback, suited to Serverless / horizontal scaling
53
85
  const bot = new QQBot({
54
86
  appId, appSecret,
55
87
  transport: "webhook",
@@ -57,11 +89,12 @@ const bot = new QQBot({
57
89
  });
58
90
  ```
59
91
 
60
- 两种模式下中间件、事件监听、消息发送 API 完全一致。
92
+ Middleware, event listeners and send APIs are identical in both modes.
61
93
 
62
- ### 2. Koa-style 中间件
94
+ ### 2. Koa-style middleware
63
95
 
64
- SDK 采用洋葱模型中间件,`bot.on("message")` 作为 chain 最内层 downstream:
96
+ The SDK uses an onion-model middleware chain; `bot.on("message")` is the
97
+ innermost downstream:
65
98
 
66
99
  ```ts
67
100
  import { errorHandler, messageFilter, contentSanitizer, mentionGate } from "@tencent-connect/qqbot-nodejs";
@@ -71,7 +104,7 @@ bot.use(messageFilter({ skipSelfEcho: true, dedup: { windowMs: 5000 } }));
71
104
  bot.use(contentSanitizer({ stripBotMention: true }));
72
105
  bot.use(mentionGate({ requireMentionInGroup: true }));
73
106
 
74
- // 自定义中间件
107
+ // Custom middleware
75
108
  bot.use(async (ctx, next) => {
76
109
  const start = Date.now();
77
110
  await next();
@@ -79,33 +112,33 @@ bot.use(async (ctx, next) => {
79
112
  });
80
113
  ```
81
114
 
82
- 内置中间件:
115
+ Built-in middleware:
83
116
 
84
- | 中间件 | 说明 |
117
+ | Middleware | Purpose |
85
118
  |--------|------|
86
- | `errorHandler` | 统一错误捕获 + 友好回复 |
87
- | `messageFilter` | 过滤 bot 回声 + 消息去重 |
88
- | `rateLimiter` | 三层限流(sender / group / global) |
89
- | `concurrencyGuard` | 同用户/群串行处理(防 stream 并发冲突) |
90
- | `accessPolicy` | 黑白名单 |
91
- | `contentSanitizer` | 去 @marker / face tags / 空白清洗 |
92
- | `mentionGate` | 群聊 @bot 判定 |
93
- | `quoteRef` | 消息索引记录 + 引用消息解析 |
94
- | `historyBuffer` | 群历史缓冲 |
95
- | `envelopeFormatter` | 组装 LLM prompt 上下文(XML tags) |
96
- | `typingIndicator` | C2C 自动 typing |
97
- | `slashCommand` | /cmd 命令框架 |
98
-
99
- ### 3. 文本消息
119
+ | `errorHandler` | Unified error capture + friendly reply |
120
+ | `messageFilter` | Bot echo filtering + message dedup |
121
+ | `rateLimiter` | Three-tier rate limiting (sender / group / global) |
122
+ | `concurrencyGuard` | Serial processing per user / group (avoids stream races) |
123
+ | `accessPolicy` | Allow / block lists |
124
+ | `contentSanitizer` | Strip @markers / face tags / whitespace |
125
+ | `mentionGate` | Group @bot gating |
126
+ | `quoteRef` | Message index recording + quoted-message resolution |
127
+ | `historyBuffer` | Group history buffer |
128
+ | `envelopeFormatter` | Assemble LLM prompt context (XML tags) |
129
+ | `typingIndicator` | Automatic C2C typing |
130
+ | `slashCommand` | /cmd command framework |
131
+
132
+ ### 3. Text messages
100
133
 
101
134
  ```ts
102
135
  await bot.sendText(target, "hello");
103
136
  ```
104
137
 
105
- ### 4. 文件 / 图片 / 语音
138
+ ### 4. Files / images / voice
106
139
 
107
- `sendImage` / `sendVoice` / `sendVideo` / `sendFile` 是 `sendMedia` 的便捷封装。
108
- 当源文件 ≥ 5MB 时自动走分块上传。
140
+ `sendImage` / `sendVoice` / `sendVideo` / `sendFile` are convenience wrappers
141
+ over `sendMedia`. Sources ≥ 5 MB switch to chunked upload automatically.
109
142
 
110
143
  ```ts
111
144
  await bot.sendImage(target, { localPath: "/tmp/cat.jpg" });
@@ -120,7 +153,7 @@ await bot.sendFile(
120
153
  );
121
154
  ```
122
155
 
123
- ### 5. C2C 流式消息
156
+ ### 5. C2C streaming messages
124
157
 
125
158
  ```ts
126
159
  const stream = bot.openStream({ target });
@@ -130,19 +163,48 @@ for (const partial of generator) {
130
163
  await stream.complete();
131
164
  ```
132
165
 
133
- QQ 开放平台限制:`stream_messages` 仅在 C2C(私聊)开放。
166
+ QQ Open Platform constraint: `stream_messages` is available for C2C (private chat) only.
134
167
 
135
- ### 6. 事件监听
168
+ ### 6. Events
136
169
 
137
170
  ```ts
138
171
  bot.on("ready", () => console.log("connected"));
139
172
  bot.on("resumed", () => console.log("reconnected"));
140
- bot.on("error", (err) => console.error(err));
173
+ bot.on("disconnected", ({ code, willReconnect }) => console.log("closed", code, willReconnect));
174
+ bot.on("error", (err) => console.error(err)); // recoverable failures; never ends start()
141
175
  bot.on("message", (ctx, msg) => { /* C2C / Group / Guild / DM */ });
142
176
  bot.on("interaction", (ctx, event) => { /* button click etc. */ });
143
177
  ```
144
178
 
145
- ### 7. 协议层直接访问
179
+ ### 7. Lifecycle
180
+
181
+ WebSocket mode reconnects forever by default. `start()` resolves on `stop()` /
182
+ abort, and rejects — after releasing the connection and token refresher — only
183
+ when it cannot recover:
184
+
185
+ | Rejection | Cause | Handling |
186
+ |---|---|---|
187
+ | `GatewayError` `GATEWAY_FATAL_CLOSE` | 4914 offline / sandbox-only, 4915 banned | Needs operator action; don't restart |
188
+ | `GatewayError` `GATEWAY_RETRY_EXHAUSTED` | Only with a finite `reconnect.maxAttempts` | Restart with backoff |
189
+ | `Error` | Startup token fetch failed (default `tokenPrefetch: "sync"`) | Check credentials / network |
190
+
191
+ ```ts
192
+ import { GatewayErrorCode, QQBot } from "@tencent-connect/qqbot-nodejs";
193
+
194
+ // Set a limit only when an outer supervisor owns process-level restarts
195
+ const bot = new QQBot({ appId, appSecret, reconnect: { maxAttempts: 10 } });
196
+ try {
197
+ await bot.start(signal);
198
+ } catch (err) {
199
+ if ((err as { code?: string }).code === GatewayErrorCode.FATAL_CLOSE) markBlocked(err);
200
+ else scheduleRestart(err);
201
+ }
202
+ ```
203
+
204
+ `bot.stop(); bot.start();` restarts in place. See [USAGE.md §7](./USAGE.md#7-生命周期管理)
205
+ for close-code handling.
206
+
207
+ ### 8. Protocol-level access
146
208
 
147
209
  ```ts
148
210
  import {
@@ -153,55 +215,88 @@ import {
153
215
  } from "@tencent-connect/qqbot-nodejs/protocol";
154
216
  ```
155
217
 
156
- ## 模块结构
218
+ ## Documentation
219
+
220
+ - **[USAGE.md](./USAGE.md)** — complete usage guide (currently in Chinese;
221
+ contributions to translate are very welcome).
222
+
223
+ ## Optional dependencies
224
+
225
+ These `peerDependencies` are declared as optional. Install them only if you
226
+ need the feature:
227
+
228
+ | Package | Enables |
229
+ | ----------------- | ------------------------------------------ |
230
+ | `silk-wasm` | Sending voice messages (SILK encoding) |
231
+ | `mpg123-decoder` | Decoding MP3 audio to PCM before encoding |
232
+
233
+ ## Contributing
234
+
235
+ Bug reports, feature proposals and pull requests are welcome. Please read:
236
+
237
+ - [CONTRIBUTING.md](./CONTRIBUTING.md) — dev workflow & commit convention
238
+ - [SECURITY.md](./SECURITY.md) — how to report vulnerabilities privately
239
+
240
+ ## Module structure
157
241
 
158
242
  ```
159
243
  src/
160
- ├── QQBot.ts ← 高层 facade
161
- ├── streaming.ts ← C2C 流式消息控制器
162
- ├── index.ts ← 公开 API
163
- ├── middleware/ ← Koa-style 中间件
164
- │ ├── types.ts 中间件类型 + 洋葱执行器
165
- │ ├── error-handler.ts 统一错误捕获
166
- │ ├── message-filter.ts 回声过滤 + 去重
167
- │ ├── rate-limiter.ts 三层限流
168
- │ ├── concurrency-guard.ts 同用户/群串行处理
169
- │ ├── access-policy.ts 黑白名单
170
- │ ├── content-sanitizer.ts 内容清洗
171
- │ ├── mention-gate.ts @bot 判定
172
- │ ├── quote-ref.ts 引用消息解析 + 消息索引
173
- │ ├── history-buffer.ts 群历史缓冲
174
- │ ├── envelope-formatter.ts LLM prompt 组装
175
- │ ├── typing-indicator.ts typing 状态
176
- │ └── slash-command.ts 命令框架
177
- └── protocol/ ← 协议层
244
+ ├── QQBot.ts ← High-level facade
245
+ ├── streaming.ts ← C2C streaming-message controller
246
+ ├── index.ts ← Public API
247
+ ├── middleware/ ← Koa-style middleware
248
+ │ ├── types.ts Middleware types + onion runner
249
+ │ ├── error-handler.ts Unified error capture
250
+ │ ├── message-filter.ts Echo filtering + dedup
251
+ │ ├── rate-limiter.ts Three-tier rate limiting
252
+ │ ├── concurrency-guard.ts Serial processing per user / group
253
+ │ ├── access-policy.ts Allow / block lists
254
+ │ ├── content-sanitizer.ts Content sanitizing
255
+ │ ├── mention-gate.ts @bot gating
256
+ │ ├── quote-ref.ts Quote resolution + message index
257
+ │ ├── history-buffer.ts Group history buffer
258
+ │ ├── envelope-formatter.ts LLM prompt assembly
259
+ │ ├── typing-indicator.ts Typing state
260
+ │ └── slash-command.ts Command framework
261
+ └── protocol/ ← Protocol layer
178
262
  ├── api/
179
- │ ├── api-client.ts HTTP 客户端
180
- │ ├── token.ts access_token 管理
181
- │ ├── messages.ts 消息发送
182
- │ ├── media.ts 小文件上传
183
- │ ├── media-chunked.ts 大文件分块上传
184
- │ ├── retry.ts 重试引擎
185
- │ └── routes.ts 路由模板
263
+ │ ├── api-client.ts HTTP client
264
+ │ ├── token.ts access_token management
265
+ │ ├── messages.ts Message sending
266
+ │ ├── media.ts Small-file upload
267
+ │ ├── media-chunked.ts Chunked large-file upload
268
+ │ ├── retry.ts Retry engine
269
+ │ └── routes.ts Route templates
186
270
  ├── gateway/
187
271
  │ ├── constants.ts opcode / intent / close code
188
- │ ├── codec.ts 消息解码
189
- │ ├── reconnect.ts 重连状态机
190
- │ ├── event-dispatcher.ts 事件 → InboundMessage
191
- │ └── gateway-connection.ts WebSocket 生命周期
272
+ │ ├── codec.ts Message decoding
273
+ │ ├── reconnect.ts Reconnect state machine + reconnect policy
274
+ │ ├── errors.ts GatewayError (terminal start() errors)
275
+ │ ├── event-dispatcher.ts Event → InboundMessage
276
+ │ └── gateway-connection.ts WebSocket lifecycle
192
277
  ├── transport/
193
- │ ├── types.ts EventTransport 接口
194
- │ ├── webhook.ts Webhook 传输
195
- │ ├── webhook-verify.ts Ed25519 签名验证
196
- │ └── webhook-server-node.ts 内置 node:http 适配器
278
+ │ ├── types.ts EventTransport interface
279
+ │ ├── webhook.ts Webhook transport
280
+ │ ├── webhook-verify.ts Ed25519 signature verification
281
+ │ └── webhook-server-node.ts Built-in node:http adapter
197
282
  ├── utils/
198
- │ ├── format.ts 格式化工具
199
- │ ├── file-utils.ts 文件工具
200
- │ └── upload-cache.ts file_info TTL 缓存
201
- ├── types.ts 全部公共类型 + 错误
202
- └── index.ts protocol 子入口
283
+ │ ├── format.ts Formatting helpers
284
+ │ ├── file-utils.ts File helpers
285
+ │ └── upload-cache.ts file_info TTL cache
286
+ ├── types.ts All public types + errors
287
+ └── index.ts protocol sub-entry
203
288
  ```
204
289
 
290
+ ## Contributors
291
+
292
+ Thanks to everyone who has contributed to this project!
293
+
294
+ <a href="https://github.com/tencent-connect/qqbot-nodejs/graphs/contributors">
295
+ <img src="https://contrib.rocks/image?repo=tencent-connect/qqbot-nodejs" alt="Contributors" />
296
+ </a>
297
+
298
+ <sub>Contributor avatars are rendered by [contrib.rocks](https://contrib.rocks).</sub>
299
+
205
300
  ## License
206
301
 
207
- MIT
302
+ [MIT](./LICENSE) © Tencent