feat: add tell me more button for promotion emails with AI-generated details
This commit is contained in:
@@ -3,7 +3,7 @@ import logging
|
||||
from email.utils import parseaddr
|
||||
import requests
|
||||
from src.config import TelegramConfig, Config
|
||||
from src.ai_client import generate_more_replies
|
||||
from src.ai_client import generate_more_replies, expand_promo_detail
|
||||
from src.smtp_client import send_reply
|
||||
from src.retry import retry
|
||||
|
||||
@@ -154,11 +154,15 @@ CALLBACK_SELECT_REPLY = "sr"
|
||||
CALLBACK_REGEN = "rg"
|
||||
CALLBACK_HINT = "h"
|
||||
CALLBACK_CANCEL = "c"
|
||||
CALLBACK_PROMO_DETAIL = "pd"
|
||||
|
||||
|
||||
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}]]}
|
||||
return {"inline_keyboard": [
|
||||
[{"text": "告诉我更多", "callback_data": CALLBACK_PROMO_DETAIL}],
|
||||
[{"text": "查看原文", "callback_data": CALLBACK_VIEW_ORIG}],
|
||||
]}
|
||||
kb = [
|
||||
[
|
||||
{"text": "查看原文", "callback_data": CALLBACK_VIEW_ORIG},
|
||||
@@ -360,6 +364,33 @@ def _handle_callback(tg_cfg: TelegramConfig, cfg: Config, cb: dict):
|
||||
delete_message(tg_cfg, str(chat_id), msg_id)
|
||||
logger.info(" 取消, 删除提示消息")
|
||||
|
||||
elif action == CALLBACK_PROMO_DETAIL and ctx:
|
||||
try:
|
||||
details = expand_promo_detail(
|
||||
cfg.ai, ctx["sender"], ctx["subject"], ctx["original_body"],
|
||||
)
|
||||
except Exception as e:
|
||||
send_text(tg_cfg, str(chat_id), f"获取详情失败: {e}")
|
||||
return
|
||||
summary = ctx["summary_data"].get("summary", "")
|
||||
detail_lines = "\n".join(f"\\- {_escape(d)}" for d in details) if details else "暂无更多详情"
|
||||
expanded = (
|
||||
f"📢 *推广*\n"
|
||||
f"━━━━━━━━━━━━━━━━━━\n"
|
||||
f"*收件账户:* {_escape(ctx.get('account_email', ''))}\n"
|
||||
f"\n{_escape(summary)}\n"
|
||||
f"\n*📋 详情:*\n{detail_lines}"
|
||||
)
|
||||
_tg_req(tg_cfg, "editMessageText", {
|
||||
"chat_id": chat_id, "message_id": msg_id,
|
||||
"text": expanded, "parse_mode": "MarkdownV2",
|
||||
"reply_markup": {"inline_keyboard": [
|
||||
[{"text": "收起", "callback_data": CALLBACK_VIEW_SUMM}],
|
||||
[{"text": "查看原文", "callback_data": CALLBACK_VIEW_ORIG}],
|
||||
]},
|
||||
})
|
||||
logger.info(" 显示推广详情")
|
||||
|
||||
|
||||
def _handle_message(tg_cfg: TelegramConfig, cfg: Config, msg: dict):
|
||||
chat_id = msg["chat"]["id"]
|
||||
|
||||
Reference in New Issue
Block a user