feat(telegram): Bot API 10.1 rich messages (opt-in)#44829
Conversation
Introduce opportunistic support for Telegram Bot API 10.1 rich messages by sending raw agent Markdown via sendRichMessage and streaming previews via sendRichMessageDraft. Implements a rich-path fast‑path in gateway/platforms/telegram.py (RICH_MESSAGE_MAX_BYTES=32768, feature gate platforms.telegram.extra.rich_messages, bot capability checks, routing/thread handling, and conservative fallback rules: permanent/capability errors fall back to the legacy MarkdownV2 path, transient/network errors are surfaced without legacy-resend). Also add a latch for draft capability failures (_rich_draft_disabled) and preserve legacy chunking and draft behavior when needed. Update agent prompt hints (telegram encourages rich Markdown/tables), add CLI config example option, update English and Chinese docs to describe rich messages and fallbacks, and add/adjust tests for rich send and draft behavior.
…default - Use reply_parameters per the sendRichMessage spec instead of the undocumented reply_to_message_id scalar (silently ignored -> reply anchor quietly dropped). - Latch rich sends off after an endpoint-capability failure (old PTB / server without sendRichMessage) so every later reply doesn't pay a doomed extra roundtrip; per-message BadRequests do NOT latch. - Default rich_messages to OFF (opt-in) while the day-old Bot API 10.1 endpoint is validated live; revert the prompt-hint table guidance until the default flips on. - Tests: reply_parameters shape, send-latch behavior, BadRequest non-latch; rich tests opt in explicitly via extra.
🔎 Lint report:
|
| Rule | Count |
|---|---|
unresolved-import |
2 |
unresolved-attribute |
1 |
First entries
gateway/platforms/telegram.py:1168: [unresolved-attribute] unresolved-attribute: Attribute `do_api_request` is not defined on `None` in union `Unknown | None`
tests/gateway/test_telegram_rich_messages.py:16: [unresolved-import] unresolved-import: Cannot resolve imported module `pytest`
tests/gateway/test_telegram_rich_messages.py:21: [unresolved-import] unresolved-import: Cannot resolve imported module `telegram.error`
✅ Fixed issues: none
Unchanged: 5697 pre-existing issues carried over.
Diagnostics are surfaced as warnings — this check never fails the build.
|
Nice salvage — the three follow-ups address most of what came up in my verification pass on #44780 (details there: live-spec check of the endpoint shapes, negative control, routing-mirror audit). One bug from that review carried over, plus three small notes: Pool timeouts are still non-retryable on the rich path. Legacy "Telegram exposes no rich-edit method" is no longer true. 10.1 added a
Body nit: consider adding We've been running the #44780 variant on our fork since this morning; happy to flip our copy to this opt-in version once it lands. |
|
There are more changes and fixes that have been committed to the original branch that need to be picked up. |
Summary
Telegram replies can now render native tables, task lists, headings, math, and collapsible details via Bot API 10.1 Rich Messages (
sendRichMessage/sendRichMessageDraft) — shipped opt-in (default off) while the day-old endpoint is validated live.Salvages #44780 by @ITheEqualizer (cherry-picked, authorship preserved) onto current main, plus three follow-up fixes.
Changes
gateway/platforms/telegram.py: rich fast-path insend()/send_draft()via rawBot.do_api_request(PTB 22.6 has no typed method), conservative permanent-vs-transient fallback classifier, routing parity with the legacy path (contributor's work).reply_parametersper thesendRichMessagespec instead of the undocumentedreply_to_message_idscalar (unknown params are silently ignored → reply anchor would quietly drop).rich_messagesdefaults tofalse; prompt hint left unchanged (still steers away from tables) until the default flips on. Docs/example config updated to match.test_telegram_rich_messages.py.Enabling
Validation
Endpoint shape verified against the live core.telegram.org/bots/api spec (
InputRichMessage{markdown},reply_parameters, draft = private-chat-only). Live bot validation pending — that's the gate for flipping the default on in a follow-up.Closes #44780.
Infographic