- 新增 notify_boss():POST /api/cma/lead 时,除既有全员群 notify_wecom 外, 额外经 ai-cs 实盘分流脚本(routing-live.py)通知 wecom:200653946(加性,不改动既有逻辑) - 跨 profile 调用必须显式传 HOME/HERMES_HOME=/var/lib/wecom-ai-cs/profile: cma-backend.service Environment 为空,缺省会解析到非 ai-cs profile(实测无 wecom 目标) - 失败静默(capture_output + except pass),不影响主流程 任务: ai-cs-20261013-website-lead-to-boss-and-routing-hook-ops
This commit is contained in:
+26
-1
@@ -1,10 +1,17 @@
|
||||
"""AI获客 - 客户咨询接口"""
|
||||
from fastapi import APIRouter, HTTPException
|
||||
from pydantic import BaseModel
|
||||
import json, os, datetime, urllib.request
|
||||
import json, os, datetime, subprocess, urllib.request
|
||||
|
||||
router = APIRouter(prefix="/api/cma/lead", tags=["AI获客"])
|
||||
|
||||
# ai-cs 实盘分流脚本(跨 profile 调用)
|
||||
# 必须以 ai-cs 身份 + 其 HERMES_HOME/HOME 运行:脚本内用 `hermes send` 复用该 profile 的企微凭据;
|
||||
# cma-backend.service 的 Environment 为空,不显式传入会解析到非 ai-cs 的 profile(root 默认 profile)。
|
||||
AI_CS_USER = "ai-cs"
|
||||
AI_CS_HOME = "/var/lib/wecom-ai-cs/profile"
|
||||
AI_CS_ROUTING_SCRIPT = AI_CS_HOME + "/scripts/routing-live.py"
|
||||
|
||||
class LeadRequest(BaseModel):
|
||||
name: str
|
||||
phone: str
|
||||
@@ -31,6 +38,22 @@ def notify_wecom(name, phone, requirement, source):
|
||||
except:
|
||||
pass # 通知失败不影响主流程
|
||||
|
||||
def notify_boss(name, phone, requirement):
|
||||
"""额外推给任总(经 ai-cs 实盘分流脚本;失败不影响主流程)"""
|
||||
try:
|
||||
subprocess.run(
|
||||
["runuser", "-u", AI_CS_USER, "--",
|
||||
"env", f"HOME={AI_CS_HOME}", f"HERMES_HOME={AI_CS_HOME}",
|
||||
f"USER={AI_CS_USER}", f"LOGNAME={AI_CS_USER}",
|
||||
"/usr/bin/python3", AI_CS_ROUTING_SCRIPT,
|
||||
requirement or "(未填需求)",
|
||||
f"{name} {phone}",
|
||||
"website:sxbh.ltd"],
|
||||
timeout=30, capture_output=True,
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
@router.post("")
|
||||
def create_lead(data: LeadRequest):
|
||||
"""接收客户咨询并保存"""
|
||||
@@ -45,5 +68,7 @@ def create_lead(data: LeadRequest):
|
||||
|
||||
# 异步推送企微通知
|
||||
notify_wecom(data.name, data.phone, data.requirement, data.source)
|
||||
# 加性:额外推给任总 DM(口径与 ai-cs 客服分流一致)
|
||||
notify_boss(data.name, data.phone, data.requirement)
|
||||
|
||||
return {"success": True, "message": "咨询已提交,我们将在30分钟内联系您"}
|
||||
|
||||
Reference in New Issue
Block a user