#13961: fix(telegram): support media attachments in replied Telegram messages
channel: telegram
stale
Cluster:
Media Handling Improvements
## Problem
Currently, the agent has no context to media attachments in a replied Telegram message.
Example:
1. User/bot sent a message containing an image in the session
2. User reply to that message, asking about that image
3. The bot is unable to access or read that image
## Fix
This PR adds several metadata about ReplyToMedia into MsgContext, making the bot able to access and read the media attachments in replied messages.
## Test
Added a test file (src/auto-reply/reply/inbound-meta.test.ts) and modified two test cases in existing tests to ensure the new behavior works as expected.
The patch is built and verified manually in my local deployment.
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
This PR adds support for staging and exposing media attachments from replied Telegram messages by:
- Downloading media from `reply_to_message`/`external_reply` in Telegram delivery, and passing it into message-context construction.
- Extending `MsgContext`/templating metadata with `ReplyToMedia*` fields.
- Updating sandbox media staging to copy replied media into the sandbox workspace and rewrite paths/URLs.
- Including replied-media paths/types in the inbound “replied message” context block.
Main issue to address before merge: the new unit test for `buildInboundUserContextPrefix` is brittle because it parses the first JSON block, but the function may emit other JSON blocks before the replied-message block depending on inputs.
<h3>Confidence Score: 4/5</h3>
- Mostly safe to merge once the failing/brittle unit test is fixed.
- Behavioral changes are localized and covered by new tests for reply-media download and sandbox staging, but the new inbound-meta test is structured in a way that will fail under common inputs because it assumes the first JSON block is the reply context.
- src/auto-reply/reply/inbound-meta.test.ts
<!-- greptile_other_comments_section -->
<sub>(2/5) Greptile learns from your feedback when you react with thumbs up/down!</sub>
<!-- /greptile_comment -->
Most Similar PRs
#14794: fix: parse inline MEDIA: tokens in agent replies
by explainanalyze · 2026-02-12
81.8%
#8042: feat(telegram): add media index for reply-to media lookup
by batumilove · 2026-02-03
80.8%
#7261: fix(telegram): preserve DM topic thread id for outbound media
by ViffyGwaanl · 2026-02-02
79.2%
#22434: feat(telegram): support sending original quality images
by godenjan · 2026-02-21
78.2%
#19399: telegram: fix MEDIA false positives and partial final drop
by HOYALIM · 2026-02-17
78.1%
#20735: fix: skip auto-attaching tool MEDIA: paths already sent via message t…
by anillBhoi · 2026-02-19
77.7%
#21898: fix(telegram): auto-detect captionable messages for editMessageCaption
by ptrkstr · 2026-02-20
77.4%
#21309: feat(telegram): support outbound media groups (albums) via sendMedi...
by smysle · 2026-02-19
77.3%
#22113: feat: support non-image file attachments in webchat chat.send
by Kt-L · 2026-02-20
77.1%
#21276: fix(telegram): stabilize partial finalization and MEDIA dedupe (AI-...
by HOYALIM · 2026-02-19
77.1%