> For the complete documentation index, see [llms.txt](https://apidocs.nhanh.vn/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://apidocs.nhanh.vn/v3/vpage/conversation/reply.md).

# Trả lời hội thoại

* Trả lời hội thoại tin nhắn, bình luận.

## Request

* Xem sample Postman [tại đây](https://www.postman.com/nhanh-vn/vpage-open-nhanh-vn/request/aciyuok/reply-conversation?tab=body).

```curl
curl --location 'https://vpage.open.nhanh.vn/v3.0/conversation/reply?appId={{appId}}&businessId={{businessId}}' \
--header 'Authorization: {{accessToken}}' \
--header 'Content-Type: application/json' \
--data '{
    "pageId": "{{pageId}}",
    "conversationId": "{{conversationId}}",
    "messageType": {{messageType}} 
    "message": "{{message}}", 
    "recipientId": "{{recipientId}}", 
    "attachments": {{attachments}}
}'
```

### Common params

| Param              | Type                          | Mô tả                                                                                                                           |
| ------------------ | ----------------------------- | ------------------------------------------------------------------------------------------------------------------------------- |
| `conversationId`   | string $$^{{\color{red}\*}}$$ | ID hội thoại                                                                                                                    |
| `pageId`           | string $$^{{\color{red}\*}}$$ | ID page/fanpage                                                                                                                 |
| `recipientId`      | string $$^{{\color{red}\*}}$$ | ID người nhận                                                                                                                   |
| `messageType`      | string                        | Loại tin nhắn.                                                                                                                  |
| `message`          | string                        | Nội dung text                                                                                                                   |
| `attachments`      | array                         | Danh sách URL file đính kèm                                                                                                     |
| `buttons`          | array                         | Danh sách nút bấm (chỉ button)                                                                                                  |
| `quickReplies`     | array                         | Danh sách nút trả lời nhanh (chỉ quickReply)                                                                                    |
| `galleryCards`     | array                         | Danh sách card carousel (chỉ gallery)                                                                                           |
| `replyToMessageId` | string                        | ID tin nhắn cần trả lời trực tiếp. Chỉ dùng được ở các kênh ghi rõ bên dưới. Tin nhắn phải thuộc đúng pageId và conversationId. |

***

### Reply to a message

Truyền ID của tin nhắn đã có trong hội thoại vào replyToMessageId để gửi một tin nhắn trả lời trực tiếp (quote/reply). Hệ thống tự lấy nội dung preview và dữ liệu quote cần thiết từ tin nhắn đã lưu.

| Channel            | Hỗ trợ | Điều kiện                            |
| ------------------ | :----: | ------------------------------------ |
| Zalo OA            |   Có   | Áp dụng cho text và image.           |
| Zalo Cá nhân       |   Có   | Áp dụng cho text, image và video.    |
| TikTok Business    |   Có   | Chỉ áp dụng khi messageType là text. |
| Facebook Messenger |  Không |                                      |
| Instagram          |  Không |                                      |
| TikTok Shop        |  Không |                                      |
| Shopee             |  Không |                                      |
| Lazada             |  Không |                                      |
| WhatsApp           |  Không |                                      |

***

### Text - Tin nhắn văn bản

```json
{
  "conversationId": "conv_123",
  "pageId": "page_001",
  "recipientId": "user_123",
  "messageType": "text",
  "message": "Xin chào! Chúng tôi có thể giúp gì cho bạn?"
}
```

### Image - Tin nhắn ảnh

Gửi 1 hoặc nhiều ảnh. Mỗi ảnh là 1 URL.

```json
{
  "conversationId": "conv_123",
  "pageId": "page_001",
  "recipientId": "user_123",
  "messageType": "image",
  "attachments": ["https://example.com/photo.jpg"]
}
```

Nhiều ảnh (chỉ Facebook hỗ trợ 1 request, các kênh khác gửi từng ảnh 1 request):

```json
{
  "conversationId": "conv_123",
  "pageId": "page_001",
  "recipientId": "user_123",
  "messageType": "image",
  "attachments": [
    "https://example.com/photo1.jpg",
    "https://example.com/photo2.jpg"
  ]
}
```

### Video - Tin nhắn video

```json
{
  "conversationId": "conv_123",
  "pageId": "page_001",
  "recipientId": "user_123",
  "messageType": "video",
  "attachments": ["https://example.com/video.mp4"]
}
```

### Audio - Tin nhắn âm thanh

```json
{
  "conversationId": "conv_123",
  "pageId": "page_001",
  "recipientId": "user_123",
  "messageType": "audio",
  "attachments": ["https://example.com/audio.mp3"]
}
```

### File - Tin nhắn file đính kèm

```json
{
  "conversationId": "conv_123",
  "pageId": "page_001",
  "recipientId": "user_123",
  "messageType": "file",
  "attachments": ["https://example.com/document.pdf"]
}
```

### Button - Tin nhắn có nút bấm (chỉ Facebook)

Gửi tin nhắn text kèm tối đa 3 nút bấm.

```json
{
  "conversationId": "conv_123",
  "pageId": "page_001",
  "recipientId": "user_123",
  "messageType": "button",
  "message": "Bạn muốn xem thông tin gì?",
  "buttons": [
    {"type": "block", "title": "Xem đơn hàng", "blockId": "block_order_123"},
    {"type": "url", "title": "Xem sản phẩm", "url": "https://example.com/products"},
    {"type": "phone_number", "title": "Gọi hỗ trợ", "phoneNumber": "0987654321"}
  ]
}
```

Các loại nút:

* `block`: trigger chatbot block khi user bấm (cần `blockId`)
* `url`: mở URL trong webview (cần `url`)
* `phone_number`: mở app điện thoại gọi (cần `phoneNumber`)

### Gallery/Carousel - Tin nhắn carousel (chỉ Facebook)

Gửi carousel tối đa 10 card, mỗi card có ảnh, tiêu đề và nút bấm.

```json
{
  "conversationId": "conv_123",
  "pageId": "page_001",
  "recipientId": "user_123",
  "messageType": "gallery",
  "galleryCards": [
    {
      "title": "Sản phẩm 1",
      "subtitle": "Giá: 100.000đ",
      "imageUrl": "https://example.com/product1.jpg",
      "link": "https://example.com/product/1",
      "buttons": [{"type": "block", "title": "Mua ngay", "blockId": "buy_123"}]
    }
  ]
}
```

### Quick Reply - Nút trả lời nhanh (chỉ Facebook)

```json
{
  "conversationId": "conv_123",
  "pageId": "page_001",
  "recipientId": "user_123",
  "messageType": "quickReply",
  "message": "Bạn muốn làm gì tiếp?",
  "quickReplies": [
    {"title": "Xem đơn hàng", "blockId": "block_order_123"},
    {"title": "Hỗ trợ"}
  ]
}
```

***

## Response

* Xem cấu trúc chung [tại đây](/v3/readme.md#response).

### Failed response

* Xem các mã lỗi chung [tại đây](/v3/readme.md#failed-response).

### Successful response

```json
{
    "code": 1,
    "data": {
        "conversation": {
            "id": "101286204573840_1155721606569955_6289022961168486",
            "type": 1,
            "channel": 1,
            "pageId": "101286204573840",
            "pageUserId": "6289022961168486",
            "pageUserName": "Lý Sơn",
            "pagePostId": "101286204573840_1155721606569955",
            "commentId": "1155721606569955_722713100448041",
            "lastMessage": "open cmt 6",
            "status": 2,
            "hasPhone": false,
            "hasReply": true,
            "updatedAt": 1753349855,
            "createdAt": 1750066386,
            "customerAvatar": "https://example.com/user_1.jpg",
            "isFromLive": 0,
            "isSentPrivateMessage": 1,
            "postIds": [
                "101286204573840_1155721606569955"
            ],
        }
    }
}
```
