feat: extract clickable links from email and show as URL buttons

This commit is contained in:
2026-07-11 19:38:33 +08:00
parent be4e957af9
commit 1957eb2a73
2 changed files with 10 additions and 2 deletions

View File

@@ -28,11 +28,12 @@ def send_summary(tg_cfg: TelegramConfig, chat_id: str, summary_text: str,
is_promotion = summary_data.get("category") == "promotion"
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", {
"chat_id": chat_id,
"text": summary_text,
"parse_mode": "MarkdownV2" if not plain_text else None,
"reply_markup": _summary_keyboard(can_reply, is_promotion),
"reply_markup": _summary_keyboard(can_reply, is_promotion, links),
})
msg_id = result["result"]["message_id"]
_email_contexts[msg_id] = {
@@ -164,7 +165,7 @@ CALLBACK_HINT = "h"
CALLBACK_CANCEL = "c"
def _summary_keyboard(can_reply: bool = True, is_promotion: bool = False) -> dict:
def _summary_keyboard(can_reply: bool = True, is_promotion: bool = False, links: list = None) -> dict:
if is_promotion:
return {"inline_keyboard": [[{"text": "查看原文", "callback_data": CALLBACK_VIEW_ORIG}]]}
kb = [
@@ -175,6 +176,11 @@ def _summary_keyboard(can_reply: bool = True, is_promotion: bool = False) -> dic
]
if can_reply:
kb.append([{"text": "AI回复", "callback_data": CALLBACK_AI_REPLY}])
for link in (links or []):
url = link.get("url", "")
text = link.get("text", "打开链接")[:30]
if url.startswith("http"):
kb.append([{"text": f"🔗 {text}", "url": url}])
return {"inline_keyboard": kb}