Skip to content

fix(photos): do not serve web-preview images as message photos - #311

Merged
chigwell merged 2 commits into
chigwell:mainfrom
axisrow:fix/304-web-preview-not-message-photo
Oct 16, 2026
Merged

chigwell merged 2 commits into
chigwell:mainfrom
axisrow:fix/304-web-preview-not-message-photo

Conversation

@axisrow

@axisrow axisrow commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Follow-up to #291 (issue #304): open_photo(message_id=...) fetched the message directly and read Message.photo, but Telethon's Message.photo also returns the web-page preview image. A text-only message carrying a link preview therefore returned its thumbnail — while list_photos, which defines the message-id space via InputMessagesFilterPhotos, does not list such messages, and get_media_label does not count a link preview as an attachment.

Require isinstance(message.media, types.MessageMediaPhoto) in the direct path, so open_photo answers "photo not found" for preview-only messages.

Before

A text-only message whose only image is a web-page (e.g. YouTube) preview is invisible to list_photos, yet the direct-by-id path still served the preview thumbnail:

SCENARIO: message #42 is a plain text link with a web preview, no attached photo
list_photos(chat)                          -> #42 is not listed
open_photo(chat_id=chat, message_id=42)    -> returned the web-preview thumbnail image
                                              # wrong: it is not a message photo

After

The direct path requires real MessageMediaPhoto media, consistent with list_photos and get_media_label:

SCENARIO: message #42 is a plain text link with a web preview, no attached photo
list_photos(chat)                          -> #42 is not listed
open_photo(chat_id=chat, message_id=42)
-> "No messages photo found for chat <chat_id> with id 42."

Real photos posted in the chat keep working exactly as before.

Changes

  • telegram_mcp/photo_source.py: guard in find_photo_reference before reading message.photo.
  • tests/test_photo_source.py: stub messages now carry a real .media (MessageMediaPhoto); new test: a message with MessageMediaWebPage media whose .photo exposes the preview thumbnail returns None and does not scan history.
  • tests/test_photo_tools.py: SinglePhotoClient stub updated to model a real Telethon message (.media present) — it previously relied on the buggy behavior.

Tests

uv run pytest -q — 1193 passed (full suite).

Fixes #304

🤖 Generated with Claude Code

axisrow and others added 2 commits October 16, 2026 01:00
The direct-by-id path in find_photo_reference read Message.photo, which
Telethon also fills from web-page previews. A text-only message with a
link preview therefore returned its thumbnail via open_photo, even
though list_photos (InputMessagesFilterPhotos, which defines the
message-id space) does not list it and get_media_label does not count a
preview as an attachment.

Require MessageMediaPhoto media before returning, so open_photo answers
"not found" for preview-only messages.

Fixes chigwell#304

Co-Authored-By: Claude Code <[email protected]>
Same reformat as landed on main in b5149a1: this file was written
under a pre-24.x black that kept hand-wrapped call sites; current
black collapses them. No behavior change.

Co-Authored-By: Claude Code <[email protected]>
@chigwell
chigwell merged commit c25ae26 into chigwell:main Oct 16, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

open_photo(message_id=...) returns web-preview images as message photos (follow-up to #291)

2 participants