feat: promotional emails summarized as who promotes what

This commit is contained in:
2026-07-08 16:13:54 +08:00
parent ea6358019d
commit 9991e4ef17
2 changed files with 25 additions and 3 deletions

View File

@@ -25,11 +25,12 @@ def send_summary(tg_cfg: TelegramConfig, chat_id: str, summary_text: str,
original_sender: str = "", original_recipient: str = "",
original_reply_to: str = "", account_email: str = "") -> int:
can_reply = summary_data.get("can_reply", True)
is_promotion = summary_data.get("category") == "promotion"
result = _tg_req(tg_cfg, "sendMessage", {
"chat_id": chat_id,
"text": summary_text,
"parse_mode": "MarkdownV2",
"reply_markup": _summary_keyboard(can_reply),
"parse_mode": "MarkdownV2" if not is_promotion else None,
"reply_markup": _summary_keyboard(can_reply, is_promotion),
})
msg_id = result["result"]["message_id"]
_email_contexts[msg_id] = {
@@ -93,6 +94,22 @@ def poll_telegram(tg_cfg: TelegramConfig, cfg: Config, last_update_id: int) -> i
# ── Formatting ──────────────────────────────────────────
def format_summary(data: dict, account_email: str = "") -> str:
category = data.get("category", "normal")
if category == "promotion":
return _format_promotion(data, account_email)
return _format_normal(data, account_email)
def _format_promotion(data: dict, account_email: str = "") -> str:
summary = data.get("summary", "")
lines = [
f"📢 {_escape(summary)}",
f"账户: {_escape(account_email)}",
]
return "\n".join(lines)
def _format_normal(data: dict, account_email: str = "") -> str:
priority = data.get("priority", "medium")
icon = _priority_icon.get(priority, "")
lines = [
@@ -134,7 +151,9 @@ CALLBACK_HINT = "h"
CALLBACK_CANCEL = "c"
def _summary_keyboard(can_reply: bool = True) -> dict:
def _summary_keyboard(can_reply: bool = True, is_promotion: bool = False) -> dict:
if is_promotion:
return {"inline_keyboard": [[{"text": "查看原文", "callback_data": CALLBACK_VIEW_ORIG}]]}
kb = [
[
{"text": "查看原文", "callback_data": CALLBACK_VIEW_ORIG},