Lewati ke konten

Impor riwayat chat dan kontak

Mulai impor di aplikasi agen pada Aplikasi > Impor dari platform lain, atau lewat API. Token memerlukan settings.manage, ditambah cakupan izin untuk setiap jenis record yang ditulis: team.manage untuk grup dan agen, tags.manage untuk tag, canned.manage untuk balasan tersimpan, customers.write untuk pelanggan, serta archives.write bersama customers.write untuk chat. Hanya satu impor yang berjalan dalam satu waktu. Menjalankan impor yang sama lagi aman: data yang sudah diimpor akan dilewati, dan chat tetap memakai ID serta waktu aslinya. Agen masuk sebagai undangan, karena kata sandi tidak pernah keluar dari platform lain.

DariCaraYang ikut dipindahkan
LiveChatLewat API-nya, dengan token Andagroups, agents, tags, canned responses, customers, archives
IntercomLewat API-nya, dengan token Andagroups, agents, tags, customers, archives
CrispLewat API-nya, dengan token Andaagents, customers, archives
Zendesk ChatLewat API-nya, dengan token Andagroups, agents, canned responses, archives
tawk.toFile ekspor (json, csv)customers, archives
TidioFile ekspor (csv, json)customers, archives
OlarkFile ekspor (csv, json)customers, archives
CSV or JSON fileFile ekspor (json, ndjson, csv)groups, agents, tags, canned responses, customers, archives

Untuk sumber API, formulir impor meminta kredensial yang diperlukan dan menjelaskan tempat menemukannya; kredensial itu disimpan terenkripsi sampai impor selesai. GET /v1/imports/sources mencantumkan hal yang sama.

Jika data Anda berasal dari tempat lain, masukkan ke salah satu file berikut. source_id sebuah record adalah ID milik Anda sendiri untuk record tersebut, dan itulah yang mencegah record diimpor dua kali pada proses kedua; tag dicocokkan berdasarkan name.

Satu objek, dengan satu daftar per jenis record. Hilangkan jenis yang tidak Anda miliki:

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

Field wajib dicetak tebal; field lainnya boleh dihilangkan.

  • groups: source_id, name.
  • agents: source_id, email, name, role (admin atau agent), group_source_ids.
  • tags: name, color dalam format #rrggbb.
  • canned_responses: source_id, text, shortcuts, group_source_id.
  • customers: source_id, name, email, phone, external_user_id (ID pengguna milik Anda sendiri), session_fields sebagai pasangan nama dan nilai, first_seen_at, last_seen_at.
  • archives: chat dengan source_id, customer-nya, dan threads (minimal satu). Sebuah thread memiliki source_id, created_at, events, serta closed_at, tags, rating (good atau bad), dan group_source_id. Sebuah event memiliki created_at, author (dengan type berupa customer, agent, atau system), body, serta source_id dan visibility (agents untuk catatan internal). type pada body adalah message dengan text, file dengan url dan name, filled_form dengan form_kind dan answers, system dengan text, atau custom.

Waktu ditulis dalam ISO 8601 dengan Z atau offset, misalnya 2026-03-02T10:15:00Z atau 2026-03-02T17:15:00+07:00; sel CSV juga menerima detik atau milidetik Unix.

Satu record per baris, dengan jenisnya di type. Gunakan format ini untuk ekspor besar: datanya di-stream.

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

Satu file per jenis record, dengan header yang menyebutkan field record, dan jenisnya ditentukan saat impor dimulai (csv_entity). CSV archives memiliki satu baris per pesan, dengan baris-baris dari satu chat berurutan:

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?

File CSV atau NDJSON boleh berukuran hingga 50 MB; file JSON, yang dibaca utuh, hingga 20 MB.

Unggah file ke signed URL, mulai impor, lalu lakukan polling:

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

Impor yang gagal atau dibatalkan dapat dilanjutkan dari titik berhentinya dengan POST /v1/imports/{id}:resume; POST /v1/imports/{id}:cancel menghentikan impor yang sedang berjalan.