# API Lịch sử hội thoại

#### 🧩 Endpoint

```
GET https://api.dev.kamimind.ai/api/bot/story/detail/{storyId}
```

***

#### 🧾 Ví dụ lệnh `curl`

```bash
curl --location 'https://api.dev.kamimind.ai/api/bot/story/detail/{storyId}' \
  --header 'accept: application/json' \
  --header 'Authorization: Bearer *********************'
```

> 🔸 Thay `{storyId}` bằng ID hội thoại thực tế bạn muốn truy xuất\
> (ví dụ: `4f4c5ed4-e084-4c53-a20a-9c7cf88ea72e`).

***

#### 🔐 Xác thực

* Bắt buộc dùng **Bearer Token** trong phần header:

  ```
  Authorization: Bearer <token>
  ```
* Token được cấp bởi hệ thống KamiMind để xác định người dùng và quyền truy cập.

***

#### ⚙️ Tham số đường dẫn (Path Parameter)

| Tên       | Bắt buộc | Kiểu     | Mô tả                                                                                                       |
| --------- | -------- | -------- | ----------------------------------------------------------------------------------------------------------- |
| `storyId` | Có       | `string` | Mã định danh của hội thoại cần lấy thông tin. Lấy từ phản hồi của API chat khi tạo hoặc tiếp tục hội thoại. |

#### 📥 Phản hồi (Response)

**✅ Ví dụ phản hồi thành công**

```json
{
  "success": true,
  "data": {
    "botToken": "d701296c-3062-4326-bb60-68a4dc252646",
    "storyId": "4f4c5ed4-e084-4c53-a20a-9c7cf88ea72e",
    "storyName": "xin chào",
    "platformSource": "KAMI",
    "latestMessage": "xin chào",
    "createTime": "2025-10-03T10:39:14.399",
    "modifiedTime": "2025-10-03T10:39:22.032",
    "totalHist": 2,
    "history": [
      {
        "chat_id": "39fed64b-2a80-44e4-911f-57a0071a048d",
        "actor": "CLIENT",
        "question": "xin chào",
        "createTime": "03/10/2025 10:39:15"
      },
      {
        "chat_id": "14925777-65ee-4f55-b37f-78d3e37353db",
        "actor": "AGENT",
        "answer": "Chào bạn, tôi có thể giúp gì cho bạn?",
        "createTime": "03/10/2025 10:39:22"
      }
    ]
  }
}
```

***

#### 📄 Cấu trúc phản hồi

| Trường           | Kiểu      | Mô tả                                           |
| ---------------- | --------- | ----------------------------------------------- |
| `success`        | `boolean` | Kết quả xử lý yêu cầu (`true` nếu thành công).  |
| `data.botToken`  | `string`  | Mã của Trợ lý AI đang tham gia hội thoại.       |
| `data.storyId`   | `string`  | ID duy nhất của cuộc hội thoại.                 |
| `data.storyName` | `string`  | Tên hoặc nội dung đầu tiên của hội thoại.       |
| `data.totalHist` | `number`  | Tổng số tin nhắn trong hội thoại.               |
| `data.history`   | `array`   | Danh sách các tin nhắn (theo thứ tự thời gian). |

***

#### 💬 Cấu trúc mỗi phần tử trong `history`

| Trường             | Kiểu     | Mô tả                                                                                     |
| ------------------ | -------- | ----------------------------------------------------------------------------------------- |
| `chat_id`          | `string` | ID tin nhắn.                                                                              |
| `story_id`         | `string` | ID của hội thoại chứa tin nhắn này.                                                       |
| `actor`            | `string` | Vai trò người gửi: `"CLIENT"` (người dùng) hoặc `"AGENT"` (Trợ lý AI).                    |
| `question`         | `string` | Nội dung tin nhắn người dùng gửi.                                                         |
| `answer`           | `string` | Phản hồi từ Trợ lý AI (nếu có).                                                           |
| `createTime`       | `string` | Thời gian tạo tin nhắn.                                                                   |
| `chunks`           | `array`  | Các bước suy nghĩ hoặc quá trình sinh phản hồi của Trợ lý AI  (nếu bật ghi log chi tiết). |
| `attachments`      | `array`  | Danh sách tệp người dùng gửi.                                                             |
| `agentAttachments` | `array`  | Danh sách tệp do Trợ lý AI gửi lại.                                                       |


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://book.kamimind.ai/api-tich-hop/api-lich-su-hoi-thoai.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
