跳转到内容

导入聊天记录和客户数据

您可以在客服应用的应用 > 从其他平台导入中开始导入,也可以通过 API 导入。令牌需要 settings.manage,以及每种记录类型写入所需的权限范围:分组和客服需要 team.manage,标签需要 tags.manage,快捷回复需要 canned.manage,客户需要 customers.write,聊天则需要 archives.write 和 customers.write。同一时间只能运行一个导入。重复运行同一导入是安全的:已导入的内容会被跳过,聊天会保留原始的 ID 和时间。客服会以邀请的形式导入,因为密码永远不会离开原平台。

来源方式导入的内容
LiveChat通过对方 API,使用您的令牌groups, agents, tags, canned responses, customers, archives
Intercom通过对方 API,使用您的令牌groups, agents, tags, customers, archives
Crisp通过对方 API,使用您的令牌agents, customers, archives
Zendesk Chat通过对方 API,使用您的令牌groups, agents, canned responses, archives
tawk.to导出文件(json, csv)customers, archives
Tidio导出文件(csv, json)customers, archives
Olark导出文件(csv, json)customers, archives
CSV or JSON file导出文件(json, ndjson, csv)groups, agents, tags, canned responses, customers, archives

对于 API 来源,导入表单会要求填写所需的凭据,并说明在哪里可以找到;凭据在导入结束之前会加密保存。GET /v1/imports/sources 也会列出相同的信息。

如果您的数据来自其他地方,请将其整理为以下任一格式的文件。记录的 source_id 是您自己为它设定的 ID,正是它确保再次运行时不会重复导入;标签则按 name 匹配。

一个对象,每种记录类型对应一个列表。没有的类型可以省略:

import.json
{
"groups": [{ "source_id": "g-sales", "name": "Sales" }],
"agents": [{ "source_id": "a-1", "email": "maria@example.com", "name": "Maria Lopez", "role": "agent", "group_source_ids": ["g-sales"] }],
"tags": [{ "name": "refund", "color": "#e5484d" }],
"canned_responses": [{ "source_id": "c-1", "text": "Thanks for reaching out! How can I help?", "shortcuts": ["hi"], "group_source_id": null }],
"customers": [{ "source_id": "u-1", "name": "Ana Silva", "email": "ana@example.com", "phone": null, "external_user_id": "user-1001", "session_fields": [["plan", "pro"]] }],
"archives": [
{
"source_id": "chat-1",
"customer": { "source_id": "u-1", "name": "Ana Silva", "email": "ana@example.com" },
"threads": [
{
"source_id": "thread-1",
"created_at": "2026-03-02T10:15:00Z",
"closed_at": "2026-03-02T10:21:00Z",
"tags": ["refund"],
"rating": "good",
"group_source_id": "g-sales",
"events": [
{ "source_id": "e-1", "created_at": "2026-03-02T10:15:00Z", "author": { "type": "customer", "source_id": "u-1", "name": "Ana Silva" }, "body": { "type": "message", "text": "Hi, can I get a refund for order 1001?" } },
{ "source_id": "e-2", "created_at": "2026-03-02T10:16:30Z", "author": { "type": "agent", "source_id": "a-1", "name": "Maria Lopez", "email": "maria@example.com" }, "body": { "type": "message", "text": "Of course. I have started it, you will see it in 3 to 5 days." } },
{ "source_id": "e-3", "created_at": "2026-03-02T10:17:00Z", "author": { "type": "agent", "source_id": "a-1", "name": "Maria Lopez" }, "visibility": "agents", "body": { "type": "message", "text": "Refund approved under the 30-day policy." } }
]
}
]
}
]
}

