智能体按 reply_code 读后台回复语;陆运整车报价单顶栏色与填表更稳,工单页展示同步收紧。
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -118,7 +118,7 @@ async def _accept_upload_files(
|
||||
return HTMLResponse(expired_upload_page(), status_code=410)
|
||||
if phase in {"reject_type", "need_file"}:
|
||||
return HTMLResponse(render_upload_message("无法上传", hint), status_code=400)
|
||||
return HTMLResponse(render_upload_message("上传成功", copy.ATTACH_H5_OK))
|
||||
return HTMLResponse(render_upload_message("上传成功", copy.attach_h5_ok()))
|
||||
|
||||
|
||||
@router.get("/upload/{token}", response_class=HTMLResponse)
|
||||
|
||||
@@ -319,4 +319,4 @@ def render_upload_message(title: str, body: str, *, expired: bool = False) -> st
|
||||
|
||||
|
||||
def expired_upload_page() -> str:
|
||||
return render_upload_message("链接已过期", copy.ATTACH_H5_EXPIRED, expired=True)
|
||||
return render_upload_message("链接已过期", copy.attach_h5_expired(), expired=True)
|
||||
|
||||
@@ -207,7 +207,7 @@ def join_attachment_image(
|
||||
if not wave.ack_sent:
|
||||
msg_store.enqueue_outbound(
|
||||
touser=message.sender_id,
|
||||
content=copy.IMAGE_RECOGNIZING,
|
||||
content=copy.image_recognizing(),
|
||||
dedupe_key=f"attach-ack:{wave.wave_id}",
|
||||
)
|
||||
book.mark_ack(message.sender_id, "image")
|
||||
@@ -258,7 +258,7 @@ def accept_h5_uploads(
|
||||
book = get_attach_wave_book()
|
||||
wave = book.active(sid, now=stamp)
|
||||
if wave is None:
|
||||
return "expired", copy.ATTACH_H5_EXPIRED
|
||||
return "expired", copy.attach_h5_expired()
|
||||
incoming = [(str(n or "").strip(), raw or b"") for n, raw in files if str(n or "").strip()]
|
||||
if not incoming:
|
||||
return "need_file", copy.ATTACH_H5_NEED_FILE
|
||||
@@ -268,12 +268,12 @@ def accept_h5_uploads(
|
||||
start_index = len(wave.materials)
|
||||
wave = book.add_files(sid, [n for n, _r in incoming], now=stamp)
|
||||
if wave is None:
|
||||
return "expired", copy.ATTACH_H5_EXPIRED
|
||||
return "expired", copy.attach_h5_expired()
|
||||
msg_store = store or get_message_store()
|
||||
if not wave.ack_sent:
|
||||
msg_store.enqueue_outbound(
|
||||
touser=sid,
|
||||
content=copy.ATTACH_RECOGNIZING,
|
||||
content=copy.attach_recognizing(),
|
||||
dedupe_key=f"attach-ack:{wave.wave_id}",
|
||||
)
|
||||
book.mark_ack(sid, "file")
|
||||
@@ -304,8 +304,8 @@ def accept_h5_uploads(
|
||||
wave = book.active(sid, now=stamp)
|
||||
if process_now and wave is not None and book.pending(wave) <= 0:
|
||||
finish_attach_wave(sid, store=msg_store)
|
||||
return "done", copy.ATTACH_H5_OK
|
||||
return "recognizing", copy.ATTACH_H5_OK
|
||||
return "done", copy.attach_h5_ok()
|
||||
return "recognizing", copy.attach_h5_ok()
|
||||
|
||||
|
||||
def finish_queued_attachment(payload: dict[str, Any]) -> dict[str, Any]:
|
||||
@@ -403,7 +403,7 @@ def finish_attach_wave(
|
||||
oral = book.compose_oral(sender_id)
|
||||
reason = ""
|
||||
if not oral.strip():
|
||||
reason = copy.ATTACH_TECH_FAIL if book.has_errors(sender_id) else copy.ATTACH_UNREADABLE
|
||||
reason = copy.attach_tech_fail() if book.has_errors(sender_id) else copy.ATTACH_UNREADABLE
|
||||
|
||||
msg_store = store or get_message_store()
|
||||
prefix_used = {"v": False}
|
||||
@@ -441,7 +441,7 @@ def finish_attach_wave(
|
||||
if reason and not prefix_used["v"]:
|
||||
msg_store.enqueue_outbound(
|
||||
touser=sender_id,
|
||||
content=copy.image_fail_then_clarify(reason, copy.ASK_TRANSPORT),
|
||||
content=copy.image_fail_then_clarify(reason, copy.ask_transport()),
|
||||
dedupe_key=f"attach-empty:{(wave.wave_id if wave else inbound.message_id)}",
|
||||
)
|
||||
phase = "need_mode"
|
||||
|
||||
@@ -79,7 +79,7 @@ def handle_image_inquiry(
|
||||
drop_all_private_bookmarks(message.sender_id)
|
||||
msg_store.enqueue_outbound(
|
||||
touser=message.sender_id,
|
||||
content=copy.IMAGE_RECOGNIZING,
|
||||
content=copy.image_recognizing(),
|
||||
dedupe_key=f"img-ack:{wave.wave_id}",
|
||||
)
|
||||
book.mark_ack(message.sender_id)
|
||||
@@ -341,7 +341,7 @@ def finish_wave(
|
||||
oral = book.compose_oral(sender_id)
|
||||
reason = ""
|
||||
if not oral.strip():
|
||||
reason = copy.IMAGE_TECH_FAIL if (wave and wave.errors) else copy.IMAGE_UNREADABLE
|
||||
reason = copy.image_tech_fail() if (wave and wave.errors) else copy.IMAGE_UNREADABLE
|
||||
|
||||
msg_store = store or get_message_store()
|
||||
prefix_used = {"v": False}
|
||||
@@ -373,7 +373,7 @@ def finish_wave(
|
||||
if reason and not prefix_used["v"]:
|
||||
msg_store.enqueue_outbound(
|
||||
touser=sender_id,
|
||||
content=copy.image_fail_then_clarify(reason, copy.ASK_TRANSPORT),
|
||||
content=copy.image_fail_then_clarify(reason, copy.ask_transport()),
|
||||
dedupe_key=f"img-empty:{inbound.message_id}",
|
||||
)
|
||||
phase = "need_mode"
|
||||
|
||||
@@ -478,18 +478,7 @@ def handle_text_other(message: InboundMessage, *, store=None) -> str:
|
||||
logger.info("text_other 陆运确定/重查,改走询价流程 sender=%s", message.sender_id)
|
||||
return handle_text_inquiry(message, store=msg_store)
|
||||
|
||||
from agent.schema.land_options import looks_like_confirm
|
||||
|
||||
if looks_like_confirm(message.content or ""):
|
||||
body = copy.LAND_CONFIRM_EXPIRED
|
||||
msg_store.enqueue_outbound(
|
||||
touser=message.sender_id,
|
||||
content=body,
|
||||
dedupe_key=f"land-confirm-expired:{message.message_id}",
|
||||
)
|
||||
return "land_confirm_expired"
|
||||
|
||||
body = copy.FIRST_CHAT
|
||||
body = copy.first_chat()
|
||||
msg_store.enqueue_outbound(
|
||||
touser=message.sender_id,
|
||||
content=body,
|
||||
|
||||
@@ -103,6 +103,15 @@ class LedgerApiShell:
|
||||
params={"enabledOnly": str(bool(enabled_only)).lower()},
|
||||
)
|
||||
|
||||
def list_bot_replies(self) -> LedgerResponse:
|
||||
"""
|
||||
已启用机器人回复语。
|
||||
|
||||
正式路径:GET /inquiry/agent/botReply/listEnabled
|
||||
只读;停用项不在列表里。
|
||||
"""
|
||||
return self.client.request_json("GET", "/inquiry/agent/botReply/listEnabled")
|
||||
|
||||
def wake_agent_ack(
|
||||
self,
|
||||
*,
|
||||
|
||||
@@ -484,7 +484,7 @@ def _send_air_activate_sheet(
|
||||
return
|
||||
err = str(painted.get("error") or "")
|
||||
if err == "NO_TEMPLATE":
|
||||
send_group_text(client, chat_id, painted.get("message") or copy.QUOTE_TEMPLATE_MISSING)
|
||||
send_group_text(client, chat_id, painted.get("message") or copy.quote_template_missing())
|
||||
return
|
||||
if err in {"no_renderer_or_chat", "no_file_client"}:
|
||||
send_group_text(client, chat_id, copy.group_sheet_send_fail())
|
||||
|
||||
@@ -418,21 +418,21 @@ class AirTextInquiryFlow:
|
||||
hit.business_line = str(view.get("business_line") or "").strip().upper()
|
||||
if hit is None:
|
||||
if not callable(getter):
|
||||
reply(f"找不到工单 {no},请核对工单号后再试。")
|
||||
reply(copy.continue_ticket_not_found(no))
|
||||
return "ticket_missing"
|
||||
if not view.get("found"):
|
||||
reply(f"找不到工单 {no},请核对工单号后再试。")
|
||||
reply(copy.continue_ticket_not_found(no))
|
||||
return "ticket_missing"
|
||||
line = str(view.get("business_line") or "").strip().upper()
|
||||
owner = self._handoff_owner_for_line(line)
|
||||
if owner is None:
|
||||
reply(copy.ASK_TRANSPORT)
|
||||
reply(copy.ask_transport())
|
||||
return "need_mode"
|
||||
hit = owner._session_from_ledger(sender_id=sender_id, view=view)
|
||||
line = (hit.business_line or "").strip().upper()
|
||||
owner = self._handoff_owner_for_line(line)
|
||||
if owner is None:
|
||||
reply(copy.ASK_TRANSPORT)
|
||||
reply(copy.ask_transport())
|
||||
return "need_mode"
|
||||
logger.info(
|
||||
"handoff.named wo=%s line=%s phase=%s chat=%s",
|
||||
@@ -474,7 +474,7 @@ class AirTextInquiryFlow:
|
||||
mode = (sess.business_line if sess else "") or detect_transport_mode(text) or ""
|
||||
mode = (mode or "").upper()
|
||||
if not mode:
|
||||
reply(copy.ASK_TRANSPORT)
|
||||
reply(copy.ask_transport())
|
||||
self._save(
|
||||
FlowSession(
|
||||
sender_id=sender_id,
|
||||
@@ -538,7 +538,7 @@ class AirTextInquiryFlow:
|
||||
sess.business_line = "SEA"
|
||||
line = (sess.business_line or "").upper()
|
||||
if has_collab_group(sess):
|
||||
reply(copy.HANDOFF_ALREADY_COLLAB)
|
||||
reply(copy.already_collab())
|
||||
return "handoff_already"
|
||||
why = copy.HANDOFF_CLARIFY_REASON if reason == "clarify" else copy.HANDOFF_INTENT_REASON
|
||||
if line == "AIR":
|
||||
@@ -711,7 +711,7 @@ class AirTextInquiryFlow:
|
||||
"""
|
||||
no = (work_order_no or "").strip().upper()
|
||||
if not no:
|
||||
reply("请告诉我要继续的工单号,例如 WO202609140034。")
|
||||
reply(copy.continue_need_wo())
|
||||
return "need_work_order"
|
||||
with self._lock:
|
||||
sess = self._by_ticket.get(no)
|
||||
@@ -730,11 +730,11 @@ class AirTextInquiryFlow:
|
||||
return self._replay_wait(keep, reply, source="session")
|
||||
getter = getattr(self._ledger, "get_for_agent", None)
|
||||
if not callable(getter):
|
||||
reply(f"找不到工单 {no},请核对工单号后再试。")
|
||||
reply(copy.continue_ticket_not_found(no))
|
||||
return "ticket_missing"
|
||||
view = getter(work_order_no=no, sender_id=sender_id) or {}
|
||||
if not view.get("found"):
|
||||
reply(f"找不到工单 {no},请核对工单号后再试。")
|
||||
reply(copy.continue_ticket_not_found(no))
|
||||
return "ticket_missing"
|
||||
if view.get("owned") is False:
|
||||
reply("这张工单不属于当前账号,不能继续。")
|
||||
@@ -879,7 +879,7 @@ class AirTextInquiryFlow:
|
||||
if sess.phase == "wait_file":
|
||||
self._refresh_wait_file(sess)
|
||||
if sess.phase == "wait_file":
|
||||
reply("报价单正在生成,请稍候。")
|
||||
reply(copy.quote_generating())
|
||||
return "wait_file"
|
||||
if sess.phase == "wait_deal":
|
||||
# 成交卡已经绑在报价文件那条出站上。只续办、没说成交结果时不再另发一张卡。
|
||||
@@ -964,9 +964,8 @@ class AirTextInquiryFlow:
|
||||
reply=reply,
|
||||
sess=sess,
|
||||
)
|
||||
if (not sess or sess.phase != "wait_confirm") and looks_like_confirm(text) and not sess:
|
||||
reply(copy.AIR_CONFIRM_EXPIRED)
|
||||
return "confirm_expired"
|
||||
# 核对卡不再设时效。没有待确定会话时不当成「已过期」,
|
||||
# 让本句按新询价走,避免正文里的「确认」误伤。
|
||||
sess = self._detach_ticketed_for_new_inquiry(sess)
|
||||
|
||||
snap = extract_inquiry_snapshot(
|
||||
@@ -1006,7 +1005,7 @@ class AirTextInquiryFlow:
|
||||
)
|
||||
|
||||
if not mode:
|
||||
reply(copy.ASK_TRANSPORT)
|
||||
reply(copy.ask_transport())
|
||||
self._save(
|
||||
FlowSession(
|
||||
sender_id=sender_id,
|
||||
@@ -1055,7 +1054,7 @@ class AirTextInquiryFlow:
|
||||
chat_fn=chat_fn,
|
||||
inbound_raw=inbound_raw,
|
||||
)
|
||||
reply(copy.ASK_TRANSPORT)
|
||||
reply(copy.ask_transport())
|
||||
return "need_mode"
|
||||
|
||||
if is_waiting_mode_session(sess):
|
||||
|
||||
@@ -0,0 +1,156 @@
|
||||
"""
|
||||
后台机器人回复语:按 reply_code 取正文。
|
||||
|
||||
本文件职责:短缓存主账已启用列表,把 {{ticket_no}} 等变量填进模板。
|
||||
禁止:当六态;禁止回调线程同步等完整 LLM;失败必须回退 inquiry_copy 默认句。
|
||||
线程:进程内锁刷新;不同工单可读同一份缓存。
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
import os
|
||||
import re
|
||||
import threading
|
||||
import time
|
||||
from typing import Any, Optional
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
# 后台改文案后最多这么久出现在销售侧;不当 checkpoint。
|
||||
_TTL_SECONDS = 60.0
|
||||
_PLACEHOLDER = re.compile(r"\{\{\s*([a-zA-Z0-9_]+)\s*\}\}")
|
||||
|
||||
_lock = threading.Lock()
|
||||
_loaded_at = 0.0
|
||||
_by_code: dict[str, str] = {}
|
||||
# 单测注入;None 表示走主账/空缓存。
|
||||
_override: Optional[dict[str, str]] = None
|
||||
|
||||
|
||||
def override_catalog(mapping: Optional[dict[str, str]]) -> None:
|
||||
"""
|
||||
单测注入调用编码 → 正文。传 None 清掉注入。
|
||||
|
||||
副作用:清空加载时间,下次 render 重新取。不打主账。
|
||||
"""
|
||||
global _override, _loaded_at, _by_code
|
||||
with _lock:
|
||||
_override = dict(mapping) if mapping is not None else None
|
||||
_loaded_at = 0.0
|
||||
if mapping is None:
|
||||
_by_code = {}
|
||||
|
||||
|
||||
def fill(template: str, values: dict[str, Any] | None = None) -> str:
|
||||
"""把 {{ticket_no}} 换成实值;未提供的占位原样保留。"""
|
||||
src = dict(values or {})
|
||||
|
||||
def _repl(match: re.Match[str]) -> str:
|
||||
key = match.group(1)
|
||||
if key not in src:
|
||||
return match.group(0)
|
||||
raw = src.get(key)
|
||||
if raw is None:
|
||||
return ""
|
||||
return str(raw)
|
||||
|
||||
return _PLACEHOLDER.sub(_repl, template or "")
|
||||
|
||||
|
||||
def render(code: str, default: str, **kwargs: Any) -> str:
|
||||
"""
|
||||
取已启用回复语并填变量。
|
||||
|
||||
停用、库空、主账失败、编码对不上:返回 default(已是拼好的默认句)。
|
||||
副作用:缓存过期时 GET 主账;超时/失败吞掉,不抛给销售。
|
||||
"""
|
||||
key = (code or "").strip()
|
||||
fallback = default if default is not None else ""
|
||||
if not key:
|
||||
return fallback
|
||||
tpl = _lookup(key)
|
||||
if not (tpl or "").strip():
|
||||
return fallback
|
||||
return fill(tpl, kwargs)
|
||||
|
||||
|
||||
def _lookup(code: str) -> str:
|
||||
"""读缓存;过期再拉主账。override 优先。"""
|
||||
global _loaded_at, _by_code
|
||||
with _lock:
|
||||
if _override is not None:
|
||||
return str(_override.get(code) or "")
|
||||
now = time.monotonic()
|
||||
if _loaded_at > 0 and (now - _loaded_at) < _TTL_SECONDS:
|
||||
return str(_by_code.get(code) or "")
|
||||
fresh = _fetch()
|
||||
with _lock:
|
||||
if _override is not None:
|
||||
return str(_override.get(code) or "")
|
||||
if fresh is not None:
|
||||
_by_code = fresh
|
||||
_loaded_at = time.monotonic()
|
||||
elif not _by_code:
|
||||
_loaded_at = time.monotonic()
|
||||
return str(_by_code.get(code) or "")
|
||||
|
||||
|
||||
def _fetch() -> Optional[dict[str, str]]:
|
||||
"""
|
||||
GET /inquiry/agent/botReply/listEnabled。
|
||||
|
||||
未配主账地址视为空,返回 {{}} 以免每次空打。失败返回 None 以保留旧缓存。
|
||||
"""
|
||||
try:
|
||||
from agent.config import get_settings
|
||||
|
||||
cfg = get_settings()
|
||||
backend = str(
|
||||
os.environ.get("LEDGER_BACKEND") or getattr(cfg, "ledger_backend", "") or ""
|
||||
).strip().lower()
|
||||
if backend in {"memory", "mem", "stub"}:
|
||||
return {}
|
||||
if not str(getattr(cfg, "biz_api_base_url", "") or "").strip():
|
||||
return {}
|
||||
from agent.ledger import LedgerClient
|
||||
from agent.ledger.api_shell import LedgerApiShell
|
||||
|
||||
client = LedgerClient.from_settings()
|
||||
client.timeout_seconds = min(float(client.timeout_seconds or 10), 3.0)
|
||||
resp = LedgerApiShell(client=client).list_bot_replies()
|
||||
if not resp.ok:
|
||||
logger.warning("bot_reply listEnabled fail status=%s err=%s", resp.status_code, resp.error)
|
||||
return None
|
||||
rows = _unwrap_rows(resp.data)
|
||||
out: dict[str, str] = {}
|
||||
for row in rows:
|
||||
if not isinstance(row, dict):
|
||||
continue
|
||||
code = str(row.get("replyCode") or row.get("reply_code") or "").strip()
|
||||
text = str(row.get("replyText") or row.get("reply_text") or "")
|
||||
if code and text.strip():
|
||||
out[code] = text
|
||||
return out
|
||||
except Exception:
|
||||
logger.warning("bot_reply listEnabled 异常,回退默认句", exc_info=True)
|
||||
return None
|
||||
|
||||
|
||||
def _unwrap_rows(data: Any) -> list[Any]:
|
||||
"""解开 Jeecg Result 列表。"""
|
||||
if isinstance(data, list):
|
||||
return data
|
||||
if not isinstance(data, dict):
|
||||
return []
|
||||
inner = data.get("result")
|
||||
if isinstance(inner, list):
|
||||
return inner
|
||||
if isinstance(inner, dict):
|
||||
rec = inner.get("records")
|
||||
if isinstance(rec, list):
|
||||
return rec
|
||||
rec = data.get("records") or data.get("data")
|
||||
if isinstance(rec, list):
|
||||
return rec
|
||||
return []
|
||||
@@ -2,7 +2,8 @@
|
||||
空运文字询价出站话术(销售可见)。
|
||||
|
||||
本文件职责:集中文案;按钮字面量必须与 handler 精确匹配。
|
||||
禁止:在本文件调主账/TMS;禁止把密钥写进话术。
|
||||
销售可见固定句经 bot_reply 按调用编码读后台;停用/失败回退本文件默认句。
|
||||
禁止:在本文件直接 request 主账;禁止把密钥写进话术。
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
@@ -27,6 +28,17 @@ from agent.schema.field_validate import (
|
||||
from agent.schema.land_options import option_prompt as _land_option_prompt
|
||||
from agent.schema.quote_adjust import total_price_label
|
||||
|
||||
def _r(code: str, default: str, **kwargs: Any) -> str:
|
||||
"""
|
||||
按后台调用编码取回复语。
|
||||
|
||||
停用、库空、主账失败返回 default。本函数不打主账,只调 bot_reply 短缓存。
|
||||
"""
|
||||
from agent.policy.bot_reply import render
|
||||
|
||||
return render(code, default, **kwargs)
|
||||
|
||||
|
||||
# 空运补问:必填 7 项 + 非必填。报价日期默认当天,不进待补充。
|
||||
_AIR_EXAMPLES = {
|
||||
"起运港": "南京",
|
||||
@@ -50,9 +62,11 @@ _AIR_OPTIONAL_CLARIFY = tuple(
|
||||
(key, label, _AIR_EXAMPLES.get(key, "")) for key, label in AIR_OPTIONAL_FIELDS
|
||||
)
|
||||
AIR_CONFIRM_TAIL = "请回复“确定”进行TMS查价,内容有误时,请重新发内容。"
|
||||
# 核对卡已取消时效,不再对销售发送此句;常量仅保留避免旧引用报错。
|
||||
AIR_CONFIRM_EXPIRED = "刚才的空运核对已过期,请把空运需求再发一次,出核对卡后再回复确定。"
|
||||
# 海运私聊与空运同一句。核对卡没有工单号,回复确定后才建单查价。
|
||||
SEA_CONFIRM_TAIL = "请回复“确定”进行TMS查价,内容有误时,请重新发内容。"
|
||||
# 核对卡已取消时效,不再对销售发送此句。
|
||||
SEA_CONFIRM_EXPIRED = "刚才的海运核对已过期,请把海运需求再发一次,出核对卡后再回复确定。"
|
||||
|
||||
# 海运补问:与合同 10 项一致。报价日期默认当天,不进待补充。
|
||||
@@ -125,10 +139,79 @@ ASK_TRANSPORT = (
|
||||
"2.海运\n"
|
||||
"3.空运"
|
||||
)
|
||||
|
||||
|
||||
def ask_transport() -> str:
|
||||
"""未识别运输方式。后台 inquiring.ask_transport。"""
|
||||
return _r("inquiring.ask_transport", ASK_TRANSPORT)
|
||||
|
||||
|
||||
def first_chat() -> str:
|
||||
"""销售首次单聊。后台 inquiring.first_chat。"""
|
||||
return _r("inquiring.first_chat", FIRST_CHAT)
|
||||
|
||||
|
||||
def image_recognizing() -> str:
|
||||
"""正在识别图片。后台 inquiring.image_recognizing。"""
|
||||
return _r("inquiring.image_recognizing", IMAGE_RECOGNIZING)
|
||||
|
||||
|
||||
def image_tech_fail() -> str:
|
||||
"""图片技术失败。后台 inquiring.image_tech_fail。"""
|
||||
return _r("inquiring.image_tech_fail", IMAGE_TECH_FAIL)
|
||||
|
||||
|
||||
def attach_recognizing() -> str:
|
||||
"""正在识别附件。后台 inquiring.attach_recognizing。"""
|
||||
return _r("inquiring.attach_recognizing", ATTACH_RECOGNIZING)
|
||||
|
||||
|
||||
def attach_tech_fail() -> str:
|
||||
"""附件技术失败。后台 inquiring.attach_tech_fail。"""
|
||||
return _r("inquiring.attach_tech_fail", ATTACH_TECH_FAIL)
|
||||
|
||||
|
||||
def attach_h5_expired() -> str:
|
||||
"""H5 上传过期。后台 inquiring.attach_h5_expired。"""
|
||||
return _r("inquiring.attach_h5_expired", ATTACH_H5_EXPIRED)
|
||||
|
||||
|
||||
def attach_h5_ok() -> str:
|
||||
"""H5 上传成功。后台 inquiring.attach_h5_ok。"""
|
||||
return _r("inquiring.attach_h5_ok", ATTACH_H5_OK)
|
||||
|
||||
|
||||
def continue_need_wo() -> str:
|
||||
"""续办但未提供工单号。后台 inquiring.continue_need_wo。"""
|
||||
return _r("inquiring.continue_need_wo", "请告诉我要继续的工单号,例如 WO202609140034。")
|
||||
|
||||
|
||||
def continue_ticket_not_found(work_order_no: str) -> str:
|
||||
"""续办找不到工单。后台 inquiring.continue_not_found(工单号后有空格)。"""
|
||||
no = (work_order_no or "").strip()
|
||||
return _r(
|
||||
"inquiring.continue_not_found",
|
||||
f"找不到工单 {no},请核对工单号后再试。",
|
||||
ticket_no=no,
|
||||
)
|
||||
|
||||
|
||||
def quote_generating() -> str:
|
||||
"""报价单生成中。后台 inquiring.quote_generating。"""
|
||||
return _r("inquiring.quote_generating", "报价单正在生成,请稍候。")
|
||||
|
||||
|
||||
# 待补充清单:请销售整段复制,只在冒号后填值;示例行不算已填。
|
||||
CLARIFY_PASTE_HINT = "请复制粘贴以下内容,通过回复数字或文字方式,告知我以下字段值:"
|
||||
_PENDING_UNITS = {}
|
||||
HANDOFF_ALREADY_COLLAB = "该工单已拉产品进群协同。"
|
||||
|
||||
|
||||
def already_collab() -> str:
|
||||
"""该工单已拉过产品进群。后台 transfer.already_collab。"""
|
||||
return _r("transfer.already_collab", HANDOFF_ALREADY_COLLAB)
|
||||
|
||||
|
||||
HANDOFF_CLARIFY_REASON = "参数提取不全(连续 3 次反问仍不完整)"
|
||||
HANDOFF_INTENT_REASON = "已识别您希望转人工处理"
|
||||
CLARIFY_LIMIT_HINT = "连续 3 次反问仍不完整将触发转人工"
|
||||
@@ -214,6 +297,7 @@ def land_sample_image_fallback() -> str:
|
||||
FIRST_CHAT = "你好,我是询价机器人。请直接描述客户需求,例如「上海到洛杉矶空运,3 件 180kg,下周三前到」,我会解析需求并查询 TMS 标准报价。"
|
||||
ROUTE_MODEL_FAILED = "刚才没听清,请再说一次:是新询价,还是要接着办哪张工单?"
|
||||
LAND_CONFIRM_TAIL = "请回复“确定”进行TMS查价,内容有误时,请重新发内容。"
|
||||
# 核对卡已取消时效。仅工单号丢失时内部兜底,不对销售当「过期」主路径。
|
||||
LAND_CONFIRM_EXPIRED = "刚才的陆运核对已过期,请把陆运需求再发一次,出核对卡后再回复确定。"
|
||||
LAND_TMS_RETRY = "工单 {wo} 上次查价没成功。回复「确定」按原需求再查一次,不用重新填。"
|
||||
LAND_TMS_RETRYING = "正在重新查询TMS报价。工单:{wo}"
|
||||
@@ -274,8 +358,11 @@ def land_confirm_card(facts: dict[str, str] | None) -> str:
|
||||
|
||||
|
||||
def land_group_no_staff() -> str:
|
||||
"""没有对上线路的陆运产品,不建空群。"""
|
||||
return "没有可拉的产品人员。请先在后台「员工管理」维护本线路的陆运产品岗后再试。"
|
||||
"""没有对上线路的陆运产品,不建空群。后台 inquiring.land_no_staff。"""
|
||||
return _r(
|
||||
"inquiring.land_no_staff",
|
||||
"没有可拉的产品人员。请先在后台「员工管理」维护本线路的陆运产品岗后再试。",
|
||||
)
|
||||
|
||||
|
||||
def land_group_pair_rejected() -> str:
|
||||
@@ -1354,8 +1441,13 @@ def skip_collab_card_update(*, response_code: str, replace_name: str = "") -> di
|
||||
|
||||
|
||||
def tms_miss_quote_text(*, work_order_no: str) -> str:
|
||||
"""文字兜底里的拉群句,与现网图一致。"""
|
||||
return f"请手动拉相关人员和智能体到原有群,并在群聊发送工单编号{work_order_no}"
|
||||
"""请手动拉人进群并发送工单号。后台 inquiring.pull_group_manual。"""
|
||||
no = (work_order_no or "").strip()
|
||||
return _r(
|
||||
"inquiring.pull_group_manual",
|
||||
f"请手动拉相关人员和智能体到原有群,并在群聊发送工单编号{no}",
|
||||
ticket_no=no,
|
||||
)
|
||||
|
||||
|
||||
def tms_miss_hint() -> str:
|
||||
@@ -1438,7 +1530,11 @@ def tms_need_more(*, work_order_no: str, hint: str = "") -> str:
|
||||
|
||||
|
||||
def skip_collab_ack() -> str:
|
||||
return "好的,已跳过内部协同。正在按 TMS 标准报价生成报价单草稿…"
|
||||
"""销售跳过内部协同。后台 inquiring.skip_collab_ack。"""
|
||||
return _r(
|
||||
"inquiring.skip_collab_ack",
|
||||
"好的,已跳过内部协同。正在按 TMS 标准报价生成报价单草稿…",
|
||||
)
|
||||
|
||||
|
||||
def sea_collab_ask() -> str:
|
||||
@@ -1584,13 +1680,13 @@ def sea_tms_miss_wecom_payload(*, work_order_no: str, action_url: str = "") -> d
|
||||
|
||||
MULTI_CONFIRM_TAIL = "请回复「确定」创建工单,内容有误时,请重新发内容。"
|
||||
MULTI_SAME_MODE = "同一运输方式出现了两段,请拆开再发。"
|
||||
# 核对卡已取消时效,不再对销售发送此句。
|
||||
MULTI_CONFIRM_EXPIRED = "刚才的多段核对已过期,请把多段需求再发一次,出核对后再回复确定。"
|
||||
|
||||
|
||||
def multi_air_manual_hint(*, work_order_no: str) -> str:
|
||||
"""含空运的多段:不自动拉群,请销售把人和智能体拉进原有群并发送工单号。"""
|
||||
no = (work_order_no or "").strip()
|
||||
return f"请手动拉相关人员和智能体到原有群,并在群聊发送工单编号{no}"
|
||||
"""含空运的多段:不自动拉群。与 inquiring.pull_group_manual 同一条后台。"""
|
||||
return tms_miss_quote_text(work_order_no=work_order_no)
|
||||
|
||||
|
||||
def multi_pull_text(*, work_order_no: str) -> str:
|
||||
@@ -1629,11 +1725,16 @@ def multi_pull_wecom_payload(*, work_order_no: str) -> dict[str, Any]:
|
||||
|
||||
|
||||
def handoff_air_hint(*, work_order_no: str) -> str:
|
||||
"""空运转人工:只发文字,不建群。"""
|
||||
"""空运转人工:只发文字,不建群。后台 transfer.air_hint。"""
|
||||
no = (work_order_no or "").strip()
|
||||
if no:
|
||||
return f"触发转人工,请手动把航线和智能体拉进原有空运群,并发送工单号 {no}。"
|
||||
return "触发转人工,请手动把航线和智能体拉进原有空运群,并发送工单号。"
|
||||
default = f"触发转人工,请手动把航线和智能体拉进原有空运群,并发送工单号 {no}。"
|
||||
return _r("transfer.air_hint", default, ticket_no=no)
|
||||
return _r(
|
||||
"transfer.air_hint",
|
||||
"触发转人工,请手动把航线和智能体拉进原有空运群,并发送工单号。",
|
||||
ticket_no="",
|
||||
)
|
||||
|
||||
|
||||
def handoff_offer_text(*, reason: str, transport_mode: str) -> str:
|
||||
@@ -1729,27 +1830,45 @@ def _role_label(name: str, role: str) -> str:
|
||||
|
||||
|
||||
def sea_group_created(*, work_order_no: str, sales_name: str, product_names: list[str]) -> str:
|
||||
"""拉群成功后的私聊。已邀请写成「销售某某、产品某某」,岗位不能省略。"""
|
||||
"""拉群成功后的私聊。后台 inquiring.group_created。已邀请写成「销售某某、产品某某」。"""
|
||||
no = (work_order_no or "").strip()
|
||||
sales = _role_label(sales_name, "销售")
|
||||
products = "、".join(
|
||||
_role_label(n, "产品") for n in (product_names or []) if (n or "").strip()
|
||||
) or "产品"
|
||||
return (
|
||||
sales_raw = (sales_name or "").strip()
|
||||
sales = _role_label(sales_raw, "销售")
|
||||
name_bits = [n.strip() for n in (product_names or []) if (n or "").strip()]
|
||||
products = "、".join(_role_label(n, "产品") for n in name_bits) or "产品"
|
||||
default = (
|
||||
f"协同群已创建,群名与工单号一致:{no}。"
|
||||
f"已邀请:{sales}、{products}。请在群聊中继续确认报价。"
|
||||
)
|
||||
sales_var = sales_raw[2:] if sales_raw.startswith("销售") else sales_raw
|
||||
prod_var = "、".join(
|
||||
(n[2:] if n.startswith("产品") else n) for n in name_bits
|
||||
) or "产品"
|
||||
return _r(
|
||||
"inquiring.group_created",
|
||||
default,
|
||||
ticket_no=no,
|
||||
sales_name=sales_var,
|
||||
product_names=prod_var,
|
||||
)
|
||||
|
||||
|
||||
def sea_group_exists(*, work_order_no: str) -> str:
|
||||
"""同一工单已有群,不再新建。"""
|
||||
"""同一工单已有群,不再新建。后台 inquiring.group_exists。"""
|
||||
no = (work_order_no or "").strip()
|
||||
return f"协同群已在,群名与工单号一致:{no}。请到该群继续确认报价。"
|
||||
return _r(
|
||||
"inquiring.group_exists",
|
||||
f"协同群已在,群名与工单号一致:{no}。请到该群继续确认报价。",
|
||||
ticket_no=no,
|
||||
)
|
||||
|
||||
|
||||
def sea_group_no_staff() -> str:
|
||||
"""没有可拉的产品人员,不建空群。"""
|
||||
return "没有可拉的产品人员。请先在后台「员工管理」维护本线路的海运产品岗后再试。"
|
||||
"""没有可拉的产品人员,不建空群。后台 inquiring.sea_no_staff。"""
|
||||
return _r(
|
||||
"inquiring.sea_no_staff",
|
||||
"没有可拉的产品人员。请先在后台「员工管理」维护本线路的海运产品岗后再试。",
|
||||
)
|
||||
|
||||
|
||||
def group_sheet_send_fail() -> str:
|
||||
@@ -1758,11 +1877,10 @@ def group_sheet_send_fail() -> str:
|
||||
|
||||
|
||||
def sea_group_create_fail(*, reason: str = "") -> str:
|
||||
"""建群失败,按钮保持可点。"""
|
||||
"""建群失败,按钮保持可点。后台 inquiring.group_create_fail(无原因短句)。"""
|
||||
extra = (reason or "").strip()
|
||||
if extra:
|
||||
return f"建群失败:{extra}。请稍后重试。"
|
||||
return "建群失败,请稍后重试。"
|
||||
default = f"建群失败:{extra}。请稍后重试。" if extra else "建群失败,请稍后重试。"
|
||||
return _r("inquiring.group_create_fail", default, reason=extra)
|
||||
|
||||
|
||||
def quote_is_product(quote: dict[str, Any] | None) -> bool:
|
||||
@@ -2212,7 +2330,11 @@ def scheme_wecom_payload(
|
||||
|
||||
|
||||
def reject_ack() -> str:
|
||||
return "请问如何调整报价单,以满足您的需求?请说明要调哪一项费用,例如「提货费加 10%」。"
|
||||
"""销售选择不采用。后台 quoted.reject_ack。"""
|
||||
return _r(
|
||||
"quoted.reject_ack",
|
||||
"请问如何调整报价单,以满足您的需求?请说明要调哪一项费用,例如「提货费加 10%」。",
|
||||
)
|
||||
|
||||
|
||||
def adjust_confirm(applied: list[dict[str, Any]]) -> str:
|
||||
@@ -2278,23 +2400,32 @@ def adjust_group_body(quote: dict[str, Any] | None, business_line: str = "") ->
|
||||
|
||||
|
||||
def adopt_excel_ack() -> str:
|
||||
return "已确认采用该方案,正在生成 Excel 最终报价单…"
|
||||
"""采用并生成 Excel。后台 quoted.adopt_excel。"""
|
||||
return _r("quoted.adopt_excel", "已确认采用该方案,正在生成 Excel 最终报价单…")
|
||||
|
||||
|
||||
def adopt_pdf_ack() -> str:
|
||||
return "已确认采用该方案,正在生成PDF最终报价单…"
|
||||
"""采用并生成 PDF。后台 quoted.adopt_pdf。"""
|
||||
return _r("quoted.adopt_pdf", "已确认采用该方案,正在生成PDF最终报价单…")
|
||||
|
||||
|
||||
QUOTE_TEMPLATE_MISSING = "生成报价单失败,请联系IT运维维护后台报价模板。"
|
||||
|
||||
|
||||
def quote_template_missing() -> str:
|
||||
"""关键词与默认模板都未维护时的销售提示(产品口径,勿改字)。"""
|
||||
return QUOTE_TEMPLATE_MISSING
|
||||
"""关键词与默认模板都未维护。后台 quoted.template_missing。"""
|
||||
return _r("quoted.template_missing", QUOTE_TEMPLATE_MISSING)
|
||||
|
||||
|
||||
def file_ready(*, kind: str, work_order_no: str, filename: str) -> str:
|
||||
return f"已生成{kind}最终报价单:{filename}(工单 {work_order_no})"
|
||||
"""最终报价单生成完成。后台 quoted.file_ready。"""
|
||||
return _r(
|
||||
"quoted.file_ready",
|
||||
f"已生成{kind}最终报价单:{filename}(工单 {work_order_no})",
|
||||
kind=kind,
|
||||
filename=filename,
|
||||
ticket_no=work_order_no,
|
||||
)
|
||||
|
||||
|
||||
# 未成交原因说明跟在未成交后,不跟在协商中后。验收脚本认这个开关。
|
||||
@@ -2429,7 +2560,11 @@ def group_only_excel_pdf() -> str:
|
||||
|
||||
|
||||
def group_only_product_can_quote() -> str:
|
||||
return "只有产品能报价格,请产品在群里发价格或 Excel/PDF"
|
||||
"""非产品人员在群里报价。后台 inquiring.group_only_product。"""
|
||||
return _r(
|
||||
"inquiring.group_only_product",
|
||||
"只有产品能报价格,请产品在群里发价格或 Excel/PDF",
|
||||
)
|
||||
|
||||
|
||||
_GROUP_QUOTE_TAIL = (
|
||||
@@ -2464,14 +2599,24 @@ def group_no_tms_quote_hint(*, business_line: str = "") -> str:
|
||||
|
||||
|
||||
def quote_attachment_saved_app(work_order_no: str, count: int = 1) -> str:
|
||||
"""群里告诉大家:模板或产品附件已进后台。"""
|
||||
"""
|
||||
群里告诉大家:模板或产品附件已进后台。
|
||||
|
||||
后台 inquiring.group_file_saved。默认句带工单号和份数;后台改成短句则原样用。
|
||||
"""
|
||||
no = (work_order_no or "").strip() or "WO"
|
||||
n = count if count > 0 else 1
|
||||
return f"工单{no}的{n}个附件已保存到后台工单"
|
||||
return _r(
|
||||
"inquiring.group_file_saved",
|
||||
f"工单{no}的{n}个附件已保存到后台工单",
|
||||
ticket_no=no,
|
||||
count=n,
|
||||
)
|
||||
|
||||
|
||||
def group_confirm_need_tms() -> str:
|
||||
return "本单还没有可沿用的 TMS 报价,请直接回复协同报价或上传报价附件。"
|
||||
def group_file_saved(*, work_order_no: str = "", count: int = 1) -> str:
|
||||
"""群附件已保存。与 quote_attachment_saved_app 同一条后台编码。"""
|
||||
return quote_attachment_saved_app(work_order_no, count)
|
||||
|
||||
|
||||
def group_ask_tms_or_product() -> str:
|
||||
@@ -2490,8 +2635,8 @@ def group_need_price_before_choice() -> str:
|
||||
return "请产品先发价格,再说在TMS基础上改或不用TMS报价"
|
||||
|
||||
|
||||
def group_file_saved() -> str:
|
||||
return "附件已保存后台"
|
||||
def group_confirm_need_tms() -> str:
|
||||
return "本单还没有可沿用的 TMS 报价,请直接回复协同报价或上传报价附件。"
|
||||
|
||||
|
||||
def group_quote_not_recognized() -> str:
|
||||
@@ -2561,18 +2706,26 @@ def deal_ack(
|
||||
next_followup_at: str = "",
|
||||
lost_reason: str = "",
|
||||
) -> str:
|
||||
"""成交三态回执。协商中写明顺延三个工作日和下次再问的月日 9:00。"""
|
||||
"""成交三态回执。后台 deal.recorded_won / lost.ask_reason / negotiating.recorded。"""
|
||||
no = (work_order_no or "").strip()
|
||||
if outcome == "已成交":
|
||||
return f"已记录为「已成交」。工单 {work_order_no} 已关闭智能体跟进。"
|
||||
return _r(
|
||||
"deal.recorded_won",
|
||||
f"已记录为「已成交」。工单 {no} 已关闭智能体跟进。",
|
||||
ticket_no=no,
|
||||
)
|
||||
if outcome == "未成交":
|
||||
reason = (lost_reason or "").strip()
|
||||
if reason:
|
||||
return f"已记录为「未成交」。{lost_reason_ack(reason)}"
|
||||
return "已记录为「未成交」。请补充未成交原因。"
|
||||
when = _followup_month_day(next_followup_at)
|
||||
if when:
|
||||
return f"已记录为「协商中」。已顺延三个工作日,{when}的9:00再次发起成交状态询问。"
|
||||
return "已记录为「协商中」。已顺延三个工作日,第四个工作日早上9:00再次发起成交状态询问。"
|
||||
return _r("lost.ask_reason", "已记录为「未成交」。请补充未成交原因。", ticket_no=no)
|
||||
when = _followup_month_day(next_followup_at) or "第四个工作日"
|
||||
return _r(
|
||||
"negotiating.recorded",
|
||||
f"已记录为「协商中」。已顺延三个工作日,{when}的9:00再次发起成交状态询问。",
|
||||
followup_when=when,
|
||||
ticket_no=no,
|
||||
)
|
||||
|
||||
|
||||
def _followup_month_day(raw: str) -> str:
|
||||
@@ -2592,11 +2745,13 @@ def _followup_month_day(raw: str) -> str:
|
||||
|
||||
|
||||
def lost_reason_ack(reason: str = "") -> str:
|
||||
"""收下未成交原因后回显原句,不再追问。"""
|
||||
"""收下未成交原因后回显原句。后台 lost.reason_ack。"""
|
||||
text = (reason or "").strip()
|
||||
if text.endswith(("。", ".", "!", "!", "?", "?")):
|
||||
return f"已记下未成交原因:{text}"
|
||||
return f"已记下未成交原因:{text}。" if text else "已记下未成交原因。"
|
||||
default = f"已记下未成交原因:{text}"
|
||||
else:
|
||||
default = f"已记下未成交原因:{text}。" if text else "已记下未成交原因。"
|
||||
return _r("lost.reason_ack", default, lost_reason=text)
|
||||
|
||||
|
||||
def deal_notify_card(
|
||||
@@ -2679,29 +2834,49 @@ def air_need_work_order() -> str:
|
||||
|
||||
|
||||
def air_lock_need_work_order() -> str:
|
||||
"""锁舱/释放必须自带工单号,不猜当前单。"""
|
||||
return "锁舱或释放舱位请带上工单号,例如 WO202609160001锁舱。"
|
||||
"""锁舱/释放必须自带工单号。后台 inquiring.air_lock_need_wo。"""
|
||||
return _r(
|
||||
"inquiring.air_lock_need_wo",
|
||||
"锁舱或释放舱位请带上工单号,例如 WO202609160001锁舱。",
|
||||
)
|
||||
|
||||
|
||||
def air_ticket_not_found(work_order_no: str) -> str:
|
||||
"""空运群找不到工单。后台 inquiring.air_ticket_not_found。"""
|
||||
no = (work_order_no or "").strip()
|
||||
return f"找不到工单{no},请核对工单号后再试。"
|
||||
return _r("inquiring.air_ticket_not_found", f"找不到工单{no},请核对工单号后再试。", ticket_no=no)
|
||||
|
||||
|
||||
def air_ticket_not_air(work_order_no: str) -> str:
|
||||
"""工单不是空运单。后台 inquiring.air_ticket_not_air。"""
|
||||
no = (work_order_no or "").strip()
|
||||
return f"工单{no}不是空运单,不能在空运群里跟。"
|
||||
return _r(
|
||||
"inquiring.air_ticket_not_air",
|
||||
f"工单{no}不是空运单,不能在空运群里跟。",
|
||||
ticket_no=no,
|
||||
)
|
||||
|
||||
|
||||
def air_ticket_closed(work_order_no: str, status: str) -> str:
|
||||
"""空运工单已是终态仍要激活。后台 closed.air_cannot_activate。"""
|
||||
no = (work_order_no or "").strip()
|
||||
st = (status or "").strip() or "已关闭"
|
||||
return f"工单{no}已是「{st}」,不能再激活。"
|
||||
return _r(
|
||||
"closed.air_cannot_activate",
|
||||
f"工单{no}已是「{st}」,不能再激活。",
|
||||
ticket_no=no,
|
||||
status=st,
|
||||
)
|
||||
|
||||
|
||||
def air_ticket_occupied(work_order_no: str) -> str:
|
||||
"""空运工单已在另一个群。后台 inquiring.air_ticket_occupied。"""
|
||||
no = (work_order_no or "").strip()
|
||||
return f"工单{no}已经在另一个群跟了,请到那个群继续。"
|
||||
return _r(
|
||||
"inquiring.air_ticket_occupied",
|
||||
f"工单{no}已经在另一个群跟了,请到那个群继续。",
|
||||
ticket_no=no,
|
||||
)
|
||||
|
||||
|
||||
def air_group_brief(
|
||||
@@ -2820,7 +2995,11 @@ def air_airline_only_quote() -> str:
|
||||
|
||||
|
||||
def air_airline_only_cabin() -> str:
|
||||
return "只有岗位为「航线·空运」的人能锁舱或释放舱位。"
|
||||
"""只有航线能锁舱或释放。后台 inquiring.air_airline_only_cabin。"""
|
||||
return _r(
|
||||
"inquiring.air_airline_only_cabin",
|
||||
"只有岗位为「航线·空运」的人能锁舱或释放舱位。",
|
||||
)
|
||||
|
||||
|
||||
def air_sales_only_deal() -> str:
|
||||
@@ -2844,9 +3023,13 @@ def air_no_tms_quote_to_lock(work_order_no: str) -> str:
|
||||
|
||||
|
||||
def air_lock_need_quote(work_order_no: str) -> str:
|
||||
"""没有任何报价时的锁舱拒绝。不提 TMS,避免把人工报价说成没报价。"""
|
||||
"""没有任何报价时的锁舱拒绝。后台 inquiring.air_lock_need_quote。"""
|
||||
no = (work_order_no or "").strip()
|
||||
return f"工单{no}还没有报价,不能锁舱。"
|
||||
return _r(
|
||||
"inquiring.air_lock_need_quote",
|
||||
f"工单{no}还没有报价,不能锁舱。",
|
||||
ticket_no=no,
|
||||
)
|
||||
|
||||
|
||||
def air_ask_lock_option(options: list) -> str:
|
||||
@@ -2869,23 +3052,41 @@ def air_lock_ok(
|
||||
exec_no: str,
|
||||
quote_no: str,
|
||||
) -> str:
|
||||
return (
|
||||
"""空运锁舱成功。后台 inquiring.air_lock_ok。"""
|
||||
default = (
|
||||
f"工单{work_order_no} 已通知TMS执行空运锁舱,执行成功。\n"
|
||||
f"操作人:{operator}\n"
|
||||
f"舱位选项:{option_no}\n"
|
||||
f"执行编号:{exec_no}\n"
|
||||
f"报价编号:{quote_no}"
|
||||
)
|
||||
return _r(
|
||||
"inquiring.air_lock_ok",
|
||||
default,
|
||||
ticket_no=work_order_no,
|
||||
operator=operator,
|
||||
option_no=option_no,
|
||||
exec_no=exec_no,
|
||||
quote_no=quote_no,
|
||||
)
|
||||
|
||||
|
||||
def air_lock_fail(*, work_order_no: str, operator: str, reason: str) -> str:
|
||||
"""空运锁舱失败。后台 inquiring.air_lock_fail。"""
|
||||
why = (reason or "").strip() or "TMS未返回原因"
|
||||
return (
|
||||
default = (
|
||||
f"工单{work_order_no} 空运锁舱失败。\n"
|
||||
f"操作人:{operator}\n"
|
||||
f"锁舱失败的原因:{why}\n"
|
||||
"已通知IT运维排查,请稍等。"
|
||||
)
|
||||
return _r(
|
||||
"inquiring.air_lock_fail",
|
||||
default,
|
||||
ticket_no=work_order_no,
|
||||
operator=operator,
|
||||
reason=why,
|
||||
)
|
||||
|
||||
|
||||
def air_cabin_fail_reason(*, tms_reason: str = "", flight_date: str = "", today: str = "") -> str:
|
||||
@@ -2907,33 +3108,61 @@ def air_release_ok(
|
||||
exec_no: str,
|
||||
quote_no: str,
|
||||
) -> str:
|
||||
return (
|
||||
"""空运释放成功。后台 inquiring.air_release_ok。"""
|
||||
default = (
|
||||
f"工单{work_order_no} 已通知TMS执行空运释放舱位成功\n"
|
||||
f"操作人:{operator}\n"
|
||||
f"舱位选项:{option_no}\n"
|
||||
f"执行编号:{exec_no}\n"
|
||||
f"报价编号:{quote_no}"
|
||||
)
|
||||
return _r(
|
||||
"inquiring.air_release_ok",
|
||||
default,
|
||||
ticket_no=work_order_no,
|
||||
operator=operator,
|
||||
option_no=option_no,
|
||||
exec_no=exec_no,
|
||||
quote_no=quote_no,
|
||||
)
|
||||
|
||||
|
||||
def air_release_fail(*, work_order_no: str, operator: str, reason: str) -> str:
|
||||
"""空运释放失败。后台 inquiring.air_release_fail。"""
|
||||
why = (reason or "").strip() or "TMS未返回原因"
|
||||
return (
|
||||
default = (
|
||||
f"工单{work_order_no} 空运释放舱位失败。\n"
|
||||
f"操作人:{operator}\n"
|
||||
f"释放舱位失败的原因:{why}\n"
|
||||
"已通知IT运维排查,请稍等。"
|
||||
)
|
||||
return _r(
|
||||
"inquiring.air_release_fail",
|
||||
default,
|
||||
ticket_no=work_order_no,
|
||||
operator=operator,
|
||||
reason=why,
|
||||
)
|
||||
|
||||
|
||||
def air_release_deal_blocked(work_order_no: str) -> str:
|
||||
"""已成交不能释放舱位。后台 inquiring.air_release_deal_blocked。"""
|
||||
no = (work_order_no or "").strip()
|
||||
return f"释放舱位失败,工单{no}已成交。"
|
||||
return _r(
|
||||
"inquiring.air_release_deal_blocked",
|
||||
f"释放舱位失败,工单{no}已成交。",
|
||||
ticket_no=no,
|
||||
)
|
||||
|
||||
|
||||
def air_release_need_lock(work_order_no: str) -> str:
|
||||
"""没有有效锁舱不能释放。后台 inquiring.air_release_need_lock。"""
|
||||
no = (work_order_no or "").strip()
|
||||
return f"工单{no}还没有有效锁舱,不能释放。"
|
||||
return _r(
|
||||
"inquiring.air_release_need_lock",
|
||||
f"工单{no}还没有有效锁舱,不能释放。",
|
||||
ticket_no=no,
|
||||
)
|
||||
|
||||
|
||||
# —— 系统异常(UC024):销售/群兜底与恢复;告警卡只给有权限的人 ——
|
||||
@@ -2966,29 +3195,34 @@ IMPACT_GROUP = "当前建群/加人暂停,已建群不新建第二个群"
|
||||
|
||||
|
||||
def system_exception_fallback(exception_type: str, *, names: list[str] | None = None) -> str:
|
||||
"""判定系统异常后,给卡住的会话的兜底话术。"""
|
||||
"""判定系统异常后,给卡住的会话的兜底话术。后台 sys.llm_fail / sys.tms_fail / sys.group_add_fail。"""
|
||||
kind = (exception_type or "").strip()
|
||||
if kind == TYPE_LLM:
|
||||
return SYS_EXC_LLM_FALLBACK
|
||||
return _r("sys.llm_fail", SYS_EXC_LLM_FALLBACK)
|
||||
if kind == TYPE_GROUP:
|
||||
people = [str(x).strip() for x in (names or []) if str(x).strip()]
|
||||
if not people:
|
||||
return "无法添加同事,请联系管理员检查企业微信配置。"
|
||||
joined = "、".join(people)
|
||||
return f"无法添加 {joined} 同事,请联系管理员检查企业微信配置。"
|
||||
return SYS_EXC_TMS_FALLBACK
|
||||
if joined:
|
||||
default = f"无法添加 {joined} 同事,请联系管理员检查企业微信配置。"
|
||||
else:
|
||||
default = "无法添加同事,请联系管理员检查企业微信配置。"
|
||||
text = _r("sys.group_add_fail", default, staff_name=joined)
|
||||
if not joined:
|
||||
text = re.sub(r"无法添加\s+同事", "无法添加同事", text)
|
||||
return text
|
||||
return _r("sys.tms_fail", SYS_EXC_TMS_FALLBACK)
|
||||
|
||||
|
||||
def system_exception_recovery(step: str) -> str:
|
||||
"""后台点重试成功后,先发这一句,再补没做完的事。"""
|
||||
key = (step or "").strip()
|
||||
if key == STEP_LLM or key == STEP_LLM_NO_TICKET:
|
||||
return SYS_EXC_RECOVERY_LLM
|
||||
return _r("sys.llm_recovery", SYS_EXC_RECOVERY_LLM)
|
||||
if key in {STEP_TMS_CABIN, STEP_TMS_LOCK, STEP_TMS_RELEASE}:
|
||||
return SYS_EXC_RECOVERY_CABIN
|
||||
return _r("sys.cabin_recovery", SYS_EXC_RECOVERY_CABIN)
|
||||
if key == STEP_GROUP:
|
||||
return SYS_EXC_RECOVERY_GROUP
|
||||
return SYS_EXC_RECOVERY_TMS
|
||||
return _r("sys.group_recovery", SYS_EXC_RECOVERY_GROUP)
|
||||
return _r("sys.tms_recovery", SYS_EXC_RECOVERY_TMS)
|
||||
|
||||
|
||||
def system_exception_impact(step: str) -> str:
|
||||
|
||||
@@ -174,7 +174,7 @@ class LandTextInquiryFlow(SeaTextInquiryFlow):
|
||||
if not mode:
|
||||
mode = "LAND" if (sess and (sess.business_line or "").upper() == "LAND") else ""
|
||||
if not mode:
|
||||
reply(copy.ASK_TRANSPORT)
|
||||
reply(copy.ask_transport())
|
||||
self._save(
|
||||
FlowSession(
|
||||
sender_id=sender_id,
|
||||
@@ -364,8 +364,9 @@ class LandTextInquiryFlow(SeaTextInquiryFlow):
|
||||
no = (sess.work_order_no or "").strip()
|
||||
facts = dict(sess.facts or {})
|
||||
if not no or not facts:
|
||||
reply(copy.LAND_CONFIRM_EXPIRED)
|
||||
return "land_confirm_expired"
|
||||
# 核对卡已取消时效,禁止再回「陆运核对已过期」。
|
||||
logger.warning("land.retry 缺工单或字段,不提示过期")
|
||||
return "land_retry_missing"
|
||||
reply(copy.LAND_TMS_RETRYING.format(wo=no))
|
||||
from agent.policy.system_exception import query_tms_resilient
|
||||
|
||||
|
||||
@@ -256,9 +256,7 @@ class MultiTextInquiryFlow:
|
||||
allow_b=allow_b,
|
||||
chat_fn=chat_fn,
|
||||
)
|
||||
if sess and sess.phase == "wait_confirm":
|
||||
reply(copy.MULTI_CONFIRM_EXPIRED)
|
||||
return "multi_confirm_expired"
|
||||
# 核对卡不再设时效。走到这里说明不是「确定」也不是补字段。
|
||||
reply(copy.MULTI_SAME_MODE if verdict == "same_mode" else "请按段发多段需求,例如段1海运、段2空运。")
|
||||
return "multi_need_text"
|
||||
|
||||
|
||||
@@ -120,9 +120,7 @@ class SeaTextInquiryFlow(AirTextInquiryFlow):
|
||||
reply=reply,
|
||||
sess=sess,
|
||||
)
|
||||
if not sess and looks_like_confirm(text):
|
||||
reply(copy.SEA_CONFIRM_EXPIRED)
|
||||
return "confirm_expired"
|
||||
# 核对卡不再设时效。没有待确定会话时不当成「已过期」。
|
||||
# 上一单已出号:新一轮从本句重收,禁止把旧贸易条款/分类带进下一张工单。
|
||||
sess = self._detach_ticketed_for_new_inquiry(sess)
|
||||
|
||||
@@ -159,7 +157,7 @@ class SeaTextInquiryFlow(AirTextInquiryFlow):
|
||||
mode = detect_transport_mode(f"{sess.immutable_text or ''}\n{text}")
|
||||
|
||||
if not mode:
|
||||
reply(copy.ASK_TRANSPORT)
|
||||
reply(copy.ask_transport())
|
||||
self._save(
|
||||
FlowSession(
|
||||
sender_id=sender_id,
|
||||
@@ -888,7 +886,7 @@ class SeaTextInquiryFlow(AirTextInquiryFlow):
|
||||
)
|
||||
|
||||
if sess.collab_ended or (sess.collab_chat_id or "").strip():
|
||||
reply(copy.HANDOFF_ALREADY_COLLAB)
|
||||
reply(copy.already_collab())
|
||||
return "handoff_already"
|
||||
display_no = ensure_virtual_no(sess) if not (sess.work_order_no or "").strip() else sess.work_order_no
|
||||
staff = self._match_handoff_staff(sess)
|
||||
|
||||
@@ -504,12 +504,20 @@ def looks_like_confirm(text: str) -> bool:
|
||||
"""
|
||||
判断是否在表示确定查价。
|
||||
|
||||
「确定」「确认」「查价」「可以查了」及相近说法都算。
|
||||
同一句像在改始发/目的/体积/车型/「改成」则不当确定,避免改内容被当成查价。
|
||||
「确定」「确认」「查价」「可以查了」及相近短句才算。
|
||||
长询价里「需确认/请确认」不算点核对卡,避免误回「核对已过期」。
|
||||
同一句像在改始发/目的/体积/车型/「改成」则不当确定。
|
||||
纯函数,无副作用。
|
||||
"""
|
||||
raw = (text or "").strip()
|
||||
if not raw:
|
||||
return False
|
||||
if any(x in raw for x in _CONFIRM_EXCLUDE):
|
||||
return False
|
||||
return any(p in raw for p in _CONFIRM_PHRASES)
|
||||
# 超过约 20 字一定是需求正文,不是「确定」短答。
|
||||
if len(raw) > 20:
|
||||
return False
|
||||
compact = re.sub(r"[\s。!?!?,,、]+", "", raw)
|
||||
if not compact:
|
||||
return False
|
||||
return any(p in compact for p in _CONFIRM_PHRASES)
|
||||
|
||||
Reference in New Issue
Block a user