#12381: fix(telegram): preserve original filename for inbound documents
channel: telegram
size: XS
Cluster:
WhatsApp Document Handling Fixes
## Summary
Telegram inbound documents lose their original filename when saved to disk.
## Steps to reproduce
1. Send a document to a Telegram bot (e.g. `my-report.pdf`)
2. Check the saved file in `~/.openclaw/media/inbound/`
3. File is saved as `file_12345---{uuid}.pdf` instead of `my-report---{uuid}.pdf`
## Expected behavior
The original filename from the Telegram message should be preserved in the saved file path, using the existing `{sanitized}---{uuid}.ext` naming scheme that `saveMediaBuffer()` already supports.
## Actual behavior
`resolveMedia()` passes `fetched.fileName ?? file.file_path` to `saveMediaBuffer()`. Since:
- `fetched.fileName` comes from HTTP `Content-Disposition` header, which Telegram API does **not** set → always `undefined`
- `file.file_path` is Telegram internal path (e.g. `documents/file_12345.pdf`)
The original filename (`msg.document.file_name`) is never read.
## Fix
One-line priority change: read `msg.document?.file_name` / `msg.audio?.file_name` / `msg.video?.file_name` before falling back to `fetched.fileName` and `file.file_path`.
The `saveMediaBuffer()` infrastructure for embedding original filenames already works correctly — this fix simply provides the right value.
## Related
Analogous to #5781 / #10862 (WhatsApp document filename issues) but for the Telegram inbound path.
## Testing
- [x] `pnpm build` passes
- [x] All existing tests pass (26/26 in delivery + store + download)
- [x] AI-assisted (analysis + fix), manually verified code path
---
🤖 AI-assisted PR
---
## Validation
- [x] `pnpm build` — passes
- [x] `pnpm check` — passes
- [x] `pnpm test` — 26/26 delivery + store + download tests pass
## Contribution checklist
- [x] **Focused scope**: One-line priority change for filename resolution
- [x] **What + why**: described above
- [x] **AI-assisted**: Yes, already marked as "AI-assisted PR". Testing level: fully tested (26 existing tests pass)
Most Similar PRs
#22540: fix(signal): preserve original filename in outbound attachments
by lailoo · 2026-02-21
77.7%
#21881: fix(whatsapp): pass user-provided fileName through document send pipe…
by saakshigupta2002 · 2026-02-20
73.2%
#16817: fix(whatsapp): infer extension-aware fallback filename for Baileys ...
by VintLin · 2026-02-15
72.8%
#16785: fix(whatsapp): preserve document filenames in outbound Baileys mode
by SahilSahu731 · 2026-02-15
72.2%
#15650: fix(whatsapp): pass fileName to document sends instead of hardcodin...
by whoknowsmann · 2026-02-13
72.1%
#7458: fix: pass filename through to WhatsApp document sends (#7446)
by gavinbmoore · 2026-02-02
72.0%
#21276: fix(telegram): stabilize partial finalization and MEDIA dedupe (AI-...
by HOYALIM · 2026-02-19
70.5%
#10889: fix: pass fileName through WhatsApp document send path
by DeveshParagiri · 2026-02-07
70.0%
#23238: fix(telegram): account named "default" silently breaks inbound polling
by anillBhoi · 2026-02-22
69.3%
#9734: fix(telegram): correct sender identification for channel messages (...
by divol89 · 2026-02-05
68.8%