Skip to content

📋 Cài đặt AI Agent — Hướng dẫn Nhanh

Thời gian: ~10 phút · Kết quả: AI Agent tự động quản lý leads, gửi reminders, phân tích pipeline


⚡ Quick Start (3 bước)

1️⃣ Tạo API Key

Đăng nhập salehay.com/appThêmCài đặtAPI Keys → bấm +

  • Tên: openfang-agent (hoặc tùy ý)
  • ⚠️ Copy key ngay! Key chỉ hiển thị 1 lần

Key có dạng: sk_live_523cc276...

2️⃣ Test kết nối

bash
# Thay YOUR_KEY bằng key vừa copy
curl -H "X-Agent-Token: sk_live_YOUR_KEY" \
  https://salehay.com/api/agent/analytics

✅ Thành công: JSON response chứa pipeline, today, hot_leads

3️⃣ Kết nối Agent

Nếu dùng OpenFang — cấu hình MCP Server trong Settings:

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"

Nếu dùng OpenClaw — tạo 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"
      }
    }
  }
}

Chạy kiểm tra MCP:

bash
cd mcp-server && npm install
CRM_BASE_URL=https://salehay.com CRM_AGENT_TOKEN=sk_live_YOUR_KEY node index.js
# → "SaleHay CRM MCP Server running on stdio"

🧪 Test đầy đủ (19 test cases)

Chạy test tích hợp toàn bộ 7 tools:

bash
# Sửa token trong file trước khi chạy
nano mcp-server/full-test.js

# Chạy test
node mcp-server/full-test.js

Test bao gồm: tạo lead → tìm kiếm → cập nhật → ghi call → gửi tin nhắn → bookings → analytics → verify state.

Kết quả mong đợi: 19/19 PASS — 100%


✅ Checklist Xác nhận

#Kiểm traCách verify
1API Key đã tạoThấy key trong Settings → API Keys
2Kết nối OKcurl /api/agent/analytics trả JSON
3MCP Server chạyLog: "running on stdio"
4Agent kết nốiActivities xuất hiện trong Admin
5Data đúngLeads mới thấy trong tab Leads

❓ FAQ

Lỗi 401: "Agent token required"
  • Kiểm tra header: phải là X-Agent-Token (không phải Authorization)
  • Kiểm tra key chưa bị xóa trong Settings → API Keys
  • Key phải chính xác — copy lại từ lúc tạo
Lỗi 403: "Missing scope"

API Key mặc định có scope leads:create. Liên hệ admin để cập nhật scope thành * (toàn quyền) cho agent.

Lỗi 429: Rate Limit

Mặc định 100 req/phút. Nếu agent gọi quá nhiều:

  • Giảm tần suất chạy (cron schedule)
  • Hoặc liên hệ admin tăng rate_limit
Quên key — làm gì?

Key chỉ hiển thị 1 lần. Nếu mất, tạo key mới và xóa key cũ.

🔒 Internal Documentation — Dev Team Only