{
  "openapi": "3.0.3",
  "paths": {
    "/api/open/chat/v1/pages": {
      "get": {
        "description": "Trả đúng một trang: trang mà khoá Chat được tạo cho. Đây là cách nhanh nhất để kiểm khoá hoạt động.",
        "summary": "Trang chat của khoá",
        "tags": [],
        "parameters": [],
        "responses": {
          "200": {
            "description": "Danh sách trang.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Page"
                      },
                      "description": "Các trang."
                    }
                  },
                  "required": [
                    "data"
                  ],
                  "description": "Danh sách trang."
                },
                "example": {
                  "data": [
                    {
                      "id": "018f3b8e-1c2d-7a4b-9c3d-000000001301",
                      "providerPageId": "1090000000000001",
                      "provider": "facebook_page",
                      "pageName": "Shop Mẫu",
                      "avatarUrl": null,
                      "status": "active"
                    }
                  ]
                }
              }
            },
            "headers": {
              "X-RateLimit-Limit": {
                "description": "Hạn mức số yêu cầu trong cửa sổ hiện tại.",
                "schema": {
                  "type": "integer"
                }
              },
              "X-RateLimit-Remaining": {
                "description": "Số yêu cầu còn lại trong cửa sổ hiện tại.",
                "schema": {
                  "type": "integer"
                }
              },
              "X-RateLimit-Reset": {
                "description": "Số giây còn lại tới khi cửa sổ làm mới.",
                "schema": {
                  "type": "integer"
                }
              }
            }
          },
          "401": {
            "description": "Thiếu khoá API, khoá sai hoặc đã bị thu hồi.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Khoá không có quyền thực hiện thao tác.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "429": {
            "description": "Vượt hạn mức gọi API: chờ theo header `Retry-After` rồi thử lại.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            },
            "headers": {
              "Retry-After": {
                "description": "Số giây phải chờ trước khi thử lại.",
                "schema": {
                  "type": "integer"
                }
              }
            }
          },
          "500": {
            "description": "Lỗi hệ thống.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        },
        "operationId": "listPages",
        "x-required-permissions": {
          "anyOf": [
            "social.pages.read"
          ],
          "allOf": []
        },
        "x-error-codes": [
          {
            "code": "invalid-api-key",
            "status": 401,
            "title": "Khoá API thiếu, sai hoặc đã bị thu hồi"
          },
          {
            "code": "insufficient-permission",
            "status": 403,
            "title": "Khoá API không có quyền thực hiện thao tác này"
          },
          {
            "code": "rate-limited",
            "status": 429,
            "title": "Vượt hạn mức gọi API, hãy chờ rồi thử lại"
          },
          {
            "code": "internal-error",
            "status": 500,
            "title": "Lỗi hệ thống"
          }
        ]
      }
    },
    "/api/open/chat/v1/conversations": {
      "get": {
        "description": "Phân trang theo con trỏ, hội thoại có tin mới nhất trước. Khoá chỉ thấy hội thoại của trang của nó; `pageId` (mã trang trong DANIX, `id` của `GET /pages`) khác trang ấy bị từ chối `not-found`. Hội thoại chưa có tin nào không được liệt kê (vẫn đọc được theo id).",
        "summary": "Liệt kê hội thoại",
        "tags": [],
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "description": "Số dòng mỗi trang, từ 1 đến 100. Mặc định 50.",
            "schema": {
              "default": 50,
              "type": "integer",
              "minimum": 1,
              "maximum": 100
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "description": "Con trỏ lấy từ `nextCursor` của trang trước, để lật trang trong CÙNG một lượt đọc (giữ nguyên các tham số khác). Không tự dựng, không lưu để nối lượt đồng bộ sau.",
            "schema": {
              "type": "string",
              "maxLength": 512
            }
          },
          {
            "name": "updatedSince",
            "in": "query",
            "description": "Chỉ lấy hội thoại có `lastMessageAt` từ thời điểm này (ISO 8601 UTC), tính cả mốc. `lastMessageAt` là giờ của tin mới nhất theo kênh (Facebook, Zalo), không phải mốc sửa: tin tới muộn hay lịch sử đồng bộ về sau có thể mang giờ trước mốc đã đọc, còn đổi thẻ, đánh dấu đã đọc hay đổi tên khách không làm hội thoại hiện lại. Không dùng để đồng bộ tăng dần.",
            "schema": {
              "type": "string",
              "format": "date-time",
              "pattern": "^(?!0000-)"
            }
          },
          {
            "name": "pageId",
            "in": "query",
            "description": "Chỉ lấy hội thoại của trang này: mã trang trong DANIX (`id` của `GET /pages`).",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "unread",
            "in": "query",
            "description": "`true` chỉ lấy hội thoại còn tin chưa đọc.",
            "schema": {
              "type": "string",
              "enum": [
                "true"
              ]
            }
          },
          {
            "name": "tagId",
            "in": "query",
            "description": "Chỉ lấy hội thoại có thẻ này.",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Một trang hội thoại.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Conversation"
                      },
                      "description": "Các bản ghi của trang này."
                    },
                    "nextCursor": {
                      "type": "string",
                      "description": "Con trỏ của trang kế; `null` khi đã hết dữ liệu.",
                      "nullable": true
                    }
                  },
                  "required": [
                    "data",
                    "nextCursor"
                  ],
                  "description": "Một trang hội thoại."
                },
                "example": {
                  "data": [
                    {
                      "id": "018f3b8e-1c2d-7a4b-9c3d-000000001201",
                      "pageId": "018f3b8e-1c2d-7a4b-9c3d-000000001301",
                      "providerPageId": "1090000000000001",
                      "provider": "facebook_page",
                      "type": "INBOX",
                      "customerName": "Nguyễn Văn An",
                      "customerAvatarUrl": null,
                      "unreadCount": 1,
                      "lastMessageText": "Shop ơi áo này còn size M không?",
                      "lastMessageAt": "2026-10-02T03:15:00.000Z",
                      "lastMessageBy": "customer",
                      "tags": [],
                      "createdAt": "2026-10-01T03:15:00.000Z"
                    }
                  ],
                  "nextCursor": null
                }
              }
            },
            "headers": {
              "X-RateLimit-Limit": {
                "description": "Hạn mức số yêu cầu trong cửa sổ hiện tại.",
                "schema": {
                  "type": "integer"
                }
              },
              "X-RateLimit-Remaining": {
                "description": "Số yêu cầu còn lại trong cửa sổ hiện tại.",
                "schema": {
                  "type": "integer"
                }
              },
              "X-RateLimit-Reset": {
                "description": "Số giây còn lại tới khi cửa sổ làm mới.",
                "schema": {
                  "type": "integer"
                }
              }
            }
          },
          "400": {
            "description": "Dữ liệu gửi lên không hợp lệ (xem `code` và `errors`).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Thiếu khoá API, khoá sai hoặc đã bị thu hồi.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Khoá không có quyền thực hiện thao tác.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Không tìm thấy tài nguyên (hoặc khoá không được thấy nó).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "429": {
            "description": "Vượt hạn mức gọi API: chờ theo header `Retry-After` rồi thử lại.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            },
            "headers": {
              "Retry-After": {
                "description": "Số giây phải chờ trước khi thử lại.",
                "schema": {
                  "type": "integer"
                }
              }
            }
          },
          "500": {
            "description": "Lỗi hệ thống.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        },
        "operationId": "listConversations",
        "x-required-permissions": {
          "anyOf": [
            "social.conversations.read",
            "social.conversations.reply"
          ],
          "allOf": [
            "social.pages.read"
          ]
        },
        "x-error-codes": [
          {
            "code": "invalid-api-key",
            "status": 401,
            "title": "Khoá API thiếu, sai hoặc đã bị thu hồi"
          },
          {
            "code": "insufficient-permission",
            "status": 403,
            "title": "Khoá API không có quyền thực hiện thao tác này"
          },
          {
            "code": "rate-limited",
            "status": 429,
            "title": "Vượt hạn mức gọi API, hãy chờ rồi thử lại"
          },
          {
            "code": "internal-error",
            "status": 500,
            "title": "Lỗi hệ thống"
          },
          {
            "code": "validation-failed",
            "status": 400,
            "title": "Dữ liệu gửi lên không hợp lệ"
          },
          {
            "code": "invalid-cursor",
            "status": 400,
            "title": "Con trỏ phân trang không hợp lệ"
          },
          {
            "code": "not-found",
            "status": 404,
            "title": "Không tìm thấy tài nguyên"
          }
        ]
      }
    },
    "/api/open/chat/v1/conversations/{id}": {
      "get": {
        "description": "Trả hội thoại kèm thẻ và số tin chưa đọc.",
        "summary": "Chi tiết một hội thoại",
        "tags": [],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Mã định danh (UUID) của tài nguyên."
          }
        ],
        "responses": {
          "200": {
            "description": "Một hội thoại.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Conversation"
                },
                "example": {
                  "id": "018f3b8e-1c2d-7a4b-9c3d-000000001201",
                  "pageId": "018f3b8e-1c2d-7a4b-9c3d-000000001301",
                  "providerPageId": "1090000000000001",
                  "provider": "facebook_page",
                  "type": "INBOX",
                  "customerName": "Nguyễn Văn An",
                  "customerAvatarUrl": null,
                  "unreadCount": 0,
                  "lastMessageText": "Dạ còn ạ",
                  "lastMessageAt": "2026-10-02T03:16:00.000Z",
                  "lastMessageBy": "page",
                  "tags": [],
                  "createdAt": "2026-10-01T03:15:00.000Z"
                }
              }
            },
            "headers": {
              "X-RateLimit-Limit": {
                "description": "Hạn mức số yêu cầu trong cửa sổ hiện tại.",
                "schema": {
                  "type": "integer"
                }
              },
              "X-RateLimit-Remaining": {
                "description": "Số yêu cầu còn lại trong cửa sổ hiện tại.",
                "schema": {
                  "type": "integer"
                }
              },
              "X-RateLimit-Reset": {
                "description": "Số giây còn lại tới khi cửa sổ làm mới.",
                "schema": {
                  "type": "integer"
                }
              }
            }
          },
          "401": {
            "description": "Thiếu khoá API, khoá sai hoặc đã bị thu hồi.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Khoá không có quyền thực hiện thao tác.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Không tìm thấy tài nguyên (hoặc khoá không được thấy nó).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "429": {
            "description": "Vượt hạn mức gọi API: chờ theo header `Retry-After` rồi thử lại.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            },
            "headers": {
              "Retry-After": {
                "description": "Số giây phải chờ trước khi thử lại.",
                "schema": {
                  "type": "integer"
                }
              }
            }
          },
          "500": {
            "description": "Lỗi hệ thống.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        },
        "operationId": "getConversation",
        "x-required-permissions": {
          "anyOf": [
            "social.conversations.read",
            "social.conversations.reply"
          ],
          "allOf": [
            "social.pages.read"
          ]
        },
        "x-error-codes": [
          {
            "code": "invalid-api-key",
            "status": 401,
            "title": "Khoá API thiếu, sai hoặc đã bị thu hồi"
          },
          {
            "code": "insufficient-permission",
            "status": 403,
            "title": "Khoá API không có quyền thực hiện thao tác này"
          },
          {
            "code": "rate-limited",
            "status": 429,
            "title": "Vượt hạn mức gọi API, hãy chờ rồi thử lại"
          },
          {
            "code": "internal-error",
            "status": 500,
            "title": "Lỗi hệ thống"
          },
          {
            "code": "not-found",
            "status": 404,
            "title": "Không tìm thấy tài nguyên"
          }
        ]
      }
    },
    "/api/open/chat/v1/conversations/{id}/read": {
      "post": {
        "description": "Đặt số tin chưa đọc về 0.",
        "summary": "Đánh dấu hội thoại đã đọc",
        "tags": [],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Mã định danh (UUID) của tài nguyên."
          }
        ],
        "responses": {
          "200": {
            "description": "Thao tác thành công, không có dữ liệu trả về.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ok": {
                      "type": "boolean",
                      "enum": [
                        true
                      ],
                      "description": "Luôn `true` khi thao tác thành công."
                    }
                  },
                  "required": [
                    "ok"
                  ],
                  "description": "Thao tác thành công, không có dữ liệu trả về."
                },
                "example": {
                  "ok": true
                }
              }
            },
            "headers": {
              "X-RateLimit-Limit": {
                "description": "Hạn mức số yêu cầu trong cửa sổ hiện tại.",
                "schema": {
                  "type": "integer"
                }
              },
              "X-RateLimit-Remaining": {
                "description": "Số yêu cầu còn lại trong cửa sổ hiện tại.",
                "schema": {
                  "type": "integer"
                }
              },
              "X-RateLimit-Reset": {
                "description": "Số giây còn lại tới khi cửa sổ làm mới.",
                "schema": {
                  "type": "integer"
                }
              }
            }
          },
          "401": {
            "description": "Thiếu khoá API, khoá sai hoặc đã bị thu hồi.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Khoá không có quyền thực hiện thao tác.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Không tìm thấy tài nguyên (hoặc khoá không được thấy nó).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "429": {
            "description": "Vượt hạn mức gọi API: chờ theo header `Retry-After` rồi thử lại.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            },
            "headers": {
              "Retry-After": {
                "description": "Số giây phải chờ trước khi thử lại.",
                "schema": {
                  "type": "integer"
                }
              }
            }
          },
          "500": {
            "description": "Lỗi hệ thống.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        },
        "operationId": "markConversationRead",
        "x-required-permissions": {
          "anyOf": [
            "social.conversations.read",
            "social.conversations.reply"
          ],
          "allOf": [
            "social.pages.read"
          ]
        },
        "x-error-codes": [
          {
            "code": "invalid-api-key",
            "status": 401,
            "title": "Khoá API thiếu, sai hoặc đã bị thu hồi"
          },
          {
            "code": "insufficient-permission",
            "status": 403,
            "title": "Khoá API không có quyền thực hiện thao tác này"
          },
          {
            "code": "rate-limited",
            "status": 429,
            "title": "Vượt hạn mức gọi API, hãy chờ rồi thử lại"
          },
          {
            "code": "internal-error",
            "status": 500,
            "title": "Lỗi hệ thống"
          },
          {
            "code": "not-found",
            "status": 404,
            "title": "Không tìm thấy tài nguyên"
          }
        ]
      }
    },
    "/api/open/chat/v1/conversations/{id}/messages": {
      "get": {
        "description": "Phân trang theo con trỏ, tin mới nhất trước.",
        "summary": "Tin nhắn của hội thoại",
        "tags": [],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Mã định danh (UUID) của tài nguyên."
          },
          {
            "name": "cursor",
            "in": "query",
            "description": "Con trỏ lấy từ `nextCursor` của trang trước.",
            "schema": {
              "type": "string",
              "maxLength": 512
            }
          },
          {
            "name": "limit",
            "in": "query",
            "description": "Số tin mỗi trang, 1 đến 100.",
            "schema": {
              "default": 50,
              "type": "integer",
              "minimum": 1,
              "maximum": 100
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Một trang tin nhắn.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Message"
                      },
                      "description": "Các bản ghi của trang này."
                    },
                    "nextCursor": {
                      "type": "string",
                      "description": "Con trỏ của trang kế; `null` khi đã hết dữ liệu.",
                      "nullable": true
                    }
                  },
                  "required": [
                    "data",
                    "nextCursor"
                  ],
                  "description": "Một trang tin nhắn."
                },
                "example": {
                  "data": [
                    {
                      "id": "018f3b8e-1c2d-7a4b-9c3d-000000001101",
                      "conversationId": "018f3b8e-1c2d-7a4b-9c3d-000000001201",
                      "pageId": "018f3b8e-1c2d-7a4b-9c3d-000000001301",
                      "providerPageId": "1090000000000001",
                      "provider": "facebook_page",
                      "direction": "outbound",
                      "type": "text",
                      "text": "Dạ còn ạ, anh chị cần mấy cái ạ?",
                      "status": "sent",
                      "isDeleted": false,
                      "sentByName": "Trần Thị Bình",
                      "sentByIsIntegration": false,
                      "customerName": "Nguyễn Văn An",
                      "attachments": [],
                      "createdAt": "2026-10-02T03:15:00.000Z"
                    }
                  ],
                  "nextCursor": null
                }
              }
            },
            "headers": {
              "X-RateLimit-Limit": {
                "description": "Hạn mức số yêu cầu trong cửa sổ hiện tại.",
                "schema": {
                  "type": "integer"
                }
              },
              "X-RateLimit-Remaining": {
                "description": "Số yêu cầu còn lại trong cửa sổ hiện tại.",
                "schema": {
                  "type": "integer"
                }
              },
              "X-RateLimit-Reset": {
                "description": "Số giây còn lại tới khi cửa sổ làm mới.",
                "schema": {
                  "type": "integer"
                }
              }
            }
          },
          "400": {
            "description": "Dữ liệu gửi lên không hợp lệ (xem `code` và `errors`).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Thiếu khoá API, khoá sai hoặc đã bị thu hồi.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Khoá không có quyền thực hiện thao tác.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Không tìm thấy tài nguyên (hoặc khoá không được thấy nó).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "429": {
            "description": "Vượt hạn mức gọi API: chờ theo header `Retry-After` rồi thử lại.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            },
            "headers": {
              "Retry-After": {
                "description": "Số giây phải chờ trước khi thử lại.",
                "schema": {
                  "type": "integer"
                }
              }
            }
          },
          "500": {
            "description": "Lỗi hệ thống.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        },
        "operationId": "listMessages",
        "x-required-permissions": {
          "anyOf": [
            "social.conversations.read",
            "social.conversations.reply"
          ],
          "allOf": [
            "social.pages.read"
          ]
        },
        "x-error-codes": [
          {
            "code": "invalid-api-key",
            "status": 401,
            "title": "Khoá API thiếu, sai hoặc đã bị thu hồi"
          },
          {
            "code": "insufficient-permission",
            "status": 403,
            "title": "Khoá API không có quyền thực hiện thao tác này"
          },
          {
            "code": "rate-limited",
            "status": 429,
            "title": "Vượt hạn mức gọi API, hãy chờ rồi thử lại"
          },
          {
            "code": "internal-error",
            "status": 500,
            "title": "Lỗi hệ thống"
          },
          {
            "code": "not-found",
            "status": 404,
            "title": "Không tìm thấy tài nguyên"
          },
          {
            "code": "invalid-cursor",
            "status": 400,
            "title": "Con trỏ phân trang không hợp lệ"
          }
        ]
      },
      "post": {
        "description": "Gửi một tin nhắn chữ trong hội thoại. Gửi kèm `Idempotency-Key`: cùng khoá trong CÙNG hội thoại không gửi hai lần (cùng khoá ở hội thoại khác là một tin mới). Ngoài khung thời gian cho phép của kênh trả `messaging-window-closed`.",
        "summary": "Gửi tin nhắn",
        "tags": [],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Mã định danh (UUID) của tài nguyên."
          },
          {
            "name": "Idempotency-Key",
            "in": "header",
            "schema": {
              "type": "string",
              "minLength": 1,
              "maxLength": 255,
              "description": "Khoá chống trùng do client đặt (khuyến nghị UUID). Gửi lại cùng khoá trong 24 giờ trả đúng kết quả lần đầu và header `Idempotent-Replayed: true`."
            }
          }
        ],
        "requestBody": {
          "description": "Thân yêu cầu (JSON)",
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "text": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 2000,
                    "description": "Nội dung tin nhắn."
                  },
                  "replyToMessageId": {
                    "type": "string",
                    "format": "uuid",
                    "description": "Trả lời một tin có sẵn của hội thoại."
                  }
                },
                "required": [
                  "text"
                ],
                "description": "Thân gửi tin nhắn. Nên kèm header `Idempotency-Key` để gửi lại an toàn."
              },
              "example": {
                "text": "Dạ còn ạ, anh chị cần mấy cái ạ?"
              }
            }
          },
          "required": true
        },
        "responses": {
          "201": {
            "description": "Một tin nhắn hoặc bình luận.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Message"
                },
                "example": {
                  "id": "018f3b8e-1c2d-7a4b-9c3d-000000001101",
                  "conversationId": "018f3b8e-1c2d-7a4b-9c3d-000000001201",
                  "pageId": "018f3b8e-1c2d-7a4b-9c3d-000000001301",
                  "providerPageId": "1090000000000001",
                  "provider": "facebook_page",
                  "direction": "outbound",
                  "type": "text",
                  "text": "Dạ còn ạ, anh chị cần mấy cái ạ?",
                  "status": "sent",
                  "isDeleted": false,
                  "sentByName": "Trần Thị Bình",
                  "sentByIsIntegration": false,
                  "customerName": "Nguyễn Văn An",
                  "attachments": [],
                  "createdAt": "2026-10-02T03:15:00.000Z"
                }
              }
            },
            "headers": {
              "X-RateLimit-Limit": {
                "description": "Hạn mức số yêu cầu trong cửa sổ hiện tại.",
                "schema": {
                  "type": "integer"
                }
              },
              "X-RateLimit-Remaining": {
                "description": "Số yêu cầu còn lại trong cửa sổ hiện tại.",
                "schema": {
                  "type": "integer"
                }
              },
              "X-RateLimit-Reset": {
                "description": "Số giây còn lại tới khi cửa sổ làm mới.",
                "schema": {
                  "type": "integer"
                }
              },
              "Idempotent-Replayed": {
                "description": "`true` khi đây là kết quả của lần gửi trước với cùng `Idempotency-Key`.",
                "schema": {
                  "type": "string",
                  "enum": [
                    "true"
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Dữ liệu gửi lên không hợp lệ (xem `code` và `errors`).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Thiếu khoá API, khoá sai hoặc đã bị thu hồi.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Khoá không có quyền thực hiện thao tác.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Không tìm thấy tài nguyên (hoặc khoá không được thấy nó).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "409": {
            "description": "Xung đột với trạng thái hiện tại, hoặc Idempotency-Key đang được xử lý.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "413": {
            "description": "Thân yêu cầu vượt quá dung lượng cho phép.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "415": {
            "description": "Thân yêu cầu không phải JSON: gửi `Content-Type: application/json`.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Dữ liệu hợp lệ nhưng nghiệp vụ không cho phép.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "429": {
            "description": "Vượt hạn mức gọi API: chờ theo header `Retry-After` rồi thử lại.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            },
            "headers": {
              "Retry-After": {
                "description": "Số giây phải chờ trước khi thử lại.",
                "schema": {
                  "type": "integer"
                }
              }
            }
          },
          "500": {
            "description": "Lỗi hệ thống.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "503": {
            "description": "Hãng vận chuyển hiện không với tới được: thử lại sau.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        },
        "operationId": "sendMessage",
        "x-required-permissions": {
          "anyOf": [
            "social.conversations.reply"
          ],
          "allOf": [
            "social.pages.read"
          ]
        },
        "x-error-codes": [
          {
            "code": "invalid-api-key",
            "status": 401,
            "title": "Khoá API thiếu, sai hoặc đã bị thu hồi"
          },
          {
            "code": "insufficient-permission",
            "status": 403,
            "title": "Khoá API không có quyền thực hiện thao tác này"
          },
          {
            "code": "rate-limited",
            "status": 429,
            "title": "Vượt hạn mức gọi API, hãy chờ rồi thử lại"
          },
          {
            "code": "internal-error",
            "status": 500,
            "title": "Lỗi hệ thống"
          },
          {
            "code": "validation-failed",
            "status": 400,
            "title": "Dữ liệu gửi lên không hợp lệ"
          },
          {
            "code": "payload-too-large",
            "status": 413,
            "title": "Thân yêu cầu vượt quá dung lượng cho phép"
          },
          {
            "code": "unsupported-media-type",
            "status": 415,
            "title": "Thân yêu cầu phải là JSON (`Content-Type: application/json`)"
          },
          {
            "code": "not-found",
            "status": 404,
            "title": "Không tìm thấy tài nguyên"
          },
          {
            "code": "idempotency-key-in-progress",
            "status": 409,
            "title": "Yêu cầu với cùng Idempotency-Key đang được xử lý"
          },
          {
            "code": "idempotency-key-reused",
            "status": 422,
            "title": "Idempotency-Key đã dùng cho một yêu cầu có nội dung khác"
          },
          {
            "code": "messaging-window-closed",
            "status": 422,
            "title": "Đã quá khung thời gian được phép nhắn cho khách này"
          },
          {
            "code": "page-not-connected",
            "status": 422,
            "title": "Trang chat không còn kết nối"
          },
          {
            "code": "conversation-not-replyable",
            "status": 422,
            "title": "Hội thoại này không trả lời được"
          },
          {
            "code": "channel-unavailable",
            "status": 503,
            "title": "Kênh chat tạm thời không phản hồi, hãy thử lại sau"
          }
        ],
        "x-idempotent": true
      }
    },
    "/api/open/chat/v1/tags": {
      "get": {
        "description": "Thẻ hội thoại của trang của khoá. Thẻ là của từng trang (`pageId`): chỉ gắn được vào hội thoại cùng trang.",
        "summary": "Các thẻ hội thoại",
        "tags": [],
        "parameters": [],
        "responses": {
          "200": {
            "description": "Danh sách thẻ.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/ChatTag"
                      },
                      "description": "Các thẻ."
                    }
                  },
                  "required": [
                    "data"
                  ],
                  "description": "Danh sách thẻ."
                },
                "example": {
                  "data": [
                    {
                      "id": "018f3b8e-1c2d-7a4b-9c3d-000000001401",
                      "name": "Khách quen",
                      "color": "blue",
                      "pageId": "018f3b8e-1c2d-7a4b-9c3d-000000001301"
                    }
                  ]
                }
              }
            },
            "headers": {
              "X-RateLimit-Limit": {
                "description": "Hạn mức số yêu cầu trong cửa sổ hiện tại.",
                "schema": {
                  "type": "integer"
                }
              },
              "X-RateLimit-Remaining": {
                "description": "Số yêu cầu còn lại trong cửa sổ hiện tại.",
                "schema": {
                  "type": "integer"
                }
              },
              "X-RateLimit-Reset": {
                "description": "Số giây còn lại tới khi cửa sổ làm mới.",
                "schema": {
                  "type": "integer"
                }
              }
            }
          },
          "401": {
            "description": "Thiếu khoá API, khoá sai hoặc đã bị thu hồi.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Khoá không có quyền thực hiện thao tác.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "429": {
            "description": "Vượt hạn mức gọi API: chờ theo header `Retry-After` rồi thử lại.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            },
            "headers": {
              "Retry-After": {
                "description": "Số giây phải chờ trước khi thử lại.",
                "schema": {
                  "type": "integer"
                }
              }
            }
          },
          "500": {
            "description": "Lỗi hệ thống.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        },
        "operationId": "listChatTags",
        "x-required-permissions": {
          "anyOf": [
            "social.conversations.read",
            "social.conversations.reply"
          ],
          "allOf": [
            "social.pages.read"
          ]
        },
        "x-error-codes": [
          {
            "code": "invalid-api-key",
            "status": 401,
            "title": "Khoá API thiếu, sai hoặc đã bị thu hồi"
          },
          {
            "code": "insufficient-permission",
            "status": 403,
            "title": "Khoá API không có quyền thực hiện thao tác này"
          },
          {
            "code": "rate-limited",
            "status": 429,
            "title": "Vượt hạn mức gọi API, hãy chờ rồi thử lại"
          },
          {
            "code": "internal-error",
            "status": 500,
            "title": "Lỗi hệ thống"
          }
        ]
      }
    },
    "/api/open/chat/v1/conversations/{id}/tags": {
      "post": {
        "description": "Gắn một thẻ có sẵn vào hội thoại. Gắn lại thẻ đã có là thành công.",
        "summary": "Gắn thẻ vào hội thoại",
        "tags": [],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Mã định danh (UUID) của tài nguyên."
          }
        ],
        "requestBody": {
          "description": "Thân yêu cầu (JSON)",
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "tagId": {
                    "type": "string",
                    "format": "uuid",
                    "description": "Mã thẻ cần gắn."
                  }
                },
                "required": [
                  "tagId"
                ],
                "description": "Thân gắn thẻ vào hội thoại."
              },
              "example": {
                "tagId": "018f3b8e-1c2d-7a4b-9c3d-000000001401"
              }
            }
          },
          "required": true
        },
        "responses": {
          "200": {
            "description": "Thao tác thành công, không có dữ liệu trả về.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ok": {
                      "type": "boolean",
                      "enum": [
                        true
                      ],
                      "description": "Luôn `true` khi thao tác thành công."
                    }
                  },
                  "required": [
                    "ok"
                  ],
                  "description": "Thao tác thành công, không có dữ liệu trả về."
                },
                "example": {
                  "ok": true
                }
              }
            },
            "headers": {
              "X-RateLimit-Limit": {
                "description": "Hạn mức số yêu cầu trong cửa sổ hiện tại.",
                "schema": {
                  "type": "integer"
                }
              },
              "X-RateLimit-Remaining": {
                "description": "Số yêu cầu còn lại trong cửa sổ hiện tại.",
                "schema": {
                  "type": "integer"
                }
              },
              "X-RateLimit-Reset": {
                "description": "Số giây còn lại tới khi cửa sổ làm mới.",
                "schema": {
                  "type": "integer"
                }
              }
            }
          },
          "400": {
            "description": "Dữ liệu gửi lên không hợp lệ (xem `code` và `errors`).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Thiếu khoá API, khoá sai hoặc đã bị thu hồi.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Khoá không có quyền thực hiện thao tác.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Không tìm thấy tài nguyên (hoặc khoá không được thấy nó).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "413": {
            "description": "Thân yêu cầu vượt quá dung lượng cho phép.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "415": {
            "description": "Thân yêu cầu không phải JSON: gửi `Content-Type: application/json`.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "429": {
            "description": "Vượt hạn mức gọi API: chờ theo header `Retry-After` rồi thử lại.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            },
            "headers": {
              "Retry-After": {
                "description": "Số giây phải chờ trước khi thử lại.",
                "schema": {
                  "type": "integer"
                }
              }
            }
          },
          "500": {
            "description": "Lỗi hệ thống.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        },
        "operationId": "addConversationTag",
        "x-required-permissions": {
          "anyOf": [
            "social.conversations.reply"
          ],
          "allOf": [
            "social.pages.read"
          ]
        },
        "x-error-codes": [
          {
            "code": "invalid-api-key",
            "status": 401,
            "title": "Khoá API thiếu, sai hoặc đã bị thu hồi"
          },
          {
            "code": "insufficient-permission",
            "status": 403,
            "title": "Khoá API không có quyền thực hiện thao tác này"
          },
          {
            "code": "rate-limited",
            "status": 429,
            "title": "Vượt hạn mức gọi API, hãy chờ rồi thử lại"
          },
          {
            "code": "internal-error",
            "status": 500,
            "title": "Lỗi hệ thống"
          },
          {
            "code": "validation-failed",
            "status": 400,
            "title": "Dữ liệu gửi lên không hợp lệ"
          },
          {
            "code": "payload-too-large",
            "status": 413,
            "title": "Thân yêu cầu vượt quá dung lượng cho phép"
          },
          {
            "code": "unsupported-media-type",
            "status": 415,
            "title": "Thân yêu cầu phải là JSON (`Content-Type: application/json`)"
          },
          {
            "code": "not-found",
            "status": 404,
            "title": "Không tìm thấy tài nguyên"
          }
        ]
      }
    },
    "/api/open/chat/v1/conversations/{id}/tags/{tagId}": {
      "delete": {
        "description": "Gỡ một thẻ khỏi hội thoại.",
        "summary": "Gỡ thẻ khỏi hội thoại",
        "tags": [],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Mã định danh (UUID) của tài nguyên."
          },
          {
            "name": "tagId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Mã thẻ."
          }
        ],
        "responses": {
          "200": {
            "description": "Thao tác thành công, không có dữ liệu trả về.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ok": {
                      "type": "boolean",
                      "enum": [
                        true
                      ],
                      "description": "Luôn `true` khi thao tác thành công."
                    }
                  },
                  "required": [
                    "ok"
                  ],
                  "description": "Thao tác thành công, không có dữ liệu trả về."
                },
                "example": {
                  "ok": true
                }
              }
            },
            "headers": {
              "X-RateLimit-Limit": {
                "description": "Hạn mức số yêu cầu trong cửa sổ hiện tại.",
                "schema": {
                  "type": "integer"
                }
              },
              "X-RateLimit-Remaining": {
                "description": "Số yêu cầu còn lại trong cửa sổ hiện tại.",
                "schema": {
                  "type": "integer"
                }
              },
              "X-RateLimit-Reset": {
                "description": "Số giây còn lại tới khi cửa sổ làm mới.",
                "schema": {
                  "type": "integer"
                }
              }
            }
          },
          "401": {
            "description": "Thiếu khoá API, khoá sai hoặc đã bị thu hồi.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Khoá không có quyền thực hiện thao tác.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Không tìm thấy tài nguyên (hoặc khoá không được thấy nó).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "429": {
            "description": "Vượt hạn mức gọi API: chờ theo header `Retry-After` rồi thử lại.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            },
            "headers": {
              "Retry-After": {
                "description": "Số giây phải chờ trước khi thử lại.",
                "schema": {
                  "type": "integer"
                }
              }
            }
          },
          "500": {
            "description": "Lỗi hệ thống.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        },
        "operationId": "removeConversationTag",
        "x-required-permissions": {
          "anyOf": [
            "social.conversations.reply"
          ],
          "allOf": [
            "social.pages.read"
          ]
        },
        "x-error-codes": [
          {
            "code": "invalid-api-key",
            "status": 401,
            "title": "Khoá API thiếu, sai hoặc đã bị thu hồi"
          },
          {
            "code": "insufficient-permission",
            "status": 403,
            "title": "Khoá API không có quyền thực hiện thao tác này"
          },
          {
            "code": "rate-limited",
            "status": 429,
            "title": "Vượt hạn mức gọi API, hãy chờ rồi thử lại"
          },
          {
            "code": "internal-error",
            "status": 500,
            "title": "Lỗi hệ thống"
          },
          {
            "code": "not-found",
            "status": 404,
            "title": "Không tìm thấy tài nguyên"
          }
        ]
      }
    },
    "/api/open/chat/v1/comments/{id}/hidden": {
      "post": {
        "description": "Chỉ áp dụng cho bình luận (`type = COMMENT`) của trang Facebook.",
        "summary": "Ẩn hoặc hiện một bình luận",
        "tags": [],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Mã định danh (UUID) của tài nguyên."
          }
        ],
        "requestBody": {
          "description": "Thân yêu cầu (JSON)",
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "hidden": {
                    "type": "boolean",
                    "description": "`true` ẩn bình luận, `false` hiện lại."
                  }
                },
                "required": [
                  "hidden"
                ],
                "description": "Thân ẩn hoặc hiện bình luận."
              },
              "example": {
                "hidden": true
              }
            }
          },
          "required": true
        },
        "responses": {
          "200": {
            "description": "Thao tác thành công, không có dữ liệu trả về.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ok": {
                      "type": "boolean",
                      "enum": [
                        true
                      ],
                      "description": "Luôn `true` khi thao tác thành công."
                    }
                  },
                  "required": [
                    "ok"
                  ],
                  "description": "Thao tác thành công, không có dữ liệu trả về."
                },
                "example": {
                  "ok": true
                }
              }
            },
            "headers": {
              "X-RateLimit-Limit": {
                "description": "Hạn mức số yêu cầu trong cửa sổ hiện tại.",
                "schema": {
                  "type": "integer"
                }
              },
              "X-RateLimit-Remaining": {
                "description": "Số yêu cầu còn lại trong cửa sổ hiện tại.",
                "schema": {
                  "type": "integer"
                }
              },
              "X-RateLimit-Reset": {
                "description": "Số giây còn lại tới khi cửa sổ làm mới.",
                "schema": {
                  "type": "integer"
                }
              }
            }
          },
          "400": {
            "description": "Dữ liệu gửi lên không hợp lệ (xem `code` và `errors`).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Thiếu khoá API, khoá sai hoặc đã bị thu hồi.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Khoá không có quyền thực hiện thao tác.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Không tìm thấy tài nguyên (hoặc khoá không được thấy nó).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "413": {
            "description": "Thân yêu cầu vượt quá dung lượng cho phép.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "415": {
            "description": "Thân yêu cầu không phải JSON: gửi `Content-Type: application/json`.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Dữ liệu hợp lệ nhưng nghiệp vụ không cho phép.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "429": {
            "description": "Vượt hạn mức gọi API: chờ theo header `Retry-After` rồi thử lại.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            },
            "headers": {
              "Retry-After": {
                "description": "Số giây phải chờ trước khi thử lại.",
                "schema": {
                  "type": "integer"
                }
              }
            }
          },
          "500": {
            "description": "Lỗi hệ thống.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "503": {
            "description": "Hãng vận chuyển hiện không với tới được: thử lại sau.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        },
        "operationId": "setCommentHidden",
        "x-required-permissions": {
          "anyOf": [
            "social.conversations.reply"
          ],
          "allOf": [
            "social.pages.read"
          ]
        },
        "x-error-codes": [
          {
            "code": "invalid-api-key",
            "status": 401,
            "title": "Khoá API thiếu, sai hoặc đã bị thu hồi"
          },
          {
            "code": "insufficient-permission",
            "status": 403,
            "title": "Khoá API không có quyền thực hiện thao tác này"
          },
          {
            "code": "rate-limited",
            "status": 429,
            "title": "Vượt hạn mức gọi API, hãy chờ rồi thử lại"
          },
          {
            "code": "internal-error",
            "status": 500,
            "title": "Lỗi hệ thống"
          },
          {
            "code": "validation-failed",
            "status": 400,
            "title": "Dữ liệu gửi lên không hợp lệ"
          },
          {
            "code": "payload-too-large",
            "status": 413,
            "title": "Thân yêu cầu vượt quá dung lượng cho phép"
          },
          {
            "code": "unsupported-media-type",
            "status": 415,
            "title": "Thân yêu cầu phải là JSON (`Content-Type: application/json`)"
          },
          {
            "code": "not-found",
            "status": 404,
            "title": "Không tìm thấy tài nguyên"
          },
          {
            "code": "page-not-connected",
            "status": 422,
            "title": "Trang chat không còn kết nối"
          },
          {
            "code": "conversation-not-replyable",
            "status": 422,
            "title": "Hội thoại này không trả lời được"
          },
          {
            "code": "channel-unavailable",
            "status": 503,
            "title": "Kênh chat tạm thời không phản hồi, hãy thử lại sau"
          }
        ]
      }
    },
    "/api/open/chat/v1/comments/{id}/private-reply": {
      "post": {
        "description": "Gửi một tin nhắn riêng đáp lại bình luận. Mỗi bình luận chỉ nhắn riêng được một lần.",
        "summary": "Nhắn riêng cho người bình luận",
        "tags": [],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Mã định danh (UUID) của tài nguyên."
          }
        ],
        "requestBody": {
          "description": "Thân yêu cầu (JSON)",
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "text": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 2000,
                    "description": "Nội dung tin nhắn riêng gửi cho người bình luận."
                  }
                },
                "required": [
                  "text"
                ],
                "description": "Thân nhắn riêng cho người bình luận."
              },
              "example": {
                "text": "Cảm ơn bạn đã quan tâm, shop nhắn riêng nhé"
              }
            }
          },
          "required": true
        },
        "responses": {
          "201": {
            "description": "Một tin nhắn hoặc bình luận.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Message"
                },
                "example": {
                  "id": "018f3b8e-1c2d-7a4b-9c3d-000000001101",
                  "conversationId": "018f3b8e-1c2d-7a4b-9c3d-000000001201",
                  "pageId": "018f3b8e-1c2d-7a4b-9c3d-000000001301",
                  "providerPageId": "1090000000000001",
                  "provider": "facebook_page",
                  "direction": "outbound",
                  "type": "text",
                  "text": "Dạ còn ạ, anh chị cần mấy cái ạ?",
                  "status": "sent",
                  "isDeleted": false,
                  "sentByName": "Trần Thị Bình",
                  "sentByIsIntegration": false,
                  "customerName": "Nguyễn Văn An",
                  "attachments": [],
                  "createdAt": "2026-10-02T03:15:00.000Z"
                }
              }
            },
            "headers": {
              "X-RateLimit-Limit": {
                "description": "Hạn mức số yêu cầu trong cửa sổ hiện tại.",
                "schema": {
                  "type": "integer"
                }
              },
              "X-RateLimit-Remaining": {
                "description": "Số yêu cầu còn lại trong cửa sổ hiện tại.",
                "schema": {
                  "type": "integer"
                }
              },
              "X-RateLimit-Reset": {
                "description": "Số giây còn lại tới khi cửa sổ làm mới.",
                "schema": {
                  "type": "integer"
                }
              }
            }
          },
          "400": {
            "description": "Dữ liệu gửi lên không hợp lệ (xem `code` và `errors`).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Thiếu khoá API, khoá sai hoặc đã bị thu hồi.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Khoá không có quyền thực hiện thao tác.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Không tìm thấy tài nguyên (hoặc khoá không được thấy nó).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "409": {
            "description": "Xung đột với trạng thái hiện tại, hoặc Idempotency-Key đang được xử lý.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "413": {
            "description": "Thân yêu cầu vượt quá dung lượng cho phép.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "415": {
            "description": "Thân yêu cầu không phải JSON: gửi `Content-Type: application/json`.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Dữ liệu hợp lệ nhưng nghiệp vụ không cho phép.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "429": {
            "description": "Vượt hạn mức gọi API: chờ theo header `Retry-After` rồi thử lại.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            },
            "headers": {
              "Retry-After": {
                "description": "Số giây phải chờ trước khi thử lại.",
                "schema": {
                  "type": "integer"
                }
              }
            }
          },
          "500": {
            "description": "Lỗi hệ thống.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "503": {
            "description": "Hãng vận chuyển hiện không với tới được: thử lại sau.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        },
        "operationId": "sendPrivateReply",
        "x-required-permissions": {
          "anyOf": [
            "social.conversations.reply"
          ],
          "allOf": [
            "social.pages.read"
          ]
        },
        "x-error-codes": [
          {
            "code": "invalid-api-key",
            "status": 401,
            "title": "Khoá API thiếu, sai hoặc đã bị thu hồi"
          },
          {
            "code": "insufficient-permission",
            "status": 403,
            "title": "Khoá API không có quyền thực hiện thao tác này"
          },
          {
            "code": "rate-limited",
            "status": 429,
            "title": "Vượt hạn mức gọi API, hãy chờ rồi thử lại"
          },
          {
            "code": "internal-error",
            "status": 500,
            "title": "Lỗi hệ thống"
          },
          {
            "code": "validation-failed",
            "status": 400,
            "title": "Dữ liệu gửi lên không hợp lệ"
          },
          {
            "code": "payload-too-large",
            "status": 413,
            "title": "Thân yêu cầu vượt quá dung lượng cho phép"
          },
          {
            "code": "unsupported-media-type",
            "status": 415,
            "title": "Thân yêu cầu phải là JSON (`Content-Type: application/json`)"
          },
          {
            "code": "not-found",
            "status": 404,
            "title": "Không tìm thấy tài nguyên"
          },
          {
            "code": "conflict",
            "status": 409,
            "title": "Thao tác xung đột với trạng thái hiện tại"
          },
          {
            "code": "messaging-window-closed",
            "status": 422,
            "title": "Đã quá khung thời gian được phép nhắn cho khách này"
          },
          {
            "code": "page-not-connected",
            "status": 422,
            "title": "Trang chat không còn kết nối"
          },
          {
            "code": "conversation-not-replyable",
            "status": 422,
            "title": "Hội thoại này không trả lời được"
          },
          {
            "code": "channel-unavailable",
            "status": 503,
            "title": "Kênh chat tạm thời không phản hồi, hãy thử lại sau"
          }
        ]
      }
    }
  },
  "info": {
    "title": "DANIX Open API — Chat",
    "version": "1.0.0",
    "description": "API công khai phần Chat của DANIX: trang, hội thoại, tin nhắn, thẻ, bình luận. Mỗi khoá thuộc ĐÚNG MỘT trang và chỉ thấy dữ liệu của trang ấy. Xác thực bằng khoá `dnx_live_…` trong header `Authorization: Bearer`. Tiền và số lượng là chuỗi thập phân; thời gian là ISO 8601 UTC; lỗi theo RFC 9457 kèm `code` ổn định."
  },
  "servers": [
    {
      "url": "https://danix.vn",
      "description": "Máy chủ chính"
    }
  ],
  "components": {
    "schemas": {
      "Page": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid",
            "description": "Mã trang trong DANIX. Đây là giá trị dùng làm `pageId` ở mọi chỗ khác của API."
          },
          "providerPageId": {
            "type": "string",
            "description": "Mã trang ở kênh gốc (Facebook, Zalo…). Chỉ để đối chiếu, không dùng làm tham số."
          },
          "provider": {
            "type": "string",
            "enum": [
              "facebook_page",
              "zalo_oa",
              "zalo_personal"
            ],
            "description": "Kênh: `facebook_page`, `zalo_oa` hoặc `zalo_personal`."
          },
          "pageName": {
            "type": "string",
            "description": "Tên trang."
          },
          "avatarUrl": {
            "type": "string",
            "description": "Ảnh đại diện của trang, lưu trên kho của DANIX. `null` khi chưa có bản lưu.",
            "nullable": true
          },
          "status": {
            "type": "string",
            "enum": [
              "active",
              "token_expired",
              "banned"
            ],
            "description": "Tình trạng kết nối: `active`, `token_expired` hoặc `banned`."
          }
        },
        "required": [
          "id",
          "providerPageId",
          "provider",
          "pageName",
          "avatarUrl",
          "status"
        ],
        "description": "Một trang chat mà khoá được dùng.",
        "title": "Page"
      },
      "Problem": {
        "type": "object",
        "properties": {
          "type": {
            "type": "string",
            "description": "Địa chỉ định danh loại lỗi (RFC 9457)."
          },
          "title": {
            "type": "string",
            "description": "Tiêu đề ngắn của lỗi, tiếng Việt."
          },
          "status": {
            "type": "integer",
            "description": "Mã trạng thái HTTP."
          },
          "detail": {
            "type": "string",
            "description": "Mô tả chi tiết của lần lỗi này."
          },
          "code": {
            "type": "string",
            "description": "Mã lỗi ổn định, kebab-case. Lập trình theo trường này."
          },
          "errors": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "path": {
                  "type": "string",
                  "description": "Đường tới trường sai, ví dụ `lines.0.quantity`."
                },
                "message": {
                  "type": "string",
                  "description": "Vì sao trường đó sai."
                }
              },
              "required": [
                "path",
                "message"
              ]
            },
            "description": "Chỉ có khi `code` là `validation-failed`: danh sách trường sai."
          }
        },
        "required": [
          "type",
          "title",
          "status",
          "code"
        ],
        "description": "Lỗi theo RFC 9457 kèm mã ổn định.",
        "title": "Problem"
      },
      "Conversation": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid",
            "description": "Mã hội thoại."
          },
          "pageId": {
            "type": "string",
            "format": "uuid",
            "description": "Mã trang trong DANIX (`id` của `GET /pages`)."
          },
          "providerPageId": {
            "type": "string",
            "description": "Mã trang ở kênh gốc."
          },
          "provider": {
            "type": "string",
            "enum": [
              "facebook_page",
              "zalo_oa",
              "zalo_personal"
            ],
            "description": "Kênh của hội thoại."
          },
          "type": {
            "type": "string",
            "enum": [
              "INBOX",
              "COMMENT",
              "GROUP"
            ],
            "description": "Loại: `INBOX` tin nhắn, `COMMENT` bình luận, `GROUP` nhóm."
          },
          "customerName": {
            "type": "string",
            "description": "Tên khách ở kênh gốc.",
            "nullable": true
          },
          "customerAvatarUrl": {
            "type": "string",
            "description": "Ảnh đại diện của khách, lưu trên kho của DANIX. `null` khi chưa có bản lưu.",
            "nullable": true
          },
          "unreadCount": {
            "type": "integer",
            "description": "Số tin khách chưa được đọc."
          },
          "lastMessageText": {
            "type": "string",
            "description": "Nội dung tin gần nhất.",
            "nullable": true
          },
          "lastMessageAt": {
            "type": "string",
            "format": "date-time",
            "description": "Thời điểm tin gần nhất. ISO 8601 UTC hoặc `null`.",
            "nullable": true
          },
          "lastMessageBy": {
            "type": "string",
            "enum": [
              "customer",
              "page"
            ],
            "description": "Ai gửi tin gần nhất.",
            "nullable": true
          },
          "tags": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "id": {
                  "type": "string",
                  "format": "uuid",
                  "description": "Mã thẻ."
                },
                "name": {
                  "type": "string",
                  "description": "Tên thẻ."
                }
              },
              "required": [
                "id",
                "name"
              ]
            },
            "description": "Các thẻ gắn vào hội thoại."
          },
          "createdAt": {
            "type": "string",
            "format": "date-time",
            "description": "Thời điểm tạo hội thoại. ISO 8601, múi giờ UTC."
          }
        },
        "required": [
          "id",
          "pageId",
          "providerPageId",
          "provider",
          "type",
          "customerName",
          "customerAvatarUrl",
          "unreadCount",
          "lastMessageText",
          "lastMessageAt",
          "lastMessageBy",
          "tags",
          "createdAt"
        ],
        "description": "Một hội thoại.",
        "title": "Conversation"
      },
      "MessageAttachment": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid",
            "description": "Mã tệp đính kèm."
          },
          "type": {
            "type": "string",
            "enum": [
              "image",
              "video",
              "audio",
              "file",
              "link",
              "button"
            ],
            "description": "Loại: bốn loại đầu là tệp; `link` và `button` là nút của tin mẫu."
          },
          "url": {
            "type": "string",
            "description": "Tệp: bản GỐC trên kho của DANIX, `null` khi chưa lưu về (xem `originalState`). Loại `link`: địa chỉ nút trỏ tới. Không bao giờ là đường dẫn của Facebook hay Zalo.",
            "nullable": true
          },
          "previewUrl": {
            "type": "string",
            "description": "Bản xem trước (ảnh thu nhỏ, ảnh bìa video) trên kho của DANIX; `null` khi không có.",
            "nullable": true
          },
          "originalState": {
            "type": "string",
            "enum": [
              "pending",
              "stored",
              "gone"
            ],
            "description": "`stored`: bản gốc có ở `url`. `pending`: chưa có bản gốc trên kho của DANIX. Tệp của hội thoại lâu không hoạt động đã được cất đi; lượt đọc trang ĐẦU tin nhắn (`GET /conversations/{id}/messages` không `cursor`) hay lượt nhân viên mở hội thoại kéo nó về ở nền trong ít phút — đọc lại sau để nhận `url`. Tệp chưa từng lưu bản gốc thì được lưu khi nhân viên mở xem. `gone`: nguồn không còn, sẽ không bao giờ có."
          },
          "fileName": {
            "type": "string",
            "description": "Tên tệp.",
            "nullable": true
          },
          "mimeType": {
            "type": "string",
            "description": "Loại nội dung (MIME).",
            "nullable": true
          }
        },
        "required": [
          "id",
          "type",
          "url",
          "previewUrl",
          "originalState",
          "fileName",
          "mimeType"
        ],
        "description": "Một tệp đính kèm của tin nhắn.",
        "title": "MessageAttachment"
      },
      "Message": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid",
            "description": "Mã tin nhắn."
          },
          "conversationId": {
            "type": "string",
            "format": "uuid",
            "description": "Hội thoại chứa tin."
          },
          "pageId": {
            "type": "string",
            "format": "uuid",
            "description": "Mã trang trong DANIX (`id` của `GET /pages`)."
          },
          "providerPageId": {
            "type": "string",
            "description": "Mã trang ở kênh gốc."
          },
          "provider": {
            "type": "string",
            "enum": [
              "facebook_page",
              "zalo_oa",
              "zalo_personal"
            ],
            "description": "Kênh của tin nhắn."
          },
          "direction": {
            "type": "string",
            "enum": [
              "inbound",
              "outbound"
            ],
            "description": "`inbound` khách gửi, `outbound` shop gửi."
          },
          "type": {
            "type": "string",
            "enum": [
              "text",
              "image",
              "video",
              "audio",
              "file",
              "sticker",
              "location",
              "reel",
              "share",
              "like",
              "postback",
              "order",
              "referral"
            ],
            "description": "Loại tin nhắn."
          },
          "text": {
            "type": "string",
            "description": "Nội dung chữ.",
            "nullable": true
          },
          "status": {
            "type": "string",
            "enum": [
              "pending",
              "sent",
              "delivered",
              "read",
              "failed"
            ],
            "description": "Trạng thái gửi."
          },
          "isDeleted": {
            "type": "boolean",
            "description": "Tin đã bị thu hồi."
          },
          "sentByName": {
            "type": "string",
            "description": "Tên nhân viên hay ứng dụng đã gửi; rỗng với tin của khách.",
            "nullable": true
          },
          "sentByIsIntegration": {
            "type": "boolean",
            "description": "`true` khi tin do một ứng dụng kết nối gửi."
          },
          "customerName": {
            "type": "string",
            "description": "Tên khách của hội thoại; với nhóm (`GROUP`) là người gửi tin.",
            "nullable": true
          },
          "attachments": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/MessageAttachment"
            },
            "description": "Tệp đính kèm."
          },
          "createdAt": {
            "type": "string",
            "format": "date-time",
            "description": "Thời điểm tin được ghi nhận. ISO 8601, múi giờ UTC."
          }
        },
        "required": [
          "id",
          "conversationId",
          "pageId",
          "providerPageId",
          "provider",
          "direction",
          "type",
          "text",
          "status",
          "isDeleted",
          "sentByName",
          "sentByIsIntegration",
          "customerName",
          "attachments",
          "createdAt"
        ],
        "description": "Một tin nhắn hoặc bình luận.",
        "title": "Message"
      },
      "ChatTag": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid",
            "description": "Mã thẻ."
          },
          "name": {
            "type": "string",
            "description": "Tên thẻ."
          },
          "color": {
            "type": "string",
            "enum": [
              "red",
              "orange",
              "amber",
              "green",
              "teal",
              "cyan",
              "blue",
              "indigo",
              "purple",
              "pink"
            ],
            "description": "Màu của thẻ."
          },
          "pageId": {
            "type": "string",
            "format": "uuid",
            "description": "Trang sở hữu thẻ. Thẻ là của TỪNG trang: chỉ gắn được vào hội thoại cùng trang, và hai trang có thể có thẻ trùng tên."
          }
        },
        "required": [
          "id",
          "name",
          "color",
          "pageId"
        ],
        "description": "Một thẻ hội thoại.",
        "title": "ChatTag"
      }
    },
    "securitySchemes": {
      "ApiKey": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "dnx_live_…",
        "description": "Khoá API của một trang chat, tạo trong cài đặt của trang ấy. Khoá POS không gọi được gốc này. Gửi `Authorization: Bearer dnx_live_…`."
      }
    }
  },
  "security": [
    {
      "ApiKey": []
    }
  ]
}
