fix: send immediate greeting for each inbound message
This commit is contained in:
@@ -256,15 +256,6 @@ class SystemOrchestrator:
|
||||
sanitized.append(normalized)
|
||||
return sanitized
|
||||
|
||||
@staticmethod
|
||||
def _ensure_first_reply_presence(text: str) -> str:
|
||||
cleaned = str(text or "").strip()
|
||||
if not cleaned:
|
||||
return "在呢"
|
||||
if cleaned.startswith(("在呢", "在哈", "在的", "在哦", "在")):
|
||||
return cleaned
|
||||
return f"在呢,{cleaned}"
|
||||
|
||||
@staticmethod
|
||||
def _extract_designer_name(transfer_cmd: str) -> str:
|
||||
text = str(transfer_cmd or "").strip()
|
||||
@@ -424,7 +415,22 @@ class SystemOrchestrator:
|
||||
if std_msg.msg_id in self._processed_msg_ids: return
|
||||
self._processed_msg_ids.append(std_msg.msg_id)
|
||||
|
||||
# 进入防抖(使用 session_key 隔离不同店铺)
|
||||
# 每次收到客户新消息:先立即回一条固定承接,不经过 AI
|
||||
first_greet = StandardResponse(
|
||||
reply_content="在的 亲",
|
||||
metadata={"acc_id": std_msg.acc_id, "acc_type": std_msg.acc_type},
|
||||
)
|
||||
await self.qianniu_adapter.translate_outbound(first_greet, user_id)
|
||||
await repo.save_chat(
|
||||
platform,
|
||||
user_id,
|
||||
first_greet.reply_content,
|
||||
"out",
|
||||
acc_id=std_msg.acc_id,
|
||||
msg_type=first_greet.msg_type,
|
||||
)
|
||||
|
||||
# 进入防抖(使用 session_key 隔离不同店铺)
|
||||
if session_key in self._debounce_tasks: self._debounce_tasks[session_key].cancel()
|
||||
if session_key not in self._pending_messages: self._pending_messages[session_key] = []
|
||||
self._pending_messages[session_key].append(std_msg)
|
||||
@@ -634,19 +640,12 @@ class SystemOrchestrator:
|
||||
total_elapsed = time.time() - process_start
|
||||
logger.info(f"[计时] user={user_id} AI思考: {ai_elapsed:.1f}s | 总耗时: {total_elapsed:.1f}s")
|
||||
|
||||
is_new_customer_first_turn = len(ai_history) == 0
|
||||
|
||||
# F. 发送并记录时间
|
||||
if std_res.should_reply:
|
||||
std_res.reply_content = self._sanitize_outbound_text(std_res.reply_content)
|
||||
meta = dict(std_res.metadata or {})
|
||||
meta.update({"acc_id": acc_id, "acc_type": acc_type})
|
||||
if is_new_customer_first_turn and "[转移会话]" in std_res.reply_content:
|
||||
if not str(meta.get("transfer_prelude") or "").strip():
|
||||
meta["transfer_prelude"] = "在呢,我叫设计师看下哈"
|
||||
std_res.metadata = meta
|
||||
if is_new_customer_first_turn and "[转移会话]" not in std_res.reply_content and int(std_res.msg_type or 0) == 0:
|
||||
std_res.reply_content = self._ensure_first_reply_presence(std_res.reply_content)
|
||||
|
||||
# 转接场景:先发一句安抚话,再发转接指令
|
||||
if "[转移会话]" in std_res.reply_content:
|
||||
|
||||
Reference in New Issue
Block a user