{
  "openapi": "3.1.0",
  "info": {
    "title": "FlowX by NOVIX API",
    "version": "1.0.0",
    "summary": "Connect any chat application to a Novix shared inbox.",
    "description": "Two directions. **Inbound**: your app POSTs end-user messages to Novix. **Outbound**: Novix POSTs events to your webhook, signed with HMAC-SHA256.\n\nNothing here is specific to one vendor — any application that can make an HTTPS request can integrate.\n\n## Authentication\nEvery request carries `Authorization: Bearer nvx_…`. The key determines the workspace; you never pass a workspace id. Keys are shown once at creation and stored only as a SHA-256 hash.\n\n## Idempotency\nSend `message_id` with every inbound message. Re-delivering the same `message_id` returns the original ids with `duplicate: true` instead of creating a second message. Webhook retries are normal operation, not an incident.\n\n## Webhook signatures\n```\nNovix-Signature: t=1727000000,v1=<hex hmac-sha256>\n```\nThe signed string is `${t}.${rawBody}`. Reject payloads whose `t` is more than 5 minutes old — that is what stops replay of a captured request.",
    "contact": {
      "name": "Novix",
      "url": "https://conv.ai-novix.com/docs",
      "email": "support@ai-novix.com"
    },
    "license": {
      "name": "Proprietary"
    }
  },
  "servers": [
    {
      "url": "https://conv.ai-novix.com",
      "description": "Production"
    },
    {
      "url": "http://localhost:5041",
      "description": "Local development"
    }
  ],
  "security": [
    {
      "apiKey": []
    }
  ],
  "tags": [
    {
      "name": "Messages",
      "description": "Send and receive messages"
    },
    {
      "name": "Conversations",
      "description": "Read conversation state"
    },
    {
      "name": "System",
      "description": "Connectivity checks"
    },
    {
      "name": "Calls",
      "description": "Voice calls over the internet"
    }
  ],
  "paths": {
    "/v1/health": {
      "get": {
        "tags": [
          "System"
        ],
        "operationId": "health",
        "summary": "Verify an API key",
        "description": "First call to make when integrating. Confirms the key works and shows which workspace and channel it is bound to.",
        "responses": {
          "200": {
            "description": "Key is valid",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ok": {
                      "type": "boolean"
                    },
                    "workspace_id": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "scope": {
                      "type": "string",
                      "enum": [
                        "read",
                        "read_write"
                      ]
                    },
                    "channel_id": {
                      "type": [
                        "string",
                        "null"
                      ],
                      "format": "uuid"
                    },
                    "server_time": {
                      "type": "string",
                      "format": "date-time"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      }
    },
    "/v1/inbound": {
      "post": {
        "tags": [
          "Messages"
        ],
        "operationId": "inbound",
        "summary": "Deliver an end-user message into Novix",
        "description": "Call this when a customer sends a message in your application. Novix creates the contact and conversation on first contact and reuses them afterwards.\n\nA conversation closed less than 24 hours ago is reopened rather than duplicated.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/InboundMessage"
              },
              "examples": {
                "text": {
                  "summary": "Plain text",
                  "value": {
                    "user_id": "u_8891",
                    "message_id": "m_5512",
                    "text": "Is my order shipped yet?",
                    "name": "Lan Nguyen",
                    "lang": "vi"
                  }
                },
                "withImage": {
                  "summary": "With an attachment",
                  "value": {
                    "user_id": "u_8891",
                    "message_id": "m_5513",
                    "text": "Here is the receipt",
                    "media": [
                      {
                        "type": "image",
                        "url": "https://cdn.example.com/r.jpg"
                      }
                    ]
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Message accepted",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/IngestResult"
                }
              }
            }
          },
          "200": {
            "description": "Duplicate — this `message_id` was already accepted. The original ids are returned.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/IngestResult"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        }
      }
    },
    "/v1/messages": {
      "post": {
        "tags": [
          "Messages"
        ],
        "operationId": "sendMessage",
        "summary": "Send a reply on behalf of the business",
        "description": "Use this when your own bot answers. Messages authored by a human agent in the Novix inbox do not go through this endpoint.\n\nFor channels with an external platform (Telegram and others), a `502` means the message is stored in the inbox marked as failed and was not delivered to the platform.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/OutboundMessage"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Sent",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "delivery_status": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "502": {
            "description": "Stored, but the platform rejected delivery"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        }
      }
    },
    "/v1/conversations": {
      "get": {
        "tags": [
          "Conversations"
        ],
        "operationId": "listConversations",
        "summary": "List conversations",
        "description": "Newest activity first. Page with `cursor` — offset paging skips rows when new messages arrive mid-listing.",
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 50,
              "maximum": 100
            }
          },
          {
            "name": "status",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "ai",
                "needs_human",
                "open",
                "resolved",
                "closed"
              ]
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "description": "Pass `next_cursor` from the previous page.",
            "schema": {
              "type": "string",
              "format": "date-time"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Conversation"
                      }
                    },
                    "next_cursor": {
                      "type": [
                        "string",
                        "null"
                      ],
                      "format": "date-time"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      }
    },
    "/v1/conversations/{id}/messages": {
      "get": {
        "tags": [
          "Conversations"
        ],
        "operationId": "listMessages",
        "summary": "Read one conversation's history",
        "description": "Oldest first, so you can append straight into a chat view.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 50,
              "maximum": 200
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Message"
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/v1/calls": {
      "post": {
        "tags": [
          "Calls"
        ],
        "operationId": "startCall",
        "summary": "Start a voice call from your app",
        "description": "Call this when the customer taps the call button in your app. Returns a room URL and a short-lived token — join it with the LiveKit client SDK (web, iOS, Android, React Native).\n\nThe agent sees the call ringing in the Novix inbox in real time. If nobody answers within 60 seconds the call is marked missed and a note lands in the conversation thread.\n\nCalls attach to the same conversation as that customer's messages — one person, one thread, whether they typed or called.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "user_id"
                ],
                "properties": {
                  "channel_id": {
                    "type": "string",
                    "format": "uuid",
                    "description": "Required only when the key is not bound to a channel."
                  },
                  "user_id": {
                    "type": "string",
                    "maxLength": 200,
                    "description": "Same stable id you use for messages — this is what links the call to the right person."
                  },
                  "name": {
                    "type": "string",
                    "maxLength": 200
                  },
                  "metadata": {
                    "type": "object",
                    "additionalProperties": true
                  },
                  "customer_id": {
                    "type": "string",
                    "maxLength": 200,
                    "description": "Mã khách hàng bên CRM của bạn (顧客ID). Gửi kèm thì Novix gắn mã này cho khách, và nhân viên tra cứu được bằng chính mã đó. Chỉ gắn khi khách chưa có mã — không bao giờ đè lên mã đã có.",
                    "example": "KH-00123"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Call ringing",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "call_id": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "conversation_id": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "room": {
                      "type": "object",
                      "properties": {
                        "url": {
                          "type": "string",
                          "description": "wss:// address to connect to"
                        },
                        "token": {
                          "type": "string",
                          "description": "Short-lived join token, 30 minutes"
                        },
                        "name": {
                          "type": "string"
                        }
                      }
                    },
                    "expires_at": {
                      "type": "string",
                      "format": "date-time"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "503": {
            "description": "Voice calling not enabled on this platform"
          }
        }
      }
    },
    "/v1/contacts": {
      "get": {
        "summary": "Tra khách hàng theo mã CRM",
        "description": "Hai loại mã, chọn một: `customer_id` là 顧客ID bên CRM của bạn, `code` là mã Novix tự cấp: chữ cái của kênh khách liên hệ đầu tiên + 13 chữ số (f Messenger · l LINE · z Zalo · t Telegram · i Instagram · w WhatsApp · c Webchat · k TikTok · a API · p Gọi điện · n tạo tay), ví dụ z4817203958816. Khách web chat không có mã CRM nên `code` là cách duy nhất tra ra họ. Không phân biệt hoa thường, bỏ qua khoảng trắng và gạch ('Z 4817 2039 58816' vẫn ra).",
        "parameters": [
          {
            "name": "customer_id",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "maxLength": 200
            },
            "example": "KH-00123"
          },
          {
            "name": "code",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "maxLength": 40
            },
            "example": "z4817203958816"
          }
        ],
        "responses": {
          "200": {
            "description": "Tìm thấy",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "contact_id": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "customer_id": {
                      "type": "string",
                      "nullable": true
                    },
                    "name": {
                      "type": "string"
                    },
                    "email": {
                      "type": "string",
                      "nullable": true
                    },
                    "phone": {
                      "type": "string",
                      "nullable": true
                    },
                    "conversation_id": {
                      "type": "string",
                      "format": "uuid",
                      "nullable": true
                    },
                    "last_message_at": {
                      "type": "string",
                      "format": "date-time",
                      "nullable": true
                    },
                    "code": {
                      "type": "string",
                      "description": "Mã khách do Novix cấp, luôn có."
                    }
                  }
                }
              }
            }
          },
          "404": {
            "description": "Không có khách hàng nào mang mã này"
          }
        }
      },
      "patch": {
        "summary": "Cập nhật khách hàng",
        "description": "Cập nhật khách theo customer_id (mã CRM) hoặc code (mã Novix). Cần API key phạm vi read_write. Trường không gửi thì giữ nguyên; customer_id rỗng/null = gỡ mã.",
        "parameters": [
          {
            "name": "customer_id",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "maxLength": 200
            },
            "example": "KH-00123"
          },
          {
            "name": "code",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "maxLength": 40
            },
            "example": "z4817203958816"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "name": {
                    "type": "string",
                    "maxLength": 200
                  },
                  "email": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "format": "email"
                  },
                  "phone": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "maxLength": 40
                  },
                  "customer_id": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "maxLength": 200
                  },
                  "tags": {
                    "type": "array",
                    "items": {
                      "type": "string",
                      "maxLength": 40
                    },
                    "maxItems": 20
                  },
                  "stage": {
                    "type": "string",
                    "enum": [
                      "lead",
                      "engaged",
                      "customer",
                      "churned"
                    ]
                  }
                }
              },
              "example": {
                "name": "Nguyễn Lan",
                "tags": [
                  "vip"
                ],
                "stage": "customer"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Khách sau khi cập nhật"
          },
          "403": {
            "description": "API key chỉ có phạm vi read"
          },
          "404": {
            "description": "Không có khách mang mã này"
          },
          "409": {
            "description": "customer_id đang thuộc khách khác"
          }
        }
      }
    },
    "/v1/uploads": {
      "post": {
        "summary": "Xin chỗ tải một tệp lên (tới 25 MB)",
        "description": "Bước 1 của gửi ảnh/tệp. PUT nội dung tệp vào `upload_url` (header Content-Type = mime), rồi dùng nguyên object `media` trong POST /v1/inbound hoặc POST /v1/messages. `upload_url` sống 2 giờ.",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "name",
                  "size"
                ],
                "properties": {
                  "name": {
                    "type": "string",
                    "maxLength": 255
                  },
                  "size": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 26214400
                  },
                  "mime": {
                    "type": "string",
                    "maxLength": 120
                  }
                }
              },
              "example": {
                "name": "hoa-don.pdf",
                "size": 48213,
                "mime": "application/pdf"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Chỗ tải lên",
            "content": {
              "application/json": {
                "example": {
                  "upload_url": "https://…",
                  "upload_method": "PUT",
                  "expires_in": 7200,
                  "media": {
                    "type": "file",
                    "path": "…",
                    "name": "hoa-don.pdf",
                    "size": 48213,
                    "mime": "application/pdf"
                  }
                }
              }
            }
          },
          "403": {
            "description": "API key chỉ có phạm vi read"
          }
        }
      }
    }
  },
  "webhooks": {
    "message.created": {
      "post": {
        "summary": "A message was created",
        "description": "Fires for every message in either direction — customer, AI, human agent, and system notices. Check `direction` and `author` to decide what to show.",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/WebhookEnvelope"
              }
            }
          }
        },
        "responses": {
          "2XX": {
            "description": "Any 2xx marks the delivery as accepted. Anything else is retried: 1m, 5m, 15m, 1h, 3h, 6h, 12h, 24h, then given up. An endpoint failing for 3 days straight is paused automatically."
          }
        }
      }
    },
    "conversation.handoff": {
      "post": {
        "summary": "The AI handed the conversation to a human",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/WebhookEnvelope"
              }
            }
          }
        },
        "responses": {
          "2XX": {
            "description": "Accepted"
          }
        }
      }
    },
    "conversation.closed": {
      "post": {
        "summary": "A conversation was closed",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/WebhookEnvelope"
              }
            }
          }
        },
        "responses": {
          "2XX": {
            "description": "Accepted"
          }
        }
      }
    },
    "contact.updated": {
      "post": {
        "summary": "A contact profile changed",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/WebhookEnvelope"
              }
            }
          }
        },
        "responses": {
          "2XX": {
            "description": "Accepted"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "apiKey": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "nvx_<64 hex>",
        "description": "Create keys in Settings → API & Webhook. A key carries a scope (`read` or `read_write`) and may be bound to a single channel."
      }
    },
    "schemas": {
      "Media": {
        "type": "object",
        "required": [
          "type"
        ],
        "description": "Một ảnh/tệp. Dùng đúng một trong hai: `path` (từ POST /v1/uploads — khuyên dùng) hoặc `url` https công khai (Novix tự tải về kho). Khi Novix trả tệp ra (webhook, GET messages) thì chỉ có `url` — đường dẫn tải có hạn.",
        "properties": {
          "type": {
            "type": "string",
            "enum": [
              "image",
              "file",
              "audio",
              "video"
            ]
          },
          "path": {
            "type": "string",
            "maxLength": 500
          },
          "url": {
            "type": "string",
            "format": "uri"
          },
          "name": {
            "type": "string",
            "maxLength": 300
          },
          "size": {
            "type": "integer",
            "minimum": 0
          },
          "mime": {
            "type": "string",
            "maxLength": 120
          }
        }
      },
      "InboundMessage": {
        "type": "object",
        "required": [
          "user_id"
        ],
        "properties": {
          "channel_id": {
            "type": "string",
            "format": "uuid",
            "description": "Required only when the key is not bound to a channel."
          },
          "user_id": {
            "type": "string",
            "maxLength": 200,
            "description": "Stable id of the end user in your system. Novix uses it to recognise returning people."
          },
          "text": {
            "type": "string",
            "maxLength": 8000
          },
          "message_id": {
            "type": "string",
            "maxLength": 200,
            "description": "Your message id. Send it and re-delivery is free of duplicates."
          },
          "name": {
            "type": "string",
            "maxLength": 200
          },
          "handle": {
            "type": "string",
            "maxLength": 200
          },
          "lang": {
            "type": "string",
            "maxLength": 10,
            "description": "BCP-47, e.g. `vi`, `ja`, `en`."
          },
          "media": {
            "type": "array",
            "maxItems": 10,
            "items": {
              "$ref": "#/components/schemas/Media"
            }
          },
          "metadata": {
            "type": "object",
            "additionalProperties": true
          },
          "customer_id": {
            "type": "string",
            "maxLength": 200,
            "description": "Mã khách hàng bên CRM của bạn (顧客ID). Gửi kèm thì Novix gắn mã này cho khách, và nhân viên tra cứu được bằng chính mã đó. Chỉ gắn khi khách chưa có mã — không bao giờ đè lên mã đã có.",
            "example": "KH-00123"
          },
          "avatar_url": {
            "type": "string",
            "format": "uri",
            "description": "Ảnh đại diện của người dùng bên app của bạn (chỉ https). Novix hiện nó trong hộp thư.",
            "example": "https://cdn.app.example/u/123.jpg"
          },
          "profile": {
            "type": "object",
            "maxProperties": 20,
            "additionalProperties": {
              "oneOf": [
                {
                  "type": "string",
                  "maxLength": 300
                },
                {
                  "type": "number"
                },
                {
                  "type": "boolean"
                }
              ]
            },
            "description": "Thông tin hồ sơ khác để nhân viên thấy ở mục «Thông tin từ nền tảng» (hạng thành viên, gói cước…). Tên mục hiện nguyên văn — nên đặt tên dễ đọc. Gửi lại thì gộp với cái cũ.",
            "example": {
              "Hạng thành viên": "Gold",
              "Gói cước": "5G 30GB"
            }
          }
        }
      },
      "OutboundMessage": {
        "type": "object",
        "required": [
          "conversation_id"
        ],
        "properties": {
          "conversation_id": {
            "type": "string",
            "format": "uuid"
          },
          "text": {
            "type": "string",
            "maxLength": 8000
          },
          "media": {
            "type": "array",
            "maxItems": 10,
            "items": {
              "$ref": "#/components/schemas/Media"
            }
          },
          "author": {
            "type": "string",
            "enum": [
              "ai",
              "agent"
            ],
            "default": "ai",
            "description": "Changes how the message is rendered in the inbox."
          },
          "translate": {
            "type": "boolean",
            "default": true,
            "description": "Dịch tin sang ngôn ngữ khách đang dùng (nhận diện từ tin khách gửi tới) trước khi gửi. Tin đã đúng ngôn ngữ khách thì giữ nguyên. Đặt false nếu bot của bạn tự lo ngôn ngữ."
          }
        }
      },
      "IngestResult": {
        "type": "object",
        "properties": {
          "contact_id": {
            "type": "string",
            "format": "uuid"
          },
          "conversation_id": {
            "type": "string",
            "format": "uuid"
          },
          "message_id": {
            "type": "string",
            "format": "uuid"
          },
          "duplicate": {
            "type": "boolean",
            "description": "`true` means this `message_id` had already been accepted. Not an error."
          }
        }
      },
      "Conversation": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "contact_id": {
            "type": "string",
            "format": "uuid"
          },
          "channel_id": {
            "type": "string",
            "format": "uuid"
          },
          "status": {
            "type": "string",
            "enum": [
              "ai",
              "needs_human",
              "open",
              "resolved",
              "closed"
            ]
          },
          "assignee_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "last_message_at": {
            "type": "string",
            "format": "date-time"
          },
          "last_message_preview": {
            "type": [
              "string",
              "null"
            ]
          },
          "unread_count": {
            "type": "integer"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "Message": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "direction": {
            "type": "string",
            "enum": [
              "in",
              "out"
            ]
          },
          "author": {
            "type": "string",
            "enum": [
              "customer",
              "ai",
              "agent",
              "system"
            ]
          },
          "body": {
            "type": "string"
          },
          "body_translated": {
            "type": [
              "string",
              "null"
            ]
          },
          "lang": {
            "type": [
              "string",
              "null"
            ]
          },
          "media": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Media"
            }
          },
          "delivery_status": {
            "type": "string",
            "enum": [
              "pending",
              "sent",
              "delivered",
              "read",
              "failed"
            ]
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "WebhookEnvelope": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "description": "Event id, e.g. `evt_4412`. Stable across retries — use it to deduplicate."
          },
          "type": {
            "type": "string",
            "example": "message.created"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "data": {
            "type": "object",
            "additionalProperties": true
          }
        }
      },
      "Error": {
        "type": "object",
        "properties": {
          "error": {
            "type": "object",
            "properties": {
              "code": {
                "type": "string",
                "description": "Stable machine-readable code. Branch on this, not on the message."
              },
              "message": {
                "type": "string"
              }
            }
          }
        }
      }
    },
    "responses": {
      "BadRequest": {
        "description": "Malformed request",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "Unauthorized": {
        "description": "Missing, invalid or revoked API key",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "Forbidden": {
        "description": "Key lacks the scope, or targets another workspace's channel",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "NotFound": {
        "description": "No such resource in this workspace",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "TooManyRequests": {
        "description": "Rate limit exceeded for this API key (120 requests/minute)",
        "headers": {
          "Retry-After": {
            "description": "Seconds until the current window resets",
            "schema": {
              "type": "integer"
            }
          }
        },
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      }
    }
  }
}