{
  "id": "c3d4e5f6-a7b8-9012-cdef-012345678901",
  "name": "FAQ-Assistent — Wissensbank-Ingestion",
  "active": false,
  "versionId": "d4e5f6a7-b8c9-0123-def0-123456789012",
  "nodes": [
    {
      "id": "ingest-webhook",
      "name": "Ingest-Webhook",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [200, 300],
      "webhookId": "faq-ingest",
      "parameters": {
        "httpMethod": "POST",
        "path": "faq-ingest",
        "responseMode": "responseNode",
        "options": {}
      }
    },
    {
      "id": "validate-input",
      "name": "Eingabe validieren",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [420, 300],
      "parameters": {
        "jsCode": "const body = $input.first().json.body || $input.first().json;\nconst content = (body.content || '').trim();\nconst source = (body.source || 'FAQ').trim();\nconst language = (body.language || 'de').trim();\n\nif (!content) return [{ json: { valid: false, error: 'Kein Inhalt angegeben.' } }];\nif (content.length > 2000) return [{ json: { valid: false, error: 'Inhalt zu lang (max. 2000 Zeichen).' } }];\n\nreturn [{ json: { valid: true, content, source, language } }];"
      }
    },
    {
      "id": "check-valid",
      "name": "Validierung OK?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2,
      "position": [640, 300],
      "parameters": {
        "conditions": {
          "options": { "caseSensitive": true, "leftValue": "", "typeValidation": "strict" },
          "conditions": [
            {
              "leftValue": "={{ $json.valid }}",
              "rightValue": true,
              "operator": { "type": "boolean", "operation": "true" }
            }
          ],
          "combinator": "and"
        }
      }
    },
    {
      "id": "error-response",
      "name": "Fehler zurückgeben",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1,
      "position": [860, 460],
      "parameters": {
        "respondWith": "json",
        "responseBody": "={{ JSON.stringify({ success: false, error: $json.error }) }}",
        "options": { "responseCode": 400 }
      }
    },
    {
      "id": "embed-content",
      "name": "Inhalt einbetten (OpenAI)",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [860, 200],
      "credentials": {
        "httpHeaderAuth": {
          "id": "openai-api-header-auth",
          "name": "OpenAI API (Bearer)"
        }
      },
      "parameters": {
        "method": "POST",
        "url": "https://api.openai.com/v1/embeddings",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ { input: $json.content, model: 'text-embedding-3-small' } }}",
        "options": {}
      }
    },
    {
      "id": "store-in-supabase",
      "name": "In Wissensdatenbank speichern",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [1080, 200],
      "parameters": {
        "method": "POST",
        "url": "https://YOUR_PROJECT_REF.supabase.co/rest/v1/documents",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            { "name": "apikey", "value": "YOUR_SUPABASE_ANON_KEY" },
            { "name": "Authorization", "value": "Bearer YOUR_SUPABASE_ANON_KEY" },
            { "name": "Prefer", "value": "return=minimal" }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ { content: $('Eingabe validieren').first().json.content, source: $('Eingabe validieren').first().json.source, language: $('Eingabe validieren').first().json.language, embedding: $json.data[0].embedding } }}",
        "options": {}
      }
    },
    {
      "id": "success-response",
      "name": "Gespeichert",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1,
      "position": [1300, 200],
      "parameters": {
        "respondWith": "json",
        "responseBody": "={{ JSON.stringify({ success: true, message: 'Inhalt gespeichert.' }) }}",
        "options": { "responseCode": 201 }
      }
    }
  ],
  "connections": {
    "Ingest-Webhook": {
      "main": [[{ "node": "Eingabe validieren", "type": "main", "index": 0 }]]
    },
    "Eingabe validieren": {
      "main": [[{ "node": "Validierung OK?", "type": "main", "index": 0 }]]
    },
    "Validierung OK?": {
      "main": [
        [{ "node": "Inhalt einbetten (OpenAI)", "type": "main", "index": 0 }],
        [{ "node": "Fehler zurückgeben", "type": "main", "index": 0 }]
      ]
    },
    "Inhalt einbetten (OpenAI)": {
      "main": [[{ "node": "In Wissensdatenbank speichern", "type": "main", "index": 0 }]]
    },
    "In Wissensdatenbank speichern": {
      "main": [[{ "node": "Gespeichert", "type": "main", "index": 0 }]]
    }
  },
  "settings": { "executionOrder": "v1" },
  "meta": { "templateCredsSetupCompleted": true }
}
