fix: handle MessageReplyStoryHeader without reply_to_msg_id attribute#128
Merged
chigwell merged 1 commit intoMay 21, 2026
Merged
Conversation
Telethon's Message.reply_to can be either MessageReplyHeader (replies to
regular messages) or MessageReplyStoryHeader (replies to stories). Only
the former has a reply_to_msg_id attribute; the latter has story_id and
peer instead.
Before this fix, get_history() and list_messages() crashed with
AttributeError as soon as the requested range contained a reply-to-story
message:
File "telegram_mcp/tools/messages.py", line 1080, in get_history
if msg.reply_to and msg.reply_to.reply_to_msg_id:
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'MessageReplyStoryHeader' object has no attribute
'reply_to_msg_id'
This made any sufficiently large history fetch unreliable for users
whose chats contain story-reply messages.
Use getattr() to safely probe for the attribute on whichever
reply-header class is attached. The behavior for ordinary
MessageReplyHeader is unchanged.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
chigwell
approved these changes
May 21, 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
Message.reply_toin Telethon can be eitherMessageReplyHeader(when themessage replies to another regular message) or
MessageReplyStoryHeader(when it replies to a story). Only the former carries
reply_to_msg_id;the latter has
story_id+peerinstead.Before this fix,
get_history()andlist_messages()crashed withAttributeErroras soon as the requested range contained areply-to-story message:
This made any sufficiently large history fetch unreliable for users whose
chats include story-reply messages — symptom is
GEN-ERR-971in MCP logs.Fix
Use
getattr(msg.reply_to, "reply_to_msg_id", None)to safely probe forthe attribute on whichever reply-header class is attached. Behavior for
ordinary
MessageReplyHeaderis unchanged.Test plan
get_history(chat_id, limit=200)on a chat containing a reply-to-story message
reply_tofield in theoutput (verified on a chat with both reply types)