Skip to content

Commit 834dcb5

Browse files
authored
Merge pull request #171 from xiaokui-bot/pr/typing-keepalive
feat: C2C 正在输入(InputNotify)心跳续发(每 5s),避免气泡中途消失
2 parents 9646486 + 05dce16 commit 834dcb5

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

src/gateway.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1174,6 +1174,20 @@ ${mediaSection}
11741174
let toolRenewalCount = 0; // 已续期次数
11751175
let timeoutId: ReturnType<typeof setTimeout> | null = null;
11761176
let toolOnlyTimeoutId: ReturnType<typeof setTimeout> | null = null;
1177+
let typingIntervalId: ReturnType<typeof setInterval> | null = null;
1178+
1179+
// 启动 typing 心跳:每 5 秒重发一次 C2C InputNotify,保持"正在输入"状态
1180+
// 仅对私聊(C2C)有效;实际发消息前停止
1181+
if (event.type === "c2c") {
1182+
typingIntervalId = setInterval(async () => {
1183+
try {
1184+
const token = await getAccessToken(account.appId, account.clientSecret);
1185+
await sendC2CInputNotify(token, event.senderId, event.messageId, 60);
1186+
} catch {
1187+
// 非关键,忽略错误
1188+
}
1189+
}, 5000);
1190+
}
11771191

11781192
// 格式化 tool 兜底消息:极简,只展示工具原始参数
11791193
const formatToolFallback = (): string => {
@@ -1398,7 +1412,13 @@ ${mediaSection}
13981412
if (textAfter) {
13991413
sendQueue.push({ type: "text", content: filterInternalMarkers(textAfter) });
14001414
}
1401-
1415+
1416+
1417+
// 发送第一条消息前停止 typing 心跳,多段回复之间保持气泡显示
1418+
if (typingIntervalId) {
1419+
clearInterval(typingIntervalId);
1420+
typingIntervalId = null;
1421+
}
14021422
log?.info(`[qqbot:${account.accountId}] Send queue: ${sendQueue.map(item => `${item.type}`).join(" -> ")}`);
14031423

14041424
// 按顺序发送

0 commit comments

Comments
 (0)