t3-code-qqbot 0.0.0-stage → 1.2.2
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/LICENSE +21 -0
- package/README.md +122 -2
- package/config.example.json +34 -0
- package/credentials.example.json +5 -0
- package/dist/bridge.mjs +2472 -0
- package/dist/cli.mjs +2195 -0
- package/dist/gateway.mjs +248 -0
- package/dist/publish.mjs +865 -0
- package/docs/SETUP.md +386 -0
- package/package.json +69 -4
- package/scripts/install-windows-task.ps1 +60 -0
- package/scripts/start-windows.ps1 +55 -0
- package/scripts/t3-code-qqbot.service +21 -0
package/docs/SETUP.md
ADDED
|
@@ -0,0 +1,386 @@
|
|
|
1
|
+
# T3 Code QQBot 从 0 开始完整配置教程(Windows & Linux)
|
|
2
|
+
|
|
3
|
+
本教程带你从零完成 **QQ 开放平台建号 -> 本地环境准备 -> 插件安装 -> 绑定会话 -> 双向图片/文件收发 -> 后台开机自启** 的全流程。
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## 目录
|
|
8
|
+
|
|
9
|
+
1. [环境前置要求](#1-环境前置要求)
|
|
10
|
+
2. [在 QQ 开放平台创建机器人](#2-在-qq-开放平台创建机器人)
|
|
11
|
+
3. [安装插件(Windows & Linux)](#3-安装插件windows--linux)
|
|
12
|
+
4. [初始化配置与填写凭据](#4-初始化配置与填写凭据)
|
|
13
|
+
5. [获取你的 QQ `user_openid` / `group_openid`](#5-获取你的-qq-user_openid--group_openid)
|
|
14
|
+
6. [绑定 T3 Code 工作区与会话](#6-绑定-t3-code-工作区与会话)
|
|
15
|
+
7. [(可选)启用 `qqbot_send_media` 让 AI 回传图片/文件](#7-可选启用-qqbot_send_media-让-ai-回传图片文件)
|
|
16
|
+
8. [体检与验收测试](#8-体检与验收测试)
|
|
17
|
+
9. [配置后台常驻与开机自启](#9-配置后台常驻与开机自启)
|
|
18
|
+
10. [进阶:Linux 网关 + Windows T3 双机分离部署](#10-进阶linux-网关--windows-t3-双机分离部署)
|
|
19
|
+
11. [配置项与环境变量速查](#11-配置项与环境变量速查)
|
|
20
|
+
12. [常见问题排查(FAQ)](#12-常见问题排查faq)
|
|
21
|
+
|
|
22
|
+
---
|
|
23
|
+
|
|
24
|
+
## 1. 环境前置要求
|
|
25
|
+
|
|
26
|
+
### 1.1 安装 Node.js 24+
|
|
27
|
+
|
|
28
|
+
本插件要求 **Node.js 24.0.0 或更高版本**。
|
|
29
|
+
|
|
30
|
+
- **Windows**:从 [Node.js 官网](https://nodejs.org/) 下载 Node.js 24 LTS 安装包,或使用 `winget`:
|
|
31
|
+
```powershell
|
|
32
|
+
winget install OpenJS.NodeJS.24
|
|
33
|
+
node -v
|
|
34
|
+
```
|
|
35
|
+
- **Linux(Ubuntu / Debian 示例)**:
|
|
36
|
+
```bash
|
|
37
|
+
curl -fsSL https://deb.nodesource.com/setup_24.x | sudo -E bash -
|
|
38
|
+
sudo apt-get install -y nodejs
|
|
39
|
+
node -v
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
确认输出类似 `v24.x.x`。
|
|
43
|
+
|
|
44
|
+
### 1.2 安装并运行官方 T3 Code
|
|
45
|
+
|
|
46
|
+
1. 安装官方 T3 Code(Windows 桌面版或 Linux 桌面版 / CLI 服务版)。
|
|
47
|
+
2. 启动 T3 Code,并在 T3 Code 中**打开或新建至少一个项目工作区**(例如 Windows 的 `D:\Work\my-qq-workspace` 或 Linux 的 `/home/you/my-qq-workspace`)。
|
|
48
|
+
3. 确认 T3 Code 本地服务可访问(默认端口 `3773`):
|
|
49
|
+
- **Windows PowerShell**:
|
|
50
|
+
```powershell
|
|
51
|
+
Invoke-WebRequest -UseBasicParsing -Uri http://127.0.0.1:3773 -Method Head
|
|
52
|
+
```
|
|
53
|
+
- **Linux Bash**:
|
|
54
|
+
```bash
|
|
55
|
+
curl -I http://127.0.0.1:3773
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
> **提示**:
|
|
59
|
+
> - Windows 桌面版 T3 Code 安装后即使 `%USERPROFILE%\.t3\bin` 未加入 `PATH`,插件的 `t3.executable: "auto"` 也会自动定位 `%USERPROFILE%\.t3\bin\t3.cmd` 并解析底层可执行文件。
|
|
60
|
+
> - 如果你的 T3 Code 监听在非 `3773` 端口,记下它的地址(例如 `http://127.0.0.1:4773`),稍后填入 `config.json` 的 `t3.origin`。
|
|
61
|
+
|
|
62
|
+
---
|
|
63
|
+
|
|
64
|
+
## 2. 在 QQ 开放平台创建机器人
|
|
65
|
+
|
|
66
|
+
1. 登录 [QQ 开放平台](https://q.qq.com/),进入 **机器人** 控制台并创建一个新的 QQ 机器人。
|
|
67
|
+
2. 在 **开发管理 -> 开发设置** 页面获取以下两项凭据:
|
|
68
|
+
- **AppID**(一串数字,如 `102xxxxxx`)
|
|
69
|
+
- **AppSecret**(机器人密钥,点击重置/查看并妥善保管)
|
|
70
|
+
3. **配置 IP 白名单(关键步骤)**:
|
|
71
|
+
- 在 **开发设置 -> IP 白名单** 中,添加运行 `gateway` 机器的**公网出口 IP**。
|
|
72
|
+
- 查询本机公网 IP:
|
|
73
|
+
- **Windows PowerShell**:`curl.exe https://ifconfig.me`
|
|
74
|
+
- **Linux Bash**:`curl https://ifconfig.me`
|
|
75
|
+
- 若公网 IP 未加入白名单,连接 QQ OpenAPI 获取 Token 时会报鉴权失败。
|
|
76
|
+
- **家庭宽带提醒**:若家庭宽带公网 IP 频繁变动,建议把 `gateway` 部署在固定 IP 的 Linux 云主机,参考第 10 节做双机分离转发。
|
|
77
|
+
4. **开启沙箱 / 消息权限**:
|
|
78
|
+
- 确认事件接收方式支持 **WebSocket** 模式。
|
|
79
|
+
- 在 **开发管理 -> 沙箱配置** 中添加你自己的 QQ 号(以及需要测试的 QQ 群)。
|
|
80
|
+
- 确保机器人拥有 **单聊消息(`C2C_MESSAGE_CREATE`)** 和/或 **群聊 @ 消息(`GROUP_AT_MESSAGE_CREATE`)** 权限。
|
|
81
|
+
5. 用手机 QQ 扫描机器人的测试二维码,将机器人添加到你的好友列表(或拉入测试群)。
|
|
82
|
+
|
|
83
|
+
---
|
|
84
|
+
|
|
85
|
+
## 3. 安装插件(Windows & Linux)
|
|
86
|
+
|
|
87
|
+
### 方式一:npm 全局安装(推荐,跨平台统一命令 `t3-qqbot`)
|
|
88
|
+
|
|
89
|
+
```bash
|
|
90
|
+
npm i -g t3-code-qqbot
|
|
91
|
+
mkdir -p ~/t3-qqbot && cd ~/t3-qqbot
|
|
92
|
+
```
|
|
93
|
+
(Windows PowerShell 下执行 `mkdir C:\Tools\t3-qqbot; cd C:\Tools\t3-qqbot`。)
|
|
94
|
+
|
|
95
|
+
### 方式二:下载 GitHub Release 离线发布包
|
|
96
|
+
|
|
97
|
+
- **Windows(PowerShell)**:
|
|
98
|
+
```powershell
|
|
99
|
+
Expand-Archive -Path .\t3-code-qqbot-v1.2.2.zip -DestinationPath C:\Tools\
|
|
100
|
+
cd C:\Tools\t3-code-qqbot-v1.2.2
|
|
101
|
+
npm ci --omit=dev
|
|
102
|
+
```
|
|
103
|
+
- **Linux(Bash)**:
|
|
104
|
+
```bash
|
|
105
|
+
mkdir -p ~/t3-code-qqbot
|
|
106
|
+
tar -xzf t3-code-qqbot-v1.2.2.tar.gz -C ~/t3-code-qqbot --strip-components=1
|
|
107
|
+
cd ~/t3-code-qqbot
|
|
108
|
+
npm ci --omit=dev
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
> 下文命令以 `t3-qqbot` 为例;如果你使用离线发布包(未全局安装),将 `t3-qqbot` 替换为 `node dist/cli.mjs` 即可。
|
|
112
|
+
|
|
113
|
+
---
|
|
114
|
+
|
|
115
|
+
## 4. 交互式安装向导、扫码绑定与配置菜单
|
|
116
|
+
|
|
117
|
+
直接运行初始化向导(支持**手机 QQ 终端扫码一键绑定**,直接拿到 `AppID`、`AppSecret` 和你的 `user_openid`,省去手抄密钥和查 openid 的步骤;同时引导配置端口、斜杠指令面板、群聊 `@`、侧边栏自动收纳、项目绑定以及**一键注册开机自启与后台自守护**):
|
|
118
|
+
|
|
119
|
+
```bash
|
|
120
|
+
t3-qqbot init
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
- 也可以随时单独运行 `t3-qqbot login` 扫码重新绑定 QQ 机器人。
|
|
124
|
+
- 自动化脚本或无需交互时,加 `--yes`(或 `-y`)直接生成默认配置:`t3-qqbot init --yes`。
|
|
125
|
+
- 以后随时想改任何一项配置,运行 `t3-qqbot config` 即可再次打开完整交互式配置菜单:
|
|
126
|
+
- `[1]` QQ Bot 凭据(`AppID` / `AppSecret` / 重新生成随机 `bridgeSecret`)
|
|
127
|
+
- `[2]` T3 Code 连接(`t3.origin` / `t3.executable` / `t3.home`)
|
|
128
|
+
- `[3]` 桥接与网关参数(端口 / 单条字数上限 / 群聊 `@` / 指令前缀)
|
|
129
|
+
- `[4]` QQ 会话绑定管理(自动读取 T3 已注册项目列表按编号选择)
|
|
130
|
+
- `[5]` 附件域名白名单
|
|
131
|
+
- `[6]` 一键安装与管理后台自守护服务
|
|
132
|
+
- `[7]` 可选主会话侧边栏收纳(`autoSettleThread`)与补丁版静音线程 ID 导出
|
|
133
|
+
- `[8]` 运行 6 步全链路体检(`doctor`)
|
|
134
|
+
|
|
135
|
+
也可使用非交互命令快捷修改单项配置:
|
|
136
|
+
```bash
|
|
137
|
+
t3-qqbot config show
|
|
138
|
+
t3-qqbot config set bridge.port 18774
|
|
139
|
+
t3-qqbot config set bridge.autoSettleThread true
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
若习惯直接手动编辑 `credentials.json`,填入第 2 步从 QQ 开放平台拿到的 `appId` 和 `appSecret`:
|
|
143
|
+
|
|
144
|
+
```json
|
|
145
|
+
{
|
|
146
|
+
"appId": "你的QQ机器人AppID",
|
|
147
|
+
"appSecret": "你的QQ机器人AppSecret",
|
|
148
|
+
"bridgeSecret": "保留 init 自动生成的随机密钥"
|
|
149
|
+
}
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
> **Linux 权限建议**:确保凭据文件仅当前用户可读:
|
|
153
|
+
> ```bash
|
|
154
|
+
> chmod 600 credentials.json
|
|
155
|
+
> ```
|
|
156
|
+
|
|
157
|
+
> **环境变量替代方式(可选)**:如果你不希望把密钥落盘在 `credentials.json`,直接在环境中注入 `QQ_APP_ID`、`QQ_APP_SECRET`、`QQ_BRIDGE_SECRET` 即可(环境变量已完整提供时,即使未创建 `credentials.json` 也能直接运行)。
|
|
158
|
+
|
|
159
|
+
---
|
|
160
|
+
|
|
161
|
+
## 5. 获取你的 QQ `user_openid` / `group_openid`
|
|
162
|
+
|
|
163
|
+
QQ 开放平台后台不会直接显示你个人账号对应的 `user_openid`。最简单的获取方式是直接启动插件并给机器人发一条消息:
|
|
164
|
+
|
|
165
|
+
1. 启动插件:
|
|
166
|
+
```bash
|
|
167
|
+
t3-qqbot start
|
|
168
|
+
```
|
|
169
|
+
看到类似日志表示连接成功:
|
|
170
|
+
```text
|
|
171
|
+
T3 QQBot bridge listening on http://127.0.0.1:18773 (0 binding(s))
|
|
172
|
+
T3 QQBot gateway READY -> http://127.0.0.1:18773/events
|
|
173
|
+
```
|
|
174
|
+
2. 用你的 QQ 给机器人发一条私聊消息(例如 `hello`),或在群里 `@机器人 hello`。
|
|
175
|
+
3. 查看终端日志,桥接会打印一条带精确标识的提示:
|
|
176
|
+
```text
|
|
177
|
+
[unbound] Ignored message from "c2c:ABC1234567890..." (sha256:...). Add this scope to "bindings" in .../config.json to enable it.
|
|
178
|
+
```
|
|
179
|
+
4. 复制引号内的 `c2c:ABC1234567890...`(群聊则为 `group:...`),然后按 `Ctrl+C` 暂时停止服务。
|
|
180
|
+
|
|
181
|
+
---
|
|
182
|
+
|
|
183
|
+
## 6. 绑定 T3 Code 工作区与会话
|
|
184
|
+
|
|
185
|
+
你有**两种绑定方式**可选,均通过 `bind` 命令一键校验并写入 `config.json`:
|
|
186
|
+
|
|
187
|
+
### 方式 A:绑定到工作区,首次聊天自动新建 T3 会话(最简单)
|
|
188
|
+
|
|
189
|
+
- **Windows**:
|
|
190
|
+
```powershell
|
|
191
|
+
t3-qqbot bind --scope c2c:你的USER_OPENID --workspace "D:\Work\my-qq-workspace" --install-media-mcp
|
|
192
|
+
```
|
|
193
|
+
- **Linux**:
|
|
194
|
+
```bash
|
|
195
|
+
t3-qqbot bind --scope c2c:你的USER_OPENID --workspace "/home/you/my-qq-workspace" --install-media-mcp
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
首次在 QQ 发消息时,插件会自动在 T3 Code 对应的项目中创建一条线程并持久化到 `state/bindings/<hash>.thread`,之后的所有消息都会持续在同一线程中续聊。
|
|
199
|
+
|
|
200
|
+
### 方式 B:绑定到 T3 Code 中已有的指定主会话(保留历史上下文)
|
|
201
|
+
|
|
202
|
+
1. 查询目标项目中的线程列表,记下目标 `threadId`(注意必须通过 `--project` 指定项目工作区路径):
|
|
203
|
+
```bash
|
|
204
|
+
t3 thread list --project "<T3项目工作区路径>"
|
|
205
|
+
```
|
|
206
|
+
2. 执行绑定:
|
|
207
|
+
```bash
|
|
208
|
+
t3-qqbot bind --scope c2c:你的USER_OPENID --thread "你的T3_THREAD_ID" --install-media-mcp
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
> **多会话 / 群聊支持**:可对不同的 `c2c:<openid>` 或 `group:<openid>` 重复执行 `bind` 命令。若希望在多会话场景下使用 `qqbot_send_media` 回传文件,请为每个 QQ 对话绑定独立的工作区目录。
|
|
212
|
+
|
|
213
|
+
> **隐私加固(可选)**:如果你不希望 `config.json` 中明文出现 `openid`,也可以把 `scope` 替换为日志里给出的 `sha256:<64位十六进制哈希>`,桥接同样识别。
|
|
214
|
+
|
|
215
|
+
---
|
|
216
|
+
|
|
217
|
+
## 7. (可选)启用 `qqbot_send_media` 让 AI 回传图片/文件
|
|
218
|
+
|
|
219
|
+
加上 `--install-media-mcp` 参数后:
|
|
220
|
+
|
|
221
|
+
- **Antigravity Provider**:
|
|
222
|
+
- 传入 `--thread <threadId>` 时(或本机仅存在单个 Antigravity Provider 实例时),`bind` 会自动把 `qqbot-media` 注册到 `~/.t3/userdata/providers/antigravity/<instanceHash>/config/mcp_config.json`(并自动备份原文件为 `.pre-t3-qqbot`)。
|
|
223
|
+
- 若本机有多个 Antigravity 账号实例且未传 `--thread`,请按提示带上 `--thread <threadId>` 再执行一次 `bind` 即可精确定位对应实例。
|
|
224
|
+
- **Claude Code / 其他 JSON MCP 客户端**:将 `bind` 打印的 JSON 片段加入 MCP 配置:
|
|
225
|
+
```json
|
|
226
|
+
{
|
|
227
|
+
"mcpServers": {
|
|
228
|
+
"qqbot-media": {
|
|
229
|
+
"command": "/path/to/node",
|
|
230
|
+
"args": [
|
|
231
|
+
"/path/to/t3-code-qqbot/dist/publish.mjs",
|
|
232
|
+
"/path/to/config.json"
|
|
233
|
+
]
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
```
|
|
238
|
+
- **Codex CLI(`~/.codex/config.toml`)**:使用 TOML 格式:
|
|
239
|
+
```toml
|
|
240
|
+
[mcp_servers.qqbot-media]
|
|
241
|
+
command = "/path/to/node"
|
|
242
|
+
args = ["/path/to/t3-code-qqbot/dist/publish.mjs", "/path/to/config.json"]
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
配置完成后重启对应 T3 会话或 Provider;之后你在 QQ 里让 AI「画张图发给我」或「把生成的报告发到 QQ」,AI 调用 `qqbot_send_media({ path: "output.png" })` 即可直接把工作区内的文件发回当前 QQ 对话。
|
|
246
|
+
|
|
247
|
+
> **安全边界**:`qqbot_send_media` 严格限制只能发送当前绑定工作区目录内的文件(最大 12 MiB),拒绝 `../` 越界及 Windows UNC 路径;且该 MCP 进程仅需 `appId`/`appSecret`,不需要 `bridgeSecret`。
|
|
248
|
+
|
|
249
|
+
---
|
|
250
|
+
|
|
251
|
+
## 8. 体检与验收测试
|
|
252
|
+
|
|
253
|
+
### 8.1 运行 6 项自动体检
|
|
254
|
+
|
|
255
|
+
```bash
|
|
256
|
+
t3-qqbot doctor
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
> 说明:`doctor` 的 `[3/6]` 仅校验本地凭据非空且非占位符,不向腾讯服务器发包;`AppID`/`AppSecret` 与公网 IP 白名单的有效性会在执行 `start` 连接 QQ 网关时校验。
|
|
260
|
+
|
|
261
|
+
预期全部通过:
|
|
262
|
+
```text
|
|
263
|
+
[1/6] Node.js: v24.x.x (...) OK
|
|
264
|
+
[2/6] Config loaded: .../config.json (1 binding(s))
|
|
265
|
+
[3/6] Credentials loaded: OK (local check only; QQ OpenAPI & IP whitelist verified on gateway connect)
|
|
266
|
+
[4/6] T3 CLI resolved: ...
|
|
267
|
+
[5/6] T3 Code server reachable: http://127.0.0.1:3773
|
|
268
|
+
Binding c2c:... -> ... OK
|
|
269
|
+
[6/6] T3 native attachment upload & discard round-trip: OK
|
|
270
|
+
|
|
271
|
+
All checks passed.
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
### 8.2 启动并实机验收
|
|
275
|
+
|
|
276
|
+
```bash
|
|
277
|
+
t3-qqbot start
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
按以下顺序在 QQ 测试:
|
|
281
|
+
1. **私聊流式回包**:发一条中文消息(如「用三句话介绍你自己」),观察 QQ 内是否实时流式出字,同时打开 T3 Code 桌面端/手机端应能看到同一条对话实时同步。
|
|
282
|
+
2. **连续续聊**:在第一条正在回复或刚结束时紧接着发第二条消息,验证自动排队且上下文连续。
|
|
283
|
+
3. **附件入站**:在 QQ 发送一张图片或语音,检查 T3 会话中是否以原生附件形式干净收到,并能在 `<workspace>/attachments/` 找到落盘原件。
|
|
284
|
+
4. **(若已配 MCP)媒体回传**:让 AI 在工作区生成一张图片并调用 `qqbot_send_media` 发回 QQ。
|
|
285
|
+
|
|
286
|
+
---
|
|
287
|
+
|
|
288
|
+
## 9. 一键配置后台自守护与开机自启(推荐)
|
|
289
|
+
|
|
290
|
+
插件内置跨平台守护服务管理命令,**无需手动编写或修改服务文件**,Windows 与 Linux 统一执行同一条命令即可:
|
|
291
|
+
|
|
292
|
+
```bash
|
|
293
|
+
# 一键注册开机自启并立即在后台启动
|
|
294
|
+
t3-qqbot service install
|
|
295
|
+
|
|
296
|
+
# 常用管理命令
|
|
297
|
+
t3-qqbot service status
|
|
298
|
+
t3-qqbot service restart
|
|
299
|
+
t3-qqbot service stop
|
|
300
|
+
t3-qqbot service uninstall
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
底层行为:
|
|
304
|
+
- **Windows**:在当前用户下免管理员权限注册 Windows 计划任务(`T3 Code QQBot`),通过隐藏 PowerShell 包装启动 `t3-qqbot start --supervise`,无黑框弹窗、崩溃自动指数退避拉起,全部日志落盘至 `state\service.log`、`state\bridge.log` 与 `state\gateway.log`。执行 `t3-qqbot service stop` / `uninstall` 时会自动一并清理子进程,不留端口占用残留。
|
|
305
|
+
- **Linux**:自动生成并启用 `~/.config/systemd/user/t3-code-qqbot.service`(含 `Restart=always`、`RestartSec=5`、`KillMode=control-group`)。如需在退出 SSH 后持续运行,按安装完成时的提示执行一次 `sudo loginctl enable-linger "$USER"` 即可;日志通过 `journalctl --user -u t3-code-qqbot.service -f` 查看。
|
|
306
|
+
|
|
307
|
+
*(仓库 `scripts/` 目录下仍保留手工脚本模板 `install-windows-task.ps1` 与 `t3-code-qqbot.service` 供定制参考。)*
|
|
308
|
+
|
|
309
|
+
---
|
|
310
|
+
|
|
311
|
+
## 10. 进阶:Linux 网关 + Windows T3 双机分离部署
|
|
312
|
+
|
|
313
|
+
如果你的 QQ IP 白名单绑定在一台固定公网 IP 的 Linux 云主机(主机 A),而 T3 Code 运行在另一台 Windows / Linux 电脑(主机 B),可将 `gateway` 与 `bridge` 分开部署:
|
|
314
|
+
|
|
315
|
+
1. **在运行 T3 Code 的机器(主机 B)**:
|
|
316
|
+
- 完成正常 `config.json` 与 `credentials.json` 配置,仅启动桥接:
|
|
317
|
+
```bash
|
|
318
|
+
t3-qqbot bridge --config ./config.json
|
|
319
|
+
```
|
|
320
|
+
- 桥接监听 `127.0.0.1:18773`。
|
|
321
|
+
2. **在具备白名单公网 IP 的 Linux 服务器(主机 A)**:
|
|
322
|
+
- 建立 SSH 本地端口转发,将主机 A 的 `127.0.0.1:18773` 转发到主机 B 的 `127.0.0.1:18773`:
|
|
323
|
+
```bash
|
|
324
|
+
ssh -NT -o ServerAliveInterval=15 -o ServerAliveCountMax=3 \
|
|
325
|
+
-L 127.0.0.1:18773:127.0.0.1:18773 user@<主机B的IP>
|
|
326
|
+
```
|
|
327
|
+
- 在主机 A 放置相同 `bridgeSecret` 的 `credentials.json` 与最小化 `gateway.json`(无需配置 `t3` 与 `bindings`):
|
|
328
|
+
```json
|
|
329
|
+
{
|
|
330
|
+
"stateDir": "./state",
|
|
331
|
+
"credentialsFile": "./credentials.json",
|
|
332
|
+
"gateway": {
|
|
333
|
+
"bridgeUrl": "http://127.0.0.1:18773/events",
|
|
334
|
+
"requireMentionInGroup": true
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
```
|
|
338
|
+
- 仅启动网关:
|
|
339
|
+
```bash
|
|
340
|
+
t3-qqbot gateway --config ./gateway.json
|
|
341
|
+
```
|
|
342
|
+
|
|
343
|
+
这样既无需把 T3 桥接暴露到公网,又能通过 SSH 加密隧道稳定跨机转发。
|
|
344
|
+
|
|
345
|
+
---
|
|
346
|
+
|
|
347
|
+
## 11. 配置项与环境变量速查
|
|
348
|
+
|
|
349
|
+
### 可选配置项
|
|
350
|
+
|
|
351
|
+
| 字段 | 默认值 | 说明 |
|
|
352
|
+
|---|---|---|
|
|
353
|
+
| `t3.home` | `$T3CODE_HOME` 或 `~/.t3` | 自定义 T3 Code 数据目录 |
|
|
354
|
+
| `bridge.maxMessageChars` | `1600` | 单条 QQ 回复最大字符数(范围 `100`~`4000`,超出自动分段) |
|
|
355
|
+
| `bridge.proactiveBackgroundReports` | `false` | 异步子任务超过 QQ 被动回复窗口时是否使用主动消息推送(需账号具备权限) |
|
|
356
|
+
| `bridge.autoSettleThread` | `false` | 每轮回复结束后自动调用 `t3_thread_organize(settle)` 收起 T3 侧边栏活跃状态(官方 T3 直接支持;不屏蔽手机完成推送) |
|
|
357
|
+
| `bridge.enableSlashCommands` | `true` | 是否启用 QQ 聊天内斜杠指令面板(`/help`、`/model`、`/think`、`/provider`、`/new`、`/threads`、`/use`、`/rewind`、`/stop`、`/update` 等) |
|
|
358
|
+
| `t3.muteMobileCompletionThreadId` | 省略 | 可选主会话 `threadId`,用于在配置菜单导出 `T3CODE_MUTE_MOBILE_COMPLETION_THREAD_ID`(需配合支持该环境变量的补丁/自编译 T3 服务端,官方原版暂未内置) |
|
|
359
|
+
| `gateway.requireMentionInGroup` | `true` | 群聊是否要求 `@机器人` 才转发 |
|
|
360
|
+
| `gateway.stripPrefix` | `""` | 可选指令前缀过滤(如设 `"/ai"` 则自动剥离消息开头的 `/ai`) |
|
|
361
|
+
| `bindings[].modelSelection` | 省略 | 自动新建线程时指定的默认模型,如 `{ "provider": "...", "model": "..." }` |
|
|
362
|
+
|
|
363
|
+
### 支持的环境变量
|
|
364
|
+
|
|
365
|
+
| 变量名 | 说明 |
|
|
366
|
+
|---|---|
|
|
367
|
+
| `T3_QQBOT_CONFIG` | 默认配置文件路径(可替代每次传 `--config`) |
|
|
368
|
+
| `QQ_CREDENTIALS_FILE` | 覆盖 `config.json` 中的 `credentialsFile` 路径 |
|
|
369
|
+
| `QQ_APP_ID` / `QQ_APP_SECRET` / `QQ_BRIDGE_SECRET` | 环境变量注入凭据,优先级高于 `credentials.json` |
|
|
370
|
+
| `QQ_BRIDGE_URL` | 覆盖 `gateway.bridgeUrl` |
|
|
371
|
+
| `T3CODE_HOME` | 指定 T3 Code 主数据目录 |
|
|
372
|
+
|
|
373
|
+
---
|
|
374
|
+
|
|
375
|
+
## 12. 常见问题排查(FAQ)
|
|
376
|
+
|
|
377
|
+
| 现象 / 报错 | 原因 | 解决方法 |
|
|
378
|
+
|---|---|---|
|
|
379
|
+
| `T3 Code server is unreachable at http://127.0.0.1:3773` | T3 Code 未启动,或端口不是 `3773` | 先打开 T3 Code,或检查实际端口后修改 `config.json` 中的 `t3.origin` |
|
|
380
|
+
| Windows 下 `T3 CLI (...) failed` | 自定义安装路径导致自动探测未命中 `%USERPROFILE%\.t3\bin\t3.cmd` | 在 `config.json` 中手动填写 `t3.executable`(如 `T3 Code (Beta).exe`)、`t3.prefix`(`bin.mjs` 路径)与 `t3.env`(`ELECTRON_RUN_AS_NODE: "1"`) |
|
|
381
|
+
| 网关启动报 `401` / `IP not in whitelist` | 公网出口 IP 未加入 QQ 开放平台白名单,或 `appId`/`appSecret` 有误 | 在 QQ 开放平台更新 IP 白名单,核对 `credentials.json` |
|
|
382
|
+
| 发消息日志出现 `403` 与 `[unbound]` | 当前 QQ 用户的 `scope` 尚未写入 `config.json` 的 `bindings` | 使用日志里打印的 `c2c:<openid>` 执行 `t3-qqbot bind ...` 后重启 |
|
|
383
|
+
| 回复内容已经生成,但连发下一条卡顿几十秒 | 绑定的工作区目录下存在一个未提交任何 commit 的空 `.git` 目录,可能拖慢 T3 收尾检查点 | 初始化至少一次正常 commit,或移除不需要的空 `.git` 目录 |
|
|
384
|
+
| 桥接中途意外崩溃,T3 已完成回复但 QQ 没收到 | 进程中断导致订阅断开,但运行记录已持久化 | 从 `state/bridge.log` 的 `T3 accepted <key> <threadId> <runId>`(或最新 `state/*.run.json` 内的 `runId` 字段)获取 `runId`,执行 `t3-qqbot recover <runId>` 补发(可在桥接在线时直接运行,不会重跑模型) |
|
|
385
|
+
| 群聊里没有流式打字机效果 | QQ 官方 `stream_messages` 接口仅支持私聊(C2C) | 属腾讯平台限制;群聊会在正文完成后自动通过标准消息发出 |
|
|
386
|
+
| 图片/文件下载报 `Unrecognized QQ attachment origin` | 腾讯附件 CDN 域名更新,不在默认白名单内 | 从日志记下实际域名,追加到 `config.json` 的 `attachmentHosts` 数组中重启即可 |
|
package/package.json
CHANGED
|
@@ -1,6 +1,71 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "t3-code-qqbot",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "1.2.2",
|
|
4
|
+
"description": "跨平台(Windows & Linux)T3 Code 官方 QQ 机器人桥接与富媒体 MCP 插件",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "Shiratsuk1",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/Shiratsuk1/t3-code-qqbot.git"
|
|
10
|
+
},
|
|
11
|
+
"homepage": "https://github.com/Shiratsuk1/t3-code-qqbot#readme",
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/Shiratsuk1/t3-code-qqbot/issues"
|
|
14
|
+
},
|
|
15
|
+
"keywords": [
|
|
16
|
+
"t3code",
|
|
17
|
+
"t3-code",
|
|
18
|
+
"qqbot",
|
|
19
|
+
"qq-bot",
|
|
20
|
+
"mcp",
|
|
21
|
+
"ai-agent",
|
|
22
|
+
"bridge",
|
|
23
|
+
"windows",
|
|
24
|
+
"linux"
|
|
25
|
+
],
|
|
26
|
+
"type": "module",
|
|
27
|
+
"engines": {
|
|
28
|
+
"node": ">=24.0.0"
|
|
29
|
+
},
|
|
30
|
+
"bin": {
|
|
31
|
+
"t3-qqbot": "dist/cli.mjs"
|
|
32
|
+
},
|
|
33
|
+
"files": [
|
|
34
|
+
"dist/*.mjs",
|
|
35
|
+
"docs/SETUP.md",
|
|
36
|
+
"scripts/start-windows.ps1",
|
|
37
|
+
"scripts/install-windows-task.ps1",
|
|
38
|
+
"scripts/t3-code-qqbot.service",
|
|
39
|
+
"config.example.json",
|
|
40
|
+
"credentials.example.json",
|
|
41
|
+
"README.md",
|
|
42
|
+
"LICENSE"
|
|
43
|
+
],
|
|
44
|
+
"scripts": {
|
|
45
|
+
"typecheck": "tsc --noEmit",
|
|
46
|
+
"build": "node scripts/build.mjs",
|
|
47
|
+
"package": "node scripts/build.mjs --package",
|
|
48
|
+
"prepack": "npm run build",
|
|
49
|
+
"prepublishOnly": "npm run typecheck && npm test && npm run build",
|
|
50
|
+
"test": "node --test test/*.test.ts",
|
|
51
|
+
"start": "node dist/cli.mjs start",
|
|
52
|
+
"login": "node dist/cli.mjs login",
|
|
53
|
+
"config": "node dist/cli.mjs config",
|
|
54
|
+
"service": "node dist/cli.mjs service",
|
|
55
|
+
"bridge": "node dist/cli.mjs bridge",
|
|
56
|
+
"gateway": "node dist/cli.mjs gateway",
|
|
57
|
+
"recover": "node dist/cli.mjs recover",
|
|
58
|
+
"doctor": "node dist/cli.mjs doctor"
|
|
59
|
+
},
|
|
60
|
+
"dependencies": {
|
|
61
|
+
"@tencent-connect/qqbot-connector": "^1.2.0",
|
|
62
|
+
"@tencent-connect/qqbot-nodejs": "1.0.5",
|
|
63
|
+
"ws": "^8.18.0"
|
|
64
|
+
},
|
|
65
|
+
"devDependencies": {
|
|
66
|
+
"@types/node": "^24.0.0",
|
|
67
|
+
"@types/ws": "^8.18.0",
|
|
68
|
+
"esbuild": "^0.25.0",
|
|
69
|
+
"typescript": "^5.8.0"
|
|
70
|
+
}
|
|
71
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
param(
|
|
2
|
+
[string]$TaskName = 'T3 Code QQBot',
|
|
3
|
+
[string]$ConfigPath = (Join-Path (Split-Path -Parent $PSScriptRoot) 'config.json'),
|
|
4
|
+
[string]$NodePath = ''
|
|
5
|
+
)
|
|
6
|
+
|
|
7
|
+
$ErrorActionPreference = 'Stop'
|
|
8
|
+
|
|
9
|
+
if (-not $NodePath) {
|
|
10
|
+
$cmd = Get-Command node -ErrorAction Stop
|
|
11
|
+
$NodePath = $cmd.Source
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
$nodeVer = (& $NodePath -v).Trim()
|
|
15
|
+
$major = [int](($nodeVer -replace '^v', '').Split('.')[0])
|
|
16
|
+
if ($major -lt 24) {
|
|
17
|
+
throw "Node.js 24+ is required, but '$NodePath' is $nodeVer. Pass -NodePath pointing to Node 24+."
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
$ConfigPath = [System.IO.Path]::GetFullPath($ConfigPath)
|
|
21
|
+
if (-not (Test-Path -LiteralPath $ConfigPath)) {
|
|
22
|
+
throw "Config file not found: $ConfigPath"
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
$rootDir = Split-Path -Parent $PSScriptRoot
|
|
26
|
+
$cliEntry = Join-Path $rootDir 'dist\cli.mjs'
|
|
27
|
+
if (-not (Test-Path -LiteralPath $cliEntry)) {
|
|
28
|
+
throw "Missing $cliEntry. Build or extract a release package first."
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
$startScript = Join-Path $PSScriptRoot 'start-windows.ps1'
|
|
32
|
+
if (-not (Test-Path -LiteralPath $startScript)) {
|
|
33
|
+
throw "Missing $startScript."
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
$psExe = Join-Path $env:WINDIR 'System32\WindowsPowerShell\v1.0\powershell.exe'
|
|
37
|
+
$action = New-ScheduledTaskAction `
|
|
38
|
+
-Execute $psExe `
|
|
39
|
+
-Argument "-NoProfile -WindowStyle Hidden -ExecutionPolicy Bypass -File `"$startScript`" -ConfigPath `"$ConfigPath`" -NodePath `"$NodePath`"" `
|
|
40
|
+
-WorkingDirectory $rootDir
|
|
41
|
+
|
|
42
|
+
$trigger = New-ScheduledTaskTrigger -AtLogOn -User $env:USERNAME
|
|
43
|
+
$settings = New-ScheduledTaskSettingsSet `
|
|
44
|
+
-AllowStartIfOnBatteries `
|
|
45
|
+
-DontStopIfGoingOnBatteries `
|
|
46
|
+
-RestartCount 5 `
|
|
47
|
+
-RestartInterval (New-TimeSpan -Minutes 1) `
|
|
48
|
+
-ExecutionTimeLimit ([TimeSpan]::Zero)
|
|
49
|
+
|
|
50
|
+
Register-ScheduledTask `
|
|
51
|
+
-TaskName $TaskName `
|
|
52
|
+
-Action $action `
|
|
53
|
+
-Trigger $trigger `
|
|
54
|
+
-Settings $settings `
|
|
55
|
+
-Description 'T3 Code QQBot Bridge & Official WebSocket Gateway' `
|
|
56
|
+
-Force | Out-Null
|
|
57
|
+
|
|
58
|
+
Write-Host "Registered Windows Scheduled Task '$TaskName' (Node $nodeVer)."
|
|
59
|
+
Write-Host "Logs will be written to state\service.log, state\bridge.log, and state\gateway.log."
|
|
60
|
+
Write-Host "Start it now with: Start-ScheduledTask -TaskName '$TaskName'"
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
param(
|
|
2
|
+
[string]$ConfigPath = (Join-Path (Split-Path -Parent $PSScriptRoot) 'config.json'),
|
|
3
|
+
[string]$NodePath = ''
|
|
4
|
+
)
|
|
5
|
+
|
|
6
|
+
$ErrorActionPreference = 'Stop'
|
|
7
|
+
|
|
8
|
+
if (-not $NodePath) {
|
|
9
|
+
$cmd = Get-Command node -ErrorAction SilentlyContinue
|
|
10
|
+
if (-not $cmd) {
|
|
11
|
+
throw 'Node.js 24+ not found on PATH. Pass -NodePath explicitly.'
|
|
12
|
+
}
|
|
13
|
+
$NodePath = $cmd.Source
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
$ConfigPath = [System.IO.Path]::GetFullPath($ConfigPath)
|
|
17
|
+
if (-not (Test-Path -LiteralPath $ConfigPath)) {
|
|
18
|
+
throw "Config file not found: $ConfigPath"
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
$rootDir = Split-Path -Parent $PSScriptRoot
|
|
22
|
+
$cliEntry = Join-Path $rootDir 'dist\cli.mjs'
|
|
23
|
+
if (-not (Test-Path -LiteralPath $cliEntry)) {
|
|
24
|
+
throw "Missing $cliEntry. Run npm run build first (or use a release package)."
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
$config = Get-Content -LiteralPath $ConfigPath -Raw -Encoding utf8 | ConvertFrom-Json
|
|
28
|
+
$stateDir = $config.stateDir
|
|
29
|
+
if (-not $stateDir) {
|
|
30
|
+
$stateDir = './state'
|
|
31
|
+
}
|
|
32
|
+
if (-not [System.IO.Path]::IsPathRooted($stateDir)) {
|
|
33
|
+
$stateDir = Join-Path (Split-Path -Parent $ConfigPath) $stateDir
|
|
34
|
+
}
|
|
35
|
+
New-Item -Path $stateDir -ItemType Directory -Force | Out-Null
|
|
36
|
+
$logPath = Join-Path $stateDir 'service.log'
|
|
37
|
+
|
|
38
|
+
$env:NODE_NO_WARNINGS = '1'
|
|
39
|
+
|
|
40
|
+
# PowerShell 5.1 converts native stderr lines into ErrorRecords when using 2>&1;
|
|
41
|
+
# switch to Continue around the native command so warnings never abort the service.
|
|
42
|
+
$previousPreference = $ErrorActionPreference
|
|
43
|
+
$ErrorActionPreference = 'Continue'
|
|
44
|
+
try {
|
|
45
|
+
& $NodePath $cliEntry start --config $ConfigPath 2>&1 | ForEach-Object {
|
|
46
|
+
$text = if ($_ -is [System.Management.Automation.ErrorRecord]) { $_.ToString() } else { "$_" }
|
|
47
|
+
$line = '[{0:yyyy-MM-dd HH:mm:ss}] {1}' -f [DateTime]::Now, $text
|
|
48
|
+
Add-Content -LiteralPath $logPath -Encoding utf8 -Value $line
|
|
49
|
+
}
|
|
50
|
+
$exitCode = $LASTEXITCODE
|
|
51
|
+
} finally {
|
|
52
|
+
$ErrorActionPreference = $previousPreference
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
exit $exitCode
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# Example systemd user service for Linux
|
|
2
|
+
# Copy to ~/.config/systemd/user/t3-code-qqbot.service
|
|
3
|
+
# Replace /opt/t3-code-qqbot and /usr/bin/node with your actual paths, then run:
|
|
4
|
+
# systemctl --user daemon-reload
|
|
5
|
+
# systemctl --user enable --now t3-code-qqbot.service
|
|
6
|
+
# sudo loginctl enable-linger "$USER"
|
|
7
|
+
|
|
8
|
+
[Unit]
|
|
9
|
+
Description=T3 Code QQBot Bridge and Official WebSocket Gateway
|
|
10
|
+
After=default.target
|
|
11
|
+
|
|
12
|
+
[Service]
|
|
13
|
+
Type=simple
|
|
14
|
+
WorkingDirectory=/opt/t3-code-qqbot
|
|
15
|
+
Environment=NODE_NO_WARNINGS=1
|
|
16
|
+
ExecStart=/usr/bin/node /opt/t3-code-qqbot/dist/cli.mjs start --config /opt/t3-code-qqbot/config.json
|
|
17
|
+
Restart=always
|
|
18
|
+
RestartSec=5
|
|
19
|
+
|
|
20
|
+
[Install]
|
|
21
|
+
WantedBy=default.target
|