feat(discord): download attachments from forwarded messages (#17049)

Co-authored-by: Shadow <shadow@openclaw.ai>
This commit is contained in:
pip-nomel
2026-02-16 22:23:40 +01:00
committed by GitHub
parent c593709d25
commit 1567d6cbb4
4 changed files with 133 additions and 3 deletions

View File

@@ -156,6 +156,46 @@ export async function resolveMediaList(
return out;
}
export async function resolveForwardedMediaList(
message: Message,
maxBytes: number,
): Promise<DiscordMediaInfo[]> {
const snapshots = resolveDiscordMessageSnapshots(message);
if (snapshots.length === 0) {
return [];
}
const out: DiscordMediaInfo[] = [];
for (const snapshot of snapshots) {
const attachments = snapshot.message?.attachments;
if (!attachments || attachments.length === 0) {
continue;
}
for (const attachment of attachments) {
try {
const fetched = await fetchRemoteMedia({
url: attachment.url,
filePathHint: attachment.filename ?? attachment.url,
});
const saved = await saveMediaBuffer(
fetched.buffer,
fetched.contentType ?? attachment.content_type,
"inbound",
maxBytes,
);
out.push({
path: saved.path,
contentType: saved.contentType,
placeholder: inferPlaceholder(attachment),
});
} catch (err) {
const id = attachment.id ?? attachment.url;
logVerbose(`discord: failed to download forwarded attachment ${id}: ${String(err)}`);
}
}
}
return out;
}
function inferPlaceholder(attachment: APIAttachment): string {
const mime = attachment.content_type ?? "";
if (mime.startsWith("image/")) {