feat: two-stage status messages: 获取邮件中 -> AI思考中
This commit is contained in:
@@ -23,15 +23,18 @@ def poll_accounts(cfg: Config, skip_uids: set[bytes] | None = None) -> Generator
|
||||
|
||||
def ai_process(cfg: Config, acct_idx: int, mail: Email) -> Optional[dict]:
|
||||
logger.info(f" 正在摘要: {mail.subject}")
|
||||
# 先发思考中消息
|
||||
thinking_msg_id = send_thinking(cfg.telegram, cfg.telegram.chat_id)
|
||||
logger.info(f" 思考中消息已发送: msg_id={thinking_msg_id}")
|
||||
# 阶段1:显示获取邮件中
|
||||
msg_id = send_thinking(cfg.telegram, cfg.telegram.chat_id, "📥 获取邮件中...")
|
||||
logger.info(f" 获取邮件中消息已发送: msg_id={msg_id}")
|
||||
|
||||
# 阶段2:AI 处理,更新为思考中
|
||||
edit_message(cfg.telegram, cfg.telegram.chat_id, msg_id, "🤖 AI思考中...")
|
||||
summary = summarize_email(cfg.ai, mail.recipient, mail.subject, mail.sender, mail.body, mail.account_email)
|
||||
summary["recipient"] = mail.recipient
|
||||
if "@" not in summary.get("sender", ""):
|
||||
summary["sender"] = mail.sender
|
||||
text = format_summary(summary, mail.account_email)
|
||||
# 阶段3:编辑为最终结果
|
||||
return {
|
||||
"text": text,
|
||||
"data": summary,
|
||||
@@ -43,7 +46,7 @@ def ai_process(cfg: Config, acct_idx: int, mail: Email) -> Optional[dict]:
|
||||
"account_email": mail.account_email,
|
||||
"uid": mail.uid,
|
||||
"folder": mail.folder,
|
||||
"thinking_msg_id": thinking_msg_id,
|
||||
"thinking_msg_id": msg_id,
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -57,10 +57,10 @@ def send_text(tg_cfg: TelegramConfig, chat_id: str, text: str,
|
||||
return result["result"]["message_id"]
|
||||
|
||||
|
||||
def send_thinking(tg_cfg: TelegramConfig, chat_id: str) -> int:
|
||||
def send_thinking(tg_cfg: TelegramConfig, chat_id: str, text: str = "💭 思考中...") -> int:
|
||||
result = _tg_req(tg_cfg, "sendMessage", {
|
||||
"chat_id": chat_id,
|
||||
"text": "💭 思考中...",
|
||||
"text": text,
|
||||
})
|
||||
return result["result"]["message_id"]
|
||||
|
||||
@@ -345,10 +345,10 @@ def _handle_callback(tg_cfg: TelegramConfig, cfg: Config, cb: dict):
|
||||
if not conv or conv.get("summary_msg_id") != msg_id:
|
||||
return
|
||||
logger.info(" 换一批 (已有 %d 条历史)", len(conv.get("all_suggestions", [])))
|
||||
# 先显示思考中
|
||||
# AI 处理中
|
||||
_tg_req(tg_cfg, "editMessageText", {
|
||||
"chat_id": chat_id, "message_id": msg_id,
|
||||
"text": "💭 思考中...", "parse_mode": None,
|
||||
"text": "🤖 AI思考中...", "parse_mode": None,
|
||||
})
|
||||
try:
|
||||
new_suggestions = generate_more_replies(
|
||||
@@ -390,10 +390,9 @@ def _handle_callback(tg_cfg: TelegramConfig, cfg: Config, cb: dict):
|
||||
logger.info(" 取消, 删除提示消息")
|
||||
|
||||
elif action == CALLBACK_PROMO_DETAIL and ctx:
|
||||
# 先显示思考中
|
||||
_tg_req(tg_cfg, "editMessageText", {
|
||||
"chat_id": chat_id, "message_id": msg_id,
|
||||
"text": "💭 思考中...", "parse_mode": None,
|
||||
"text": "🤖 AI思考中...", "parse_mode": None,
|
||||
})
|
||||
try:
|
||||
details = expand_promo_detail(
|
||||
|
||||
Reference in New Issue
Block a user