第 28 期:综合项目 — 智能客服系统

更新于 2026/4/6

系统架构

graph TB
    subgraph "用户接入"
        Web[网页 Widget]
        WeCom[企业微信]
        API[API 集成]
    end
    
    subgraph "Dify Chatflow"
        Entry[用户消息入口]
        QC[意图分类器]
        
        QC -->|产品咨询| KB[知识库检索]
        QC -->|订单问题| OrderAPI[HTTP: 订单系统]
        QC -->|投诉建议| Escalate[人工转接]
        QC -->|闲聊| Chat[友好对话]
        
        KB --> LLM1[LLM: 知识回答]
        OrderAPI --> Code1[Code: 格式化]
        Code1 --> LLM2[LLM: 自然语言包装]
        
        LLM1 --> Feedback[满意度评分]
        LLM2 --> Feedback
        Chat --> Feedback
        
        Feedback --> |不满意| Escalate
        Feedback --> Answer[Answer]
        Escalate --> Notify[HTTP: 通知人工客服]
    end
    
    Web --> Entry
    WeCom --> Entry
    API --> Entry

步骤一:创建知识库

# 导入产品文档、FAQ、使用手册
documents = [
    "产品使用手册.pdf",
    "常见问题FAQ.md",
    "退换货政策.txt",
    "定价方案说明.docx"
]

for doc in documents:
    upload_to_knowledge_base(
        dataset_id="customer-service-kb",
        file_path=f"docs/{doc}",
        indexing_technique="high_quality"
    )

步骤二:意图分类器配置

# Question Classifier 节点配置
classes:
  - name: "product_inquiry"
    description: "产品功能、规格、使用方法相关问题"
    examples:
      - "这个产品支持什么系统?"
      - "如何安装?"
  - name: "order_issue"
    description: "订单状态、物流、退换货相关"
    examples:
      - "我的订单到哪了?"
      - "如何退货?"
  - name: "complaint"
    description: "投诉、建议、不满"
    examples:
      - "产品质量太差了"
      - "你们客服态度不好"
  - name: "casual"
    description: "闲聊、打招呼"
    examples:
      - "你好"
      - "谢谢"

步骤三:订单查询集成

# Code 节点:调用订单系统 API
def main(order_response: str) -> dict:
    import json
    data = json.loads(order_response)
    
    if data.get("status") == "not_found":
        return {"message": "未找到该订单,请确认订单号是否正确。"}
    
    order = data["order"]
    status_map = {
        "pending": "待发货",
        "shipped": "已发货",
        "delivered": "已签收",
        "returned": "退货中"
    }
    
    return {
        "message": f"订单号: {order['id']}\n"
                   f"状态: {status_map.get(order['status'], order['status'])}\n"
                   f"物流: {order.get('tracking_number', '暂无')}\n"
                   f"预计送达: {order.get('eta', '未知')}"
    }

步骤四:人工转接

# HTTP 节点调用:通知人工客服
"""
POST https://your-helpdesk.com/api/tickets
{
  "title": "客户转接 - {{#sys.conversation_id#}}",
  "customer_id": "{{#sys.user_id#}}",
  "priority": "high",
  "context": "{{#llm_1.text#}}",
  "conversation_history": "最近5轮对话摘要"
}
"""

步骤五:满意度追踪

# 在 Answer 节点后添加评分机制
# Dify 支持 Suggested Questions 功能
suggested_questions_after = [
    "还有其他问题吗?",
    "请为本次服务评分 (1-5分)",
    "需要转接人工客服吗?"
]