# CareSoft Live Chat SDK – API Hỗ Trợ Tương Tác Widget

#### **Cách sử dụng**

Sau khi đã nhúng thành công widget Live Chat vào website, bạn có thể tương tác với box chat thông qua hàm toàn cục:

```javascript
cslw(action, params)
```

* `action` *(string)*: Tên hành động muốn thực hiện.
* `params` *(object)*: Tham số tùy chọn, chứa dữ liệu bổ sung phục vụ cho action.

⚠️ **Lưu ý:** Mọi action chỉ hoạt động sau khi box chat đã được khởi tạo thành công.

#### **Danh sách các action hỗ trợ**

| Tên Action            | Mô tả                                                | Ví dụ sử dụng                                                       |
| --------------------- | ---------------------------------------------------- | ------------------------------------------------------------------- |
| `open-widget`         | Mở widget chat lên (trạng thái hiển thị).            | `cslw('open-widget')`                                               |
| `reload-widget`       | Tải lại (re-initialize) widget chat.                 | `cslw('reload-widget')`                                             |
| `change-chat-service` | Thay đổi dịch vụ chat hiện tại theo `service_id`.    | `cslw('change-chat-service', { service_id: 123 })`                  |
| `compose-message`     | Gửi sẵn nội dung vào ô nhập tin nhắn trong box chat. | `cslw('compose-message', { message: 'Xin chào, tôi cần hỗ trợ!' })` |

#### **Ví dụ thực tế**

```html
<!-- Mở widget khi người dùng click nút -->
<button onclick="cslw('open-widget')">Chat với CSKH</button>

<!-- Chuyển sang dịch vụ hỗ trợ kỹ thuật -->
<button onclick="cslw('change-chat-service', { service_id: 456 })">Liên hệ bộ phận kỹ thuật</button>
```

***

#### 📍 **Ghi chú quan trọng**

* Chỉ nên gọi `cslw(...)` **sau khi widget đã được khởi tạo hoàn tất**.


---

# 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://docs.caresoft.vn/danh-muc/nhung-live-chat-ticket-form/nhung-live-chat-vao-website/caresoft-live-chat-sdk-api-ho-tro-tuong-tac-widget.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.
