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,