Skip to content

fix(gateway): pass message_thread_id in send_image_file, send_document, send_video#1809

Closed
unmodeled-tyler wants to merge 1 commit into
NousResearch:mainfrom
unmodeled-tyler:fix/telegram-media-thread-id
Closed

fix(gateway): pass message_thread_id in send_image_file, send_document, send_video#1809
unmodeled-tyler wants to merge 1 commit into
NousResearch:mainfrom
unmodeled-tyler:fix/telegram-media-thread-id

Conversation

@unmodeled-tyler

@unmodeled-tyler unmodeled-tyler commented Mar 17, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #1803 — media files (images, documents, videos) sent via MEDIA: tags failed in Telegram forum groups/supergroups with Topics enabled.

  • send_image_file, send_document, and send_video were not forwarding message_thread_id to the Telegram Bot API
  • send_voice already handled this correctly via an explicit metadata parameter
  • In Telegram forum groups, message_thread_id is required to post to a topic; omitting it causes the API call to fail

Changes:

  • Added metadata: Optional[Dict[str, Any]] = None parameter to all three methods
  • Extract thread_id from metadata and pass it as message_thread_id (matching the pattern in send_voice)
  • Added tests for the thread_id forwarding path in TestSendDocument, TestSendVideo, and TestTelegramSendImageFile

Test plan

  • Run pytest tests/gateway/test_telegram_documents.py tests/gateway/test_send_image_file.py -v — all 54 tests pass
  • Manually send a file via MEDIA: tag in a Telegram forum group with Topics — file should arrive in the correct topic thread
  • Verify existing behavior unchanged in regular chats (no thread_id in metadata → message_thread_id=None → no-op)

Platform tested: Linux

…t, send_video

Fixes NousResearch#1803. send_image_file, send_document, and send_video were missing
message_thread_id forwarding, causing them to fail in Telegram forum/supergroups
where thread_id is required. send_voice already handled this correctly. Adds
metadata parameter + message_thread_id to all three methods, and adds tests
covering the thread_id forwarding path.
@unmodeled-tyler

Copy link
Copy Markdown
Contributor Author

The CI failures are pre-existing and unrelated to this PR:

  • _saved_tool_names NameError in test_delegate.py / test_cli_interrupt_subagent.py / test_real_interrupt_subagent.py: these tests pass in isolation but fail under pytest-xdist parallel execution — a pre-existing flakiness issue on main.
  • test_whatsapp_reply_prefix.py: this file doesn't exist in this branch at all; it was added to upstream main after our branch diverged.

This PR only touches gateway/platforms/telegram.py and two test files in tests/gateway/. All 54 relevant tests pass.

@teknium1

Copy link
Copy Markdown
Contributor

Merged via PR #2339 — cherry-picked with authorship preserved. Clean fix matching the existing send_voice pattern. Thanks!

@teknium1 teknium1 closed this Mar 21, 2026
@unmodeled-tyler unmodeled-tyler deleted the fix/telegram-media-thread-id branch March 21, 2026 20:19
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.

MEDIA: tag fails to send files - document upload not working

2 participants