Skip to content

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
chigwell:mainfrom
mmaximov97:feat/media-reply-to
Open

Expose reply_to on send_file/send_album so media can be posted into forum topics#174
mmaximov97 wants to merge 2 commits into
chigwell:mainfrom
mmaximov97:feat/media-reply-to

Conversation

@mmaximov97

Copy link
Copy Markdown

Problem

Media cannot be placed inside a forum topic. send_message and reply_to_message can 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_file already accepts reply_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_history shows no reply_to on it, while a text message sent to the same topic shows reply_to: <topic id>.

Change

send_file and send_album take an optional reply_to: Optional[int] = None and forward it to Telethon. _send_album threads it through as well, so the album path behaves the same as the single-file path.

Two smaller things that come with it:

  • The docstrings state explicitly that the topic id goes in this field, since "reply to a message" does not obviously imply "post into a topic".
  • The success string echoes reply_to when 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_file in tests/test_media_album.py did not accept reply_to, so forwarding the argument broke the two existing album tests with a TypeError. The stub is widened and now asserts the field, plus new cases:

  • reply_to reaches the client for a single file and for an album
  • the success string includes it
  • omitting it leaves the previous behaviour and message unchanged
120 passed

black --check and the blocking flake8 selection 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> in get_history, and captions kept markdown link parsing, so [text](url) still renders as a hyperlink.

…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.
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.

1 participant