钉钉 AI 客服:API 接口文档详解

4 阅读1分钟

钉钉 AI 客服:API 接口文档详解

Pro 版提供完整的 API 接口,方便二次开发。


一、接口概览

接口方法说明
/api/chatPOST对话接口
/api/faqGET/POSTFAQ 管理
/api/statsGET统计数据
/api/exportGET导出数据

二、对话接口

2.1 发送消息

请求

POST /api/chat
Content-Type: application/json

{
  "message": "你好",
  "session_id": "user_123"
}

响应

{
  "code": 0,
  "data": {
    "response": "你好!有什么可以帮你?",
    "session_id": "user_123",
    "resolved": true
  }
}

2.2 多轮对话

请求

{
  "message": "我想退货",
  "session_id": "user_123",
  "context": {
    "order_id": "20260314001"
  }
}

三、FAQ 管理

3.1 获取 FAQ 列表

请求

GET /api/faq?page=1&size=20

响应

{
  "code": 0,
  "data": {
    "list": [
      {"id": 1, "question": "营业时间", "answer": "周一至周五 9:00-18:00"}
    ],
    "total": 100
  }
}

3.2 添加 FAQ

请求

POST /api/faq
Content-Type: application/json

{
  "question": "发货时间",
  "answer": "下单后 24 小时内发货",
  "keywords": ["发货", "配送"]
}

3.3 更新 FAQ

请求

PUT /api/faq/1
Content-Type: application/json

{
  "answer": "下单后 48 小时内发货"
}

3.4 删除 FAQ

请求

DELETE /api/faq/1

四、统计数据

4.1 获取统计

请求

GET /api/stats?start=2026-03-01&end=2026-03-14

响应

{
  "code": 0,
  "data": {
    "total_chats": 10000,
    "resolved_rate": 0.87,
    "avg_response_time": 0.8,
    "satisfaction": 0.92
  }
}

五、数据导出

5.1 导出对话记录

请求

GET /api/export?type=chat&format=json

响应

[
  {
    "session_id": "xxx",
    "user_message": "你好",
    "ai_response": "你好!",
    "timestamp": "2026-03-14T10:00:00Z"
  }
]

六、错误码

错误码说明
0成功
1001参数错误
1002未授权
1003资源不存在
2001AI 服务异常
2002API 限流

七、SDK 示例

Python

import requests

response = requests.post(
    "http://localhost:3000/api/chat",
    json={"message": "你好", "session_id": "test"}
)
print(response.json())

Node.js

const response = await fetch("http://localhost:3000/api/chat", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({ message: "你好", session_id: "test" })
});
const data = await response.json();
console.log(data);

项目地址:GitHub - dingtalk-connector-pro 有问题欢迎 Issue 或评论区交流