Skip to content

🤖 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:

  1. Agent nhận lệnh (cron schedule hoặc user prompt)
  2. Agent đọc skills → quyết định hành động
  3. Gọi CRM tools qua MCP Server
  4. 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/appCài đặtAPI 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.js

7 Tools có sẵn cho Agent

Agent có thể dùng 7 tools sau tự động:

#ToolViệc gìVí dụ
1crm_create_leadTạo lead mới"Tạo lead SĐT 0901234567, tên Nguyễn Văn A"
2crm_searchTìm lead"Tìm leads có SĐT 090..."
3crm_update_leadCập nhật"Chuyển lead sang trạng thái contacted"
4crm_log_callGhi cuộc gọi"Đã gọi lead X, khách nghe máy 3 phút"
5crm_send_messageGửi tin"Gửi Zalo nhắc lịch hẹn ngày mai"
6crm_get_bookingsXem lịch hẹn"Hôm nay có bao nhiêu bookings?"
7crm_get_analyticsPhâ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 = 50

Giải thích sections

SectionMục đích
scheduleKhi nào agent chạy (cron + timezone)
settingsConfig URL, giới hạn per-run
toolsMCP tools agent được dùng
skillsSkills agent cần đọc
guardrailsAn 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

  1. Assessment: Gọi crm_get_analytics → đánh giá pipeline
  2. Outreach: Gọi hot leads → crm_log_call + crm_send_message
  3. Booking: crm_get_bookings → gửi reminders cho bookings hôm nay
  4. 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.com19/19 PASS (100%):

TestKế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ải Authorization)
  • 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

SaleHay CRM Documentation