{
  "openapi": "3.1.0",
  "info": {
    "title": "vybeflow API — inbox",
    "version": "0.1.0",
    "description": "Setiap endpoint memerlukan API key tenant (Pengaturan → API Key di konsol vybeflow) dan hanya berjalan jika kunci itu mencakup izin yang tercantum pada x-vybeflow-scope. Permintaan dibatasi per kunci dan per tenant; setiap jawaban membawa header RateLimit-*, dan penolakan 429 membawa Retry-After."
  },
  "servers": [
    {
      "url": "https://vybeflow.vyber.id"
    }
  ],
  "components": {
    "securitySchemes": {
      "ApiKeyAuth": {
        "type": "apiKey",
        "in": "header",
        "name": "x-api-key",
        "description": "Kunci berformat vf_live_… Boleh juga dikirim sebagai Authorization: Bearer."
      }
    }
  },
  "security": [
    {
      "ApiKeyAuth": []
    }
  ],
  "tags": [
    {
      "name": "contact"
    },
    {
      "name": "campaign"
    },
    {
      "name": "inbox"
    },
    {
      "name": "channel"
    },
    {
      "name": "product"
    },
    {
      "name": "billing"
    },
    {
      "name": "tenant"
    }
  ],
  "paths": {
    "/api/ai/v1/tickets": {
      "get": {
        "operationId": "inbox.ticket.list",
        "summary": "Daftar tiket percakapan.",
        "tags": [
          "inbox"
        ],
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "x-vybeflow-scope": "inbox.read",
        "x-vybeflow-risk": "safe",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": {
                      "type": "integer"
                    },
                    "errorCode": {
                      "type": "integer"
                    },
                    "data": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "_id": {},
                          "ticketID": {},
                          "status": {},
                          "channel": {},
                          "customerName": {},
                          "msisdn": {},
                          "lastMessageAt": {},
                          "unread": {}
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "API key tidak berlaku, dicabut, atau kedaluwarsa"
          },
          "403": {
            "description": "Kunci tidak mencakup `inbox.read`"
          },
          "429": {
            "description": "Batas permintaan terlampaui. Tunggu selama `Retry-After` detik lalu ulangi permintaan yang sama.",
            "headers": {
              "Retry-After": {
                "description": "Detik sampai permintaan ini bisa berhasil.",
                "schema": {
                  "type": "integer"
                }
              },
              "RateLimit-Limit": {
                "description": "Permintaan per menit untuk kunci ini.",
                "schema": {
                  "type": "integer"
                }
              },
              "RateLimit-Remaining": {
                "description": "Sisa token pada bucket.",
                "schema": {
                  "type": "integer"
                }
              },
              "RateLimit-Reset": {
                "description": "Detik sampai bucket penuh kembali.",
                "schema": {
                  "type": "integer"
                }
              }
            }
          }
        }
      },
      "post": {
        "operationId": "inbox.ticket.create",
        "summary": "Buat tiket baru.",
        "tags": [
          "inbox"
        ],
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "x-vybeflow-scope": "inbox.manage",
        "x-vybeflow-risk": "confirm",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": {
                      "type": "integer"
                    },
                    "errorCode": {
                      "type": "integer"
                    },
                    "data": {}
                  }
                }
              }
            }
          },
          "401": {
            "description": "API key tidak berlaku, dicabut, atau kedaluwarsa"
          },
          "403": {
            "description": "Kunci tidak mencakup `inbox.manage`"
          },
          "429": {
            "description": "Batas permintaan terlampaui. Tunggu selama `Retry-After` detik lalu ulangi permintaan yang sama.",
            "headers": {
              "Retry-After": {
                "description": "Detik sampai permintaan ini bisa berhasil.",
                "schema": {
                  "type": "integer"
                }
              },
              "RateLimit-Limit": {
                "description": "Permintaan per menit untuk kunci ini.",
                "schema": {
                  "type": "integer"
                }
              },
              "RateLimit-Remaining": {
                "description": "Sisa token pada bucket.",
                "schema": {
                  "type": "integer"
                }
              },
              "RateLimit-Reset": {
                "description": "Detik sampai bucket penuh kembali.",
                "schema": {
                  "type": "integer"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "msisdn",
                  "channel"
                ],
                "properties": {
                  "msisdn": {
                    "type": "string"
                  },
                  "channel": {
                    "type": "string"
                  },
                  "message": {
                    "type": "string"
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/ai/v1/tickets/stats": {
      "get": {
        "operationId": "inbox.ticket.stats",
        "summary": "Jumlah tiket per channel dan per status.",
        "tags": [
          "inbox"
        ],
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "x-vybeflow-scope": "inbox.read",
        "x-vybeflow-risk": "safe",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": {
                      "type": "integer"
                    },
                    "errorCode": {
                      "type": "integer"
                    },
                    "data": {}
                  }
                }
              }
            }
          },
          "401": {
            "description": "API key tidak berlaku, dicabut, atau kedaluwarsa"
          },
          "403": {
            "description": "Kunci tidak mencakup `inbox.read`"
          },
          "429": {
            "description": "Batas permintaan terlampaui. Tunggu selama `Retry-After` detik lalu ulangi permintaan yang sama.",
            "headers": {
              "Retry-After": {
                "description": "Detik sampai permintaan ini bisa berhasil.",
                "schema": {
                  "type": "integer"
                }
              },
              "RateLimit-Limit": {
                "description": "Permintaan per menit untuk kunci ini.",
                "schema": {
                  "type": "integer"
                }
              },
              "RateLimit-Remaining": {
                "description": "Sisa token pada bucket.",
                "schema": {
                  "type": "integer"
                }
              },
              "RateLimit-Reset": {
                "description": "Detik sampai bucket penuh kembali.",
                "schema": {
                  "type": "integer"
                }
              }
            }
          }
        }
      }
    },
    "/api/ai/v1/tickets/{ticketID}": {
      "get": {
        "operationId": "inbox.ticket.get",
        "summary": "Satu tiket beserta riwayat pesannya.",
        "tags": [
          "inbox"
        ],
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "x-vybeflow-scope": "inbox.read",
        "x-vybeflow-risk": "safe",
        "parameters": [
          {
            "name": "ticketID",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": {
                      "type": "integer"
                    },
                    "errorCode": {
                      "type": "integer"
                    },
                    "data": {}
                  }
                }
              }
            }
          },
          "401": {
            "description": "API key tidak berlaku, dicabut, atau kedaluwarsa"
          },
          "403": {
            "description": "Kunci tidak mencakup `inbox.read`"
          },
          "429": {
            "description": "Batas permintaan terlampaui. Tunggu selama `Retry-After` detik lalu ulangi permintaan yang sama.",
            "headers": {
              "Retry-After": {
                "description": "Detik sampai permintaan ini bisa berhasil.",
                "schema": {
                  "type": "integer"
                }
              },
              "RateLimit-Limit": {
                "description": "Permintaan per menit untuk kunci ini.",
                "schema": {
                  "type": "integer"
                }
              },
              "RateLimit-Remaining": {
                "description": "Sisa token pada bucket.",
                "schema": {
                  "type": "integer"
                }
              },
              "RateLimit-Reset": {
                "description": "Detik sampai bucket penuh kembali.",
                "schema": {
                  "type": "integer"
                }
              }
            }
          }
        }
      }
    },
    "/api/ai/v1/tickets/status/{status}": {
      "get": {
        "operationId": "inbox.ticket.byStatus",
        "summary": "Tiket dengan satu status tertentu.",
        "tags": [
          "inbox"
        ],
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "x-vybeflow-scope": "inbox.read",
        "x-vybeflow-risk": "safe",
        "parameters": [
          {
            "name": "status",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": {
                      "type": "integer"
                    },
                    "errorCode": {
                      "type": "integer"
                    },
                    "data": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "_id": {},
                          "ticketID": {},
                          "status": {},
                          "channel": {},
                          "customerName": {},
                          "lastMessageAt": {}
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "API key tidak berlaku, dicabut, atau kedaluwarsa"
          },
          "403": {
            "description": "Kunci tidak mencakup `inbox.read`"
          },
          "429": {
            "description": "Batas permintaan terlampaui. Tunggu selama `Retry-After` detik lalu ulangi permintaan yang sama.",
            "headers": {
              "Retry-After": {
                "description": "Detik sampai permintaan ini bisa berhasil.",
                "schema": {
                  "type": "integer"
                }
              },
              "RateLimit-Limit": {
                "description": "Permintaan per menit untuk kunci ini.",
                "schema": {
                  "type": "integer"
                }
              },
              "RateLimit-Remaining": {
                "description": "Sisa token pada bucket.",
                "schema": {
                  "type": "integer"
                }
              },
              "RateLimit-Reset": {
                "description": "Detik sampai bucket penuh kembali.",
                "schema": {
                  "type": "integer"
                }
              }
            }
          }
        }
      }
    },
    "/api/ai/v1/tickets/{ticketID}/reply": {
      "post": {
        "operationId": "inbox.ticket.reply",
        "summary": "Kirim balasan ke pelanggan pada satu tiket.",
        "tags": [
          "inbox"
        ],
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "x-vybeflow-scope": "inbox.reply",
        "x-vybeflow-risk": "destructive",
        "parameters": [
          {
            "name": "ticketID",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": {
                      "type": "integer"
                    },
                    "errorCode": {
                      "type": "integer"
                    },
                    "data": {}
                  }
                }
              }
            }
          },
          "401": {
            "description": "API key tidak berlaku, dicabut, atau kedaluwarsa"
          },
          "403": {
            "description": "Kunci tidak mencakup `inbox.reply`"
          },
          "429": {
            "description": "Batas permintaan terlampaui. Tunggu selama `Retry-After` detik lalu ulangi permintaan yang sama.",
            "headers": {
              "Retry-After": {
                "description": "Detik sampai permintaan ini bisa berhasil.",
                "schema": {
                  "type": "integer"
                }
              },
              "RateLimit-Limit": {
                "description": "Permintaan per menit untuk kunci ini.",
                "schema": {
                  "type": "integer"
                }
              },
              "RateLimit-Remaining": {
                "description": "Sisa token pada bucket.",
                "schema": {
                  "type": "integer"
                }
              },
              "RateLimit-Reset": {
                "description": "Detik sampai bucket penuh kembali.",
                "schema": {
                  "type": "integer"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "message"
                ],
                "properties": {
                  "message": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "description": "Pesan ini sampai ke pelanggan sungguhan dan tidak bisa ditarik kembali."
      }
    },
    "/api/ai/v1/tickets/{ticketID}/close": {
      "post": {
        "operationId": "inbox.ticket.close",
        "summary": "Tutup tiket.",
        "tags": [
          "inbox"
        ],
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "x-vybeflow-scope": "inbox.manage",
        "x-vybeflow-risk": "confirm",
        "parameters": [
          {
            "name": "ticketID",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": {
                      "type": "integer"
                    },
                    "errorCode": {
                      "type": "integer"
                    },
                    "data": {}
                  }
                }
              }
            }
          },
          "401": {
            "description": "API key tidak berlaku, dicabut, atau kedaluwarsa"
          },
          "403": {
            "description": "Kunci tidak mencakup `inbox.manage`"
          },
          "429": {
            "description": "Batas permintaan terlampaui. Tunggu selama `Retry-After` detik lalu ulangi permintaan yang sama.",
            "headers": {
              "Retry-After": {
                "description": "Detik sampai permintaan ini bisa berhasil.",
                "schema": {
                  "type": "integer"
                }
              },
              "RateLimit-Limit": {
                "description": "Permintaan per menit untuk kunci ini.",
                "schema": {
                  "type": "integer"
                }
              },
              "RateLimit-Remaining": {
                "description": "Sisa token pada bucket.",
                "schema": {
                  "type": "integer"
                }
              },
              "RateLimit-Reset": {
                "description": "Detik sampai bucket penuh kembali.",
                "schema": {
                  "type": "integer"
                }
              }
            }
          }
        }
      }
    }
  }
}
