- 新增 inq_synonym 表、62组同义词种子与智能体只读接口 - Python 同义词加载/归一化与 1板/2箱 机读 - 同步当前分支既有协作、报价识别、陆运等改动
152 lines
4.8 KiB
Python
152 lines
4.8 KiB
Python
"""
|
||
报价/调价先回识别回执,等成员@机器人回「确认/确定」后再出价格方案/改价。
|
||
|
||
产品 2026-11-24 口径:
|
||
* 产品报价:先回「我识别内容为…请确认是否正确」;
|
||
* 销售调价:先回「我识别内容为…请确认是否正确」;
|
||
* 只有产品/航线岗回确认才算数;
|
||
* 确认后才写主账/出价格方案/改价。
|
||
|
||
本模块只做开关、确认话术和身份判断;不写主账、不发企微。
|
||
"""
|
||
|
||
from __future__ import annotations
|
||
|
||
import os
|
||
from typing import Any
|
||
|
||
from agent.policy.bot_name import strip_mention_keep_layout
|
||
|
||
# 整句就是确认才算。口令不写死整段长句,但也不把含价格的话当确认。
|
||
_CONFIRM_TEXTS = frozenset(
|
||
{
|
||
"确认",
|
||
"确定",
|
||
"正确",
|
||
"确认无误",
|
||
"确认正确",
|
||
"正确无误",
|
||
"对的",
|
||
"对",
|
||
"是",
|
||
"是的",
|
||
"没问题",
|
||
"无误",
|
||
"同意",
|
||
"可以",
|
||
"好的",
|
||
"好",
|
||
"ok",
|
||
"确认一下",
|
||
"确认报价",
|
||
"确认该报价",
|
||
"确认这个报价",
|
||
}
|
||
)
|
||
|
||
|
||
def quote_confirm_enabled() -> bool:
|
||
"""
|
||
是否启用「先回执、后确认」流程。默认开;单测可用 QUOTE_CONFIRM_ENABLED=false 关掉。
|
||
"""
|
||
raw = str(os.environ.get("QUOTE_CONFIRM_ENABLED", "true")).strip().lower()
|
||
return raw not in {"0", "false", "no", "off"}
|
||
|
||
|
||
def is_confirm_text(text: str) -> bool:
|
||
"""
|
||
整句只是确认/确定/正确等(去掉 @机器人 和标点后)。
|
||
|
||
为什么用 strip_mention_keep_layout 而不是 strip_bot_mention:
|
||
群里显示名可能比后台配置名长(测服真机:「智价通AIQ测试」),
|
||
后者只按配置名剥会留下「测试」,把「@… 正确」变成「测试正确」判不成确认。
|
||
"""
|
||
blob = strip_mention_keep_layout(text or "").replace(" ", "").replace(" ", "")
|
||
blob = blob.strip("。.!!,,;;::").lower()
|
||
return blob in _CONFIRM_TEXTS
|
||
|
||
|
||
def sender_display_name(flow: Any, ticket: object, sender_id: str) -> str:
|
||
"""回执里 @ 当前报价人员:优先员工管理姓名,再工单销售/产品名单,最后 userid。"""
|
||
uid = (sender_id or "").strip()
|
||
if not uid:
|
||
return ""
|
||
book = getattr(flow, "ledger", None) or getattr(flow, "_ledger", None)
|
||
getter = getattr(book, "get_staff_by_wecom_id", None) if book else None
|
||
if callable(getter):
|
||
try:
|
||
row = getter(wecom_id=uid) or {}
|
||
name = str(row.get("name") or "").strip()
|
||
if name:
|
||
return name
|
||
except Exception:
|
||
pass
|
||
try:
|
||
from agent.policy.sea_group_ops import ticket_view
|
||
|
||
view = ticket_view(ticket or {})
|
||
except Exception:
|
||
view = {}
|
||
sales = str(view.get("sales_wecom_id") or view.get("salesWecomId") or "").strip()
|
||
if uid == sales:
|
||
name = str(view.get("sales_name") or view.get("salesName") or "").strip()
|
||
if name:
|
||
return name
|
||
ids = [str(x) for x in (view.get("product_ids") or [])]
|
||
names = [str(x) for x in (view.get("product_names") or [])]
|
||
if uid in ids:
|
||
idx = ids.index(uid)
|
||
if idx < len(names) and names[idx]:
|
||
return names[idx]
|
||
return uid
|
||
|
||
|
||
def can_confirm_quote(
|
||
flow: Any, ticket: object, sender_id: str, *, business_line: str = ""
|
||
) -> bool:
|
||
"""
|
||
确认报价的人:本单销售本人,或产品/航线岗。
|
||
|
||
产品 2026-11-24:销售本人也能点确认,不用非等产品。
|
||
business_line 传段落方式(MULTI 群按目标段传 AIR/LAND/SEA)。
|
||
"""
|
||
from agent.policy.sea_group_ops import is_sales
|
||
|
||
if is_sales(ticket, sender_id):
|
||
return True
|
||
line = (business_line or "").strip().upper()
|
||
if line == "AIR":
|
||
from agent.policy.air_group_ops import is_airline
|
||
|
||
return is_airline(flow, sender_id)
|
||
from agent.policy.sea_group_ops import is_product
|
||
|
||
return is_product(ticket, sender_id, flow=flow)
|
||
|
||
|
||
def can_confirm_adjust(
|
||
flow: Any,
|
||
ticket: object,
|
||
sender_id: str,
|
||
*,
|
||
pending_sender: str = "",
|
||
) -> bool:
|
||
"""
|
||
确认调价的人:发起调价的本人(销售),或产品/航线岗。
|
||
|
||
私聊调价只有销售本人,不能要求产品来点;群里销售发起后也允许本人确认。
|
||
"""
|
||
if pending_sender and (sender_id or "").strip() == (pending_sender or "").strip():
|
||
return True
|
||
from agent.policy.sea_group_ops import is_sales
|
||
|
||
if is_sales(ticket, sender_id):
|
||
return True
|
||
from agent.policy.air_group_ops import is_airline
|
||
|
||
if is_airline(flow, sender_id):
|
||
return True
|
||
from agent.policy.sea_group_ops import is_product
|
||
|
||
return is_product(ticket, sender_id, flow=flow)
|