fix: remove null parse_mode from tg payload, add error logging
This commit is contained in:
@@ -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"):
|
||||
|
||||
Reference in New Issue
Block a user