diff --git a/src/tg_bot.py b/src/tg_bot.py index d76ab53..5732a8e 100644 --- a/src/tg_bot.py +++ b/src/tg_bot.py @@ -356,11 +356,23 @@ def _handle_callback(tg_cfg: TelegramConfig, cfg: Config, cb: dict): logger.info(" 进入回复流程, prompt_msg_id=%d", prompt_msg_id) elif action in (CALLBACK_AI_REPLY_FULL, CALLBACK_AI_REPLY_SHORT) and ctx: - suggestions = ctx["summary_data"].get("reply_suggestions", []) style = "full" if action == CALLBACK_AI_REPLY_FULL else "short" + suggestions = ctx["summary_data"].get("reply_suggestions", []) + + # 缓存为空时重新生成 if not suggestions: - send_text(tg_cfg, str(chat_id), "此邮件无需回复。") - logger.info(" AI 判定无需回复,隐藏") + logger.info(" 缓存为空,重新生成 AI 回复 (style=%s)", style) + _tg_req(tg_cfg, "editMessageText", { + "chat_id": chat_id, "message_id": msg_id, + "text": "🤖 *AI思考中…*", "parse_mode": "MarkdownV2", + }) + conv = load_conversation(chat_id) or {} + conv["state"] = "ai_reply_selection" + conv["summary_msg_id"] = msg_id + conv["reply_style"] = style + conv["all_suggestions"] = [] + save_conversation(chat_id, conv) + _ai_pool.submit(_do_regen, cfg, chat_id, msg_id, ctx, conv) return save_conversation(chat_id, { @@ -433,7 +445,10 @@ def _handle_callback(tg_cfg: TelegramConfig, cfg: Config, cb: dict): elif action == CALLBACK_CANCEL: delete_conversation(chat_id) + # 清除回复建议缓存,重新选择时会重新生成 if ctx: + ctx["summary_data"]["reply_suggestions"] = [] + save_email_context(msg_id, ctx) can_reply = ctx.get("can_reply", True) _tg_req(tg_cfg, "editMessageText", { "chat_id": chat_id, "message_id": msg_id,