Repository navigation
fix(photos): do not serve web-preview images as message photos - #311
Merged
chigwell merged 2 commits intoOct 16, 2026
Merged
Conversation
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
approved these changes
Oct 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Follow-up to #291 (issue #304):
open_photo(message_id=...)fetched the message directly and readMessage.photo, but Telethon'sMessage.photoalso returns the web-page preview image. A text-only message carrying a link preview therefore returned its thumbnail — whilelist_photos, which defines the message-id space viaInputMessagesFilterPhotos, does not list such messages, andget_media_labeldoes not count a link preview as an attachment.Require
isinstance(message.media, types.MessageMediaPhoto)in the direct path, soopen_photoanswers "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:After
The direct path requires real
MessageMediaPhotomedia, consistent withlist_photosandget_media_label:Real photos posted in the chat keep working exactly as before.
Changes
telegram_mcp/photo_source.py: guard infind_photo_referencebefore readingmessage.photo.tests/test_photo_source.py: stub messages now carry a real.media(MessageMediaPhoto); new test: a message withMessageMediaWebPagemedia whose.photoexposes the preview thumbnail returnsNoneand does not scan history.tests/test_photo_tools.py:SinglePhotoClientstub updated to model a real Telethon message (.mediapresent) — it previously relied on the buggy behavior.Tests
uv run pytest -q— 1193 passed (full suite).Fixes #304
🤖 Generated with Claude Code