From 43994d2b0d648848f2da26f86979ca85042b714f Mon Sep 17 00:00:00 2001 From: Zichao Lin Date: Sat, 11 Jul 2026 21:22:20 +0800 Subject: [PATCH] fix: remove null parse_mode from tg payload, add error logging --- src/tg_bot.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/tg_bot.py b/src/tg_bot.py index 7ed4f51..6286f96 100644 --- a/src/tg_bot.py +++ b/src/tg_bot.py @@ -26,12 +26,14 @@ def send_summary(tg_cfg: TelegramConfig, chat_id: str, summary_text: str, is_verification = summary_data.get("category") == "notification" and summary_data.get("verification_code") plain_text = is_promotion or is_verification links = summary_data.get("links", []) - result = _tg_req(tg_cfg, "sendMessage", { + msg_payload = { "chat_id": chat_id, "text": summary_text, - "parse_mode": "MarkdownV2" if not plain_text else None, "reply_markup": _summary_keyboard(can_reply, is_promotion, links), - }) + } + if not plain_text: + msg_payload["parse_mode"] = "MarkdownV2" + result = _tg_req(tg_cfg, "sendMessage", msg_payload) msg_id = result["result"]["message_id"] _email_contexts[msg_id] = { "summary_text": summary_text, @@ -207,7 +209,10 @@ def _ai_reply_keyboard(msg_id: int, suggestions: list) -> dict: def _tg_req(tg_cfg: TelegramConfig, method: str, payload: dict) -> dict: url = f"https://api.telegram.org/bot{tg_cfg.bot_token}/{method}" + logger.info("Telegram API %s: %s", method, {k: (v if k != "reply_markup" else "...") for k, v in payload.items()}) r = requests.post(url, json=payload, timeout=30) + if not r.ok: + logger.error("Telegram API %s 失败: %s %s", method, r.status_code, r.text[:500]) r.raise_for_status() result = r.json() if not result.get("ok"):