Appearance
🤖 OpenFang / OpenClaw + SaleHay CRM
OpenFang: Agent platform — chạy 24/7 theo schedule, có guardrails OpenClaw: Agent CLI — chạy on-demand, interactive SaleHay CRM: Hệ thống quản lý leads, bookings, analytics
Xem thêm: Cài đặt Agent · Agent API · MCP Server
Tổng quan
Luồng hoạt động:
- Agent nhận lệnh (cron schedule hoặc user prompt)
- Agent đọc skills → quyết định hành động
- Gọi CRM tools qua MCP Server
- CRM API xử lý → trả data → Agent phân tích và hành động tiếp
⚡ Quick Start (3 bước)
1️⃣ Tạo API Key
salehay.com/app → Cài đặt → API Keys → +
Copy key: sk_live_xxx... (⚠️ chỉ hiển thị 1 lần!)
2️⃣ Cấu hình MCP Server
OpenFang — Settings → MCP Servers:
toml
[mcp.salehay-crm]
command = "node"
args = ["/path/to/mcp-server/index.js"]
[mcp.salehay-crm.env]
CRM_BASE_URL = "https://salehay.com"
CRM_AGENT_TOKEN = "sk_live_YOUR_KEY"OpenClaw — file openclaw.json:
json
{
"mcpServers": {
"salehay-crm": {
"command": "node",
"args": ["/path/to/mcp-server/index.js"],
"env": {
"CRM_BASE_URL": "https://salehay.com",
"CRM_AGENT_TOKEN": "sk_live_YOUR_KEY"
}
}
}
}3️⃣ Test kết nối
bash
# Test trực tiếp
curl -H "X-Agent-Token: sk_live_xxx" https://salehay.com/api/agent/analytics
# Test toàn bộ 19 cases
cd mcp-server && node full-test.js7 Tools có sẵn cho Agent
Agent có thể dùng 7 tools sau tự động:
| # | Tool | Việc gì | Ví dụ |
|---|---|---|---|
| 1 | crm_create_lead | Tạo lead mới | "Tạo lead SĐT 0901234567, tên Nguyễn Văn A" |
| 2 | crm_search | Tìm lead | "Tìm leads có SĐT 090..." |
| 3 | crm_update_lead | Cập nhật | "Chuyển lead sang trạng thái contacted" |
| 4 | crm_log_call | Ghi cuộc gọi | "Đã gọi lead X, khách nghe máy 3 phút" |
| 5 | crm_send_message | Gửi tin | "Gửi Zalo nhắc lịch hẹn ngày mai" |
| 6 | crm_get_bookings | Xem lịch hẹn | "Hôm nay có bao nhiêu bookings?" |
| 7 | crm_get_analytics | Phân tích | "Pipeline hiện tại thế nào?" |
HAND Configuration (OpenFang)
File HAND.toml định nghĩa agent behavior:
toml
[hand]
name = "crm-sales-agent"
version = "1.0.0"
description = "CRM lead management agent"
[hand.schedule]
cron = "*/30 8-18 * * 1-6" # Mỗi 30 phút, 8h-18h, T2-T7
timezone = "Asia/Ho_Chi_Minh"
[hand.settings]
crm_base_url = "https://salehay.com"
max_calls_per_run = 10
max_messages_per_run = 20
[hand.tools]
required = [
"crm_create_lead", "crm_search", "crm_log_call",
"crm_get_bookings", "crm_send_message",
"crm_get_analytics", "crm_update_lead"
]
[hand.skills]
required = ["crm-operations", "crm-outreach", "crm-analytics"]
[hand.guardrails]
approval_required = ["crm_send_message"] # Cần duyệt trước khi gửi tin
max_tool_calls = 50Giải thích sections
| Section | Mục đích |
|---|---|
schedule | Khi nào agent chạy (cron + timezone) |
settings | Config URL, giới hạn per-run |
tools | MCP tools agent được dùng |
skills | Skills agent cần đọc |
guardrails | An toàn: approval, max calls |
CRM Skills
3 skills dạy agent cách làm việc:
1. crm-operations — CRUD cơ bản
- Tạo / tìm / cập nhật leads
- Luồng status:
new → contacted → appointment_set → showed_up → converted - Best practice: search trước khi tạo (tránh duplicate)
2. crm-outreach — Tiếp cận khách
- Gọi điện + log kết quả
- Gửi tin nhắn (Zalo, SMS, WhatsApp, Telegram)
- Workflows:
- New Lead Follow-up: search → call → log → update status
- Booking Reminder: get bookings → remind → confirm
- Lost Lead Re-engagement: search lost → message → re-activate
3. crm-analytics — Phân tích data
- Đọc pipeline health
- Ưu tiên hot leads (high priority + new/contacted)
- Target: Contact Rate >60%, Show-up >70%, Conversion >25%
Agent Workflow — Quy trình 4 Phase
- Assessment: Gọi
crm_get_analytics→ đánh giá pipeline - Outreach: Gọi hot leads →
crm_log_call+crm_send_message - Booking:
crm_get_bookings→ gửi reminders cho bookings hôm nay - Reporting: Tóm tắt actions, flag leads cần human attention
Rules
- Không gọi 1 lead quá 3 lần/ngày
- Luôn log outcomes (kể cả unsuccessful)
- Dùng tiếng Việt trong tin nhắn
- Chỉ hoạt động 8h-18h, T2-T7
- Escalate nếu khách giận dữ
Đã Verify — Kết quả Test
Test trên production salehay.com — 19/19 PASS (100%):
| Test | Kết quả |
|---|---|
| Tạo lead (full + minimal) | ✅ 2/2 |
| Tìm kiếm (SĐT, tên, status, edge) | ✅ 4/4 |
| Cập nhật lead (3 trạng thái) | ✅ 3/3 |
| Ghi cuộc gọi (3 outcomes) | ✅ 3/3 |
| Gửi tin (4 channels) | ✅ 4/4 |
| Bookings hôm nay | ✅ 1/1 |
| Analytics | ✅ 1/1 |
| Verify final state | ✅ 1/1 |
Chạy test: node mcp-server/full-test.js
Troubleshooting
401 — Agent token required
- Header phải là
X-Agent-Token(không phảiAuthorization) - Key đúng format
sk_live_xxx - Key chưa bị xóa trong Admin → API Keys
403 — Missing scope
Key mặc định chỉ có scope leads:create. Cần update scope thành * để agent có toàn quyền.
429 — Rate limit exceeded
Mặc định 100 req/phút. Giảm tần suất agent schedule hoặc tăng rate_limit.
MCP Server "fetch failed"
- Kiểm tra
CRM_BASE_URL=https://salehay.com(không trailing slash) - Kiểm tra mạng — MCP Server cần kết nối được internet
- Test:
curl -H "X-Agent-Token: xxx" https://salehay.com/api/health