openapi: 3.1.0 info: title: Api version: 0.1.0 description: Omniflow CRM API servers: - url: /api description: Base API path tags: - name: health description: Health operations - name: clients description: CRM client management - name: appointments description: Appointment calendar - name: messages description: WhatsApp AI assistant - name: stats description: Dashboard statistics paths: /healthz: get: operationId: healthCheck tags: [health] summary: Health check responses: "200": description: Healthy content: application/json: schema: $ref: "#/components/schemas/HealthStatus" # ── Clients ────────────────────────────────────────────────────────────── /clients: get: operationId: listClients tags: [clients] summary: List all clients parameters: - name: search in: query schema: type: string - name: status in: query schema: type: string - name: page in: query schema: type: integer - name: limit in: query schema: type: integer - name: commercialStatus in: query schema: type: string - name: sector in: query schema: type: string - name: priority in: query schema: type: string - name: autopilotActive in: query schema: type: boolean - name: hasFollowupPending in: query schema: type: boolean responses: "200": description: List of clients content: application/json: schema: type: array items: $ref: "#/components/schemas/Client" post: operationId: createClient tags: [clients] summary: Create a new client requestBody: required: true content: application/json: schema: $ref: "#/components/schemas/ClientInput" responses: "201": description: Created content: application/json: schema: $ref: "#/components/schemas/Client" /clients/{id}: get: operationId: getClient tags: [clients] summary: Get a client by ID parameters: - name: id in: path required: true schema: type: integer responses: "200": description: Client content: application/json: schema: $ref: "#/components/schemas/Client" "404": description: Not found patch: operationId: updateClient tags: [clients] summary: Update a client parameters: - name: id in: path required: true schema: type: integer requestBody: required: true content: application/json: schema: $ref: "#/components/schemas/ClientUpdate" responses: "200": description: Updated client content: application/json: schema: $ref: "#/components/schemas/Client" delete: operationId: deleteClient tags: [clients] summary: Delete a client parameters: - name: id in: path required: true schema: type: integer responses: "204": description: Deleted /clients/{id}/activity: get: operationId: getClientActivity tags: [clients] summary: Activity feed for a single client (Autopilot events, edits, etc.) parameters: - name: id in: path required: true schema: type: integer responses: "200": description: List of activity entries for this client content: application/json: schema: type: array items: $ref: "#/components/schemas/ClientActivity" # ── Appointments ────────────────────────────────────────────────────────── /appointments: get: operationId: listAppointments tags: [appointments] summary: List appointments parameters: - name: from in: query schema: type: string - name: to in: query schema: type: string - name: clientId in: query schema: type: integer - name: includeCancelled in: query description: >- By default only pending/confirmed appointments are returned. Set to true to also include cancelled and rescheduled ones (e.g. for a full-history view). schema: type: boolean responses: "200": description: List of appointments content: application/json: schema: type: array items: $ref: "#/components/schemas/Appointment" post: operationId: createAppointment tags: [appointments] summary: Create an appointment requestBody: required: true content: application/json: schema: $ref: "#/components/schemas/AppointmentInput" responses: "201": description: Created content: application/json: schema: $ref: "#/components/schemas/Appointment" /appointments/{id}: patch: operationId: updateAppointment tags: [appointments] summary: Update an appointment parameters: - name: id in: path required: true schema: type: integer requestBody: required: true content: application/json: schema: $ref: "#/components/schemas/AppointmentUpdate" responses: "200": description: Updated content: application/json: schema: $ref: "#/components/schemas/Appointment" delete: operationId: deleteAppointment tags: [appointments] summary: Delete an appointment parameters: - name: id in: path required: true schema: type: integer responses: "204": description: Deleted # ── WhatsApp Messages ────────────────────────────────────────────────────── /messages: get: operationId: listMessages tags: [messages] summary: List messages for a client conversation parameters: - name: clientId in: query required: true schema: type: integer responses: "200": description: Messages content: application/json: schema: type: array items: $ref: "#/components/schemas/Message" post: operationId: sendMessage tags: [messages] summary: Send a message (AI-assisted) requestBody: required: true content: application/json: schema: $ref: "#/components/schemas/MessageInput" responses: "201": description: Message sent content: application/json: schema: $ref: "#/components/schemas/Message" /messages/ai-reply: post: operationId: generateAiReply tags: [messages] summary: Generate an AI reply suggestion requestBody: required: true content: application/json: schema: $ref: "#/components/schemas/AiReplyRequest" responses: "200": description: AI reply suggestion content: application/json: schema: $ref: "#/components/schemas/AiReplyResponse" /conversations: get: operationId: listConversations tags: [messages] summary: List all client conversations responses: "200": description: Conversations content: application/json: schema: type: array items: $ref: "#/components/schemas/Conversation" # ── Statistics ──────────────────────────────────────────────────────────── /stats/dashboard: get: operationId: getDashboardStats tags: [stats] summary: Get dashboard summary stats responses: "200": description: Dashboard stats content: application/json: schema: $ref: "#/components/schemas/DashboardStats" /stats/revenue: get: operationId: getRevenueStats tags: [stats] summary: Get monthly revenue chart data responses: "200": description: Revenue data content: application/json: schema: type: array items: $ref: "#/components/schemas/RevenuePoint" /stats/clients: get: operationId: getClientStats tags: [stats] summary: Get client acquisition stats responses: "200": description: Client stats content: application/json: schema: type: array items: $ref: "#/components/schemas/ClientStatPoint" /stats/activity: get: operationId: getRecentActivity tags: [stats] summary: Get recent activity feed responses: "200": description: Activity feed content: application/json: schema: type: array items: $ref: "#/components/schemas/ActivityItem" components: schemas: HealthStatus: type: object properties: status: type: string required: [status] # ── Client ────────────────────────────────────────────────────────────── Client: type: object required: [id, name, email, status, createdAt] properties: id: type: integer name: type: string email: type: string phone: type: ["string", "null"] company: type: ["string", "null"] status: type: string enum: [lead, active, inactive, churned] tags: type: ["string", "null"] notes: type: ["string", "null"] value: type: ["number", "null"] commercialStatus: type: ["string", "null"] sector: type: ["string", "null"] contactPerson: type: ["string", "null"] companyPhone: type: ["string", "null"] companyEmail: type: ["string", "null"] instagram: type: ["string", "null"] website: type: ["string", "null"] location: type: ["string", "null"] firstContactAt: type: ["string", "null"] dolorPrincipal: type: ["string", "null"] recursoEnviado: type: ["string", "null"] fuenteLead: type: ["string", "null"] followup1At: type: ["string", "null"] followup2At: type: ["string", "null"] followup3At: type: ["string", "null"] nextFollowupAt: type: ["string", "null"] lastContactAt: type: ["string", "null"] attemptCount: type: integer preferredChannel: type: ["string", "null"] resultado: type: ["string", "null"] nextAction: type: ["string", "null"] priority: type: string enum: [low, medium, high, urgent] observaciones: type: ["string", "null"] createdAt: type: string ClientInput: type: object required: [name, email, status] properties: name: type: string email: type: string phone: type: string company: type: string status: type: string enum: [lead, active, inactive, churned] tags: type: string notes: type: string value: type: number commercialStatus: type: string sector: type: string contactPerson: type: string companyPhone: type: string companyEmail: type: string instagram: type: string website: type: string location: type: string firstContactAt: type: string dolorPrincipal: type: string recursoEnviado: type: string fuenteLead: type: string followup1At: type: string followup2At: type: string followup3At: type: string nextFollowupAt: type: string lastContactAt: type: string attemptCount: type: integer preferredChannel: type: string resultado: type: string nextAction: type: string priority: type: string enum: [low, medium, high, urgent] observaciones: type: string ClientUpdate: type: object properties: name: type: string email: type: string phone: type: string company: type: string status: type: string enum: [lead, active, inactive, churned] tags: type: string notes: type: string value: type: number commercialStatus: type: string sector: type: string contactPerson: type: string companyPhone: type: string companyEmail: type: string instagram: type: string website: type: string location: type: string firstContactAt: type: string dolorPrincipal: type: string recursoEnviado: type: string fuenteLead: type: string followup1At: type: string followup2At: type: string followup3At: type: string nextFollowupAt: type: string lastContactAt: type: string attemptCount: type: integer preferredChannel: type: string resultado: type: string nextAction: type: string priority: type: string enum: [low, medium, high, urgent] observaciones: type: string ClientActivity: type: object required: [id, type, description, createdAt] properties: id: type: integer type: type: string description: type: string createdAt: type: string # ── Appointment ────────────────────────────────────────────────────────── Appointment: type: object required: [id, title, startTime, endTime, clientId, status] properties: id: type: integer title: type: string description: type: ["string", "null"] startTime: type: string endTime: type: string clientId: type: integer clientName: type: ["string", "null"] clientCompany: type: ["string", "null"] status: type: string enum: [pending, confirmed, completed, cancelled, scheduled, no_show] type: type: ["string", "null"] reminder: type: boolean tags: type: ["string", "null"] location: type: ["string", "null"] createdAt: type: string AppointmentInput: type: object required: [title, startTime, endTime, clientId] properties: title: type: string description: type: string startTime: type: string endTime: type: string clientId: type: integer status: type: string enum: [pending, confirmed, completed, cancelled, scheduled, no_show] type: type: string reminder: type: boolean tags: type: string location: type: string AppointmentUpdate: type: object properties: title: type: string description: type: string startTime: type: string endTime: type: string status: type: string enum: [pending, confirmed, completed, cancelled, scheduled, no_show] type: type: string reminder: type: boolean tags: type: string location: type: string # ── Message ────────────────────────────────────────────────────────────── Message: type: object required: [id, clientId, content, direction, createdAt] properties: id: type: integer clientId: type: integer content: type: string direction: type: string enum: [inbound, outbound] isAi: type: boolean status: type: ["string", "null"] createdAt: type: string MessageInput: type: object required: [clientId, content] properties: clientId: type: integer content: type: string isAi: type: boolean AiReplyRequest: type: object required: [clientId, lastMessage] properties: clientId: type: integer lastMessage: type: string context: type: string AiReplyResponse: type: object required: [reply] properties: reply: type: string Conversation: type: object required: [clientId, clientName, lastMessage, lastMessageAt, unreadCount] properties: clientId: type: integer clientName: type: string clientPhone: type: ["string", "null"] lastMessage: type: string lastMessageAt: type: string unreadCount: type: integer # ── Stats ──────────────────────────────────────────────────────────────── DashboardStats: type: object required: [totalClients, activeClients, totalRevenue, appointmentsToday, leadsThisMonth, conversionRate] properties: totalClients: type: integer activeClients: type: integer totalRevenue: type: number appointmentsToday: type: integer leadsThisMonth: type: integer conversionRate: type: number revenueGrowth: type: number clientGrowth: type: number RevenuePoint: type: object required: [month, revenue] properties: month: type: string revenue: type: number target: type: ["number", "null"] ClientStatPoint: type: object required: [month, leads, converted] properties: month: type: string leads: type: integer converted: type: integer ActivityItem: type: object required: [id, type, description, createdAt] properties: id: type: integer type: type: string enum: [client_added, appointment_scheduled, message_sent, client_updated, appointment_completed] description: type: string clientName: type: ["string", "null"] createdAt: type: string