fix(notify): switch Telegram parse_mode from Markdown to HTML

Underscores in alert text (dark_green, FIRE_BUY) broke Telegram's
legacy Markdown parser, causing ok:false → retries exhausted → failed.
HTML parse_mode is more robust and doesn't treat _ as italic.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Claude Agent
2026-04-16 23:01:28 +00:00
parent 840c23f74c
commit 51e98ae3d3
2 changed files with 5 additions and 4 deletions

View File

@@ -1,5 +1,6 @@
from __future__ import annotations
import html as _html
from pathlib import Path
from typing import Any
@@ -22,7 +23,7 @@ class TelegramNotifier:
return _BASE.format(token=self._token, method=method)
def send(self, alert: Alert) -> None:
text = f"*{alert.title}*\n{alert.body}"
text = f"<b>{_html.escape(alert.title)}</b>\n{_html.escape(alert.body)}"
if alert.image_path and Path(alert.image_path).exists():
with open(alert.image_path, "rb") as fh:
@@ -31,7 +32,7 @@ class TelegramNotifier:
data={
"chat_id": self._chat_id,
"caption": text,
"parse_mode": "Markdown",
"parse_mode": "HTML",
},
files={"photo": fh},
timeout=10,
@@ -42,7 +43,7 @@ class TelegramNotifier:
json={
"chat_id": self._chat_id,
"text": text,
"parse_mode": "Markdown",
"parse_mode": "HTML",
},
timeout=10,
)

View File

@@ -228,7 +228,7 @@ def test_telegram_send_ok() -> None:
n = TelegramNotifier("token", "chat123", session=session)
n.send(_alert("Hi"))
assert len(session.calls) == 1
assert "*Hi*" in session.calls[0]["json"]["text"]
assert "<b>Hi</b>" in session.calls[0]["json"]["text"]
def test_telegram_429_raises() -> None: