@ryantest/openclaw-qqbot 0.0.1
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 +22 -0
- package/README.md +483 -0
- package/README.zh.md +478 -0
- package/bin/qqbot-cli.js +243 -0
- package/clawdbot.plugin.json +16 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.js +26 -0
- package/dist/src/admin-resolver.d.ts +27 -0
- package/dist/src/admin-resolver.js +122 -0
- package/dist/src/api.d.ts +156 -0
- package/dist/src/api.js +599 -0
- package/dist/src/channel.d.ts +11 -0
- package/dist/src/channel.js +354 -0
- package/dist/src/config.d.ts +25 -0
- package/dist/src/config.js +161 -0
- package/dist/src/credential-backup.d.ts +31 -0
- package/dist/src/credential-backup.js +66 -0
- package/dist/src/gateway.d.ts +18 -0
- package/dist/src/gateway.js +1265 -0
- package/dist/src/image-server.d.ts +68 -0
- package/dist/src/image-server.js +462 -0
- package/dist/src/inbound-attachments.d.ts +58 -0
- package/dist/src/inbound-attachments.js +234 -0
- package/dist/src/known-users.d.ts +100 -0
- package/dist/src/known-users.js +263 -0
- package/dist/src/message-queue.d.ts +50 -0
- package/dist/src/message-queue.js +115 -0
- package/dist/src/onboarding.d.ts +10 -0
- package/dist/src/onboarding.js +203 -0
- package/dist/src/outbound-deliver.d.ts +48 -0
- package/dist/src/outbound-deliver.js +462 -0
- package/dist/src/outbound.d.ts +203 -0
- package/dist/src/outbound.js +1102 -0
- package/dist/src/proactive.d.ts +170 -0
- package/dist/src/proactive.js +399 -0
- package/dist/src/ref-index-store.d.ts +70 -0
- package/dist/src/ref-index-store.js +273 -0
- package/dist/src/reply-dispatcher.d.ts +35 -0
- package/dist/src/reply-dispatcher.js +311 -0
- package/dist/src/runtime.d.ts +3 -0
- package/dist/src/runtime.js +10 -0
- package/dist/src/session-store.d.ts +52 -0
- package/dist/src/session-store.js +254 -0
- package/dist/src/slash-commands.d.ts +71 -0
- package/dist/src/slash-commands.js +1179 -0
- package/dist/src/startup-greeting.d.ts +30 -0
- package/dist/src/startup-greeting.js +78 -0
- package/dist/src/stt.d.ts +21 -0
- package/dist/src/stt.js +70 -0
- package/dist/src/tools/channel.d.ts +16 -0
- package/dist/src/tools/channel.js +234 -0
- package/dist/src/tools/remind.d.ts +2 -0
- package/dist/src/tools/remind.js +247 -0
- package/dist/src/types.d.ts +175 -0
- package/dist/src/types.js +1 -0
- package/dist/src/typing-keepalive.d.ts +27 -0
- package/dist/src/typing-keepalive.js +64 -0
- package/dist/src/update-checker.d.ts +34 -0
- package/dist/src/update-checker.js +166 -0
- package/dist/src/user-messages.d.ts +8 -0
- package/dist/src/user-messages.js +8 -0
- package/dist/src/utils/audio-convert.d.ts +89 -0
- package/dist/src/utils/audio-convert.js +704 -0
- package/dist/src/utils/file-utils.d.ts +55 -0
- package/dist/src/utils/file-utils.js +150 -0
- package/dist/src/utils/image-size.d.ts +51 -0
- package/dist/src/utils/image-size.js +234 -0
- package/dist/src/utils/media-tags.d.ts +14 -0
- package/dist/src/utils/media-tags.js +164 -0
- package/dist/src/utils/payload.d.ts +112 -0
- package/dist/src/utils/payload.js +186 -0
- package/dist/src/utils/platform.d.ts +137 -0
- package/dist/src/utils/platform.js +390 -0
- package/dist/src/utils/text-parsing.d.ts +32 -0
- package/dist/src/utils/text-parsing.js +80 -0
- package/dist/src/utils/upload-cache.d.ts +34 -0
- package/dist/src/utils/upload-cache.js +93 -0
- package/index.ts +31 -0
- package/moltbot.plugin.json +16 -0
- package/node_modules/@eshaz/web-worker/LICENSE +201 -0
- package/node_modules/@eshaz/web-worker/README.md +134 -0
- package/node_modules/@eshaz/web-worker/browser.js +17 -0
- package/node_modules/@eshaz/web-worker/cjs/browser.js +16 -0
- package/node_modules/@eshaz/web-worker/cjs/node.js +219 -0
- package/node_modules/@eshaz/web-worker/index.d.ts +4 -0
- package/node_modules/@eshaz/web-worker/node.js +223 -0
- package/node_modules/@eshaz/web-worker/package.json +54 -0
- package/node_modules/@wasm-audio-decoders/common/index.js +5 -0
- package/node_modules/@wasm-audio-decoders/common/package.json +36 -0
- package/node_modules/@wasm-audio-decoders/common/src/WASMAudioDecoderCommon.js +231 -0
- package/node_modules/@wasm-audio-decoders/common/src/WASMAudioDecoderWorker.js +129 -0
- package/node_modules/@wasm-audio-decoders/common/src/puff/README +67 -0
- package/node_modules/@wasm-audio-decoders/common/src/puff/build_puff.js +31 -0
- package/node_modules/@wasm-audio-decoders/common/src/puff/puff.c +863 -0
- package/node_modules/@wasm-audio-decoders/common/src/puff/puff.h +35 -0
- package/node_modules/@wasm-audio-decoders/common/src/utilities.js +3 -0
- package/node_modules/@wasm-audio-decoders/common/types.d.ts +7 -0
- package/node_modules/mpg123-decoder/README.md +265 -0
- package/node_modules/mpg123-decoder/dist/mpg123-decoder.min.js +185 -0
- package/node_modules/mpg123-decoder/dist/mpg123-decoder.min.js.map +1 -0
- package/node_modules/mpg123-decoder/index.js +8 -0
- package/node_modules/mpg123-decoder/package.json +58 -0
- package/node_modules/mpg123-decoder/src/EmscriptenWasm.js +464 -0
- package/node_modules/mpg123-decoder/src/MPEGDecoder.js +200 -0
- package/node_modules/mpg123-decoder/src/MPEGDecoderWebWorker.js +21 -0
- package/node_modules/mpg123-decoder/types.d.ts +30 -0
- package/node_modules/silk-wasm/LICENSE +21 -0
- package/node_modules/silk-wasm/README.md +85 -0
- package/node_modules/silk-wasm/lib/index.cjs +16 -0
- package/node_modules/silk-wasm/lib/index.d.ts +70 -0
- package/node_modules/silk-wasm/lib/index.mjs +16 -0
- package/node_modules/silk-wasm/lib/silk.wasm +0 -0
- package/node_modules/silk-wasm/lib/utils.d.ts +4 -0
- package/node_modules/silk-wasm/package.json +39 -0
- package/node_modules/simple-yenc/.github/FUNDING.yml +1 -0
- package/node_modules/simple-yenc/.prettierignore +1 -0
- package/node_modules/simple-yenc/LICENSE +7 -0
- package/node_modules/simple-yenc/README.md +163 -0
- package/node_modules/simple-yenc/dist/esm.js +1 -0
- package/node_modules/simple-yenc/dist/index.js +1 -0
- package/node_modules/simple-yenc/package.json +50 -0
- package/node_modules/simple-yenc/rollup.config.js +27 -0
- package/node_modules/simple-yenc/src/simple-yenc.js +302 -0
- package/node_modules/ws/LICENSE +20 -0
- package/node_modules/ws/README.md +548 -0
- package/node_modules/ws/browser.js +8 -0
- package/node_modules/ws/index.js +13 -0
- package/node_modules/ws/lib/buffer-util.js +131 -0
- package/node_modules/ws/lib/constants.js +19 -0
- package/node_modules/ws/lib/event-target.js +292 -0
- package/node_modules/ws/lib/extension.js +203 -0
- package/node_modules/ws/lib/limiter.js +55 -0
- package/node_modules/ws/lib/permessage-deflate.js +528 -0
- package/node_modules/ws/lib/receiver.js +706 -0
- package/node_modules/ws/lib/sender.js +602 -0
- package/node_modules/ws/lib/stream.js +161 -0
- package/node_modules/ws/lib/subprotocol.js +62 -0
- package/node_modules/ws/lib/validation.js +152 -0
- package/node_modules/ws/lib/websocket-server.js +554 -0
- package/node_modules/ws/lib/websocket.js +1393 -0
- package/node_modules/ws/package.json +69 -0
- package/node_modules/ws/wrapper.mjs +8 -0
- package/openclaw.plugin.json +16 -0
- package/package.json +76 -0
- package/scripts/cleanup-legacy-plugins.sh +124 -0
- package/scripts/proactive-api-server.ts +369 -0
- package/scripts/send-proactive.ts +293 -0
- package/scripts/set-markdown.sh +156 -0
- package/scripts/test-sendmedia.ts +116 -0
- package/scripts/upgrade-via-alt-pkg.sh +307 -0
- package/scripts/upgrade-via-npm.ps1 +296 -0
- package/scripts/upgrade-via-npm.sh +301 -0
- package/scripts/upgrade-via-source.sh +774 -0
- package/skills/qqbot-channel/SKILL.md +263 -0
- package/skills/qqbot-channel/references/api_references.md +521 -0
- package/skills/qqbot-media/SKILL.md +56 -0
- package/skills/qqbot-remind/SKILL.md +149 -0
- package/src/admin-resolver.ts +140 -0
- package/src/api.ts +819 -0
- package/src/bot-logs-2026-03-21T11-21-47(2).txt +46 -0
- package/src/channel.ts +381 -0
- package/src/config.ts +187 -0
- package/src/credential-backup.ts +72 -0
- package/src/gateway.log +43 -0
- package/src/gateway.ts +1404 -0
- package/src/image-server.ts +539 -0
- package/src/inbound-attachments.ts +304 -0
- package/src/known-users.ts +353 -0
- package/src/message-queue.ts +169 -0
- package/src/onboarding.ts +274 -0
- package/src/openclaw-2026-03-21.log +3729 -0
- package/src/openclaw-plugin-sdk.d.ts +522 -0
- package/src/outbound-deliver.ts +552 -0
- package/src/outbound.ts +1266 -0
- package/src/proactive.ts +530 -0
- package/src/ref-index-store.ts +357 -0
- package/src/reply-dispatcher.ts +334 -0
- package/src/runtime.ts +14 -0
- package/src/session-store.ts +303 -0
- package/src/slash-commands.ts +1305 -0
- package/src/startup-greeting.ts +98 -0
- package/src/stt.ts +86 -0
- package/src/tools/channel.ts +281 -0
- package/src/tools/remind.ts +296 -0
- package/src/types.ts +183 -0
- package/src/typing-keepalive.ts +59 -0
- package/src/update-checker.ts +179 -0
- package/src/user-messages.ts +7 -0
- package/src/utils/audio-convert.ts +803 -0
- package/src/utils/file-utils.ts +167 -0
- package/src/utils/image-size.ts +266 -0
- package/src/utils/media-tags.ts +182 -0
- package/src/utils/payload.ts +265 -0
- package/src/utils/platform.ts +435 -0
- package/src/utils/text-parsing.ts +82 -0
- package/src/utils/upload-cache.ts +128 -0
- package/tsconfig.json +16 -0
|
@@ -0,0 +1,462 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 出站消息投递模块
|
|
3
|
+
*
|
|
4
|
+
* 从 gateway deliver 回调中提取的两大发送管线:
|
|
5
|
+
* 1. parseAndSendMediaTags — 解析 <qqimg/qqvoice/qqvideo/qqfile/qqmedia> 标签并按顺序发送
|
|
6
|
+
* 2. sendPlainReply — 处理不含媒体标签的普通回复(markdown 图片/纯文本+图片)
|
|
7
|
+
*/
|
|
8
|
+
import { sendC2CMessage, sendGroupMessage, sendChannelMessage, sendC2CImageMessage, sendGroupImageMessage } from "./api.js";
|
|
9
|
+
import { sendPhoto, sendVoice, sendVideoMsg, sendDocument, sendMedia as sendMediaAuto } from "./outbound.js";
|
|
10
|
+
import { chunkText, TEXT_CHUNK_LIMIT } from "./channel.js";
|
|
11
|
+
import { getQQBotRuntime } from "./runtime.js";
|
|
12
|
+
import { getImageSize, formatQQBotMarkdownImage, hasQQBotImageSize } from "./utils/image-size.js";
|
|
13
|
+
import { normalizeMediaTags } from "./utils/media-tags.js";
|
|
14
|
+
import { normalizePath, isLocalPath as isLocalFilePath } from "./utils/platform.js";
|
|
15
|
+
import { filterInternalMarkers } from "./utils/text-parsing.js";
|
|
16
|
+
// ============ 1. 媒体标签解析 + 发送 ============
|
|
17
|
+
/**
|
|
18
|
+
* 解析回复文本中的媒体标签并按顺序发送。
|
|
19
|
+
*
|
|
20
|
+
* @returns true 如果检测到媒体标签并已处理;false 表示无媒体标签,调用方继续走普通文本管线
|
|
21
|
+
*/
|
|
22
|
+
export async function parseAndSendMediaTags(replyText, event, actx, sendWithRetry, consumeQuoteRef) {
|
|
23
|
+
const { account, log } = actx;
|
|
24
|
+
const prefix = `[qqbot:${account.accountId}]`;
|
|
25
|
+
// 预处理:纠正小模型常见的标签拼写错误和格式问题
|
|
26
|
+
const text = normalizeMediaTags(replyText);
|
|
27
|
+
const mediaTagRegex = /<(qqimg|qqvoice|qqvideo|qqfile|qqmedia)>([^<>]+)<\/(?:qqimg|qqvoice|qqvideo|qqfile|qqmedia|img)>/gi;
|
|
28
|
+
const mediaTagMatches = [...text.matchAll(mediaTagRegex)];
|
|
29
|
+
if (mediaTagMatches.length === 0) {
|
|
30
|
+
return { handled: false, normalizedText: text };
|
|
31
|
+
}
|
|
32
|
+
const tagCounts = mediaTagMatches.reduce((acc, m) => { const t = m[1].toLowerCase(); acc[t] = (acc[t] ?? 0) + 1; return acc; }, {});
|
|
33
|
+
log?.info(`${prefix} Detected media tags: ${Object.entries(tagCounts).map(([k, v]) => `${v} <${k}>`).join(", ")}`);
|
|
34
|
+
const sendQueue = [];
|
|
35
|
+
let lastIndex = 0;
|
|
36
|
+
const regex2 = /<(qqimg|qqvoice|qqvideo|qqfile|qqmedia)>([^<>]+)<\/(?:qqimg|qqvoice|qqvideo|qqfile|qqmedia|img)>/gi;
|
|
37
|
+
let match;
|
|
38
|
+
while ((match = regex2.exec(text)) !== null) {
|
|
39
|
+
const textBefore = text.slice(lastIndex, match.index).replace(/\n{3,}/g, "\n\n").trim();
|
|
40
|
+
if (textBefore) {
|
|
41
|
+
sendQueue.push({ type: "text", content: filterInternalMarkers(textBefore) });
|
|
42
|
+
}
|
|
43
|
+
const tagName = match[1].toLowerCase();
|
|
44
|
+
let mediaPath = decodeMediaPath(match[2]?.trim() ?? "", log, prefix);
|
|
45
|
+
if (mediaPath) {
|
|
46
|
+
const typeMap = {
|
|
47
|
+
qqmedia: "media", qqvoice: "voice", qqvideo: "video", qqfile: "file",
|
|
48
|
+
};
|
|
49
|
+
const itemType = typeMap[tagName] ?? "image";
|
|
50
|
+
sendQueue.push({ type: itemType, content: mediaPath });
|
|
51
|
+
log?.info(`${prefix} Found ${itemType} in <${tagName}>: ${mediaPath}`);
|
|
52
|
+
}
|
|
53
|
+
lastIndex = match.index + match[0].length;
|
|
54
|
+
}
|
|
55
|
+
const textAfter = text.slice(lastIndex).replace(/\n{3,}/g, "\n\n").trim();
|
|
56
|
+
if (textAfter) {
|
|
57
|
+
sendQueue.push({ type: "text", content: filterInternalMarkers(textAfter) });
|
|
58
|
+
}
|
|
59
|
+
log?.info(`${prefix} Send queue: ${sendQueue.map(item => item.type).join(" -> ")}`);
|
|
60
|
+
// 按顺序发送
|
|
61
|
+
const mediaTarget = {
|
|
62
|
+
targetType: event.type === "c2c" ? "c2c" : event.type === "group" ? "group" : "channel",
|
|
63
|
+
targetId: event.type === "c2c" ? event.senderId : event.type === "group" ? event.groupOpenid : event.channelId,
|
|
64
|
+
account,
|
|
65
|
+
replyToId: event.messageId,
|
|
66
|
+
logPrefix: prefix,
|
|
67
|
+
};
|
|
68
|
+
for (const item of sendQueue) {
|
|
69
|
+
if (item.type === "text") {
|
|
70
|
+
await sendTextChunks(item.content, event, actx, sendWithRetry, consumeQuoteRef);
|
|
71
|
+
}
|
|
72
|
+
else if (item.type === "image") {
|
|
73
|
+
const result = await sendPhoto(mediaTarget, item.content);
|
|
74
|
+
if (result.error)
|
|
75
|
+
log?.error(`${prefix} sendPhoto error: ${result.error}`);
|
|
76
|
+
}
|
|
77
|
+
else if (item.type === "voice") {
|
|
78
|
+
await sendVoiceWithTimeout(mediaTarget, item.content, account, log, prefix);
|
|
79
|
+
}
|
|
80
|
+
else if (item.type === "video") {
|
|
81
|
+
const result = await sendVideoMsg(mediaTarget, item.content);
|
|
82
|
+
if (result.error)
|
|
83
|
+
log?.error(`${prefix} sendVideoMsg error: ${result.error}`);
|
|
84
|
+
}
|
|
85
|
+
else if (item.type === "file") {
|
|
86
|
+
const result = await sendDocument(mediaTarget, item.content);
|
|
87
|
+
if (result.error)
|
|
88
|
+
log?.error(`${prefix} sendDocument error: ${result.error}`);
|
|
89
|
+
}
|
|
90
|
+
else if (item.type === "media") {
|
|
91
|
+
const result = await sendMediaAuto({
|
|
92
|
+
to: actx.qualifiedTarget,
|
|
93
|
+
text: "",
|
|
94
|
+
mediaUrl: item.content,
|
|
95
|
+
accountId: account.accountId,
|
|
96
|
+
replyToId: event.messageId,
|
|
97
|
+
account,
|
|
98
|
+
});
|
|
99
|
+
if (result.error)
|
|
100
|
+
log?.error(`${prefix} sendMedia(auto) error: ${result.error}`);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return { handled: true, normalizedText: text };
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* 发送不含媒体标签的普通回复。
|
|
107
|
+
* 处理 markdown 图片嵌入、Base64 富媒体、纯文本分块、本地媒体自动路由。
|
|
108
|
+
*/
|
|
109
|
+
export async function sendPlainReply(payload, replyText, event, actx, sendWithRetry, consumeQuoteRef, toolMediaUrls) {
|
|
110
|
+
const { account, qualifiedTarget, log } = actx;
|
|
111
|
+
const prefix = `[qqbot:${account.accountId}]`;
|
|
112
|
+
const collectedImageUrls = [];
|
|
113
|
+
const localMediaToSend = [];
|
|
114
|
+
const collectImageUrl = (url) => {
|
|
115
|
+
if (!url)
|
|
116
|
+
return false;
|
|
117
|
+
const isHttpUrl = url.startsWith("http://") || url.startsWith("https://");
|
|
118
|
+
const isDataUrl = url.startsWith("data:image/");
|
|
119
|
+
if (isHttpUrl || isDataUrl) {
|
|
120
|
+
if (!collectedImageUrls.includes(url)) {
|
|
121
|
+
collectedImageUrls.push(url);
|
|
122
|
+
log?.info(`${prefix} Collected ${isDataUrl ? "Base64" : "media URL"}: ${isDataUrl ? `(length: ${url.length})` : url.slice(0, 80) + "..."}`);
|
|
123
|
+
}
|
|
124
|
+
return true;
|
|
125
|
+
}
|
|
126
|
+
if (isLocalFilePath(url)) {
|
|
127
|
+
if (!localMediaToSend.includes(url)) {
|
|
128
|
+
localMediaToSend.push(url);
|
|
129
|
+
log?.info(`${prefix} Collected local media for auto-routing: ${url}`);
|
|
130
|
+
}
|
|
131
|
+
return true;
|
|
132
|
+
}
|
|
133
|
+
return false;
|
|
134
|
+
};
|
|
135
|
+
if (payload.mediaUrls?.length) {
|
|
136
|
+
for (const url of payload.mediaUrls)
|
|
137
|
+
collectImageUrl(url);
|
|
138
|
+
}
|
|
139
|
+
if (payload.mediaUrl)
|
|
140
|
+
collectImageUrl(payload.mediaUrl);
|
|
141
|
+
// 提取 markdown 图片
|
|
142
|
+
const mdImageRegex = /!\[([^\]]*)\]\(([^)]+)\)/gi;
|
|
143
|
+
const mdMatches = [...replyText.matchAll(mdImageRegex)];
|
|
144
|
+
for (const m of mdMatches) {
|
|
145
|
+
const url = m[2]?.trim();
|
|
146
|
+
if (url && !collectedImageUrls.includes(url)) {
|
|
147
|
+
if (url.startsWith("http://") || url.startsWith("https://")) {
|
|
148
|
+
collectedImageUrls.push(url);
|
|
149
|
+
log?.info(`${prefix} Extracted HTTP image from markdown: ${url.slice(0, 80)}...`);
|
|
150
|
+
}
|
|
151
|
+
else if (isLocalFilePath(url)) {
|
|
152
|
+
if (!localMediaToSend.includes(url)) {
|
|
153
|
+
localMediaToSend.push(url);
|
|
154
|
+
log?.info(`${prefix} Collected local media from markdown for auto-routing: ${url}`);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
// 提取裸 URL 图片
|
|
160
|
+
const bareUrlRegex = /(?<![(\["'])(https?:\/\/[^\s)"'<>]+\.(?:png|jpg|jpeg|gif|webp)(?:\?[^\s"'<>]*)?)/gi;
|
|
161
|
+
const bareUrlMatches = [...replyText.matchAll(bareUrlRegex)];
|
|
162
|
+
for (const m of bareUrlMatches) {
|
|
163
|
+
const url = m[1];
|
|
164
|
+
if (url && !collectedImageUrls.includes(url)) {
|
|
165
|
+
collectedImageUrls.push(url);
|
|
166
|
+
log?.info(`${prefix} Extracted bare image URL: ${url.slice(0, 80)}...`);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
const useMarkdown = account.markdownSupport === true;
|
|
170
|
+
log?.info(`${prefix} Markdown mode: ${useMarkdown}, images: ${collectedImageUrls.length}`);
|
|
171
|
+
let textWithoutImages = filterInternalMarkers(replyText);
|
|
172
|
+
if (useMarkdown) {
|
|
173
|
+
await sendMarkdownReply(textWithoutImages, collectedImageUrls, mdMatches, bareUrlMatches, event, actx, sendWithRetry, consumeQuoteRef);
|
|
174
|
+
}
|
|
175
|
+
else {
|
|
176
|
+
await sendPlainTextReply(textWithoutImages, collectedImageUrls, mdMatches, bareUrlMatches, event, actx, sendWithRetry, consumeQuoteRef);
|
|
177
|
+
}
|
|
178
|
+
// 发送本地媒体(由 payload.mediaUrl 或 markdown 本地路径触发)
|
|
179
|
+
if (localMediaToSend.length > 0) {
|
|
180
|
+
log?.info(`${prefix} Sending ${localMediaToSend.length} local media via sendMedia auto-routing`);
|
|
181
|
+
for (const mediaPath of localMediaToSend) {
|
|
182
|
+
try {
|
|
183
|
+
const result = await sendMediaAuto({
|
|
184
|
+
to: qualifiedTarget, text: "", mediaUrl: mediaPath,
|
|
185
|
+
accountId: account.accountId, replyToId: event.messageId, account,
|
|
186
|
+
});
|
|
187
|
+
if (result.error)
|
|
188
|
+
log?.error(`${prefix} sendMedia(auto) error for ${mediaPath}: ${result.error}`);
|
|
189
|
+
else
|
|
190
|
+
log?.info(`${prefix} Sent local media: ${mediaPath}`);
|
|
191
|
+
}
|
|
192
|
+
catch (err) {
|
|
193
|
+
log?.error(`${prefix} sendMedia(auto) failed for ${mediaPath}: ${err}`);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
// 转发 tool 阶段收集的媒体
|
|
198
|
+
if (toolMediaUrls.length > 0) {
|
|
199
|
+
log?.info(`${prefix} Forwarding ${toolMediaUrls.length} tool-collected media URL(s) after block deliver`);
|
|
200
|
+
for (const mediaUrl of toolMediaUrls) {
|
|
201
|
+
try {
|
|
202
|
+
const result = await sendMediaAuto({
|
|
203
|
+
to: qualifiedTarget, text: "", mediaUrl,
|
|
204
|
+
accountId: account.accountId, replyToId: event.messageId, account,
|
|
205
|
+
});
|
|
206
|
+
if (result.error)
|
|
207
|
+
log?.error(`${prefix} Tool media forward error: ${result.error}`);
|
|
208
|
+
else
|
|
209
|
+
log?.info(`${prefix} Forwarded tool media: ${mediaUrl.slice(0, 80)}...`);
|
|
210
|
+
}
|
|
211
|
+
catch (err) {
|
|
212
|
+
log?.error(`${prefix} Tool media forward failed: ${err}`);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
toolMediaUrls.length = 0;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
// ============ 内部辅助函数 ============
|
|
219
|
+
/** 解码媒体路径:剥离 MEDIA: 前缀、展开 ~、修复转义 */
|
|
220
|
+
function decodeMediaPath(raw, log, prefix) {
|
|
221
|
+
let mediaPath = raw;
|
|
222
|
+
if (mediaPath.startsWith("MEDIA:")) {
|
|
223
|
+
mediaPath = mediaPath.slice("MEDIA:".length);
|
|
224
|
+
}
|
|
225
|
+
mediaPath = normalizePath(mediaPath);
|
|
226
|
+
mediaPath = mediaPath.replace(/\\\\/g, "\\");
|
|
227
|
+
try {
|
|
228
|
+
const hasOctal = /\\[0-7]{1,3}/.test(mediaPath);
|
|
229
|
+
const hasNonASCII = /[\u0080-\u00FF]/.test(mediaPath);
|
|
230
|
+
if (hasOctal || hasNonASCII) {
|
|
231
|
+
log?.debug?.(`${prefix} Decoding path with mixed encoding: ${mediaPath}`);
|
|
232
|
+
let decoded = mediaPath.replace(/\\([0-7]{1,3})/g, (_, octal) => {
|
|
233
|
+
return String.fromCharCode(parseInt(octal, 8));
|
|
234
|
+
});
|
|
235
|
+
const bytes = [];
|
|
236
|
+
for (let i = 0; i < decoded.length; i++) {
|
|
237
|
+
const code = decoded.charCodeAt(i);
|
|
238
|
+
if (code <= 0xFF) {
|
|
239
|
+
bytes.push(code);
|
|
240
|
+
}
|
|
241
|
+
else {
|
|
242
|
+
const charBytes = Buffer.from(decoded[i], "utf8");
|
|
243
|
+
bytes.push(...charBytes);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
const buffer = Buffer.from(bytes);
|
|
247
|
+
const utf8Decoded = buffer.toString("utf8");
|
|
248
|
+
if (!utf8Decoded.includes("\uFFFD") || utf8Decoded.length < decoded.length) {
|
|
249
|
+
mediaPath = utf8Decoded;
|
|
250
|
+
log?.debug?.(`${prefix} Successfully decoded path: ${mediaPath}`);
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
catch (decodeErr) {
|
|
255
|
+
log?.error(`${prefix} Path decode error: ${decodeErr}`);
|
|
256
|
+
}
|
|
257
|
+
return mediaPath;
|
|
258
|
+
}
|
|
259
|
+
/** 发送文本分块(共用逻辑) */
|
|
260
|
+
async function sendTextChunks(text, event, actx, sendWithRetry, consumeQuoteRef) {
|
|
261
|
+
const { account, log } = actx;
|
|
262
|
+
const prefix = `[qqbot:${account.accountId}]`;
|
|
263
|
+
const chunks = getQQBotRuntime().channel.text.chunkMarkdownText(text, TEXT_CHUNK_LIMIT);
|
|
264
|
+
for (const chunk of chunks) {
|
|
265
|
+
try {
|
|
266
|
+
await sendWithRetry(async (token) => {
|
|
267
|
+
const ref = consumeQuoteRef();
|
|
268
|
+
if (event.type === "c2c") {
|
|
269
|
+
return await sendC2CMessage(token, event.senderId, chunk, event.messageId, ref);
|
|
270
|
+
}
|
|
271
|
+
else if (event.type === "group" && event.groupOpenid) {
|
|
272
|
+
return await sendGroupMessage(token, event.groupOpenid, chunk, event.messageId);
|
|
273
|
+
}
|
|
274
|
+
else if (event.channelId) {
|
|
275
|
+
return await sendChannelMessage(token, event.channelId, chunk, event.messageId);
|
|
276
|
+
}
|
|
277
|
+
});
|
|
278
|
+
log?.info(`${prefix} Sent text chunk (${chunk.length}/${text.length} chars): ${chunk.slice(0, 50)}...`);
|
|
279
|
+
}
|
|
280
|
+
catch (err) {
|
|
281
|
+
log?.error(`${prefix} Failed to send text chunk: ${err}`);
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
/** 语音发送(带 45s 超时保护) */
|
|
286
|
+
async function sendVoiceWithTimeout(target, voicePath, account, log, prefix) {
|
|
287
|
+
const uploadFormats = account.config?.audioFormatPolicy?.uploadDirectFormats ?? account.config?.voiceDirectUploadFormats;
|
|
288
|
+
const transcodeEnabled = account.config?.audioFormatPolicy?.transcodeEnabled !== false;
|
|
289
|
+
const voiceTimeout = 45000;
|
|
290
|
+
try {
|
|
291
|
+
const result = await Promise.race([
|
|
292
|
+
sendVoice(target, voicePath, uploadFormats, transcodeEnabled),
|
|
293
|
+
new Promise((resolve) => setTimeout(() => resolve({ channel: "qqbot", error: "语音发送超时,已跳过" }), voiceTimeout)),
|
|
294
|
+
]);
|
|
295
|
+
if (result.error)
|
|
296
|
+
log?.error(`${prefix} sendVoice error: ${result.error}`);
|
|
297
|
+
}
|
|
298
|
+
catch (err) {
|
|
299
|
+
log?.error(`${prefix} sendVoice unexpected error: ${err}`);
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
/** Markdown 模式发送 */
|
|
303
|
+
async function sendMarkdownReply(textWithoutImages, imageUrls, mdMatches, bareUrlMatches, event, actx, sendWithRetry, consumeQuoteRef) {
|
|
304
|
+
const { account, log } = actx;
|
|
305
|
+
const prefix = `[qqbot:${account.accountId}]`;
|
|
306
|
+
// 分离图片:公网 URL vs Base64
|
|
307
|
+
const httpImageUrls = [];
|
|
308
|
+
const base64ImageUrls = [];
|
|
309
|
+
for (const url of imageUrls) {
|
|
310
|
+
if (url.startsWith("data:image/"))
|
|
311
|
+
base64ImageUrls.push(url);
|
|
312
|
+
else if (url.startsWith("http://") || url.startsWith("https://"))
|
|
313
|
+
httpImageUrls.push(url);
|
|
314
|
+
}
|
|
315
|
+
log?.info(`${prefix} Image classification: httpUrls=${httpImageUrls.length}, base64=${base64ImageUrls.length}`);
|
|
316
|
+
// 发送 Base64 图片
|
|
317
|
+
if (base64ImageUrls.length > 0) {
|
|
318
|
+
log?.info(`${prefix} Sending ${base64ImageUrls.length} image(s) via Rich Media API...`);
|
|
319
|
+
for (const imageUrl of base64ImageUrls) {
|
|
320
|
+
try {
|
|
321
|
+
await sendWithRetry(async (token) => {
|
|
322
|
+
if (event.type === "c2c") {
|
|
323
|
+
await sendC2CImageMessage(token, event.senderId, imageUrl, event.messageId);
|
|
324
|
+
}
|
|
325
|
+
else if (event.type === "group" && event.groupOpenid) {
|
|
326
|
+
await sendGroupImageMessage(token, event.groupOpenid, imageUrl, event.messageId);
|
|
327
|
+
}
|
|
328
|
+
else if (event.channelId) {
|
|
329
|
+
log?.info(`${prefix} Channel does not support rich media, skipping Base64 image`);
|
|
330
|
+
}
|
|
331
|
+
});
|
|
332
|
+
log?.info(`${prefix} Sent Base64 image via Rich Media API (size: ${imageUrl.length} chars)`);
|
|
333
|
+
}
|
|
334
|
+
catch (imgErr) {
|
|
335
|
+
log?.error(`${prefix} Failed to send Base64 image via Rich Media API: ${imgErr}`);
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
// 处理公网 URL 图片
|
|
340
|
+
const existingMdUrls = new Set(mdMatches.map((m) => m[2]));
|
|
341
|
+
const imagesToAppend = [];
|
|
342
|
+
for (const url of httpImageUrls) {
|
|
343
|
+
if (!existingMdUrls.has(url)) {
|
|
344
|
+
try {
|
|
345
|
+
const size = await getImageSize(url);
|
|
346
|
+
imagesToAppend.push(formatQQBotMarkdownImage(url, size));
|
|
347
|
+
log?.info(`${prefix} Formatted HTTP image: ${size ? `${size.width}x${size.height}` : "default size"} - ${url.slice(0, 60)}...`);
|
|
348
|
+
}
|
|
349
|
+
catch (err) {
|
|
350
|
+
log?.info(`${prefix} Failed to get image size, using default: ${err}`);
|
|
351
|
+
imagesToAppend.push(formatQQBotMarkdownImage(url, null));
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
// 补充已有 markdown 图片的尺寸信息
|
|
356
|
+
let result = textWithoutImages;
|
|
357
|
+
for (const m of mdMatches) {
|
|
358
|
+
const fullMatch = m[0];
|
|
359
|
+
const imgUrl = m[2];
|
|
360
|
+
const isHttpUrl = imgUrl.startsWith("http://") || imgUrl.startsWith("https://");
|
|
361
|
+
if (isHttpUrl && !hasQQBotImageSize(fullMatch)) {
|
|
362
|
+
try {
|
|
363
|
+
const size = await getImageSize(imgUrl);
|
|
364
|
+
result = result.replace(fullMatch, formatQQBotMarkdownImage(imgUrl, size));
|
|
365
|
+
log?.info(`${prefix} Updated image with size: ${size ? `${size.width}x${size.height}` : "default"} - ${imgUrl.slice(0, 60)}...`);
|
|
366
|
+
}
|
|
367
|
+
catch (err) {
|
|
368
|
+
log?.info(`${prefix} Failed to get image size for existing md, using default: ${err}`);
|
|
369
|
+
result = result.replace(fullMatch, formatQQBotMarkdownImage(imgUrl, null));
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
// 移除裸 URL 图片
|
|
374
|
+
for (const m of bareUrlMatches) {
|
|
375
|
+
result = result.replace(m[0], "").trim();
|
|
376
|
+
}
|
|
377
|
+
// 追加图片
|
|
378
|
+
if (imagesToAppend.length > 0) {
|
|
379
|
+
result = result.trim();
|
|
380
|
+
result = result ? result + "\n\n" + imagesToAppend.join("\n") : imagesToAppend.join("\n");
|
|
381
|
+
}
|
|
382
|
+
// 发送 markdown 文本
|
|
383
|
+
if (result.trim()) {
|
|
384
|
+
const mdChunks = chunkText(result, TEXT_CHUNK_LIMIT);
|
|
385
|
+
for (const chunk of mdChunks) {
|
|
386
|
+
try {
|
|
387
|
+
await sendWithRetry(async (token) => {
|
|
388
|
+
const ref = consumeQuoteRef();
|
|
389
|
+
if (event.type === "c2c") {
|
|
390
|
+
return await sendC2CMessage(token, event.senderId, chunk, event.messageId, ref);
|
|
391
|
+
}
|
|
392
|
+
else if (event.type === "group" && event.groupOpenid) {
|
|
393
|
+
return await sendGroupMessage(token, event.groupOpenid, chunk, event.messageId);
|
|
394
|
+
}
|
|
395
|
+
else if (event.channelId) {
|
|
396
|
+
return await sendChannelMessage(token, event.channelId, chunk, event.messageId);
|
|
397
|
+
}
|
|
398
|
+
});
|
|
399
|
+
log?.info(`${prefix} Sent markdown chunk (${chunk.length}/${result.length} chars) with ${httpImageUrls.length} HTTP images (${event.type})`);
|
|
400
|
+
}
|
|
401
|
+
catch (err) {
|
|
402
|
+
log?.error(`${prefix} Failed to send markdown message chunk: ${err}`);
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
/** 普通文本模式发送 */
|
|
408
|
+
async function sendPlainTextReply(textWithoutImages, imageUrls, mdMatches, bareUrlMatches, event, actx, sendWithRetry, consumeQuoteRef) {
|
|
409
|
+
const { account, log } = actx;
|
|
410
|
+
const prefix = `[qqbot:${account.accountId}]`;
|
|
411
|
+
const imgMediaTarget = {
|
|
412
|
+
targetType: event.type === "c2c" ? "c2c" : event.type === "group" ? "group" : "channel",
|
|
413
|
+
targetId: event.type === "c2c" ? event.senderId : event.type === "group" ? event.groupOpenid : event.channelId,
|
|
414
|
+
account,
|
|
415
|
+
replyToId: event.messageId,
|
|
416
|
+
logPrefix: prefix,
|
|
417
|
+
};
|
|
418
|
+
let result = textWithoutImages;
|
|
419
|
+
for (const m of mdMatches)
|
|
420
|
+
result = result.replace(m[0], "").trim();
|
|
421
|
+
for (const m of bareUrlMatches)
|
|
422
|
+
result = result.replace(m[0], "").trim();
|
|
423
|
+
// 群聊 URL 点号过滤
|
|
424
|
+
if (result && event.type !== "c2c") {
|
|
425
|
+
result = result.replace(/([a-zA-Z0-9])\.([a-zA-Z0-9])/g, "$1_$2");
|
|
426
|
+
}
|
|
427
|
+
try {
|
|
428
|
+
for (const imageUrl of imageUrls) {
|
|
429
|
+
try {
|
|
430
|
+
const imgResult = await sendPhoto(imgMediaTarget, imageUrl);
|
|
431
|
+
if (imgResult.error)
|
|
432
|
+
log?.error(`${prefix} Failed to send image: ${imgResult.error}`);
|
|
433
|
+
else
|
|
434
|
+
log?.info(`${prefix} Sent image via sendPhoto: ${imageUrl.slice(0, 80)}...`);
|
|
435
|
+
}
|
|
436
|
+
catch (imgErr) {
|
|
437
|
+
log?.error(`${prefix} Failed to send image: ${imgErr}`);
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
if (result.trim()) {
|
|
441
|
+
const plainChunks = chunkText(result, TEXT_CHUNK_LIMIT);
|
|
442
|
+
for (const chunk of plainChunks) {
|
|
443
|
+
await sendWithRetry(async (token) => {
|
|
444
|
+
const ref = consumeQuoteRef();
|
|
445
|
+
if (event.type === "c2c") {
|
|
446
|
+
return await sendC2CMessage(token, event.senderId, chunk, event.messageId, ref);
|
|
447
|
+
}
|
|
448
|
+
else if (event.type === "group" && event.groupOpenid) {
|
|
449
|
+
return await sendGroupMessage(token, event.groupOpenid, chunk, event.messageId);
|
|
450
|
+
}
|
|
451
|
+
else if (event.channelId) {
|
|
452
|
+
return await sendChannelMessage(token, event.channelId, chunk, event.messageId);
|
|
453
|
+
}
|
|
454
|
+
});
|
|
455
|
+
log?.info(`${prefix} Sent text chunk (${chunk.length}/${result.length} chars) (${event.type})`);
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
catch (err) {
|
|
460
|
+
log?.error(`${prefix} Send failed: ${err}`);
|
|
461
|
+
}
|
|
462
|
+
}
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* QQ Bot 消息发送模块
|
|
3
|
+
*/
|
|
4
|
+
import type { ResolvedQQBotAccount } from "./types.js";
|
|
5
|
+
/** 限流检查结果 */
|
|
6
|
+
export interface ReplyLimitResult {
|
|
7
|
+
/** 是否允许被动回复 */
|
|
8
|
+
allowed: boolean;
|
|
9
|
+
/** 剩余被动回复次数 */
|
|
10
|
+
remaining: number;
|
|
11
|
+
/** 是否需要降级为主动消息(超期或超过次数) */
|
|
12
|
+
shouldFallbackToProactive: boolean;
|
|
13
|
+
/** 降级原因 */
|
|
14
|
+
fallbackReason?: "expired" | "limit_exceeded";
|
|
15
|
+
/** 提示消息 */
|
|
16
|
+
message?: string;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* 检查是否可以回复该消息(限流检查)
|
|
20
|
+
* @param messageId 消息ID
|
|
21
|
+
* @returns ReplyLimitResult 限流检查结果
|
|
22
|
+
*/
|
|
23
|
+
export declare function checkMessageReplyLimit(messageId: string): ReplyLimitResult;
|
|
24
|
+
/**
|
|
25
|
+
* 记录一次消息回复
|
|
26
|
+
* @param messageId 消息ID
|
|
27
|
+
*/
|
|
28
|
+
export declare function recordMessageReply(messageId: string): void;
|
|
29
|
+
/**
|
|
30
|
+
* 获取消息回复统计信息
|
|
31
|
+
*/
|
|
32
|
+
export declare function getMessageReplyStats(): {
|
|
33
|
+
trackedMessages: number;
|
|
34
|
+
totalReplies: number;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* 获取消息回复限制配置(供外部查询)
|
|
38
|
+
*/
|
|
39
|
+
export declare function getMessageReplyConfig(): {
|
|
40
|
+
limit: number;
|
|
41
|
+
ttlMs: number;
|
|
42
|
+
ttlHours: number;
|
|
43
|
+
};
|
|
44
|
+
export interface OutboundContext {
|
|
45
|
+
to: string;
|
|
46
|
+
text: string;
|
|
47
|
+
accountId?: string | null;
|
|
48
|
+
replyToId?: string | null;
|
|
49
|
+
account: ResolvedQQBotAccount;
|
|
50
|
+
}
|
|
51
|
+
export interface MediaOutboundContext extends OutboundContext {
|
|
52
|
+
mediaUrl: string;
|
|
53
|
+
/** 可选的 MIME 类型,优先于扩展名判断媒体类型 */
|
|
54
|
+
mimeType?: string;
|
|
55
|
+
}
|
|
56
|
+
export interface OutboundResult {
|
|
57
|
+
channel: string;
|
|
58
|
+
messageId?: string;
|
|
59
|
+
timestamp?: string | number;
|
|
60
|
+
error?: string;
|
|
61
|
+
/** 出站消息的引用索引(ext_info.ref_idx),供引用消息缓存使用 */
|
|
62
|
+
refIdx?: string;
|
|
63
|
+
}
|
|
64
|
+
/** 媒体发送的目标上下文(从 deliver 回调或 sendText 中提取) */
|
|
65
|
+
export interface MediaTargetContext {
|
|
66
|
+
/** 目标类型 */
|
|
67
|
+
targetType: "c2c" | "group" | "channel";
|
|
68
|
+
/** 目标 ID */
|
|
69
|
+
targetId: string;
|
|
70
|
+
/** QQ Bot 账户配置 */
|
|
71
|
+
account: ResolvedQQBotAccount;
|
|
72
|
+
/** 被动回复消息 ID(可选) */
|
|
73
|
+
replyToId?: string;
|
|
74
|
+
/** 日志前缀(可选,用于区分调用来源) */
|
|
75
|
+
logPrefix?: string;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* sendPhoto — 发送图片消息(对齐 Telegram sendPhoto)
|
|
79
|
+
*
|
|
80
|
+
* 支持三种来源:
|
|
81
|
+
* - 本地文件路径(自动读取转 Base64)
|
|
82
|
+
* - 公网 HTTP/HTTPS URL(urlDirectUpload=true 时先直传平台,失败自动下载重试;=false 时直接下载)
|
|
83
|
+
* - Base64 Data URL
|
|
84
|
+
*/
|
|
85
|
+
export declare function sendPhoto(ctx: MediaTargetContext, imagePath: string): Promise<OutboundResult>;
|
|
86
|
+
/**
|
|
87
|
+
* sendVoice — 发送语音消息(对齐 Telegram sendVoice)
|
|
88
|
+
*
|
|
89
|
+
* 支持本地音频文件和公网 URL:
|
|
90
|
+
* - urlDirectUpload=true + 公网URL:先直传平台,失败后下载到本地再转码重试
|
|
91
|
+
* - urlDirectUpload=false + 公网URL:直接下载到本地再转码发送
|
|
92
|
+
* - 本地文件:自动转换为 SILK 格式后上传
|
|
93
|
+
*
|
|
94
|
+
* 支持 transcodeEnabled 配置:禁用时非原生格式 fallback 到文件发送。
|
|
95
|
+
*/
|
|
96
|
+
export declare function sendVoice(ctx: MediaTargetContext, voicePath: string,
|
|
97
|
+
/** 直传格式列表(跳过 SILK 转换),可选 */
|
|
98
|
+
directUploadFormats?: string[],
|
|
99
|
+
/** 是否启用转码(默认 true),false 时非原生格式直接返回错误 */
|
|
100
|
+
transcodeEnabled?: boolean): Promise<OutboundResult>;
|
|
101
|
+
/**
|
|
102
|
+
* sendVideoMsg — 发送视频消息(对齐 Telegram sendVideo)
|
|
103
|
+
*
|
|
104
|
+
* 支持公网 URL(urlDirectUpload 控制直传或下载,失败自动 fallback)和本地文件路径。
|
|
105
|
+
*/
|
|
106
|
+
export declare function sendVideoMsg(ctx: MediaTargetContext, videoPath: string): Promise<OutboundResult>;
|
|
107
|
+
/**
|
|
108
|
+
* sendDocument — 发送文件消息(对齐 Telegram sendDocument)
|
|
109
|
+
*
|
|
110
|
+
* 支持本地文件路径和公网 URL(urlDirectUpload 控制直传或下载,失败自动 fallback)。
|
|
111
|
+
*/
|
|
112
|
+
export declare function sendDocument(ctx: MediaTargetContext, filePath: string): Promise<OutboundResult>;
|
|
113
|
+
/**
|
|
114
|
+
* 发送文本消息
|
|
115
|
+
* - 有 replyToId: 被动回复,1小时内最多回复4次
|
|
116
|
+
* - 无 replyToId: 主动发送,有配额限制(每月4条/用户/群)
|
|
117
|
+
*
|
|
118
|
+
* 注意:
|
|
119
|
+
* 1. 主动消息(无 replyToId)必须有消息内容,不支持流式发送
|
|
120
|
+
* 2. 当被动回复不可用(超期或超过次数)时,自动降级为主动消息
|
|
121
|
+
* 3. 支持 <qqimg>路径</qqimg> 或 <qqimg>路径</img> 格式发送图片
|
|
122
|
+
*/
|
|
123
|
+
export declare function sendText(ctx: OutboundContext): Promise<OutboundResult>;
|
|
124
|
+
/**
|
|
125
|
+
* 主动发送消息(不需要 replyToId,有配额限制:每月 4 条/用户/群)
|
|
126
|
+
*
|
|
127
|
+
* @param account - 账户配置
|
|
128
|
+
* @param to - 目标地址,格式:openid(单聊)或 group:xxx(群聊)
|
|
129
|
+
* @param text - 消息内容
|
|
130
|
+
*/
|
|
131
|
+
export declare function sendProactiveMessage(account: ResolvedQQBotAccount, to: string, text: string): Promise<OutboundResult>;
|
|
132
|
+
/**
|
|
133
|
+
* 发送富媒体消息(图片)
|
|
134
|
+
*
|
|
135
|
+
* 支持以下 mediaUrl 格式:
|
|
136
|
+
* - 公网 URL: https://example.com/image.png
|
|
137
|
+
* - Base64 Data URL: data:image/png;base64,xxxxx
|
|
138
|
+
* - 本地文件路径: /path/to/image.png(自动读取并转换为 Base64)
|
|
139
|
+
*
|
|
140
|
+
* @param ctx - 发送上下文,包含 mediaUrl
|
|
141
|
+
* @returns 发送结果
|
|
142
|
+
*
|
|
143
|
+
* @example
|
|
144
|
+
* ```typescript
|
|
145
|
+
* // 发送网络图片
|
|
146
|
+
* const result = await sendMedia({
|
|
147
|
+
* to: "group:xxx",
|
|
148
|
+
* text: "这是图片说明",
|
|
149
|
+
* mediaUrl: "https://example.com/image.png",
|
|
150
|
+
* account,
|
|
151
|
+
* replyToId: msgId,
|
|
152
|
+
* });
|
|
153
|
+
*
|
|
154
|
+
* // 发送 Base64 图片
|
|
155
|
+
* const result = await sendMedia({
|
|
156
|
+
* to: "group:xxx",
|
|
157
|
+
* text: "这是图片说明",
|
|
158
|
+
* mediaUrl: "data:image/png;base64,iVBORw0KGgo...",
|
|
159
|
+
* account,
|
|
160
|
+
* replyToId: msgId,
|
|
161
|
+
* });
|
|
162
|
+
*
|
|
163
|
+
* // 发送本地文件(自动读取并转换为 Base64)
|
|
164
|
+
* const result = await sendMedia({
|
|
165
|
+
* to: "group:xxx",
|
|
166
|
+
* text: "这是图片说明",
|
|
167
|
+
* mediaUrl: "/tmp/generated-chart.png",
|
|
168
|
+
* account,
|
|
169
|
+
* replyToId: msgId,
|
|
170
|
+
* });
|
|
171
|
+
* ```
|
|
172
|
+
*/
|
|
173
|
+
export declare function sendMedia(ctx: MediaOutboundContext): Promise<OutboundResult>;
|
|
174
|
+
/**
|
|
175
|
+
* 发送 Cron 触发的消息
|
|
176
|
+
*
|
|
177
|
+
* 当 OpenClaw cron 任务触发时,消息内容可能是:
|
|
178
|
+
* 1. QQBOT_CRON:{base64} 格式的结构化载荷 - 解码后根据 targetType 和 targetAddress 发送
|
|
179
|
+
* 2. 普通文本 - 直接发送到指定目标
|
|
180
|
+
*
|
|
181
|
+
* @param account - 账户配置
|
|
182
|
+
* @param to - 目标地址(作为后备,如果载荷中没有指定)
|
|
183
|
+
* @param message - 消息内容(可能是 QQBOT_CRON: 格式或普通文本)
|
|
184
|
+
* @returns 发送结果
|
|
185
|
+
*
|
|
186
|
+
* @example
|
|
187
|
+
* ```typescript
|
|
188
|
+
* // 处理结构化载荷
|
|
189
|
+
* const result = await sendCronMessage(
|
|
190
|
+
* account,
|
|
191
|
+
* "user_openid", // 后备地址
|
|
192
|
+
* "QQBOT_CRON:eyJ0eXBlIjoiY3Jvbl9yZW1pbmRlciIs..." // Base64 编码的载荷
|
|
193
|
+
* );
|
|
194
|
+
*
|
|
195
|
+
* // 处理普通文本
|
|
196
|
+
* const result = await sendCronMessage(
|
|
197
|
+
* account,
|
|
198
|
+
* "user_openid",
|
|
199
|
+
* "这是一条普通的提醒消息"
|
|
200
|
+
* );
|
|
201
|
+
* ```
|
|
202
|
+
*/
|
|
203
|
+
export declare function sendCronMessage(account: ResolvedQQBotAccount, to: string, message: string): Promise<OutboundResult>;
|