Fix Telegram link preview suppression for bot sends

This commit is contained in:
Kovyrin Family Claw
2026-04-13 11:53:12 -04:00
committed by Teknium
parent 192ef00bb2
commit 00ff9a26cd
4 changed files with 43 additions and 2 deletions

View File

@@ -284,6 +284,22 @@ class TestLoadGatewayConfig:
assert config.unauthorized_dm_behavior == "ignore"
assert config.platforms[Platform.WHATSAPP].extra["unauthorized_dm_behavior"] == "pair"
def test_bridges_telegram_disable_link_previews_from_config_yaml(self, tmp_path, monkeypatch):
hermes_home = tmp_path / ".hermes"
hermes_home.mkdir()
config_path = hermes_home / "config.yaml"
config_path.write_text(
"telegram:\n"
" disable_link_previews: true\n",
encoding="utf-8",
)
monkeypatch.setenv("HERMES_HOME", str(hermes_home))
config = load_gateway_config()
assert config.platforms[Platform.TELEGRAM].extra["disable_link_previews"] is True
class TestHomeChannelEnvOverrides:
"""Home channel env vars should apply even when the platform was already

View File

@@ -577,7 +577,7 @@ class TestSendToPlatformChunking:
sent_calls = []
async def fake_send(token, chat_id, message, media_files=None, thread_id=None):
async def fake_send(token, chat_id, message, media_files=None, thread_id=None, disable_link_previews=False):
sent_calls.append(media_files or [])
return {"success": True, "platform": "telegram", "chat_id": chat_id, "message_id": str(len(sent_calls))}
@@ -756,6 +756,17 @@ class TestSendTelegramHtmlDetection:
kwargs = bot.send_message.await_args.kwargs
assert kwargs["parse_mode"] == "MarkdownV2"
def test_disable_link_previews_sets_disable_web_page_preview(self, monkeypatch):
bot = self._make_bot()
_install_telegram_mock(monkeypatch, bot)
asyncio.run(
_send_telegram("tok", "123", "https://example.com", disable_link_previews=True)
)
kwargs = bot.send_message.await_args.kwargs
assert kwargs["disable_web_page_preview"] is True
def test_html_with_code_and_pre_tags(self, monkeypatch):
bot = self._make_bot()
_install_telegram_mock(monkeypatch, bot)