{
  "openapi": "3.1.0",
  "info": {
    "title": "worcflow.ai API",
    "description": "Commitment tracking API for WhatsApp conversations. Extracts promises, deadlines, and follow-ups from chat messages. Monitors compliance and sends nudges for at-risk commitments.",
    "version": "1.0.0",
    "contact": {
      "name": "Lastbyte AI Labs Pvt Ltd",
      "url": "https://worcflow.ai",
      "email": "api@worcflow.ai"
    },
    "license": {
      "name": "Proprietary"
    }
  },
  "servers": [
    {
      "url": "https://api.worcflow.ai/v1",
      "description": "Production"
    }
  ],
  "paths": {
    "/messages/ingest": {
      "post": {
        "operationId": "ingestMessages",
        "summary": "Ingest WhatsApp messages",
        "description": "Submit WhatsApp chat messages for commitment extraction. Accepts raw chat export text, structured message arrays, or forwarded message objects.",
        "tags": ["Messages"],
        "security": [{ "bearerAuth": [] }],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["source", "format", "content"],
                "properties": {
                  "source": {
                    "type": "string",
                    "enum": ["whatsapp"],
                    "description": "Message source platform"
                  },
                  "format": {
                    "type": "string",
                    "enum": ["chat_export", "message_array", "forwarded"],
                    "description": "Format of the submitted content"
                  },
                  "content": {
                    "type": "string",
                    "description": "Raw message content or JSON string of messages"
                  },
                  "workspace_id": {
                    "type": "string",
                    "description": "Target workspace ID"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Messages ingested and commitments extracted",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "commitments_found": {
                      "type": "integer",
                      "description": "Number of commitments extracted"
                    },
                    "commitments": {
                      "type": "array",
                      "items": { "$ref": "#/components/schemas/Commitment" }
                    }
                  }
                }
              }
            }
          },
          "401": { "description": "Unauthorized" },
          "422": { "description": "Invalid input format" }
        }
      }
    },
    "/commitments": {
      "get": {
        "operationId": "queryCommitments",
        "summary": "Query commitments",
        "description": "Retrieve and filter tracked commitments by status, owner, client, date range, or confidence threshold.",
        "tags": ["Commitments"],
        "security": [{ "bearerAuth": [] }],
        "parameters": [
          {
            "name": "status",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": ["on_track", "at_risk", "overdue", "completed"]
            },
            "description": "Filter by commitment status"
          },
          {
            "name": "owner",
            "in": "query",
            "schema": { "type": "string" },
            "description": "Filter by commitment owner name"
          },
          {
            "name": "client",
            "in": "query",
            "schema": { "type": "string" },
            "description": "Filter by client name"
          },
          {
            "name": "due_before",
            "in": "query",
            "schema": { "type": "string", "format": "date" },
            "description": "Filter commitments due before this date"
          },
          {
            "name": "due_after",
            "in": "query",
            "schema": { "type": "string", "format": "date" },
            "description": "Filter commitments due after this date"
          },
          {
            "name": "limit",
            "in": "query",
            "schema": { "type": "integer", "default": 20 },
            "description": "Maximum number of results"
          },
          {
            "name": "offset",
            "in": "query",
            "schema": { "type": "integer", "default": 0 },
            "description": "Pagination offset"
          }
        ],
        "responses": {
          "200": {
            "description": "List of commitments",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "commitments": {
                      "type": "array",
                      "items": { "$ref": "#/components/schemas/Commitment" }
                    },
                    "total": { "type": "integer" },
                    "limit": { "type": "integer" },
                    "offset": { "type": "integer" }
                  }
                }
              }
            }
          },
          "401": { "description": "Unauthorized" }
        }
      }
    },
    "/commitments/at-risk": {
      "get": {
        "operationId": "getAtRiskCommitments",
        "summary": "Get at-risk commitments",
        "description": "Retrieve commitments that are approaching their deadline without completion confirmation. Returns commitments sorted by urgency.",
        "tags": ["Commitments"],
        "security": [{ "bearerAuth": [] }],
        "parameters": [
          {
            "name": "hours_ahead",
            "in": "query",
            "schema": { "type": "integer", "default": 24 },
            "description": "Look-ahead window in hours to identify at-risk commitments"
          }
        ],
        "responses": {
          "200": {
            "description": "List of at-risk commitments sorted by urgency",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "commitments": {
                      "type": "array",
                      "items": { "$ref": "#/components/schemas/Commitment" }
                    },
                    "total": { "type": "integer" }
                  }
                }
              }
            }
          },
          "401": { "description": "Unauthorized" }
        }
      }
    },
    "/nudges": {
      "post": {
        "operationId": "sendNudge",
        "summary": "Send a nudge",
        "description": "Send a reminder to the commitment owner via WhatsApp or email. Includes commitment details and deadline.",
        "tags": ["Nudges"],
        "security": [{ "bearerAuth": [] }],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["commitment_id"],
                "properties": {
                  "commitment_id": {
                    "type": "string",
                    "description": "ID of the commitment to nudge about"
                  },
                  "channel": {
                    "type": "string",
                    "enum": ["whatsapp", "email", "in_app"],
                    "default": "whatsapp",
                    "description": "Delivery channel for the nudge"
                  },
                  "message": {
                    "type": "string",
                    "description": "Optional custom message to include in the nudge"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Nudge sent successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "nudge_id": { "type": "string" },
                    "status": {
                      "type": "string",
                      "enum": ["sent", "queued", "failed"]
                    },
                    "commitment_id": { "type": "string" },
                    "channel": { "type": "string" },
                    "sent_at": { "type": "string", "format": "date-time" }
                  }
                }
              }
            }
          },
          "401": { "description": "Unauthorized" },
          "404": { "description": "Commitment not found" }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "API Key",
        "description": "API key authentication. Get your key at https://worcflow.ai/dashboard/api-keys"
      },
      "oauth2": {
        "type": "oauth2",
        "flows": {
          "clientCredentials": {
            "tokenUrl": "https://auth.worcflow.ai/oauth/token",
            "scopes": {
              "messages:write": "Ingest messages",
              "commitments:read": "Read commitments",
              "nudges:write": "Send nudges"
            }
          }
        }
      }
    },
    "schemas": {
      "Commitment": {
        "type": "object",
        "properties": {
          "id": { "type": "string", "example": "cmt_a1b2c3" },
          "text": {
            "type": "string",
            "example": "Will ship revised samples by Thursday"
          },
          "owner": { "type": "string", "example": "Rajesh" },
          "client": { "type": "string", "example": "Mehta Textiles" },
          "due": {
            "type": "string",
            "format": "date-time",
            "example": "2026-02-10T18:00:00+05:30"
          },
          "status": {
            "type": "string",
            "enum": ["on_track", "at_risk", "overdue", "completed"],
            "example": "at_risk"
          },
          "source_message_id": { "type": "string", "example": "msg_x7y8z9" },
          "confidence": { "type": "number", "example": 0.94 },
          "created_at": { "type": "string", "format": "date-time" },
          "updated_at": { "type": "string", "format": "date-time" }
        }
      }
    }
  }
}