必填字段以粗体标出;其余字段均可省略。

  • groups:source_id、name。
  • agents:source_id、email、name、role(admin 或 agent)、group_source_ids。
  • tags:name、color(格式为 #rrggbb)。
  • canned_responses:source_id、text、shortcuts、group_source_id。
  • customers:source_id、name、email、phone、external_user_id(您自己的用户 ID)、session_fields(名称与值的键值对)、first_seen_at、last_seen_at。
  • archives:一个聊天,包含 source_id、其 customer,以及 threads(至少一个)。会话包含 source_id、created_at、events,以及 closed_at、tags、rating(good 或 bad)和 group_source_id。事件包含 created_at、一个 author(其 type 为 customer、agent 或 system)、一个 body,以及 source_id 和 visibility(agents 表示内部备注)。body 的 type 可以是:message,带 text;file,带 url 和 name;filled_form,带 form_kind 和 answers;system,带 text;或 custom。

时间采用 ISO 8601 格式,带 Z 或时区偏移,例如 2026-03-02T10:15:00Z 或 2026-03-02T17:15:00+07:00;CSV 单元格还接受 Unix 秒或毫秒。

每行一条记录,记录类型写在 type 中。适合大型导出:它支持流式处理。

import.ndjson
{"type": "groups", "source_id": "g-sales", "name": "Sales"}
{"type": "tags", "name": "refund", "color": "#e5484d"}
{"type": "customers", "source_id": "u-1", "name": "Ana Silva", "email": "ana@example.com"}
{"type": "archives", "source_id": "chat-1", "customer": {"source_id": "u-1", "name": "Ana Silva"}, "threads": [{"source_id": "thread-1", "created_at": "2026-03-02T10:15:00Z", "events": [{"created_at": "2026-03-02T10:15:00Z", "author": {"type": "customer", "source_id": "u-1"}, "body": {"type": "message", "text": "Hi, can I get a refund for order 1001?"}}]}]}

每种记录类型一个文件,表头列出该记录的字段,记录类型在开始导入时指定(csv_entity)。聊天记录(archives)CSV 每条消息占一行,同一聊天的各行需放在一起:

archives.csv
chat_id,thread_id,created_at,author_type,author_name,author_email,text
chat-1,thread-1,2026-03-02T10:15:00Z,customer,Ana Silva,ana@example.com,"Hi, can I get a refund for order 1001?"
chat-1,thread-1,2026-03-02T10:16:30Z,agent,Maria Lopez,maria@example.com,"Of course. I have started it, you will see it in 3 to 5 days."
chat-2,thread-2,2026-03-03T08:02:00Z,customer,Joe Park,joe@example.com,Do you ship to Canada?

CSV 或 NDJSON 文件最大 50 MB;JSON 文件需要整体读取,最大 20 MB。

将文件上传到签名 URL,启动导入,然后轮询其状态:

import-file.mjs
// Import an export file in the generic format, then wait for the import to finish. Node 18 or later.
// Usage: node import-file.mjs import-generic.json (a CSV also needs its entity: archives.csv archives)
import { readFile } from "node:fs/promises";
import { basename } from "node:path";
const api = process.env.C2R_API || "https://api.click2reply.com";
const auth = { authorization: `Bearer ${process.env.C2R_TOKEN}` };
const [path, csvEntity] = process.argv.slice(2);
async function call(route, body) {
const res = await fetch(`${api}${route}`, body === undefined ? { headers: auth } : { method: "POST", headers: { ...auth, "content-type": "application/json" }, body: JSON.stringify(body) });
const json = await res.json();
if (!res.ok) throw new Error(`${res.status} ${json.error.code}: ${json.error.message}`);
return json;
}
// 1. A signed URL to upload the file to, then the upload itself.
const file = await readFile(path);
const ticket = await call("/v1/imports:upload_url", { name: basename(path), size: file.length });
const put = await fetch(ticket.upload_url, { method: "PUT", body: file });
if (!put.ok) throw new Error(`upload answered ${put.status}`);
// 2. Start the import. Leave out options.include to import every record type the file holds.
let job = await call("/v1/imports", { source: "generic", file_key: ticket.file_key, options: { csv_entity: csvEntity ?? null } });
// 3. Poll until it ends; progress counts what each step imported, skipped and failed.
while (job.status === "queued" || job.status === "running") {
await new Promise((r) => setTimeout(r, 3000));
job = await call(`/v1/imports/${job.id}`);
}
console.log(JSON.stringify({ id: job.id, status: job.status, error_code: job.error_code, progress: job.progress }));

失败或已取消的导入可以通过 POST /v1/imports/{id}:resume 从中断处继续;POST /v1/imports/{id}:cancel 可以停止正在运行的导入。