【架构实战】客服系统架构:智能客服降本增效
·
一、客服成本高企,成为企业负担
2019年,我们客服团队有100人:
- 人工成本:每月100万+
- 培训成本:新人上手需要1个月
- 高峰期响应慢:用户等待超过5分钟
- 客户满意度:只有70%
引入智能客服后:
- 机器人承接80%咨询
- 人工客服减少到30人
- 响应时间降到10秒内
- 客户满意度提升到90%
二、客服系统架构
2.1 整体架构
┌─────────────────────────────────────────────────────────────────┐
│ 客服系统架构 │
│ │
│ 用户 → 网关 → 智能路由 → ┬→ 机器人客服(80%) │
│ ↘→ 人工客服(20%) │
│ │
│ 核心组件: │
│ - IM长连接服务 │
│ - 消息路由服务 │
│ - 机器人客服 │
│ - 工单系统 │
│ - 知识库系统 │
│ │
└──────────────────────────────────────────────────────────────────┘
2.2 消息流转流程
用户发送消息 → WebSocket网关 → 消息队列 → 路由服务
↓
判断消息类型
↙ ↘
简单问题 复杂问题
↓ ↓
机器人回复 分配人工客服
三、智能客服核心
3.1 意图识别
/**
* 意图识别服务
*/
@Service
public class IntentRecognitionService {
@Autowired
private NLPModelService nlpModel;
/**
* 识别用户意图
*/
public IntentResult recognize(String message) {
// 1. 文本预处理
String text = preprocess(message);
// 2. NLP模型识别
IntentResult result = nlpModel.predict(text);
// 3. 置信度过滤
if (result.getConfidence() < 0.8) {
// 置信度低,转人工
result.setNeedHuman(true);
}
return result;
}
}
3.2 知识库匹配
/**
* 知识库服务
*/
@Service
public class KnowledgeBaseService {
@Autowired
private ElasticsearchClient esClient;
/**
* 查找最佳答案
*/
public Answer findBestAnswer(String question) {
// 1. ES相似度搜索
SearchResponse response = esClient.search(s -> s
.index("knowledge")
.query(q -> q
.match(m -> m
.field("question")
.query(question)
)
),
Knowledge.class
);
// 2. 取最高分答案
if (response.hits().total().value() > 0) {
Knowledge knowledge = response.hits().hits().get(0).source();
return new Answer(knowledge.getAnswer(), knowledge.getId());
}
return null;
}
}
3.3 多轮对话
/**
* 对话管理服务
*/
@Service
public class DialogManagerService {
// 对话状态存储
private Map<String, DialogContext> dialogContexts = new ConcurrentHashMap<>();
/**
* 处理多轮对话
*/
public String processDialog(String sessionId, String message) {
// 1. 获取对话上下文
DialogContext context = dialogContexts.computeIfAbsent(
sessionId, k -> new DialogContext());
// 2. 根据当前状态处理
switch (context.getState()) {
case INIT:
// 询问订单号
context.setState(WAITING_ORDER);
return "请问您咨询的是哪个订单?请提供订单号";
case WAITING_ORDER:
// 提取订单号
String orderId = extractOrderId(message);
if (orderId != null) {
context.setOrderId(orderId);
context.setState(WAITING_ISSUE);
return "请问您遇到什么问题?1.物流问题 2.商品问题 3.退款问题";
}
return "订单号格式不正确,请重新输入";
case WAITING_ISSUE:
// 处理问题
return handleIssue(context, message);
}
}
}
四、IM长连接
4.1 WebSocket服务
/**
* WebSocket服务
*/
@ServerEndpoint("/ws/{userId}")
@Component
public class WebSocketServer {
private static Map<String, Session> sessions = new ConcurrentHashMap<>();
@OnOpen
public void onOpen(Session session, @PathParam("userId") String userId) {
sessions.put(userId, session);
log.info("用户上线: {}", userId);
}
@OnMessage
public void onMessage(String message, Session session) {
// 1. 解析消息
ChatMessage chatMessage = JSON.parseObject(message, ChatMessage.class);
// 2. 发送到MQ处理
rocketMQTemplate.send("chat-message", chatMessage);
}
@OnClose
public void onClose(Session session, @PathParam("userId") String userId) {
sessions.remove(userId);
log.info("用户下线: {}", userId);
}
/**
* 发送消息给用户
*/
public void sendMessage(String userId, String message) {
Session session = sessions.get(userId);
if (session != null && session.isOpen()) {
session.getAsyncRemote().sendText(message);
}
}
}
五、踩坑实录
坑1:机器人回答牛头不对马嘴
解决方案:持续优化知识库,收集bad case重新训练。
坑2:高峰期排队久
解决方案:引入排队系统,预估等待时间,优化客服排班。
坑3:长连接不稳定
解决方案:心跳机制 + 自动重连。
六、总结
智能客服核心:知识库 + NLP + 多轮对话。
血的教训:
智能客服是"降本"利器,但不能完全替代人工,关键问题仍需人工介入。
个人观点,仅供参考
更多推荐

所有评论(0)