Bỏ qua để đến nội dung

SOP: Cài đặt AI Agent

Thông tin nhanh

  • Thời gian: ~15 phút
  • Yêu cầu: Tài khoản Admin CRM + access vào server/máy cài agent
  • Kết quả: AI Agent tự động follow up leads, gửi reminders, phân tích pipeline

Xem thêm: Agent API · Agent Tokens · OpenFang/OpenClaw

  1. Đăng nhập Admin Dashboard
  2. Vào SettingsAgent Tokens (hoặc Tích hợp AI)
  3. Bấm Tạo Token mới
  4. Điền thông tin:
    • Tên: Ví dụ “Sales Agent - OpenFang”
    • Loại Agent: Chọn openfang hoặc openclaw
    • Scopes: Tick các quyền cần thiết:
      • leads:read — Tìm kiếm leads
      • leads:write — Tạo/cập nhật leads
      • calls:write — Ghi nhận cuộc gọi
      • messages:write — Gửi/log tin nhắn
      • analytics:read — Xem analytics
      • bookings:read — Xem lịch hẹn
    • Rate Limit: 60 requests/phút (đủ cho agent chạy cron)
  5. Bấm Tạo
  6. ⚠️ QUAN TRỌNG: Copy token ngay! Token chỉ hiển thị 1 lần.
Terminal window
# Clone repo (nếu chưa có)
git clone https://github.com/tody-agent/service-crm
cd service-crm/mcp-server
# Cài dependencies
npm install
Terminal window
# Thay agent_xxx bằng token thực
curl -H "X-Agent-Token: agent_xxx" https://api.salehay.com/api/agent/analytics

Nếu thành công, sẽ thấy JSON response chứa pipeline, today, hot_leads.

Terminal window
CRM_BASE_URL=https://api.salehay.com \
CRM_AGENT_TOKEN=agent_xxx \
node index.js

Output: SaleHay CRM MCP Server running on stdio

Terminal window
# Lưu token an toàn
openfang secret set CRM_AGENT_TOKEN agent_xxx
# Copy HAND config
cp ../openfang-hand/HAND.toml ~/.openfang/hands/crm-lead-gen/HAND.toml
# Copy skills
cp -r ../skills/crm-operations ~/.openfang/skills/
cp -r ../skills/crm-outreach ~/.openfang/skills/
cp -r ../skills/crm-analytics ~/.openfang/skills/
# Start agent
openfang start crm-lead-gen

Tạo file ~/.openclaw/config.json:

{
"mcpServers": {
"salehay-crm": {
"command": "node",
"args": ["/path/to/service-crm/mcp-server/index.js"],
"env": {
"CRM_BASE_URL": "https://api.salehay.com",
"CRM_AGENT_TOKEN": "agent_xxx"
}
}
}
}
  1. Kiểm tra trên Admin Dashboard:

    • Vào Settings → Agent Tokens → kiểm tra last_used_at đã cập nhật
    • Vào Leads → kiểm tra có activities mới với ghi chú “Created by agent” hoặc “Updated by agent”
  2. Kiểm tra Webhooks (nếu đã setup):

    • Vào Settings → Webhooks → kiểm tra total_deliveries tăng
    • Hệ thống ngoài nhận được events lead.created, call.completed

  • Agent Token đã tạo và lưu
  • MCP Server chạy không lỗi
  • curl /api/agent/analytics trả về data
  • Agent platform (OpenFang/OpenClaw) kết nối được MCP Server
  • Agent chạy thử → kiểm tra Activities trong Admin Dashboard
  • (Tùy chọn) Webhooks đã setup và nhận được events

Agent gọi API bị lỗi 403 (Missing scope)?

Token thiếu scope cần thiết. Vào Admin → Agent Tokens → kiểm tra scopes. Nếu cần thêm scope, phải tạo token mới (không thể sửa scopes của token hiện tại).

Agent gọi quá nhiều, bị 429 Rate Limit?

Tăng rate_limit khi tạo token mới, hoặc giảm tần suất chạy trong HAND.toml (ví dụ từ */30 thành 0 */1 — mỗi giờ một lần).

Muốn agent chỉ đọc, không tạo/sửa gì?

Tạo token chỉ với scopes: leads:read, bookings:read, analytics:read. Agent sẽ chỉ xem được data, không thể tạo lead hay ghi call.