-
-
Notifications
You must be signed in to change notification settings - Fork 52.6k
Closed
Description
Summary
When a Telegram user sends a document, OpenClaw's resolveMedia() function has msg.document.file_name (the original filename from the Telegram Bot API) available but never uses it, causing the original filename to be permanently lost.
Root Cause (Code Analysis)
File: dist/pi-embedded-CQnl8oWA.js — resolveMedia()
// ctx.getFile() returns the server-side path only — not the original filename
file = await ctx.getFile();
// file.file_path = "documents/file_<server-id>.pdf" <- server-side path, NOT original
// msg.document.file_name is available here but never read
const saved = await downloadAndSaveTelegramFile(file.file_path, fetchImpl);
// msg.document?.file_name is ignoredFile: dist/local-roots-BHi_eOQs.js — fetchRemoteMedia()
const headerFileName = parseContentDispositionFileName(res.headers.get("content-disposition"));
// -> null: Telegram's download server sends no Content-Disposition header
let fileName = headerFileName || fileNameFromUrl || path.basename(filePathHint);
// fileNameFromUrl = path.basename(".../documents/file_<server-id>.pdf")
// -> "file_<server-id>.pdf" <- server-side name, not the originalFile: dist/store-Q3603hr3.js — saveMediaBuffer()
// originalFilename = "file_<server-id>.pdf" (server-side name wrongly treated as original)
const base = path.parse(originalFilename).name; // -> "file_<server-id>"
const sanitized = sanitizeFilename(base);
id = `${sanitized}---${uuid}${ext}`;
// Final saved name: "file_<server-id>---<new-uuid>.pdf"
// Double-UUID pattern — original name (e.g., "business-plan.docx") is goneExpected Behavior
When a user sends a file named business-plan.docx, the file should be saved as business-plan---<uuid>.docx, preserving the original name with a UUID suffix for uniqueness.
Actual Behavior
The saved filename is derived from the Telegram server-side path, resulting in a double-UUID pattern like file_<server-id>---<new-uuid>.pdf. The user's original filename is permanently lost.
Minimal Fix
// Step 1: Update downloadAndSaveTelegramFile to accept an optional name override
const downloadAndSaveTelegramFile = async (filePath, fetchImpl, telegramFileName) => {
const fetched = await fetchRemoteMedia({ ... });
const originalName = telegramFileName ?? fetched.fileName ?? filePath;
return saveMediaBuffer(fetched.buffer, fetched.contentType, "inbound", maxBytes, originalName);
};
// Step 2: Pass msg.document.file_name at the call site
const originalFileName = msg.document?.file_name ?? msg.audio?.file_name ?? msg.video?.file_name;
const saved = await downloadAndSaveTelegramFile(file.file_path, fetchImpl, originalFileName);Impact
- Agent cannot identify files by their original name when multiple documents are sent
- Breaks workflows where filename carries semantic meaning (numbered annexes, versioned reports, etc.)
- User must manually re-specify filenames, adding friction to every document-based task
Environment
- OpenClaw version:
2026.2.26 - OS: macOS (arm64)
- Channel: Telegram
- Related closed issue: [Bug]: Telegram inbound file documents lose original filename — saved as UUID #31757 (symptom-based report, superseded by this)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels