fix: send_model_picker fails in Telegram General topic (Message thread not found)#21542
Closed
echo-mydevbot wants to merge 1 commit into
Closed
Conversation
send_model_picker() in TelegramAdapter was bypassing the _message_thread_id_for_send() helper that correctly returns None for the General topic thread_id '1'. Instead, it converted thread_id directly with int(thread_id) if thread_id else None, passing message_thread_id=1 to the Telegram Bot API. The Telegram API rejects message_thread_id=1 with 'Message thread not found' because the General topic in supergroups doesn't use the message_thread_id parameter. This caused /model in General chats to fail, falling back to a plain text response instead of the interactive inline keyboard picker. Every other inline keyboard method (send_exec_approval, send_slash_confirm) and all regular message sends correctly use _metadata_thread_id() + _message_thread_id_for_send(). send_model_picker was the only outlier. Fix: Use the same two-step pattern: 1. Extract thread_id via _metadata_thread_id(metadata) 2. Filter via _message_thread_id_for_send(thread_id) — returns None for '1' 3. Only include message_thread_id in kwargs when it's not None Added regression tests for: - General topic (thread_id '1') → message_thread_id omitted - Real topic (thread_id '42') → message_thread_id=42 passed - No metadata → message_thread_id omitted
Collaborator
Collaborator
|
Thanks for catching this — the General-topic mapping ( The parallel code path in the Closing as superseded — thanks for the contribution and for keeping us focused on this bug class! |
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.
Bug
/modelcommand in Telegram supergroup General topic returns a plain text fallback instead of the interactive inline keyboard picker. Gateway logs show:Root Cause
send_model_picker()ingateway/platforms/telegram.pywas bypassing_message_thread_id_for_send(), the class method that correctly returnsNonefor the General topic thread_id"1". Instead, it did:Telegram's Bot API rejects
message_thread_id=1because the General topic doesn't use that parameter — it should be omitted entirely.Every other inline keyboard method (
send_exec_approval,send_slash_confirm, regularsend()) correctly uses the two-step pattern:_metadata_thread_id(metadata)→_message_thread_id_for_send(thread_id).send_model_pickerwas the only method that didn't.Fix
Use the same helper methods as all other methods:
Tests
Added
tests/gateway/test_telegram_model_picker_thread.pywith 3 tests:thread_id="1") →message_thread_idomitted (the bug case)thread_id="42") →message_thread_id=42passedmessage_thread_idnot includedAll 3 new tests + all 11 existing
test_telegram_thread_fallbacktests pass.Verification
Tested in production on a Telegram supergroup where
/modelpreviously returned text fallback. After the fix, the interactive model picker renders correctly in the General topic.