Expose reply_to on send_file/send_album so media can be posted into forum topics - #174
Open
mmaximov97 wants to merge 2 commits into
Open
Expose reply_to on send_file/send_album so media can be posted into forum topics#174mmaximov97 wants to merge 2 commits into
mmaximov97 wants to merge 2 commits into
Conversation
…um topics Telethon's send_file already accepts reply_to, but the MCP wrapper never passed it through. As a result media could only ever land in a forum supergroup's General topic — Telegram addresses topics through the reply/thread field, so without it there is no way to target a topic. Optional and defaults to None, so behavior without the argument is unchanged. Docstrings say explicitly that the topic id goes here, and the success string echoes reply_to to make mis-targeting visible.
The dummy client's send_file did not accept reply_to, so forwarding the argument broke the two existing album tests with a TypeError. Widened the stub and asserted the new field explicitly, plus cases for a single file, an album, and the unchanged no-reply_to message.
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.
Problem
Media cannot be placed inside a forum topic.
send_messageandreply_to_messagecan target a topic, but every media tool sends to the chat as a whole, so photos and documents always land in General no matter which topic was intended.The cause is not Telegram or Telethon —
TelegramClient.send_filealready acceptsreply_to, and Telegram addresses forum topics through the reply/thread field. The wrapper simply never passed the argument through, so there was no way to reach a topic from an MCP client.Reproducing it before the change: create a topic, note its id, send a photo — the photo appears in General, and
get_historyshows noreply_toon it, while a text message sent to the same topic showsreply_to: <topic id>.Change
send_fileandsend_albumtake an optionalreply_to: Optional[int] = Noneand forward it to Telethon._send_albumthreads it through as well, so the album path behaves the same as the single-file path.Two smaller things that come with it:
reply_towhen it is set, so a mis-targeted send is visible in the tool result instead of silently going to General.The parameter defaults to
None, and with it omitted the call and the returned message are byte-for-byte what they were before.Tests
_DummyClient.send_fileintests/test_media_album.pydid not acceptreply_to, so forwarding the argument broke the two existing album tests with aTypeError. The stub is widened and now asserts the field, plus new cases:reply_toreaches the client for a single file and for an albumblack --checkand the blockingflake8selection from CI both pass on the touched files.Verified against a live forum
Sent 20 photos with captions into a real topic. Every message came back with
reply_to: <topic id>inget_history, and captions kept markdown link parsing, so[text](url)still renders as a hyperlink.