hermes - 💡(How to fix) Fix fix(telegram): Reply-to-message photo not forwarded to agent

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…

Root Cause

In gateway/platforms/telegram.py, the _build_message_event method (line ~3674) only extracts text or caption from reply_to_message:

reply_to_text = message.reply_to_message.text or message.reply_to_message.caption or None

When reply_to_message contains a photo with no caption, reply_to_text is None and the agent receives zero context about what the user is referencing.

Meanwhile, in run.py (line ~6224), the reply-to injection only triggers on text:

if getattr(event, "reply_to_text", None) and event.reply_to_message_id:
    reply_snippet = event.reply_to_text[:500]
    message_text = f'[Replying to: "{reply_snippet}"]\n\n{message_text}'

The photo from reply_to_message is never downloaded or attached to event.media_urls.

Code Example

reply_to_text = message.reply_to_message.text or message.reply_to_message.caption or None

---

if getattr(event, "reply_to_text", None) and event.reply_to_message_id:
    reply_snippet = event.reply_to_text[:500]
    message_text = f'[Replying to: "{reply_snippet}"]\n\n{message_text}'
RAW_BUFFERClick to expand / collapse

Bug Description

When a user sends a text message as a reply to a message containing a photo (e.g., replying to a screenshot), the Telegram adapter does not download or forward the replied-to image to the agent. The agent receives only the text of the reply (and possibly a caption), but never sees the referenced photo.

Root Cause

In gateway/platforms/telegram.py, the _build_message_event method (line ~3674) only extracts text or caption from reply_to_message:

reply_to_text = message.reply_to_message.text or message.reply_to_message.caption or None

When reply_to_message contains a photo with no caption, reply_to_text is None and the agent receives zero context about what the user is referencing.

Meanwhile, in run.py (line ~6224), the reply-to injection only triggers on text:

if getattr(event, "reply_to_text", None) and event.reply_to_message_id:
    reply_snippet = event.reply_to_text[:500]
    message_text = f'[Replying to: "{reply_snippet}"]\n\n{message_text}'

The photo from reply_to_message is never downloaded or attached to event.media_urls.

Reproduction Steps

  1. In a Telegram chat with the bot, send a photo (e.g., an iPhone screenshot shared to the group)
  2. Reply to that photo message with a text like "What do you think about this?"
  3. The agent responds saying it cannot see any image

Expected Behavior

The agent should receive the replied-to photo and be able to analyze/discuss it, just as it would if the photo were sent directly.

Affected Scenarios

ScenarioWorks?
Send photo directly to bot
Reply to photo WITH caption⚠️ Caption forwarded, photo NOT forwarded
Reply to photo WITHOUT caption❌ No context at all

Environment

  • Platform: Telegram (group supergroup with topics)
  • Device: iPhone (screenshot shared via Telegram share sheet)
  • Gateway version: latest main

Proposed Fix

Add _fetch_reply_to_photo() async method to the Telegram adapter that:

  1. Checks if message.reply_to_message has a photo
  2. Downloads the largest PhotoSize variant
  3. Caches it locally via cache_image_from_bytes()
  4. Attaches the path to event.media_urls / event.media_types
  5. Sets reply_to_text = "[photo]" when no caption exists (so run.py still injects a disambiguation pointer)

This approach reuses the existing image-routing pipeline in run.py — the replied-to photo flows through the same native/vision-analyze path as directly-sent photos.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING