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

Nhập cuộc trò chuyện và khách hàng

Bắt đầu một lượt nhập trong ứng dụng nhân viên hỗ trợ tại Ứng dụng > Nhập từ nền tảng khác, hoặc bằng API. Token cần settings.manage, cùng phạm vi quyền mà từng loại bản ghi ghi vào: team.manage cho nhóm và nhân viên hỗ trợ, tags.manage cho thẻ, canned.manage cho câu trả lời mẫu, customers.write cho khách hàng, và archives.write cùng customers.write cho cuộc trò chuyện. Mỗi lần chỉ chạy một lượt nhập. Chạy lại cùng một lượt nhập là an toàn: những gì đã nhập sẽ được bỏ qua, và các cuộc trò chuyện giữ nguyên ID và thời gian gốc. Nhân viên hỗ trợ được thêm dưới dạng lời mời, vì mật khẩu không bao giờ rời khỏi nền tảng kia.

TừCách thứcDữ liệu được chuyển
LiveChatQua API của nền tảng đó, bằng token của bạngroups, agents, tags, canned responses, customers, archives
IntercomQua API của nền tảng đó, bằng token của bạngroups, agents, tags, customers, archives
CrispQua API của nền tảng đó, bằng token của bạnagents, customers, archives
Zendesk ChatQua API của nền tảng đó, bằng token của bạngroups, agents, canned responses, archives
tawk.toTệp xuất (json, csv)customers, archives
TidioTệp xuất (csv, json)customers, archives
OlarkTệp xuất (csv, json)customers, archives
CSV or JSON fileTệp xuất (json, ndjson, csv)groups, agents, tags, canned responses, customers, archives

Với nguồn qua API, biểu mẫu nhập sẽ hỏi thông tin đăng nhập cần thiết và cho biết nơi tìm chúng; thông tin này được lưu ở dạng mã hóa cho đến khi lượt nhập kết thúc. GET /v1/imports/sources liệt kê cùng danh sách này.

Khi dữ liệu của bạn đến từ bất kỳ nơi nào khác, hãy đưa nó vào một trong các tệp sau. source_id của một bản ghi là ID riêng của bạn cho bản ghi đó, giúp lần chạy thứ hai không nhập trùng; thẻ thì được khớp theo name.

Một đối tượng, mỗi loại bản ghi là một danh sách. Bỏ qua những loại bạn không có:

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." } }
]
}
]
}
]
}

Các trường bắt buộc được in đậm; mọi trường khác đều có thể bỏ qua.

  • groups: source_id, name.
  • agents: source_id, email, name, role (admin hoặc agent), group_source_ids.
  • tags: name, color dạng #rrggbb.
  • canned_responses: source_id, text, shortcuts, group_source_id.
  • customers: source_id, name, email, phone, external_user_id (ID người dùng riêng của bạn), session_fields dạng các cặp tên và giá trị, first_seen_at, last_seen_at.
  • archives: một cuộc trò chuyện với source_id, customer của nó, và threads (ít nhất một). Một luồng có source_id, created_at, events, cùng closed_at, tags, rating (good hoặc bad) và group_source_id. Một sự kiện có created_at, một author (với type là customer, agent hoặc system), một body, cùng source_id và visibility (agents cho ghi chú nội bộ). type của body là message với text, file với url và name, filled_form với form_kind và answers, system với text, hoặc custom.

Thời gian theo ISO 8601 với Z hoặc độ lệch múi giờ, chẳng hạn 2026-03-02T10:15:00Z hoặc 2026-03-02T17:15:00+07:00; ô CSV cũng nhận giây hoặc mili giây Unix.

Mỗi dòng một bản ghi, loại bản ghi nằm trong type. Dùng định dạng này cho tệp xuất lớn: nó được đọc theo luồng.

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?"}}]}]}

Mỗi loại bản ghi một tệp, dòng tiêu đề nêu tên các trường của bản ghi, và loại bản ghi được chỉ định khi bắt đầu lượt nhập (csv_entity). Tệp CSV archives có mỗi tin nhắn một dòng, các dòng của cùng một cuộc trò chuyện nằm liền nhau:

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?

Tệp CSV hoặc NDJSON có thể lớn tối đa 50 MB; tệp JSON, vì được đọc toàn bộ, tối đa 20 MB.

Tải tệp lên một URL đã ký, bắt đầu lượt nhập và thăm dò trạng thái của nó:

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 }));

Lượt nhập bị lỗi hoặc đã hủy sẽ tiếp tục từ chỗ dừng với POST /v1/imports/{id}:resume; POST /v1/imports/{id}:cancel dừng một lượt nhập đang chạy.