Tổng quan
ZaloChatHistory là node chuyên dụng để lấy lịch sử chat từ Zalo với 5 operations hỗ trợ auto-pagination, time filtering và nhiều tùy chọn nâng cao.
Use Cases chính
- 📊 Export lịch sử chat để phân tích
- 🔍 Tìm kiếm tin nhắn cũ
- 📈 Thống kê hoạt động chat
- 💾 Backup dữ liệu chat
- 🤖 Training AI chatbot từ dữ liệu thực
Operations
| Operation | Mô tả |
|---|---|
| Lấy Tin Nhắn | Lấy tin nhắn từ một cuộc hội thoại |
| Lấy Nhiều Tin Nhắn | Lấy với pagination tự động |
| Lấy Theo Thời Gian | Filter theo khoảng thời gian |
| Tìm Kiếm | Tìm tin nhắn theo từ khóa |
| Export | Export sang JSON/CSV |
Parameters
Lấy Tin Nhắn
| Parameter | Type | Bắt buộc | Mô tả |
|---|---|---|---|
| Conversation ID | String | ✅ | ID cuộc hội thoại (user hoặc group) |
| Limit | Number | ❌ | Số tin nhắn tối đa (default: 50) |
| Before Message ID | String | ❌ | Lấy tin nhắn trước ID này |
Example:
{
"conversationId": "user_123456789",
"limit": 100
}
Output:
{
"messages": [
{
"messageId": "msg_001",
"content": "Xin chào!",
"senderId": "user_123",
"timestamp": 1704067200000,
"type": "text"
},
{
"messageId": "msg_002",
"content": "Chào bạn!",
"senderId": "user_456",
"timestamp": 1704067260000,
"type": "text"
}
],
"hasMore": true,
"totalReturned": 100
}
Lấy Theo Thời Gian
Filter tin nhắn theo khoảng thời gian cụ thể.
Parameters:
| Parameter | Type | Mô tả |
|---|---|---|
| From Date | DateTime | Ngày bắt đầu |
| To Date | DateTime | Ngày kết thúc |
Example:
{
"conversationId": "group_789",
"fromDate": "2024-01-01T00:00:00Z",
"toDate": "2024-01-31T23:59:59Z"
}
Common Use Cases
1. Daily Chat Export
Export lịch sử chat hàng ngày vào Google Sheets:
Trigger: Daily schedule (6:00 AM)
→ ZaloChatHistory: Lấy tin nhắn 24h qua
→ Transform data (Function node)
→ Append to Google Sheets
→ Send summary via Email
2. Customer Conversation Analysis
Phân tích cuộc hội thoại khách hàng:
Trigger: Webhook từ CRM
→ ZaloChatHistory: Lấy toàn bộ chat với customer
→ Send to AI (GPT-4) để summarize
→ Update CRM với summary
3. Training Data Collection
Thu thập dữ liệu để train chatbot:
Trigger: Weekly schedule
→ ZaloChatHistory: Export tất cả conversations
→ Filter relevant Q&A pairs
→ Save to training dataset
Auto-Pagination
Node hỗ trợ tự động lấy nhiều trang kết quả:
// Workflow logic
let allMessages = [];
let hasMore = true;
let beforeId = null;
while (hasMore) {
const result = await getChatHistory({
conversationId: "group_123",
limit: 100,
beforeMessageId: beforeId
});
allMessages = [...allMessages, ...result.messages];
hasMore = result.hasMore;
beforeId = result.messages[result.messages.length - 1]?.messageId;
// Delay to respect rate limits
await delay(1000);
}
return allMessages;
Troubleshooting
❌ Lỗi: "Conversation not found"
Nguyên nhân: ID cuộc hội thoại không đúng hoặc không có quyền truy cập
Giải pháp:
- Verify conversation ID
- Đảm bảo tài khoản là thành viên của cuộc hội thoại
❌ Lỗi: "Rate limit exceeded"
Nguyên nhân: Gọi API quá nhiều lần trong thời gian ngắn
Giải pháp:
- Thêm delay giữa các requests
- Giảm limit mỗi request
Rate Limiting
| Operation | Giới hạn | Khuyến nghị |
|---|---|---|
| Lấy tin nhắn | ~30/phút | Delay 2s |
| Export lớn | ~10/phút | Delay 6s |
Tips & Best Practices
Pro Tips
- Pagination: Sử dụng
beforeMessageIdđể lấy tin nhắn cũ hơn - Time Filter: Giới hạn khoảng thời gian để giảm data size
- Incremental Export: Lưu
lastMessageIdđể chỉ lấy tin mới - Data Cleanup: Filter bỏ tin nhắn spam/system trước khi lưu
Bước tiếp theo
Trong bài tiếp theo, chúng ta sẽ tìm hiểu về ZaloUser Node - node quản lý thông tin user với 24 operations.
Bài viết hữu ích?
Chia sẻ để nhiều người biết đến!
>_ LLM-Friendly Copy
Copy as Markdown to use with ChatGPT, Claude, or other AI tools



