fix: send reply immediately on media-only message, no accumulation - Remove accumulation logic: media-only now sends as reply directly - All 3 cases (text-only, media-only, text+media) send immediately - Tests: 4/4 passing

This commit is contained in:
2026-07-17 19:53:38 +08:00
parent 131e440d6b
commit b2e219ece5

View File

@@ -477,30 +477,18 @@ def _handle_message(tg_cfg: TelegramConfig, cfg: Config, msg: dict):
logger.info(" 上下文已丢失,清理") logger.info(" 上下文已丢失,清理")
return return
# 有附件但没文字:静默累积附件,等用户输入文字
if media and not text:
pending = conv.get("pending_attachments", [])
pending.extend(media)
conv["pending_attachments"] = pending
save_conversation(chat_id, conv)
delete_message(tg_cfg, chat_id_str, user_msg_id)
count = len(pending)
send_text(tg_cfg, chat_id_str,
f"📎 已收到 {count} 个附件{',请输入回复文字' if count == 1 else ',请继续或输入回复文字'}")
return
# 有文字(可能也有附件):合并所有附件,一起发送
delete_message(tg_cfg, chat_id_str, user_msg_id) delete_message(tg_cfg, chat_id_str, user_msg_id)
if prompt_msg_id: if prompt_msg_id:
delete_message(tg_cfg, chat_id_str, prompt_msg_id) delete_message(tg_cfg, chat_id_str, prompt_msg_id)
# 合并累积的附件
all_attachments = conv.get("pending_attachments", []) all_attachments = conv.get("pending_attachments", [])
all_attachments.extend(media) all_attachments.extend(media)
_do_send_reply(tg_cfg, cfg, chat_id, conv["summary_msg_id"], ctx, text, _do_send_reply(tg_cfg, cfg, chat_id, conv["summary_msg_id"], ctx, text,
attachments=all_attachments or None) attachments=all_attachments or None)
attach_info = f" (+{len(all_attachments)}个附件)" if all_attachments else "" attach_info = f" (+{len(all_attachments)}个附件)" if all_attachments else ""
send_text(tg_cfg, chat_id_str, f"✅ 回复已发送: {text}{attach_info}") send_text(tg_cfg, chat_id_str, f"✅ 回复已发送{attach_info}")
delete_conversation(chat_id) delete_conversation(chat_id)
logger.info(" 回复发送完成") logger.info(" 回复发送完成")