{"_id":"@tencent-connect/qqbot-nodejs","_rev":"7-87d1232887f3d1c797e5cf0690eb3d32","name":"@tencent-connect/qqbot-nodejs","dist-tags":{"latest":"1.0.6"},"versions":{"1.0.3":{"name":"@tencent-connect/qqbot-nodejs","version":"1.0.3","keywords":["qqbot","qq","tencent","bot","sdk","websocket","openapi"],"license":"MIT","_id":"@tencent-connect/qqbot-nodejs@1.0.3","maintainers":[{"name":"uv-w","email":"9837438@qq.com"},{"name":"vnues","email":"1518190293@qq.com"},{"name":"zuosh","email":"13366589984@163.com"},{"name":"joyqwang","email":"645153050@qq.com"},{"name":"tencentconnectqqbot","email":"tencentconnectqqbot@gmail.com"},{"name":"ryanlee-gemini","email":"ryanlee.gemini@gmail.com"}],"dist":{"shasum":"f985e6abe40bd69d431795b5f98de012cb664f06","tarball":"https://registry.npmjs.org/@tencent-connect/qqbot-nodejs/-/qqbot-nodejs-1.0.3.tgz","fileCount":293,"integrity":"sha512-Rmd3GZYm3cipxSMg0qZVeq/+ziY+XqZaNcjvJJKQsyqd6dS7L1p9ERuxU84zsM+vhwwUp+v640p3hTo0P4Y2SQ==","signatures":[{"sig":"MEUCIQCWyHDbOuKF0JGrIljrFNCzgseLE6y3Dp47LlaEd8kY5wIgFUis/vPkAVhzmHZdqx8LHWYqWM5mJUW5nxK7MB9JXUw=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":1160698},"main":"./dist/index.js","type":"module","types":"./dist/index.d.ts","engines":{"node":">=18"},"exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js"},"./protocol":{"types":"./dist/protocol/index.d.ts","import":"./dist/protocol/index.js"}},"gitHead":"095c7179d09087033ff14740203b6e304d5325b5","scripts":{"lint":"eslint .","test":"vitest run","build":"tsc -p tsconfig.build.json","prepack":"npm run build","typecheck":"tsc -p tsconfig.json --noEmit","commitlint":"commitlint","playground":"tsx examples/playground/index.ts","test:watch":"vitest","test:coverage":"vitest run --coverage","example:webhook":"tsx examples/webhook/index.ts","playground:build":"node --import tsx examples/playground/index.ts","semantic-release":"semantic-release","ci:prepare-test-pkg":"node scripts/prepare-test-pkg.js"},"_npmUser":{"name":"tencentconnectqqbot","email":"tencentconnectqqbot@gmail.com"},"_npmVersion":"11.16.0","description":"Tencent QQ Bot Node.js SDK — protocol-level client for the QQ Open Platform (HTTP + WebSocket Gateway, message + media + streaming).","directories":{},"_nodeVersion":"24.18.0","dependencies":{"ws":"^8.21.0"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"tsx":"^4.23.0","eslint":"^10.6.0","vitest":"^4.1.10","globals":"^17.7.0","@types/ws":"^8.18.1","silk-wasm":"^3.7.1","@eslint/js":"^10.0.1","typescript":"^5.9.3","@types/node":"^22.20.1","mpg123-decoder":"^1.0.3","@commitlint/cli":"^20.5.3","semantic-release":"^25.0.5","typescript-eslint":"^8.63.0","@vitest/coverage-v8":"^4.1.10","@semantic-release/git":"^10.0.1","@semantic-release/exec":"^7.1.0","@semantic-release/changelog":"^6.0.3","@commitlint/config-conventional":"^20.5.3"},"peerDependencies":{"silk-wasm":"^3.7.1","mpg123-decoder":"^1.0.3"},"peerDependenciesMeta":{"silk-wasm":{"optional":true},"mpg123-decoder":{"optional":true}},"_npmOperationalInternal":{"tmp":"tmp/qqbot-nodejs_1.0.3_1783929096498_0.33303800286455765","host":"s3://npm-registry-packages-npm-production"}},"1.0.4":{"name":"@tencent-connect/qqbot-nodejs","version":"1.0.4","keywords":["qqbot","qq","tencent","bot","sdk","websocket","openapi"],"license":"MIT","_id":"@tencent-connect/qqbot-nodejs@1.0.4","maintainers":[{"name":"uv-w","email":"9837438@qq.com"},{"name":"vnues","email":"1518190293@qq.com"},{"name":"zuosh","email":"13366589984@163.com"},{"name":"joyqwang","email":"645153050@qq.com"},{"name":"tencentconnectqqbot","email":"tencentconnectqqbot@gmail.com"},{"name":"ryanlee-gemini","email":"ryanlee.gemini@gmail.com"}],"dist":{"shasum":"8f239c32f5dc7ec2a8930a088cb363e83ab249a7","tarball":"https://registry.npmjs.org/@tencent-connect/qqbot-nodejs/-/qqbot-nodejs-1.0.4.tgz","fileCount":293,"integrity":"sha512-gU5HySLplczZXMUjM7NtiUACY7YfX9YlI/R9PKzCLMgLmHvwsX9L2sitsrYPMentGUr9b8NLfSaSTsndF77NBA==","signatures":[{"sig":"MEQCICxSU8XBApUgA/FgqPCux4yFPYblRphKbU+pkqzZQdZjAiAnZwOM2vAVPOy8Xp3GVVLyyPylkdBIvcRoArOd35bPzA==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":1163483},"main":"./dist/index.js","type":"module","types":"./dist/index.d.ts","engines":{"node":">=18"},"exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js"},"./protocol":{"types":"./dist/protocol/index.d.ts","import":"./dist/protocol/index.js"}},"gitHead":"589597a6cb5a24dce8230ba53bfba5390e13c073","scripts":{"lint":"eslint .","test":"vitest run","build":"tsc -p tsconfig.build.json","prepack":"npm run build","typecheck":"tsc -p tsconfig.json --noEmit","commitlint":"commitlint","playground":"tsx examples/playground/index.ts","test:watch":"vitest","test:coverage":"vitest run --coverage","example:webhook":"tsx examples/webhook/index.ts","playground:build":"node --import tsx examples/playground/index.ts","semantic-release":"semantic-release","ci:prepare-test-pkg":"node scripts/prepare-test-pkg.js"},"_npmUser":{"name":"tencentconnectqqbot","email":"tencentconnectqqbot@gmail.com"},"_npmVersion":"11.16.0","description":"Tencent QQ Bot Node.js SDK — protocol-level client for the QQ Open Platform (HTTP + WebSocket Gateway, message + media + streaming).","directories":{},"_nodeVersion":"24.18.0","dependencies":{"ws":"^8.21.0"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"tsx":"^4.23.0","eslint":"^10.6.0","vitest":"^4.1.10","globals":"^17.7.0","@types/ws":"^8.18.1","silk-wasm":"^3.7.1","@eslint/js":"^10.0.1","typescript":"^5.9.3","@types/node":"^22.20.1","mpg123-decoder":"^1.0.3","@commitlint/cli":"^20.5.3","semantic-release":"^25.0.5","typescript-eslint":"^8.63.0","@vitest/coverage-v8":"^4.1.10","@semantic-release/git":"^10.0.1","@semantic-release/exec":"^7.1.0","@semantic-release/changelog":"^6.0.3","@commitlint/config-conventional":"^20.5.3"},"peerDependencies":{"silk-wasm":"^3.7.1","mpg123-decoder":"^1.0.3"},"peerDependenciesMeta":{"silk-wasm":{"optional":true},"mpg123-decoder":{"optional":true}},"_npmOperationalInternal":{"tmp":"tmp/qqbot-nodejs_1.0.4_1784000728784_0.9935049769407405","host":"s3://npm-registry-packages-npm-production"}},"1.0.5":{"name":"@tencent-connect/qqbot-nodejs","version":"1.0.5","keywords":["qqbot","qq","tencent","bot","sdk","typescript","esm","websocket","webhook","openapi","chatbot","streaming"],"author":{"name":"Tencent"},"license":"MIT","_id":"@tencent-connect/qqbot-nodejs@1.0.5","maintainers":[{"name":"uv-w","email":"9837438@qq.com"},{"name":"vnues","email":"1518190293@qq.com"},{"name":"zuosh","email":"13366589984@163.com"},{"name":"joyqwang","email":"645153050@qq.com"},{"name":"tencentconnectqqbot","email":"tencentconnectqqbot@gmail.com"},{"name":"ryanlee-gemini","email":"ryanlee.gemini@gmail.com"}],"homepage":"https://github.com/tencent-connect/qqbot-nodejs#readme","bugs":{"url":"https://github.com/tencent-connect/qqbot-nodejs/issues"},"dist":{"shasum":"97a6d5392e479441a558310d1ef40d4735aee81c","tarball":"https://registry.npmjs.org/@tencent-connect/qqbot-nodejs/-/qqbot-nodejs-1.0.5.tgz","fileCount":301,"integrity":"sha512-OAPGoZTtG3soI79lGNQ4YqdAe9xy+lYatUfzZyBPmjaRjH0uLjFeImffMlGVSmhfaM/wJQSIA2g1uZv3eorTRg==","signatures":[{"sig":"MEUCIF7ipAjekU0TEYs8n13iCoOv+YnD75gbBcUJWMw7YMqAAiEAwwzrTYrIa7Gan2HHZaYizXJQ2JcsPb0gCTPF15IR9RU=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"},{"sig":"MEYCIQD85WOJUolNzdUKZ1dhfdhwXsjILRFvRK5jVA/6aJYZogIhAIwZj03zZ2GJUOsn+Y1I5eU8bZ16xSnjXH3Z6rnSbEo5","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":1222357},"main":"./dist/index.js","type":"module","types":"./dist/index.d.ts","engines":{"node":">=20"},"exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js"},"./protocol":{"types":"./dist/protocol/index.d.ts","import":"./dist/protocol/index.js"}},"gitHead":"429a0f1b798f3b0fcef3679e207dbc0469a1df2d","scripts":{"lint":"eslint .","test":"vitest run","build":"tsc -p tsconfig.json","prepack":"npm run build","typecheck":"tsc -p tsconfig.json --noEmit","commitlint":"commitlint","playground":"tsx examples/playground/index.ts","test:watch":"vitest","test:coverage":"vitest run --coverage","example:webhook":"tsx examples/webhook/index.ts","semantic-release":"semantic-release","ci:prepare-test-pkg":"node scripts/prepare-test-pkg.js"},"_npmUser":{"name":"tencentconnectqqbot","email":"tencentconnectqqbot@gmail.com"},"repository":{"url":"git+https://github.com/tencent-connect/qqbot-nodejs.git","type":"git"},"_npmVersion":"11.19.0","description":"Tencent QQ Bot Node.js SDK — protocol-level client for the QQ Open Platform (HTTP + WebSocket Gateway, message + media + streaming).","directories":{},"_nodeVersion":"24.21.0","dependencies":{"ws":"^8.21.0"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"packageManager":"pnpm@9.15.0","devDependencies":{"tsx":"^4.23.0","eslint":"^10.6.0","vitest":"^4.1.10","globals":"^17.7.0","@types/ws":"^8.18.1","silk-wasm":"^3.7.1","@eslint/js":"^10.0.1","typescript":"^5.9.3","@types/node":"^22.20.1","mpg123-decoder":"^1.0.3","@commitlint/cli":"^20.5.3","semantic-release":"^25.0.5","typescript-eslint":"^8.63.0","@vitest/coverage-v8":"^4.1.10","@semantic-release/git":"^10.0.1","@semantic-release/changelog":"^6.0.3","@commitlint/config-conventional":"^20.5.3"},"peerDependencies":{"silk-wasm":"^3.7.1","mpg123-decoder":"^1.0.3"},"peerDependenciesMeta":{"silk-wasm":{"optional":true},"mpg123-decoder":{"optional":true}},"_npmOperationalInternal":{"tmp":"tmp/qqbot-nodejs_1.0.5_1791774685027_0.026725074411967586","host":"s3://npm-registry-packages-npm-production"}},"1.0.6":{"_id":"@tencent-connect/qqbot-nodejs@1.0.6","bugs":{"url":"https://github.com/tencent-connect/qqbot-nodejs/issues"},"dist":{"shasum":"ed1286addebef82208ba1bcd55f6f840a1a573b4","tarball":"https://registry.npmjs.org/@tencent-connect/qqbot-nodejs/-/qqbot-nodejs-1.0.6.tgz","fileCount":303,"integrity":"sha512-tXrNvkMxvQV6dpbwd2wPH6w3J2B9dnqCGsjAEALldY5x4aS7ole74IDnNoJf7CGOqiXx4R60NwSbjFzeFmK7Ow==","signatures":[{"sig":"MEYCIQDfoq3PweWQMoaZz5xkLSGuDOIGk3vLc91oDfXydZXIVAIhANSlHk4MEYJTXiNCdC0bR6s59cPzQ/DrWuQojJg4BtuI","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"},{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCIDg27EbAZUEswTXya3fzfhn3H4HhA2bGA2JLam+ANwrsAiBm8z2ojvVCeFOxVS3cvdM9GCjydOxNmSP6Pj6+1ICdpQ=="}],"unpackedSize":2038561},"main":"./dist/index.js","name":"@tencent-connect/qqbot-nodejs","type":"module","types":"./dist/index.d.ts","author":{"name":"Tencent"},"engines":{"node":">=20"},"exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js"},"./protocol":{"types":"./dist/protocol/index.d.ts","import":"./dist/protocol/index.js"}},"gitHead":"b316f184a0eddfeedfca9f724e5fa2b7ddf90aae","license":"MIT","scripts":{"lint":"eslint .","test":"vitest run","build":"tsc -p tsconfig.json","prepack":"npm run build","typecheck":"tsc -p tsconfig.json --noEmit","commitlint":"commitlint","playground":"tsx examples/playground/index.ts","test:watch":"vitest","test:coverage":"vitest run --coverage","example:webhook":"tsx examples/webhook/index.ts","semantic-release":"semantic-release","ci:prepare-test-pkg":"node scripts/prepare-test-pkg.js"},"version":"1.0.6","_npmUser":{"name":"tencentconnectqqbot","email":"tencentconnectqqbot@gmail.com"},"homepage":"https://github.com/tencent-connect/qqbot-nodejs#readme","keywords":["qqbot","qq","tencent","bot","sdk","typescript","esm","websocket","webhook","openapi","chatbot","streaming"],"repository":{"url":"git+https://github.com/tencent-connect/qqbot-nodejs.git","type":"git"},"_npmVersion":"11.19.1","description":"Tencent QQ Bot Node.js SDK — protocol-level client for the QQ Open Platform (HTTP + WebSocket Gateway, message + media + streaming).","directories":{},"maintainers":[{"name":"uv-w","email":"9837438@qq.com"},{"name":"vnues","email":"1518190293@qq.com"},{"name":"zuosh","email":"13366589984@163.com"},{"name":"joyqwang","email":"645153050@qq.com"},{"name":"tencentconnectqqbot","email":"tencentconnectqqbot@gmail.com"},{"name":"ryanlee-gemini","email":"ryanlee.gemini@gmail.com"}],"_nodeVersion":"24.22.3","dependencies":{"ws":"^8.21.0"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"packageManager":"pnpm@9.15.0","devDependencies":{"tsx":"^4.23.0","eslint":"^10.6.0","vitest":"^4.1.10","globals":"^17.7.0","@types/ws":"^8.18.1","silk-wasm":"^3.7.1","@eslint/js":"^10.0.1","typescript":"^5.9.3","@types/node":"^22.20.1","mpg123-decoder":"^1.0.3","@commitlint/cli":"^20.5.3","semantic-release":"^25.0.5","typescript-eslint":"^8.63.0","@vitest/coverage-v8":"^4.1.10","@semantic-release/git":"^10.0.1","@semantic-release/changelog":"^6.0.3","@commitlint/config-conventional":"^20.5.3"},"peerDependencies":{"silk-wasm":"^3.7.1","mpg123-decoder":"^1.0.3"},"peerDependenciesMeta":{"silk-wasm":{"optional":true},"mpg123-decoder":{"optional":true}},"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/qqbot-nodejs_1.0.6_1795414352287_0.39937332395596115"}}},"time":{"created":"2026-07-13T07:51:36.272Z","modified":"2026-11-23T06:12:32.654Z","1.0.0":"2026-04-30T09:16:06.639Z","1.0.3":"2026-07-13T07:51:36.724Z","1.0.4":"2026-07-14T03:45:28.976Z","1.0.5":"2026-10-12T03:11:25.128Z","1.0.6":"2026-11-23T06:12:32.412Z"},"bugs":{"url":"https://github.com/tencent-connect/qqbot-nodejs/issues"},"author":{"name":"Tencent"},"license":"MIT","homepage":"https://github.com/tencent-connect/qqbot-nodejs#readme","keywords":["qqbot","qq","tencent","bot","sdk","typescript","esm","websocket","webhook","openapi","chatbot","streaming"],"repository":{"url":"git+https://github.com/tencent-connect/qqbot-nodejs.git","type":"git"},"description":"Tencent QQ Bot Node.js SDK — protocol-level client for the QQ Open Platform (HTTP + WebSocket Gateway, message + media + streaming).","maintainers":[{"name":"uv-w","email":"9837438@qq.com"},{"name":"vnues","email":"1518190293@qq.com"},{"name":"zuosh","email":"13366589984@163.com"},{"name":"joyqwang","email":"645153050@qq.com"},{"name":"tencentconnectqqbot","email":"tencentconnectqqbot@gmail.com"},{"name":"ryanlee-gemini","email":"ryanlee.gemini@gmail.com"}],"readme":"# @tencent-connect/qqbot-nodejs\n\n> [English](./README.md) · **简体中文**（本文件）\n\n[![npm version](https://img.shields.io/npm/v/@tencent-connect/qqbot-nodejs.svg)](https://www.npmjs.com/package/@tencent-connect/qqbot-nodejs)\n[![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)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](./LICENSE)\n[![Node.js Version](https://img.shields.io/node/v/@tencent-connect/qqbot-nodejs.svg)](https://nodejs.org)\n\nTencent QQ Open Platform Node.js SDK。提供与 QQ 机器人开放平台对接所需的全部\n协议层能力：HTTP REST、WebSocket / Webhook 双传输、Koa-style 中间件管线、\n消息收发、媒体上传（含大文件分块）、C2C 流式消息（stream_messages）。\n\n## 资源与社区\n\n- **[QQ 开放平台官方文档](https://bot.q.qq.com/wiki/develop/api-v2/)** — 平台 API、事件与错误码的一手定义。\n\n扫码添加反馈小助手 / 加入开发者频道\n\n<table align=\"center\">\n<tr>\n<td align=\"center\" width=\"50%\"><img src=\"./assets/docs/feedback.jpg\" height=\"360\" alt=\"反馈小助手二维码\" /><br /><b>反馈小助手</b><br /><sub>QQ 机器人开放平台官方小助手 · 工单服务时间：工作日 10:00–20:00</sub></td>\n<td align=\"center\" width=\"50%\"><img src=\"./assets/docs/qqchannel.jpg\" height=\"360\" alt=\"QQ 频道二维码\" /><br /><b>QQ 开发者社区频道</b><br /><sub>频道号: 20dnumts4z</sub></td>\n</tr>\n</table>\n\n## 环境要求\n\n- Node.js **>= 20**（依赖全局 `fetch` 与 `AbortController`）。\n- 包是纯 ESM（`\"type\": \"module\"`）。如果你的工程是 CJS，请通过动态 `import()` 加载。\n\n## 安装\n\n```bash\npnpm add @tencent-connect/qqbot-nodejs\n# 或\nnpm install @tencent-connect/qqbot-nodejs\n```\n\n## 快速开始\n\n```ts\nimport { QQBot } from \"@tencent-connect/qqbot-nodejs\";\n\nconst bot = new QQBot({\n  appId: process.env.QQBOT_APP_ID!,\n  appSecret: process.env.QQBOT_APP_SECRET!,\n  logger: console,\n});\n\nbot.on(\"message\", async (ctx, msg) => {\n  // ctx — Koa-style MiddlewareContext，携带 middleware 注入的数据\n  await bot.sendText(msg.replyTarget, `Echo: ${msg.content}`);\n});\n\nawait bot.start();\n```\n\n参考 [examples/](./examples/) 下的完整示例：\n\n| 示例 | 说明 |\n|------|------|\n| [playground](./examples/playground/) | 核心能力演示（文本、流式、媒体、命令） |\n| [middleware](./examples/middleware/) | 完整 13 层 Koa-style 中间件管线 |\n| [webhook](./examples/webhook/) | Webhook（HTTP 回调）传输模式 |\n| [send-plain-100](./examples/send-plain-100/) | 普通文本发送对照实验 |\n| [send-streaming-100](./examples/send-streaming-100/) | 流式消息发送对照实验 |\n\n> 示例从 `process.env` 读取 `QQBOT_APP_ID` / `QQBOT_APP_SECRET` **仅为演示方便**。\n> SDK 自身从不读取环境变量，凭证一律通过 `new QQBot({ appId, appSecret })` 注入。\n\n## 主要能力\n\n### 1. 双传输模式（WebSocket / Webhook）\n\n```ts\n// WebSocket（默认）— 长连接 + 心跳 + RESUME\nconst bot = new QQBot({ appId, appSecret });\n\n// Webhook — HTTP 回调，适合 Serverless / 水平扩展\nconst bot = new QQBot({\n  appId, appSecret,\n  transport: \"webhook\",\n  webhook: { port: 8080, path: \"/callback\" },\n});\n```\n\n两种模式下中间件、事件监听、消息发送 API 完全一致。\n\n### 2. Koa-style 中间件\n\nSDK 采用洋葱模型中间件，`bot.on(\"message\")` 作为 chain 最内层 downstream：\n\n```ts\nimport { errorHandler, messageFilter, contentSanitizer, mentionGate } from \"@tencent-connect/qqbot-nodejs\";\n\nbot.use(errorHandler());\nbot.use(messageFilter({ skipSelfEcho: true, dedup: { windowMs: 5000 } }));\nbot.use(contentSanitizer({ stripBotMention: true }));\nbot.use(mentionGate({ requireMentionInGroup: true }));\n\n// 自定义中间件\nbot.use(async (ctx, next) => {\n  const start = Date.now();\n  await next();\n  ctx.log.debug?.(`elapsed: ${Date.now() - start}ms`);\n});\n```\n\n内置中间件：\n\n| 中间件 | 说明 |\n|--------|------|\n| `errorHandler` | 统一错误捕获 + 友好回复 |\n| `messageFilter` | 过滤 bot 回声 + 消息去重 |\n| `rateLimiter` | 三层限流（sender / group / global） |\n| `concurrencyGuard` | 同用户/群串行处理（防 stream 并发冲突） |\n| `accessPolicy` | 黑白名单 |\n| `contentSanitizer` | 去 @marker / face tags / 空白清洗 |\n| `mentionGate` | 群聊 @bot 判定 |\n| `quoteRef` | 消息索引记录 + 引用消息解析 |\n| `historyBuffer` | 群历史缓冲 |\n| `envelopeFormatter` | 组装 LLM prompt 上下文（XML tags） |\n| `typingIndicator` | C2C 自动 typing |\n| `slashCommand` | /cmd 命令框架 |\n\n### 3. 文本消息\n\n```ts\nawait bot.sendText(target, \"hello\");\n```\n\n### 4. 文件 / 图片 / 语音\n\n`sendImage` / `sendVoice` / `sendVideo` / `sendFile` 是 `sendMedia` 的便捷封装。\n当源文件 ≥ 5MB 时自动走分块上传。\n\n```ts\nawait bot.sendImage(target, { localPath: \"/tmp/cat.jpg\" });\n\nawait bot.sendFile(\n  target,\n  { buffer: bigBuffer },\n  {\n    fileName: \"report.pdf\",\n    onProgress: (uploaded, total) => console.log(`${uploaded}/${total}`),\n  },\n);\n```\n\n### 5. C2C 流式消息\n\n```ts\nconst stream = bot.openStream({ target });\nfor (const partial of generator) {\n  await stream.update(partial);\n}\nawait stream.complete();\n```\n\nQQ 开放平台限制：`stream_messages` 仅在 C2C（私聊）开放。\n\n### 6. 事件监听\n\n```ts\nbot.on(\"ready\", () => console.log(\"connected\"));\nbot.on(\"resumed\", () => console.log(\"reconnected\"));\nbot.on(\"disconnected\", ({ code, willReconnect }) => console.log(\"closed\", code, willReconnect));\nbot.on(\"error\", (err) => console.error(err)); // 可恢复的错误，不会结束 start()\nbot.on(\"message\", (ctx, msg) => { /* C2C / Group / Guild / DM */ });\nbot.on(\"interaction\", (ctx, event) => { /* button click etc. */ });\n```\n\n### 7. 生命周期\n\nWebSocket 模式默认无限重连。`start()` 在 `stop()` / abort 时正常返回；仅在无法恢复时\n先释放连接与 token 刷新任务、再拒绝：\n\n| 拒绝 | 原因 | 处理 |\n|---|---|---|\n| `GatewayError` `GATEWAY_FATAL_CLOSE` | 4914 下线/仅沙箱、4915 被封禁 | 需人工处理，不要重启 |\n| `GatewayError` `GATEWAY_RETRY_EXHAUSTED` | 仅在设置了有限 `reconnect.maxAttempts` 时 | 退避后重启 |\n| `Error` | 启动时拉取 token 失败（默认 `tokenPrefetch: \"sync\"`） | 检查凭证 / 网络 |\n\n```ts\nimport { GatewayErrorCode, QQBot } from \"@tencent-connect/qqbot-nodejs\";\n\n// 外层有进程级重启时才设上限\nconst bot = new QQBot({ appId, appSecret, reconnect: { maxAttempts: 10 } });\ntry {\n  await bot.start(signal);\n} catch (err) {\n  if ((err as { code?: string }).code === GatewayErrorCode.FATAL_CLOSE) markBlocked(err);\n  else scheduleRestart(err);\n}\n```\n\n`bot.stop(); bot.start();` 可原地重启。关闭码处理详见 [USAGE.md §7](./USAGE.md#7-生命周期管理)。\n\n### 8. 协议层直接访问\n\n```ts\nimport {\n  ApiClient,\n  TokenManager,\n  GatewayConnection,\n  withRetry,\n} from \"@tencent-connect/qqbot-nodejs/protocol\";\n```\n\n## 文档\n\n- **[USAGE.md](./USAGE.md)** — 完整使用指南。\n\n## 可选依赖\n\n以下 `peerDependencies` 声明为可选，只在使用对应功能时才需要安装：\n\n| 包 | 作用 |\n| ----------------- | ------------------------------------------ |\n| `silk-wasm`       | 发送语音消息（SILK 编码）                  |\n| `mpg123-decoder`  | 将 MP3 解码为 PCM，再编码为 SILK           |\n\n## 贡献\n\n欢迎提交 bug 反馈、功能建议与 PR。请先阅读：\n\n- [CONTRIBUTING.md](./CONTRIBUTING.md) — 开发流程与 commit 规范\n- [SECURITY.md](./SECURITY.md) — 安全漏洞的报告方式\n\n## 模块结构\n\n```\nsrc/\n├── QQBot.ts                ← 高层 facade\n├── streaming.ts            ← C2C 流式消息控制器\n├── index.ts                ← 公开 API\n├── middleware/              ← Koa-style 中间件\n│   ├── types.ts                  中间件类型 + 洋葱执行器\n│   ├── error-handler.ts          统一错误捕获\n│   ├── message-filter.ts         回声过滤 + 去重\n│   ├── rate-limiter.ts           三层限流\n│   ├── concurrency-guard.ts     同用户/群串行处理\n│   ├── access-policy.ts          黑白名单\n│   ├── content-sanitizer.ts      内容清洗\n│   ├── mention-gate.ts           @bot 判定\n│   ├── quote-ref.ts              引用消息解析 + 消息索引\n│   ├── history-buffer.ts         群历史缓冲\n│   ├── envelope-formatter.ts     LLM prompt 组装\n│   ├── typing-indicator.ts       typing 状态\n│   └── slash-command.ts          命令框架\n└── protocol/               ← 协议层\n    ├── api/\n    │   ├── api-client.ts         HTTP 客户端\n    │   ├── token.ts              access_token 管理\n    │   ├── messages.ts           消息发送\n    │   ├── media.ts              小文件上传\n    │   ├── media-chunked.ts      大文件分块上传\n    │   ├── retry.ts              重试引擎\n    │   └── routes.ts             路由模板\n    ├── gateway/\n    │   ├── constants.ts          opcode / intent / close code\n    │   ├── codec.ts              消息解码\n    │   ├── reconnect.ts          重连状态机 + 重连策略\n    │   ├── errors.ts             GatewayError（start() 终态错误）\n    │   ├── event-dispatcher.ts   事件 → InboundMessage\n    │   └── gateway-connection.ts WebSocket 生命周期\n    ├── transport/\n    │   ├── types.ts              EventTransport 接口\n    │   ├── webhook.ts            Webhook 传输\n    │   ├── webhook-verify.ts     Ed25519 签名验证\n    │   └── webhook-server-node.ts  内置 node:http 适配器\n    ├── utils/\n    │   ├── format.ts             格式化工具\n    │   ├── file-utils.ts         文件工具\n    │   └── upload-cache.ts       file_info TTL 缓存\n    ├── types.ts                  全部公共类型 + 错误\n    └── index.ts                  protocol 子入口\n```\n\n## 贡献者\n\n感谢所有为本项目作出贡献的开发者！\n\n<a href=\"https://github.com/tencent-connect/qqbot-nodejs/graphs/contributors\">\n  <img src=\"https://contrib.rocks/image?repo=tencent-connect/qqbot-nodejs\" alt=\"Contributors\" />\n</a>\n\n<sub>贡献者头像由 [contrib.rocks](https://contrib.rocks) 自动渲染。</sub>\n\n## License\n\nMIT\n","readmeFilename":"README.zh-CN.md"}