From eea1f406841cf0555af212385af82f863267d60e Mon Sep 17 00:00:00 2001 From: leoqlin Date: Sat, 31 Jan 2026 20:22:37 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=94=AF=E6=8C=81=E6=94=B6=E5=88=B0c2c?= =?UTF-8?q?=E6=B6=88=E6=81=AF=E5=90=8E=E5=9B=9E=E5=A4=8D=E8=BE=93=E5=85=A5?= =?UTF-8?q?=E4=B8=AD=E7=8A=B6=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api.ts | 23 +++++++++++++++++++++++ src/gateway.ts | 13 ++++++++++++- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/src/api.ts b/src/api.ts index eaace99..8951854 100644 --- a/src/api.ts +++ b/src/api.ts @@ -153,6 +153,29 @@ export async function sendC2CMessage( }); } +/** + * 发送 C2C 输入状态提示(告知用户机器人正在输入) + */ +export async function sendC2CInputNotify( + accessToken: string, + openid: string, + msgId?: string, + inputSecond: number = 60 +): Promise { + const msgSeq = msgId ? getNextMsgSeq(msgId) : 1; + const body = { + msg_type: 6, + input_notify: { + input_type: 1, + input_second: inputSecond, + }, + msg_seq: msgSeq, + ...(msgId ? { msg_id: msgId } : {}), + }; + + await apiRequest(accessToken, "POST", `/v2/users/${openid}/messages`, body); +} + /** * 发送频道消息 */ diff --git a/src/gateway.ts b/src/gateway.ts index cfe5560..bde105c 100644 --- a/src/gateway.ts +++ b/src/gateway.ts @@ -1,7 +1,7 @@ import WebSocket from "ws"; import path from "node:path"; import type { ResolvedQQBotAccount, WSPayload, C2CMessageEvent, GuildMessageEvent, GroupMessageEvent } from "./types.js"; -import { getAccessToken, getGatewayUrl, sendC2CMessage, sendChannelMessage, sendGroupMessage, clearTokenCache, sendC2CImageMessage, sendGroupImageMessage } from "./api.js"; +import { getAccessToken, getGatewayUrl, sendC2CMessage, sendChannelMessage, sendGroupMessage, clearTokenCache, sendC2CImageMessage, sendGroupImageMessage, sendC2CInputNotify } from "./api.js"; import { getQQBotRuntime } from "./runtime.js"; import { startImageServer, saveImage, saveImageFromPath, isImageServerRunning, downloadFile, type ImageServerConfig } from "./image-server.js"; @@ -218,6 +218,17 @@ export async function startGateway(ctx: GatewayContext): Promise { log?.info(`[qqbot:${account.accountId}] Attachments: ${event.attachments.length}`); } + // 对于 C2C 消息,先发送输入状态提示用户机器人正在输入 + if (event.type === "c2c") { + try { + const token = await getAccessToken(account.appId, account.clientSecret); + await sendC2CInputNotify(token, event.senderId, event.messageId, 60); + log?.info(`[qqbot:${account.accountId}] Sent input notify to ${event.senderId}`); + } catch (err) { + log?.error(`[qqbot:${account.accountId}] Failed to send input notify: ${err}`); + } + } + pluginRuntime.channel.activity.record({ channel: "qqbot", accountId: account.accountId,