Skip to content

🤖 Agent API Reference

Base URL: https://salehay.comAuth: X-Agent-Token: sk_live_xxx · Rate: 100 req/phút · Format: JSON

Xem thêm: Cài đặt Agent · MCP Server · Webhooks

Xác thực

Mỗi request gửi header X-Agent-Token:

bash
curl -H "X-Agent-Token: sk_live_xxx" https://salehay.com/api/agent/analytics

Tạo token tại: salehay.com/appCài đặtAPI Keys

Scopes

ScopeQuyềnEndpoints
leads:readTìm kiếm leadsSearch
leads:writeTạo, cập nhật leadsCreate, Update
calls:writeGhi nhận cuộc gọiLog Call
messages:writeGửi/log tin nhắnSend Message
bookings:readXem lịch hẹnGet Bookings
analytics:readXem analyticsGet Analytics
*Toàn quyềnTất cả

1. Tạo Lead

POST /api/agent/leads

Scope: leads:write · Tự tạo Customer nếu phone chưa có · Fire webhook lead.created

bash
curl -X POST https://salehay.com/api/agent/leads \
  -H "X-Agent-Token: sk_live_xxx" \
  -H "Content-Type: application/json" \
  -d '{
    "phone": "0901234567",
    "name": "Nguyễn Văn A",
    "email": "a@gmail.com",
    "source": "agent",
    "service_interest": "Gói khám tổng quát",
    "note": "Quan tâm gói cao cấp",
    "priority": "high"
  }'
FieldTypeBắt buộcMô tả
phonestringSĐT VN (bắt đầu 0, 9-11 số)
namestringTên khách hàng
emailstringEmail
sourcestringfacebook · google · zalo · website · agent (mặc định)
service_intereststringDịch vụ quan tâm
notestringGhi chú
prioritystringlow · normal (mặc định) · high
custom_fieldsobject{ "key": "value" }

Response 201:

json
{
  "ok": true,
  "lead_id": "6d1a8403-bfec-49ae-8c1a-10f6c7a64df3",
  "customer_id": "b2da69ae-5c1b-44b3-946f-dce3ebe97293",
  "status": "new"
}

2. Tìm kiếm Lead

GET /api/agent/leads/search?q=0901&status=new&limit=20

Scope: leads:read · Cần ít nhất q hoặc status

ParamTypeBắt buộcMô tả
qstring❌*SĐT hoặc tên (ILIKE)
statusstring❌*new · contacted · appointment_set · qualified · converted · lost
limitnumberMax kết quả (mặc định 20, tối đa 50)

Response 200:

json
{
  "leads": [
    {
      "id": "uuid", "status": "new", "priority": "high",
      "phone": "0901234567", "name": "Nguyễn Văn A",
      "source": "agent", "service_interest": "Gói khám",
      "created_at": "2026-03-17T..."
    }
  ],
  "total": 1
}

3. Cập nhật Lead

PATCH /api/agent/leads/:id

Scope: leads:write · Auto-log activity · Fire webhook lead.updated

bash
curl -X PATCH https://salehay.com/api/agent/leads/UUID \
  -H "X-Agent-Token: sk_live_xxx" \
  -H "Content-Type: application/json" \
  -d '{ "status": "contacted", "note": "Đã gọi, khách quan tâm" }'
FieldTypeBắt buộcMô tả
statusstring❌*Trạng thái mới
prioritystring❌*low · normal · high
notestring❌*Ghi chú

Ít nhất 1 field bắt buộc

Luồng trạng thái:

new → contacted → appointment_set → showed_up → qualified → converted
                                  → no_show → reschedule
                                                         → lost

4. Ghi nhận Cuộc gọi

POST /api/agent/calls/log

Scope: calls:write · Nếu outcome=answered + lead status new → tự chuyển contacted

bash
curl -X POST https://salehay.com/api/agent/calls/log \
  -H "X-Agent-Token: sk_live_xxx" \
  -H "Content-Type: application/json" \
  -d '{
    "lead_id": "uuid",
    "outcome": "answered",
    "duration_seconds": 180,
    "note": "Khách đồng ý hẹn khám"
  }'
FieldTypeBắt buộcMô tả
lead_iduuid❌*Lead UUID
booking_iduuid❌*Booking UUID (thay lead_id)
outcomestringanswered · no_answer · busy · voicemail · rejected
duration_secondsnumberThời lượng (giây)
notestringGhi chú

Ít nhất lead_id hoặc booking_id bắt buộc


5. Lịch hẹn hôm nay

GET /api/agent/bookings/today

Scope: bookings:read · Không cần params

Response 200:

json
{
  "bookings": [
    { "id": "uuid", "status": "pending", "service": "Gói khám",
      "date": "2026-03-17", "time_slot": "09:00",
      "phone": "0901234567", "name": "Nguyễn Văn A" }
  ],
  "stats": { "total": 8, "pending": 3, "confirmed": 5, "arrived": 0, "completed": 0, "cancelled": 0 }
}

6. Gửi/Log tin nhắn

POST /api/agent/messages/send

Scope: messages:write · Ghi vào activity log (không gửi tin thực tế)

bash
curl -X POST https://salehay.com/api/agent/messages/send \
  -H "X-Agent-Token: sk_live_xxx" \
  -H "Content-Type: application/json" \
  -d '{
    "lead_id": "uuid",
    "channel": "zalo",
    "message_text": "Xin chào, nhắc lịch hẹn ngày mai 9h ạ!"
  }'
FieldTypeBắt buộcMô tả
lead_iduuid❌*Lead UUID
customer_iduuid❌*Customer UUID
channelstringzalo · sms · whatsapp · telegram
message_textstringNội dung
template_namestringTên template

7. Analytics

GET /api/agent/analytics

Scope: analytics:read · Không cần params

Response 200:

json
{
  "pipeline": { "new": 12, "contacted": 8, "appointment_set": 5, "converted": 15 },
  "today": { "new_leads": 3, "bookings": { "total": 8, "pending": 3, "confirmed": 5 } },
  "hot_leads": [{ "id": "uuid", "phone": "0901234567", "name": "A", "priority": "high" }],
  "conversion_30d": { "converted": 15, "total": 50, "rate": "30.0%" }
}

Error Codes

StatusÝ nghĩa
200OK
201Tạo mới OK
400Thiếu field / sai format
401Token thiếu hoặc sai
403Token thiếu scope
404Lead/Booking không tìm thấy
429Quá rate limit

MCP Tools Mapping

MCP ToolHTTP Endpoint
crm_create_leadPOST /api/agent/leads
crm_searchGET /api/agent/leads/search
crm_update_leadPATCH /api/agent/leads/:id
crm_log_callPOST /api/agent/calls/log
crm_get_bookingsGET /api/agent/bookings/today
crm_send_messagePOST /api/agent/messages/send
crm_get_analyticsGET /api/agent/analytics

🔒 Internal Documentation — Dev Team Only