Skip to content

Commit a433677

Browse files
committed
feat(qqbot): C2C 正在输入心跳续发,每 5s 重发防止气泡中途消失
- 收到 C2C 消息后,启动 setInterval 每 5 秒重发一次 sendC2CInputNotify - 在 deliver 回调触发时(即实际回复前)立即清除 interval - 不影响群聊场景,仅对 event.type === 'c2c' 生效 ## 用户体验改善 QQ 客户端在以下情况会重置正在输入气泡: 1. 用户打开聊天界面 2. 系统切换前后台 原版只发送一次 InputNotify(inputSeconds=60),在上述情况下气泡会立即消失, 用户看不到 AI 正在处理的反馈,体验等同于无提示等待。 通过每 5 秒续发,气泡最多消失 5 秒便会重新出现, 对于处理耗时较长的消息(调用工具、生成语音等),用户始终能感知 AI 正在工作。 ## 技术细节 - 使用 setInterval 异步续发,不阻塞主处理流程 - 续发失败时静默忽略(非关键路径) - 每次处理完成后通过 clearInterval 立即停止,不产生多余 API 调用
1 parent e6276d6 commit a433677

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/gateway.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1258,6 +1258,20 @@ ${ttsHint}${sttHint}${asrFallbackHint}${voiceForwardHint}`;
12581258
let toolRenewalCount = 0; // 已续期次数
12591259
let timeoutId: ReturnType<typeof setTimeout> | null = null;
12601260
let toolOnlyTimeoutId: ReturnType<typeof setTimeout> | null = null;
1261+
let typingIntervalId: ReturnType<typeof setInterval> | null = null;
1262+
1263+
// 启动 typing 心跳:每 15 秒重发一次 C2C InputNotify,保持"正在输入"状态
1264+
// 仅对私聊(C2C)有效;deliver 时停止
1265+
if (event.type === "c2c") {
1266+
typingIntervalId = setInterval(async () => {
1267+
try {
1268+
const token = await getAccessToken(account.appId, account.clientSecret);
1269+
await sendC2CInputNotify(token, event.senderId, event.messageId, 60);
1270+
} catch {
1271+
// 非关键,忽略错误
1272+
}
1273+
}, 5000);
1274+
}
12611275

12621276
// 格式化 tool 兜底消息:极简,只展示工具原始参数
12631277
const formatToolFallback = (): string => {

0 commit comments

Comments
 (0)