AI 外呼 Open API 对接文档

文档版本:v5.2
API Base URLhttps://api.dxbcrm.cn/open_api/ai_call


1. 概述

1.1 功能说明

通过本接口可完成 AI 电话机器人外呼全流程:

  • 获取 线路Agent 列表
  • 创建 / 修改 / 删除 外呼任务
  • 导入号码启动 / 暂停 外呼
  • 注册话单回调、主动 拉取话单、查询 话费余额

Agent 在 BOSS 后台 配置并审核通过后,对接方通过 API 选择资源、创建任务、启停外呼并接收话单。

1.2 Agent 类型(agent_type)

agent_type 名称 创建任务时传参 说明
1 向量相似度算法 agent_id(兼容 dialog_res_id 传统话术模式
2 三段式 Agent agent_id 三段式大模型智能体
3 多模态 Agent agent_id E2E 一体式大模型智能体

1.3 接口清单

序号 路径 方法 说明
1 /task_options GET 获取线路与 Agent 列表
2 /task_manage POST 创建 / 修改任务
3 /task_manage PATCH 启动 / 暂停任务
4 /task_manage DELETE 删除任务
5 /task_list GET 查询任务列表
6 /import_phone POST 导入号码
7 /call_record POST 拉取话单
8 /call_balance GET 查询话费余额
9 /register_callback_url POST 注册回调地址
10 Webhook 接收话单 / 任务事件推送

2. 鉴权与通用规范

2.1 开通凭证

商务开通后,对接方将获得以下凭证:

凭证 说明
OID 渠道 OP 账户 UID,用于鉴权
secret 签名密钥,用于计算 TOKEN
TID 业务账户 UID,实际外呼团队账号

线路与 Agent 由运营在后台为业务账户配置;对接方通过 task_options 接口查询可用资源。

2.2 请求头

所有接口均需在 HTTP Header 中携带以下字段:

Header 必填 说明
OID 渠道 OP UID
TID 业务账户 UID
T Unix 时间戳(秒),与服务端时差不超过 ±300 秒
TOKEN 签名,算法见下文
Content-Type POST/PATCH/DELETE application/json

2.3 签名算法

TOKEN = MD5(secret + OID + T).toUpperCase()

Python 示例

import hashlib
import time

secret = "your_secret_key"
oid = "12345"
tid = "65804"
t = str(int(time.time()))
token = hashlib.md5(f"{secret}{oid}{t}".encode()).hexdigest().upper()

headers = {
    "OID": oid,
    "TID": tid,
    "T": t,
    "TOKEN": token,
    "Content-Type": "application/json",
}

cURL 示例

OID="12345"
TID="65804"
SECRET="your_secret_key"
T=$(date +%s)
TOKEN=$(echo -n "${SECRET}${OID}${T}" | md5sum | awk '{print toupper($1)}')

curl -s "https://api.dxbcrm.cn/open_api/ai_call/call_balance" \
  -H "OID: ${OID}" \
  -H "TID: ${TID}" \
  -H "T: ${T}" \
  -H "TOKEN: ${TOKEN}"

2.4 统一响应格式

{
  "code": 0,
  "msg": "操作成功",
  "data": {}
}
字段 类型 说明
code int 0 表示成功,非 0 表示失败,见 错误码
msg string 结果描述
data object 业务数据,失败时可能为空

3. 对接流程

1. 商务开通 OID / secret / TID;在 BOSS 配置 Agent,运营配置线路
2. POST /register_callback_url(register_type=realtime)注册话单回调
3. GET  /task_options → 获取 line_id、agent_id、agent_type
4. POST /task_manage → 创建外呼任务
5. POST /import_phone → 导入号码(可设 auto_run=1 自动启动)
6. 或通过 PATCH /task_manage 设置 target_status=5 启动、=6 暂停
7. 接收 Webhook 话单推送,或 POST /call_record 主动拉取

4. 接口详情

4.1 获取线路与 Agent 资源

GET /open_api/ai_call/task_options

Query 参数

参数 类型 必填 说明
agent_type int 1/2/3;不传则返回全部类型

响应示例

{
  "code": 0,
  "msg": "",
  "data": {
    "line_data": [
      { "id": 101, "line_name": "机器人线路A" }
    ],
    "team_max_concurrent": 50,
    "agent_data": [
      {
        "agent_id": 2001,
        "agent_name": "销售话术",
        "agent_type": 1,
        "note": "",
        "dialog_id": 68429,
        "is_tts": 0,
        "actor_id": 1243
      },
      {
        "agent_id": 10086,
        "agent_name": "销售助手",
        "agent_type": 2,
        "note": ""
      }
    ]
  }
}
字段 说明
line_data[].id 创建任务时传入的 line_id
team_max_concurrent 团队最大并发上限
agent_data[].agent_id Agent ID,创建任务时传入
agent_data[].agent_type Agent 类型:1/2/3
agent_data[].dialog_id/is_tts/actor_id agent_type=1 时返回

4.2 创建 / 修改任务

POST /open_api/ai_call/task_manage

请求示例(推荐)

{
  "task_name": "外呼任务",
  "agent_type": 2,
  "agent_id": 10086,
  "max_concurrency": 10,
  "line_id": 101,
  "valid_week": [1, 2, 3, 4, 5],
  "work_time": ["09:00:00", "20:00:00"],
  "push_willing_level": [1, 2, 3, 4]
}

兼容请求(向量相似度老对接方)

仅使用向量相似度算法(agent_type=1)时,可不传 agent_type,改用 dialog_res_id

{
  "task_name": "外呼任务",
  "max_concurrency": 10,
  "line_id": 101,
  "task_type": 3,
  "dialog_res_id": 2001,
  "valid_week": [1, 2, 3, 4, 5],
  "work_time": ["09:00:00", "20:00:00"],
  "push_willing_level": [1, 2, 3, 4]
}

字段说明

字段 类型 必填 说明
task_name string 任务名称
max_concurrency int 最大并发数
line_id int 线路 ID,取自 task_options
valid_week array 可外呼星期,1(周一)~ 7(周日)
work_time array 外呼时段 [开始, 结束],如 ["09:00:00","20:00:00"]
push_willing_level array 需回调推送的意向等级,最多 4 个
agent_type int 是* 1/2/3;老兼容请求可省略
agent_id int 是* Agent ID;agent_type=1 时可用 dialog_res_id 代替
task_type int 老请求必填 3 表示 AI 外呼;agent_type=2/3 可省略,默认 3
task_id int 传入则修改已有任务

响应示例

{
  "code": 0,
  "msg": "操作成功",
  "data": {
    "task_id": 98765,
    "agent_type": 2
  }
}

4.3 启动 / 暂停任务

PATCH /open_api/ai_call/task_manage

请求示例

{
  "task_id": 98765,
  "target_status": 5
}
target_status 含义
5 启动(运行中)
6 暂停

话费余额不足时返回错误码 838


4.4 删除任务

DELETE /open_api/ai_call/task_manage

请求示例

{ "task_id": 98765 }

4.5 任务列表

GET /open_api/ai_call/task_list

Query 参数

参数 类型 必填 说明
page int 页码,默认 1
page_size int 每页条数,默认 10
task_id int 按任务 ID 筛选
task_status int 按任务状态筛选,见 附录
task_type int 任务类型,3 为 AI 外呼

响应示例

{
  "code": 0,
  "msg": "",
  "data": {
    "total": 1,
    "task_list": [
      {
        "task_id": 98765,
        "task_name": "外呼任务",
        "task_status": 5,
        "phone_count": 100,
        "uncalled_count": 60,
        "percent": "40.0%",
        "agent_type": 2,
        "agent_id": 10086,
        "agent_name": "销售助手"
      }
    ]
  }
}

4.6 导入号码

POST /open_api/ai_call/import_phone

请求示例

{
  "task_id": 98765,
  "phone_list": [
    {
      "phone_number": "13800138000",
      "name": "张三",
      "company": "某某公司",
      "note": "",
      "address": "",
      "variables": { "product": "年卡" }
    }
  ],
  "auto_run": 1,
  "is_async": 1
}

字段说明

字段 类型 必填 说明
task_id int 任务 ID
phone_list array 号码列表
phone_list[].phone_number string 手机号码
phone_list[].name string 客户姓名
phone_list[].company string 公司名称
phone_list[].note string 备注
phone_list[].address string 地址
phone_list[].variables object 话术变量,键值对
auto_run int 1 导入后自动启动任务
is_async int 1 异步导入(推荐)

同一批次内按 phone_number 自动去重,重复号码仅保留第一条。


4.7 拉取话单

POST /open_api/ai_call/call_record

请求示例

{
  "page": 1,
  "task_id": 98765,
  "phone_number": "",
  "call_time": ["2026-07-01", "2026-07-10"]
}
字段 类型 必填 说明
page int 页码,每页 20 条
task_id int 按任务 ID 筛选
phone_number string 按号码筛选
call_time array 通话日期范围 [开始, 结束],格式 YYYY-MM-DD

响应示例

{
  "code": 0,
  "msg": "",
  "data": {
    "total": 1,
    "result": [
      {
        "phone_number": "13800138000",
        "c_name": "张三",
        "call_status": 1,
        "call_len": 45,
        "call_time": "2026-07-10 14:30:00",
        "willing_id": 1,
        "task_id": 98765,
        "record_url": "https://api.dxbcrm.cn/nas/playback/xxx.mp3?call_date=2026-07-10",
        "agent_type": 2,
        "agent_id": 10086,
        "agent_name": "销售助手"
      }
    ]
  }
}

4.8 话费余额

GET /open_api/ai_call/call_balance

响应示例

{
  "code": 0,
  "msg": "查询成功",
  "data": {
    "user_balance": [
      { "name": "话费余额", "balance": "128.50元" }
    ]
  }
}

4.9 注册回调

POST /open_api/ai_call/register_callback_url

请求示例

{
  "callback_url": "https://partner.example.com/webhook/cdr",
  "register_type": "realtime"
}
register_type 说明
realtime 每通通话结束后推送话单
task_result 任务全部完成后推送
task_upload 号码异步导入完成后推送

按 OP 维度注册,同类型重复注册将覆盖旧地址。


5. 回调推送(平台 → 对接方)

对接方需提供可公网访问的 HTTPS 地址,并在收到推送后 5 秒内 返回:

{ "code": 0, "msg": "ok" }

5.1 实时话单(realtime)

推送 Body 示例

{
  "callback_type": "realtime",
  "tid": 65804,
  "task_id": 98765,
  "phone_number": "13800138000",
  "c_name": "张三",
  "company": "某某公司",
  "note": "",
  "address": "",
  "call_status": 1,
  "call_len": 45,
  "call_time": "2026-07-10 14:30:00",
  "dialog_round": 6,
  "willing_id": 1,
  "record_url": "https://api.dxbcrm.cn/nas/playback/xxx.mp3?call_date=2026-07-10",
  "dialog_name": "销售助手",
  "actor_name": "",
  "agent_type": 2,
  "agent_id": 10086,
  "agent_name": "销售助手",
  "is_complete": 1,
  "topic_info": [],
  "dialog_txt": [
    { "seq_id": 1, "speaker": 0, "text": "您好..." },
    { "seq_id": 2, "speaker": 1, "text": "你好" }
  ]
}

主要字段说明

字段 说明
callback_type 固定为 realtime
tid 业务账户 UID
call_status 通话状态:1 接通,2 未接通
call_len 通话时长(秒)
willing_id 意向等级,见 附录
record_url 录音文件地址
agent_type / agent_id / agent_name Agent 信息
dialog_name agent_type=1 为话术名;2/3 为 Agent 名
actor_name agent_type=1 时有值
dialog_txt[].speaker 0 机器人,1 客户

5.2 任务完成 / 导入完成

任务完成(task_result)

{ "callback_type": "task_result", "task_id": 98765, "tid": 65804 }

号码导入完成(task_upload)

{ "callback_type": "task_upload", "task_id": 98765, "tid": 65804 }

6. 错误码

code 说明
0 成功
1 签名错误或 Header 缺失
6 时间戳无效(超出 ±300 秒)
287 参数校验失败
722 线路或 Agent 资源无效,或类型不匹配
723 TID 无效或不属于该 OP
726 任务已开始外呼,无法再次导入号码
838 话费余额不足
947 任务号码导入中,请勿重复导入

7. 附录

7.1 任务状态 task_status

含义
1 无号码
2 导入中
3 导入失败
4 未启动
5 运行中
6 已暂停
7 已完成
8 无线路

7.2 意向等级 willing_id

含义
1 A 类(高意向)
2 B 类
3 C 类
4 D 类
5 E 类
6 未评级

7.3 Agent 类型 agent_type

说明
1 传统向量大模型 Agent
2 三段式大模型 Agent
3 多模态大模型 Agent