@tencent-connect/qqbot-nodejs 1.0.3 → 1.0.5
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.
- package/CHANGELOG.md +96 -0
- package/LICENSE +21 -0
- package/README.md +168 -85
- package/README.zh-CN.md +280 -0
- package/USAGE.md +87 -32
- package/dist/QQBot.d.ts +33 -3
- package/dist/QQBot.d.ts.map +1 -1
- package/dist/QQBot.js +84 -34
- package/dist/QQBot.js.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/protocol/api/token.d.ts.map +1 -1
- package/dist/protocol/api/token.js +29 -9
- package/dist/protocol/api/token.js.map +1 -1
- package/dist/protocol/gateway/constants.d.ts +6 -1
- package/dist/protocol/gateway/constants.d.ts.map +1 -1
- package/dist/protocol/gateway/constants.js +6 -1
- package/dist/protocol/gateway/constants.js.map +1 -1
- package/dist/protocol/gateway/errors.d.ts +22 -0
- package/dist/protocol/gateway/errors.d.ts.map +1 -0
- package/dist/protocol/gateway/errors.js +24 -0
- package/dist/protocol/gateway/errors.js.map +1 -0
- package/dist/protocol/gateway/gateway-connection.d.ts +45 -4
- package/dist/protocol/gateway/gateway-connection.d.ts.map +1 -1
- package/dist/protocol/gateway/gateway-connection.js +252 -143
- package/dist/protocol/gateway/gateway-connection.js.map +1 -1
- package/dist/protocol/gateway/reconnect.d.ts +24 -1
- package/dist/protocol/gateway/reconnect.d.ts.map +1 -1
- package/dist/protocol/gateway/reconnect.js +42 -6
- package/dist/protocol/gateway/reconnect.js.map +1 -1
- package/dist/protocol/index.d.ts +4 -3
- package/dist/protocol/index.d.ts.map +1 -1
- package/dist/protocol/index.js +3 -2
- package/dist/protocol/index.js.map +1 -1
- package/dist/protocol/utils/file-utils.d.ts +2 -2
- package/dist/protocol/utils/file-utils.js +2 -2
- package/dist/protocol/utils/image-size.d.ts +3 -3
- package/dist/protocol/utils/image-size.js +3 -3
- package/dist/protocol/utils/ref-index-store.d.ts +1 -1
- package/dist/protocol/utils/ref-index-store.js +1 -1
- package/package.json +23 -7
- package/src/QQBot.ts +93 -37
- package/src/index.ts +5 -0
- package/src/protocol/api/token.ts +34 -9
- package/src/protocol/gateway/constants.ts +6 -1
- package/src/protocol/gateway/errors.ts +32 -0
- package/src/protocol/gateway/gateway-connection.ts +288 -157
- package/src/protocol/gateway/reconnect.ts +61 -7
- package/src/protocol/index.ts +10 -1
- package/src/protocol/utils/file-utils.ts +2 -2
- package/src/protocol/utils/image-size.ts +3 -3
- package/src/protocol/utils/ref-index-store.ts +1 -1
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
# 1.0.5 (2026-10-12)
|
|
2
|
+
|
|
3
|
+
### Features
|
|
4
|
+
|
|
5
|
+
* **gateway:** startup now fails fast with a clear reason when the connection can't be established, instead of waiting forever
|
|
6
|
+
* **gateway:** new `disconnected` event reports why the connection dropped and whether the SDK will recover on its own
|
|
7
|
+
* **gateway:** reconnects are now configurable — cap the attempts and tune the backoff; unrecoverable cases (banned bot, sandbox-only account) are reported once and explicitly
|
|
8
|
+
* **sdk:** `bot.getCredentials()` exposes the configured credentials for calling the lower-level APIs directly
|
|
9
|
+
|
|
10
|
+
### Bug Fixes
|
|
11
|
+
|
|
12
|
+
* **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
|
|
13
|
+
* **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
|
|
14
|
+
* **token:** restarting the bot no longer cancels the token refresh belonging to the new session
|
|
15
|
+
|
|
16
|
+
### Behavior changes
|
|
17
|
+
|
|
18
|
+
* 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.
|
|
19
|
+
|
|
20
|
+
## 1.0.4 (2026-07-14)
|
|
21
|
+
|
|
22
|
+
### Bug Fixes
|
|
23
|
+
|
|
24
|
+
* **token:** fetching an access token now times out, and failures report the HTTP status and server response instead of a generic error
|
|
25
|
+
* **token:** fixed edge cases that could leave token refresh stuck or log a crash that never happened
|
|
26
|
+
|
|
27
|
+
## 1.0.3 (2026-07-13)
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
### Features
|
|
31
|
+
|
|
32
|
+
* **sdk:** add universal send(), API gateway, rawEvent, and P1 messaging capabilities
|
|
33
|
+
* **media:** auto-fill fileName from localPath/URL in uploadMedia
|
|
34
|
+
* **media:** pre-check fileData size before upload
|
|
35
|
+
* **middleware:** concurrency-guard merge support
|
|
36
|
+
* **middleware:** enhance types & buffered reply
|
|
37
|
+
* **concurrency:** add maxProcessingMs timeout with abort
|
|
38
|
+
* **concurrency:** add urgentPredicate for priority flush
|
|
39
|
+
* **quote-ref:** prefer msg_elements over stored entry
|
|
40
|
+
* **quote-ref:** add enrichEntry & extend entry
|
|
41
|
+
* **api:** support data in acknowledge interaction
|
|
42
|
+
* **sanitizer:** support new face tag format
|
|
43
|
+
* **slash:** add per-command authorized check
|
|
44
|
+
* export webhook transport types
|
|
45
|
+
* update mention-gate
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
### Bug Fixes
|
|
49
|
+
|
|
50
|
+
* **slash:** check rawEventType for group @bot detection
|
|
51
|
+
* **media:** use raw https for COS chunked upload
|
|
52
|
+
* **media:** pass Uint8Array directly to fetch body
|
|
53
|
+
* **middleware:** refine mention-gate logic
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
## 1.0.2 (2026-06-10)
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
### Features
|
|
60
|
+
|
|
61
|
+
* **qqbot:** support tokenPrefetch option for sync/async token initialization
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
## 1.0.1 (2026-05-20)
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
### Features
|
|
68
|
+
|
|
69
|
+
* **middleware:** add concurrencyGuard for per-target serial processing
|
|
70
|
+
* **middleware:** add ctx.abort() and ctx.signal for async cancellation
|
|
71
|
+
* **middleware:** add typing keepalive to typingIndicator
|
|
72
|
+
* **middleware:** add receivedAt to MiddlewareContext for latency measurement
|
|
73
|
+
* **concurrency:** add merge strategy with dependency-inverted dispatch
|
|
74
|
+
* **slash:** add allowFrom option for command access control
|
|
75
|
+
* **event:** expose messageScene on C2C inbound messages
|
|
76
|
+
* **transport:** add webhook example and update readme
|
|
77
|
+
* dataflow middleware pipeline
|
|
78
|
+
* check slash scope
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
### Bug Fixes
|
|
82
|
+
|
|
83
|
+
* **webhook:** async dispatch to prevent ACK timeout on long-running handlers
|
|
84
|
+
* **webhook:** log full event payload in dispatch debug output
|
|
85
|
+
* **stream:** ensure DONE frame is sent even when flush is in progress
|
|
86
|
+
* **streaming:** catch throttle flush error to prevent unhandledRejection
|
|
87
|
+
* **streaming:** fix rate-limit retry storm in flush
|
|
88
|
+
* **concurrency-guard:** evict queued waiters on abort to prevent stale replies
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
# 1.0.0 (2026-04-30)
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
### Features
|
|
95
|
+
|
|
96
|
+
* 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,32 @@
|
|
|
1
1
|
# @tencent-connect/qqbot-nodejs
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
协议层能力:HTTP REST、WebSocket / Webhook 双传输、Koa-style 中间件管线、
|
|
5
|
-
消息收发、媒体上传(含大文件分块)、C2C 流式消息(stream_messages)。
|
|
3
|
+
> **English** (this file) · [简体中文](./README.zh-CN.md)
|
|
6
4
|
|
|
7
|
-
|
|
5
|
+
[](https://www.npmjs.com/package/@tencent-connect/qqbot-nodejs)
|
|
6
|
+
[](https://github.com/tencent-connect/qqbot-nodejs/actions/workflows/ci.yml)
|
|
7
|
+
[](./LICENSE)
|
|
8
|
+
[](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
|
+
## Requirements
|
|
17
|
+
|
|
18
|
+
- Node.js **>= 20** (uses global `fetch` / `AbortController`)
|
|
19
|
+
- Pure ESM (`"type": "module"`); CJS consumers should use dynamic `import()`
|
|
20
|
+
|
|
21
|
+
## Install
|
|
8
22
|
|
|
9
23
|
```bash
|
|
10
24
|
pnpm add @tencent-connect/qqbot-nodejs
|
|
11
|
-
#
|
|
25
|
+
# or
|
|
12
26
|
npm install @tencent-connect/qqbot-nodejs
|
|
13
27
|
```
|
|
14
28
|
|
|
15
|
-
##
|
|
29
|
+
## Quick Start
|
|
16
30
|
|
|
17
31
|
```ts
|
|
18
32
|
import { QQBot } from "@tencent-connect/qqbot-nodejs";
|
|
@@ -24,30 +38,36 @@ const bot = new QQBot({
|
|
|
24
38
|
});
|
|
25
39
|
|
|
26
40
|
bot.on("message", async (ctx, msg) => {
|
|
27
|
-
// ctx — Koa-style MiddlewareContext
|
|
41
|
+
// ctx — Koa-style MiddlewareContext carrying data injected by middleware
|
|
28
42
|
await bot.sendText(msg.replyTarget, `Echo: ${msg.content}`);
|
|
29
43
|
});
|
|
30
44
|
|
|
31
45
|
await bot.start();
|
|
32
46
|
```
|
|
33
47
|
|
|
34
|
-
|
|
48
|
+
See the complete examples under [examples/](./examples/):
|
|
35
49
|
|
|
36
|
-
|
|
|
50
|
+
| Example | Description |
|
|
37
51
|
|------|------|
|
|
38
|
-
| [playground](./examples/playground/) |
|
|
39
|
-
| [middleware](./examples/middleware/) |
|
|
40
|
-
| [webhook](./examples/webhook/) | Webhook
|
|
52
|
+
| [playground](./examples/playground/) | Core capabilities demo (text, streaming, media, commands) |
|
|
53
|
+
| [middleware](./examples/middleware/) | Full 13-layer Koa-style middleware pipeline |
|
|
54
|
+
| [webhook](./examples/webhook/) | Webhook (HTTP callback) transport |
|
|
55
|
+
| [send-plain-100](./examples/send-plain-100/) | Plain-text send baseline |
|
|
56
|
+
| [send-streaming-100](./examples/send-streaming-100/) | Streaming-message send baseline |
|
|
41
57
|
|
|
42
|
-
|
|
58
|
+
> Examples read `QQBOT_APP_ID` / `QQBOT_APP_SECRET` from `process.env` **only
|
|
59
|
+
> for demo convenience**. The SDK itself never reads environment variables —
|
|
60
|
+
> credentials are always injected via `new QQBot({ appId, appSecret })`.
|
|
43
61
|
|
|
44
|
-
|
|
62
|
+
## Features
|
|
63
|
+
|
|
64
|
+
### 1. Dual transport (WebSocket / Webhook)
|
|
45
65
|
|
|
46
66
|
```ts
|
|
47
|
-
// WebSocket
|
|
67
|
+
// WebSocket (default) — long-lived connection + heartbeat + RESUME
|
|
48
68
|
const bot = new QQBot({ appId, appSecret });
|
|
49
69
|
|
|
50
|
-
// Webhook — HTTP
|
|
70
|
+
// Webhook — HTTP callback, suited to Serverless / horizontal scaling
|
|
51
71
|
const bot = new QQBot({
|
|
52
72
|
appId, appSecret,
|
|
53
73
|
transport: "webhook",
|
|
@@ -55,11 +75,12 @@ const bot = new QQBot({
|
|
|
55
75
|
});
|
|
56
76
|
```
|
|
57
77
|
|
|
58
|
-
|
|
78
|
+
Middleware, event listeners and send APIs are identical in both modes.
|
|
59
79
|
|
|
60
|
-
### 2. Koa-style
|
|
80
|
+
### 2. Koa-style middleware
|
|
61
81
|
|
|
62
|
-
SDK
|
|
82
|
+
The SDK uses an onion-model middleware chain; `bot.on("message")` is the
|
|
83
|
+
innermost downstream:
|
|
63
84
|
|
|
64
85
|
```ts
|
|
65
86
|
import { errorHandler, messageFilter, contentSanitizer, mentionGate } from "@tencent-connect/qqbot-nodejs";
|
|
@@ -69,7 +90,7 @@ bot.use(messageFilter({ skipSelfEcho: true, dedup: { windowMs: 5000 } }));
|
|
|
69
90
|
bot.use(contentSanitizer({ stripBotMention: true }));
|
|
70
91
|
bot.use(mentionGate({ requireMentionInGroup: true }));
|
|
71
92
|
|
|
72
|
-
//
|
|
93
|
+
// Custom middleware
|
|
73
94
|
bot.use(async (ctx, next) => {
|
|
74
95
|
const start = Date.now();
|
|
75
96
|
await next();
|
|
@@ -77,33 +98,33 @@ bot.use(async (ctx, next) => {
|
|
|
77
98
|
});
|
|
78
99
|
```
|
|
79
100
|
|
|
80
|
-
|
|
101
|
+
Built-in middleware:
|
|
81
102
|
|
|
82
|
-
|
|
|
103
|
+
| Middleware | Purpose |
|
|
83
104
|
|--------|------|
|
|
84
|
-
| `errorHandler` |
|
|
85
|
-
| `messageFilter` |
|
|
86
|
-
| `rateLimiter` |
|
|
87
|
-
| `concurrencyGuard` |
|
|
88
|
-
| `accessPolicy` |
|
|
89
|
-
| `contentSanitizer` |
|
|
90
|
-
| `mentionGate` |
|
|
91
|
-
| `quoteRef` |
|
|
92
|
-
| `historyBuffer` |
|
|
93
|
-
| `envelopeFormatter` |
|
|
94
|
-
| `typingIndicator` | C2C
|
|
95
|
-
| `slashCommand` | /cmd
|
|
96
|
-
|
|
97
|
-
### 3.
|
|
105
|
+
| `errorHandler` | Unified error capture + friendly reply |
|
|
106
|
+
| `messageFilter` | Bot echo filtering + message dedup |
|
|
107
|
+
| `rateLimiter` | Three-tier rate limiting (sender / group / global) |
|
|
108
|
+
| `concurrencyGuard` | Serial processing per user / group (avoids stream races) |
|
|
109
|
+
| `accessPolicy` | Allow / block lists |
|
|
110
|
+
| `contentSanitizer` | Strip @markers / face tags / whitespace |
|
|
111
|
+
| `mentionGate` | Group @bot gating |
|
|
112
|
+
| `quoteRef` | Message index recording + quoted-message resolution |
|
|
113
|
+
| `historyBuffer` | Group history buffer |
|
|
114
|
+
| `envelopeFormatter` | Assemble LLM prompt context (XML tags) |
|
|
115
|
+
| `typingIndicator` | Automatic C2C typing |
|
|
116
|
+
| `slashCommand` | /cmd command framework |
|
|
117
|
+
|
|
118
|
+
### 3. Text messages
|
|
98
119
|
|
|
99
120
|
```ts
|
|
100
121
|
await bot.sendText(target, "hello");
|
|
101
122
|
```
|
|
102
123
|
|
|
103
|
-
### 4.
|
|
124
|
+
### 4. Files / images / voice
|
|
104
125
|
|
|
105
|
-
`sendImage` / `sendVoice` / `sendVideo` / `sendFile`
|
|
106
|
-
|
|
126
|
+
`sendImage` / `sendVoice` / `sendVideo` / `sendFile` are convenience wrappers
|
|
127
|
+
over `sendMedia`. Sources ≥ 5 MB switch to chunked upload automatically.
|
|
107
128
|
|
|
108
129
|
```ts
|
|
109
130
|
await bot.sendImage(target, { localPath: "/tmp/cat.jpg" });
|
|
@@ -118,7 +139,7 @@ await bot.sendFile(
|
|
|
118
139
|
);
|
|
119
140
|
```
|
|
120
141
|
|
|
121
|
-
### 5. C2C
|
|
142
|
+
### 5. C2C streaming messages
|
|
122
143
|
|
|
123
144
|
```ts
|
|
124
145
|
const stream = bot.openStream({ target });
|
|
@@ -128,19 +149,48 @@ for (const partial of generator) {
|
|
|
128
149
|
await stream.complete();
|
|
129
150
|
```
|
|
130
151
|
|
|
131
|
-
QQ
|
|
152
|
+
QQ Open Platform constraint: `stream_messages` is available for C2C (private chat) only.
|
|
132
153
|
|
|
133
|
-
### 6.
|
|
154
|
+
### 6. Events
|
|
134
155
|
|
|
135
156
|
```ts
|
|
136
157
|
bot.on("ready", () => console.log("connected"));
|
|
137
158
|
bot.on("resumed", () => console.log("reconnected"));
|
|
138
|
-
bot.on("
|
|
159
|
+
bot.on("disconnected", ({ code, willReconnect }) => console.log("closed", code, willReconnect));
|
|
160
|
+
bot.on("error", (err) => console.error(err)); // recoverable failures; never ends start()
|
|
139
161
|
bot.on("message", (ctx, msg) => { /* C2C / Group / Guild / DM */ });
|
|
140
|
-
bot.on("interaction", (event) => { /* button click etc. */ });
|
|
162
|
+
bot.on("interaction", (ctx, event) => { /* button click etc. */ });
|
|
141
163
|
```
|
|
142
164
|
|
|
143
|
-
### 7.
|
|
165
|
+
### 7. Lifecycle
|
|
166
|
+
|
|
167
|
+
WebSocket mode reconnects forever by default. `start()` resolves on `stop()` /
|
|
168
|
+
abort, and rejects — after releasing the connection and token refresher — only
|
|
169
|
+
when it cannot recover:
|
|
170
|
+
|
|
171
|
+
| Rejection | Cause | Handling |
|
|
172
|
+
|---|---|---|
|
|
173
|
+
| `GatewayError` `GATEWAY_FATAL_CLOSE` | 4914 offline / sandbox-only, 4915 banned | Needs operator action; don't restart |
|
|
174
|
+
| `GatewayError` `GATEWAY_RETRY_EXHAUSTED` | Only with a finite `reconnect.maxAttempts` | Restart with backoff |
|
|
175
|
+
| `Error` | Startup token fetch failed (default `tokenPrefetch: "sync"`) | Check credentials / network |
|
|
176
|
+
|
|
177
|
+
```ts
|
|
178
|
+
import { GatewayErrorCode, QQBot } from "@tencent-connect/qqbot-nodejs";
|
|
179
|
+
|
|
180
|
+
// Set a limit only when an outer supervisor owns process-level restarts
|
|
181
|
+
const bot = new QQBot({ appId, appSecret, reconnect: { maxAttempts: 10 } });
|
|
182
|
+
try {
|
|
183
|
+
await bot.start(signal);
|
|
184
|
+
} catch (err) {
|
|
185
|
+
if ((err as { code?: string }).code === GatewayErrorCode.FATAL_CLOSE) markBlocked(err);
|
|
186
|
+
else scheduleRestart(err);
|
|
187
|
+
}
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
`bot.stop(); bot.start();` restarts in place. See [USAGE.md §7](./USAGE.md#7-生命周期管理)
|
|
191
|
+
for close-code handling.
|
|
192
|
+
|
|
193
|
+
### 8. Protocol-level access
|
|
144
194
|
|
|
145
195
|
```ts
|
|
146
196
|
import {
|
|
@@ -151,55 +201,88 @@ import {
|
|
|
151
201
|
} from "@tencent-connect/qqbot-nodejs/protocol";
|
|
152
202
|
```
|
|
153
203
|
|
|
154
|
-
##
|
|
204
|
+
## Documentation
|
|
205
|
+
|
|
206
|
+
- **[USAGE.md](./USAGE.md)** — complete usage guide (currently in Chinese;
|
|
207
|
+
contributions to translate are very welcome).
|
|
208
|
+
|
|
209
|
+
## Optional dependencies
|
|
210
|
+
|
|
211
|
+
These `peerDependencies` are declared as optional. Install them only if you
|
|
212
|
+
need the feature:
|
|
213
|
+
|
|
214
|
+
| Package | Enables |
|
|
215
|
+
| ----------------- | ------------------------------------------ |
|
|
216
|
+
| `silk-wasm` | Sending voice messages (SILK encoding) |
|
|
217
|
+
| `mpg123-decoder` | Decoding MP3 audio to PCM before encoding |
|
|
218
|
+
|
|
219
|
+
## Contributing
|
|
220
|
+
|
|
221
|
+
Bug reports, feature proposals and pull requests are welcome. Please read:
|
|
222
|
+
|
|
223
|
+
- [CONTRIBUTING.md](./CONTRIBUTING.md) — dev workflow & commit convention
|
|
224
|
+
- [SECURITY.md](./SECURITY.md) — how to report vulnerabilities privately
|
|
225
|
+
|
|
226
|
+
## Module structure
|
|
155
227
|
|
|
156
228
|
```
|
|
157
229
|
src/
|
|
158
|
-
├── QQBot.ts ←
|
|
159
|
-
├── streaming.ts ← C2C
|
|
160
|
-
├── index.ts ←
|
|
161
|
-
├── middleware/ ← Koa-style
|
|
162
|
-
│ ├── types.ts
|
|
163
|
-
│ ├── error-handler.ts
|
|
164
|
-
│ ├── message-filter.ts
|
|
165
|
-
│ ├── rate-limiter.ts
|
|
166
|
-
│ ├── concurrency-guard.ts
|
|
167
|
-
│ ├── access-policy.ts
|
|
168
|
-
│ ├── content-sanitizer.ts
|
|
169
|
-
│ ├── mention-gate.ts @bot
|
|
170
|
-
│ ├── quote-ref.ts
|
|
171
|
-
│ ├── history-buffer.ts
|
|
172
|
-
│ ├── envelope-formatter.ts LLM prompt
|
|
173
|
-
│ ├── typing-indicator.ts
|
|
174
|
-
│ └── slash-command.ts
|
|
175
|
-
└── protocol/ ←
|
|
230
|
+
├── QQBot.ts ← High-level facade
|
|
231
|
+
├── streaming.ts ← C2C streaming-message controller
|
|
232
|
+
├── index.ts ← Public API
|
|
233
|
+
├── middleware/ ← Koa-style middleware
|
|
234
|
+
│ ├── types.ts Middleware types + onion runner
|
|
235
|
+
│ ├── error-handler.ts Unified error capture
|
|
236
|
+
│ ├── message-filter.ts Echo filtering + dedup
|
|
237
|
+
│ ├── rate-limiter.ts Three-tier rate limiting
|
|
238
|
+
│ ├── concurrency-guard.ts Serial processing per user / group
|
|
239
|
+
│ ├── access-policy.ts Allow / block lists
|
|
240
|
+
│ ├── content-sanitizer.ts Content sanitizing
|
|
241
|
+
│ ├── mention-gate.ts @bot gating
|
|
242
|
+
│ ├── quote-ref.ts Quote resolution + message index
|
|
243
|
+
│ ├── history-buffer.ts Group history buffer
|
|
244
|
+
│ ├── envelope-formatter.ts LLM prompt assembly
|
|
245
|
+
│ ├── typing-indicator.ts Typing state
|
|
246
|
+
│ └── slash-command.ts Command framework
|
|
247
|
+
└── protocol/ ← Protocol layer
|
|
176
248
|
├── api/
|
|
177
|
-
│ ├── api-client.ts HTTP
|
|
178
|
-
│ ├── token.ts access_token
|
|
179
|
-
│ ├── messages.ts
|
|
180
|
-
│ ├── media.ts
|
|
181
|
-
│ ├── media-chunked.ts
|
|
182
|
-
│ ├── retry.ts
|
|
183
|
-
│ └── routes.ts
|
|
249
|
+
│ ├── api-client.ts HTTP client
|
|
250
|
+
│ ├── token.ts access_token management
|
|
251
|
+
│ ├── messages.ts Message sending
|
|
252
|
+
│ ├── media.ts Small-file upload
|
|
253
|
+
│ ├── media-chunked.ts Chunked large-file upload
|
|
254
|
+
│ ├── retry.ts Retry engine
|
|
255
|
+
│ └── routes.ts Route templates
|
|
184
256
|
├── gateway/
|
|
185
257
|
│ ├── constants.ts opcode / intent / close code
|
|
186
|
-
│ ├── codec.ts
|
|
187
|
-
│ ├── reconnect.ts
|
|
188
|
-
│ ├──
|
|
189
|
-
│
|
|
258
|
+
│ ├── codec.ts Message decoding
|
|
259
|
+
│ ├── reconnect.ts Reconnect state machine + reconnect policy
|
|
260
|
+
│ ├── errors.ts GatewayError (terminal start() errors)
|
|
261
|
+
│ ├── event-dispatcher.ts Event → InboundMessage
|
|
262
|
+
│ └── gateway-connection.ts WebSocket lifecycle
|
|
190
263
|
├── transport/
|
|
191
|
-
│ ├── types.ts EventTransport
|
|
192
|
-
│ ├── webhook.ts Webhook
|
|
193
|
-
│ ├── webhook-verify.ts Ed25519
|
|
194
|
-
│ └── webhook-server-node.ts
|
|
264
|
+
│ ├── types.ts EventTransport interface
|
|
265
|
+
│ ├── webhook.ts Webhook transport
|
|
266
|
+
│ ├── webhook-verify.ts Ed25519 signature verification
|
|
267
|
+
│ └── webhook-server-node.ts Built-in node:http adapter
|
|
195
268
|
├── utils/
|
|
196
|
-
│ ├── format.ts
|
|
197
|
-
│ ├── file-utils.ts
|
|
198
|
-
│ └── upload-cache.ts file_info TTL
|
|
199
|
-
├── types.ts
|
|
200
|
-
└── index.ts protocol
|
|
269
|
+
│ ├── format.ts Formatting helpers
|
|
270
|
+
│ ├── file-utils.ts File helpers
|
|
271
|
+
│ └── upload-cache.ts file_info TTL cache
|
|
272
|
+
├── types.ts All public types + errors
|
|
273
|
+
└── index.ts protocol sub-entry
|
|
201
274
|
```
|
|
202
275
|
|
|
276
|
+
## Contributors
|
|
277
|
+
|
|
278
|
+
Thanks to everyone who has contributed to this project!
|
|
279
|
+
|
|
280
|
+
<a href="https://github.com/tencent-connect/qqbot-nodejs/graphs/contributors">
|
|
281
|
+
<img src="https://contrib.rocks/image?repo=tencent-connect/qqbot-nodejs" alt="Contributors" />
|
|
282
|
+
</a>
|
|
283
|
+
|
|
284
|
+
<sub>Contributor avatars are rendered by [contrib.rocks](https://contrib.rocks).</sub>
|
|
285
|
+
|
|
203
286
|
## License
|
|
204
287
|
|
|
205
|
-
MIT
|
|
288
|
+
[MIT](./LICENSE) © Tencent
|