Aile 消息格式完整規格說明書
版本: v1.0
最後更新: 2026-06-13
服務範圍: aile-service-room(核心)、aile-common-dependency(通用類型)
儲存引擎: Elasticsearch(index: aile.message)
1. 概述
Aile 的消息系統支援 13 種基礎消息類型、4 種模板類型、8 種消息標籤(Tag)和 5 種消息來源。消息以 MessageModel 為核心載體,透過 content 欄位(Object 類型)承載各類型專屬的結構化內容。
2. MessageModel(消息核心模型)
2.1 資料結構
// aile-api/aile-room-api/.../model/MessageModel.java
@Document(indexName = "aile.message", dynamic = Dynamic.TRUE)
public class MessageModel implements Serializable {
String id; // Elasticsearch 文檔 ID
String messageId; // 業務消息編號
MessageType type; // 消息類型
MessageSourceType sourceType; // 消息來源類型
String senderName; // 發送者名稱
String senderId; // 發送者 ID
String accountId; // 帳號 ID
long sendTime; // 發送時間(epoch ms)
String roomId; // 聊天室 ID
long sequence; // 消息序號(房間內遞增)
String tenantId; // 租戶 ID
OsType osType; // 設備類型
Channel channel; // 渠道
Channel appointChannel; // 指定渠道(多渠道發送時)
Object content; // 消息內容(類型相關)
Tag tag; // 消息標籤
String themeId; // 主題 ID
String nearMessageId; // 關聯消息 ID(回覆引用)
String sessionId; // 關聯會話 ID
String channelMessageId; // 渠道側消息 ID(Gateway 回傳)
List<String> excludeMemberIds;// 排除的成員 ID
String recipientId; // 接收者 ID(私聊)
String recipientAccountId; // 接收者帳號 ID
Integer flag; // 消息狀態標記
}
2.2 消息狀態標記(MessageFlag)
// aile-api/aile-room-api/.../enums/MessageFlag.java
public enum MessageFlag {
Deleted(-2), // 已刪除
Send(-1), // 發送中
Arrive(0), // 已送達
Received(1), // 已接收
Read(2), // 已讀
Retract(3) // 已撤回
}
2.3 消息來源類型(MessageSourceType)
// aile-api/aile-room-api/.../enums/MessageSourceType.java
public enum MessageSourceType {
User, // 用戶(員工或客戶)
Assistant, // AI 助手
System, // 系統自動消息
Consult, // 諮詢消息(客服場景)
Broadcast // 群發消息
}
3. MessageType(13 種消息類型)
// aile-api/aile-room-api/.../enums/MessageType.java
public enum MessageType {
At, // @提及消息
Text, // 純文字消息
Event, // 事件消息(系統事件)
Image, // 圖片消息
File, // 文件消息
Video, // 影片消息
Audio, // 音頻消息
Voice, // 語音消息
Sticker, // 貼圖消息
Template, // 模板/卡片消息
Location, // 位置消息
Action, // 動作消息(按鈕點擊回傳)
Json // 結構化 JSON 消息
}
4. 各消息類型詳解與示例
4.1 Text(純文字)
最基礎的消息類型。content 為純文字字串。
{
"type": "Text",
"content": "您好,歡迎使用 Aile 客服系統!",
"roomId": "room_abc123",
"senderId": "emp_001",
"senderName": "客服小王",
"sourceType": "User"
}
4.2 At(@提及)
用於在群聊中 @ 特定成員。content 中包含提及對象資訊。
{
"type": "At",
"content": {
"text": "@張三 請確認一下訂單狀態",
"mentions": [
{
"memberId": "member_zhangsan",
"name": "張三",
"type": "User"
}
]
},
"roomId": "room_group_001"
}
4.3 Image(圖片)
content 為圖片資源的結構化描述。透過 MessageSendV2Dto 上傳時,file 欄位攜帶 MultipartFile。
{
"type": "Image",
"content": {
"fileId": "file_img_001",
"url": "https://cdn.aile.com/images/abc123.jpg",
"thumbnailUrl": "https://cdn.aile.com/images/abc123_thumb.jpg",
"width": 800,
"height": 600,
"size": 102400,
"fileName": "product_photo.jpg"
},
"roomId": "room_abc123"
}