feat: add copy_text button for verification codes

This commit is contained in:
2026-07-11 21:47:54 +08:00
parent 070c32071a
commit b835812f38

View File

@@ -24,11 +24,12 @@ def send_summary(tg_cfg: TelegramConfig, chat_id: str, summary_text: str,
can_reply = summary_data.get("can_reply", True) can_reply = summary_data.get("can_reply", True)
is_promotion = summary_data.get("category") == "promotion" is_promotion = summary_data.get("category") == "promotion"
links = summary_data.get("links", []) links = summary_data.get("links", [])
verification_code = summary_data.get("verification_code", "")
result = _tg_req(tg_cfg, "sendMessage", { result = _tg_req(tg_cfg, "sendMessage", {
"chat_id": chat_id, "chat_id": chat_id,
"text": summary_text, "text": summary_text,
"parse_mode": "MarkdownV2", "parse_mode": "MarkdownV2",
"reply_markup": _summary_keyboard(can_reply, is_promotion, links), "reply_markup": _summary_keyboard(can_reply, is_promotion, links, verification_code),
}) })
msg_id = result["result"]["message_id"] msg_id = result["result"]["message_id"]
_email_contexts[msg_id] = { _email_contexts[msg_id] = {
@@ -153,7 +154,8 @@ CALLBACK_HINT = "h"
CALLBACK_CANCEL = "c" CALLBACK_CANCEL = "c"
def _summary_keyboard(can_reply: bool = True, is_promotion: bool = False, links: list = None) -> dict: def _summary_keyboard(can_reply: bool = True, is_promotion: bool = False,
links: list = None, verification_code: str = "") -> dict:
if is_promotion: if is_promotion:
return {"inline_keyboard": [[{"text": "查看原文", "callback_data": CALLBACK_VIEW_ORIG}]]} return {"inline_keyboard": [[{"text": "查看原文", "callback_data": CALLBACK_VIEW_ORIG}]]}
kb = [ kb = [
@@ -169,6 +171,9 @@ def _summary_keyboard(can_reply: bool = True, is_promotion: bool = False, links:
text = link.get("text", "打开链接")[:30] text = link.get("text", "打开链接")[:30]
if url.startswith("http"): if url.startswith("http"):
kb.append([{"text": f"🔗 {text}", "url": url}]) kb.append([{"text": f"🔗 {text}", "url": url}])
if verification_code:
code = verification_code.split(" ", 1)[-1] if " " in verification_code else verification_code
kb.append([{"text": f"📋 复制验证码 {code}", "type": "copy_text", "text": code}])
return {"inline_keyboard": kb} return {"inline_keyboard": kb}