fix: make Telegram rich messages opt in

maintainer edit: Telegram Web cannot render sendRichMessage payloads, so keep the rich path available only for explicit opt-in instead of enabling it by default.
This commit is contained in:
chengyongru
2026-06-25 16:10:33 +08:00
committed by Xubin Ren
parent c930aa3713
commit e92899607a
2 changed files with 7 additions and 8 deletions
+2 -3
View File
@@ -351,9 +351,8 @@ class TelegramConfig(Base):
streaming: bool = True
# Enable inline keyboard buttons in Telegram messages.
inline_keyboards: bool = False
# Use Bot API 10.1 sendRichMessage for markdown rendering.
# Disable if Telegram Web shows "message not supported" errors.
rich_messages: bool = True
# Opt in to Bot API 10.1 sendRichMessage for richer markdown rendering.
rich_messages: bool = False
stream_edit_interval: float = Field(default=_STREAM_EDIT_INTERVAL_DEFAULT, ge=0.1)
webhook_url: str = ""
webhook_listen_host: str = "127.0.0.1"
+5 -5
View File
@@ -471,7 +471,7 @@ async def test_send_rich_capability_error_latches_and_falls_back() -> None:
from telegram.error import BadRequest
channel = TelegramChannel(
TelegramConfig(enabled=True, token="123:abc", allow_from=["*"]),
TelegramConfig(enabled=True, token="123:abc", allow_from=["*"], rich_messages=True),
MessageBus(),
)
channel._app = _FakeApp(lambda: None)
@@ -490,7 +490,7 @@ async def test_send_rich_bad_request_does_not_latch_capability() -> None:
from telegram.error import BadRequest
channel = TelegramChannel(
TelegramConfig(enabled=True, token="123:abc", allow_from=["*"]),
TelegramConfig(enabled=True, token="123:abc", allow_from=["*"], rich_messages=True),
MessageBus(),
)
channel._app = _FakeApp(lambda: None)
@@ -506,10 +506,10 @@ async def test_send_rich_bad_request_does_not_latch_capability() -> None:
@pytest.mark.asyncio
async def test_rich_messages_config_disabled_skips_sendRichMessage() -> None:
"""When rich_messages=False, sendRichMessage should not be called."""
async def test_rich_messages_default_skips_send_rich_message() -> None:
"""By default, sendRichMessage should not be called."""
channel = TelegramChannel(
TelegramConfig(enabled=True, token="123:abc", allow_from=["*"], rich_messages=False),
TelegramConfig(enabled=True, token="123:abc", allow_from=["*"]),
MessageBus(),
)
channel._app = _FakeApp(lambda: None)