API
อ่านข้อความย้อนหลัง
อ่านประวัติการคุยเพื่อส่งให้ AI หรือเก็บในระบบของคุณ เรียงจากเก่าไปใหม่
GET/threads/{id}/messagesสิทธิ์ read
พารามิเตอร์#
| ชื่อ | ความหมาย |
|---|---|
limit | จำนวนข้อความ ไม่เกิน 200 ค่าเริ่มต้น 50 |
before | เอาข้อความที่เก่ากว่าเลขนี้ ใช้ค่าจาก next_before |
curl "https://office.takkub.com/api/v1/threads/1042/messages?limit=30" \
-H "Authorization: Bearer YOUR_API_KEY"{
"ok": true,
"data": {
"messages": [
{
"id": 6,
"sent_at": 1793857400000,
"from": "office",
"type": "text",
"text": "สวัสดีค่ะ",
"file": null,
"location": null
},
{
"id": 7,
"sent_at": 1793857502513,
"from": "customer",
"type": "image",
"text": null,
"file": { "id": "0123456789abcdef0123456789abcdef", "name": "menu.jpg", "size": 120400, "width": 1200, "height": 800, "duration_ms": null },
"location": null
}
],
"next_before": 6
}
}อ่านย้อนหลังทีละหน้า#
ส่ง next_before กลับไปเป็น before จนกว่าค่าจะเป็น null
async function loadAll(threadId) {
const all = [];
let before = 0;
do {
const url = `${BASE}/threads/${threadId}/messages?limit=200${before ? `&before=${before}` : ''}`;
const { data } = await (await fetch(url, { headers: AUTH })).json();
all.unshift(...data.messages);
before = data.next_before;
} while (before);
return all;
}def load_all(thread_id):
all_messages, before = [], 0
while True:
params = {"limit": 200, **({"before": before} if before else {})}
data = requests.get(f"{BASE}/threads/{thread_id}/messages", params=params, headers=AUTH, timeout=10).json()["data"]
all_messages = data["messages"] + all_messages
before = data["next_before"]
if not before:
return all_messagesข้อความที่ถูกลบจะไม่ถูกส่งมา เลข id จึงอาจข้ามได้