用戶進線 Session 過程規格說明書
版本: v1.0
最後更新: 2026-06-13
服務範圍: aile-service-tenant(核心)、aile-service-room(協同)
1. 概述
用戶進線 Session(ServiceSession)是 Aile 客服系統的核心會話管理機制。每當客戶透過 LINE 私聊或其他渠道向服務號發起對話時,系統會建立一條 ServiceSession 記錄,追蹤從機器人接待到人工服務的完整生命週期。
1.1 核心概念
| 概念 | 說明 |
|---|---|
| ServiceSession | 一次客戶進線的完整會話記錄 |
| Session 狀態 | 9 種狀態:RobotActive → DistributeActive → AgentActive → ... → End |
| 機器人接待 | 客戶進線後首先由機器人(AI 助 手)接待 |
| 轉人工 | 客戶請求或系統判定需要轉接人工客服 |
| 分配策略 | 基於員工權重(RoomWeight)的自動分配 |
2. ServiceSessionModel(會話持久化模型)
2.1 資料結構
MongoDB 集合:aile.tenant.servicenumber.session
// aile-api/aile-tenant-api/.../model/servicenumber/ServiceSessionModel.java
@Document("aile.tenant.servicenumber.session")
@CompoundIndexes({
@CompoundIndex(name = "serviceNumberId", def = "{'serviceNumberId': 1}"),
@CompoundIndex(name = "roomId_1_updateTime_1", def = "{'roomId': 1, 'updateTime': 1}"),
@CompoundIndex(name = "roomId_1_channel_1_updateTime_1", def = "{'roomId': 1, 'channel': 1, 'updateTime': 1}"),
@CompoundIndex(name = "gwSessionId_1", def = "{'gwSessionId': 1}"),
@CompoundIndex(name = "serviceNumberId_1_status_1", def = "{'serviceNumberId': 1, 'status': 1}"),
@CompoundIndex(name = "serviceNumberId_1_status_1_agentId_1", def = "{'serviceNumberId': 1, 'status': 1, 'agentId': 1}"),
@CompoundIndex(name = "agentId_1_status_1", def = "{'agentId': 1, 'status': 1}"),
@CompoundIndex(name = "serviceNumberId_1_scopeId_1", def = "{'serviceNumberId': 1, 'scopeId': 1}"),
@CompoundIndex(name = "status_1_activeTime_1", def = "{'status': 1, 'activeTime': 1}"),
@CompoundIndex(name = "status_1_distributeTime_1", def = "{'status': 1, 'distributeTime': 1}"),
@CompoundIndex(name = "serviceNumberId_1_startTime_1", def = "{'serviceNumberId': 1, 'startTime': 1}")
})
public class ServiceSessionModel extends BaseModel {
String tenantId; // 租戶 ID
String serviceNumberId; // 服務號 ID
ServiceNumberType serviceNumberType; // 服務號類型
String roomId; // 聊天室 ID
String accountId; // 帳號 ID
String customerId; // 客戶(聯繫人)ID
String scopeId; // 客戶渠道 scopeId
String agentId; // 接待客服的 memberId
String gwSessionId; // Gateway 側的 session ID
ServiceSessionStatus status; // 會話狀態
Channel channel; // 進線渠道(Line / WhatsApp 等)
Long startTime; // 會話開始時間
Long activeTime; // 最近活躍時間
Long endTime; // 會話結束時間
Long distributeTime; // 人工分配時間
Long robotActiveTime; // 機器人開始接待時間
Long robotStopTime; // 機器人接待結束時間
Long timeoutTime; // 超時時間
// 滿意度
Integer satisfactionScore; // 滿意度評分
String satisfactionComment; // 滿意度備註
}
3. Session 生命週期狀態機
3.1 狀態定義
// aile-api/aile-tenant-api/.../enums/ServiceSessionStatus.java
public enum ServiceSessionStatus {
RobotActive, // 機器人服務中
RobotStop, // 機器人服務結束
DistributeActive, // 轉人工,剛進件(等待分配)
AgentActive, // 客服人員服務中
AgentStop, // 客服人員服務結束
CustomerStop, // 客戶主動結束
Timeout, // 服務超時結束
NoWorkTimeStop, // 非上班時間結束
Deleted // 標記刪除
}
3.2 狀態轉換圖
客戶進線
│
▼
RobotActive ──────────────────────────────────────┐
│ │
├──→ RobotStop(機器人主動結束) │
│ │
├──→ DistributeActive(轉人工) │
│ │ │
│ ├──→ AgentActive(分配成功) │
│ │ │ │
│ │ ├──→ AgentStop(客服結束) │
│ │ ├──→ CustomerStop(客戶結束) │
│ │ └──→ Timeout(超時) │
│ │ │
│ └──→ NoWorkTimeStop(非工作時 間) │
│ │
├──→ CustomerStop(客戶主動結束) │
├──→ Timeout(超時) │
└──→ NoWorkTimeStop(非工作時間) │
│
(所有結束狀態可被標記為 Deleted) ◄──────────────────┘
3.3 活躍狀態判斷
// 以下三個狀態為「活躍中」
activeStatus = [RobotActive, DistributeActive, AgentActive]
// 「主要活躍」(人工相關)
isMainActive() → DistributeActive || AgentActive
// 「已離線」
isOffline() → RobotStop || AgentStop || CustomerStop || Timeout || NoWorkTimeStop || Deleted