{
  "name": "Website-Anfragen mit KI einordnen und Antwort entwerfen",
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "anfrage",
        "responseMode": "onReceived",
        "options": {}
      },
      "id": "a472bd72-3e54-5c7a-87b1-c0148e5d0bb7",
      "name": "Formular-Webhook",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        -440,
        0
      ],
      "webhookId": "ff5524a1-ba82-5e30-85f8-29dadeef8c4a"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "8afd9f13-f767-5ca8-a51a-196cffb46f56",
              "name": "ki_endpunkt",
              "value": "https://api.openai.com/v1/chat/completions",
              "type": "string"
            },
            {
              "id": "44f5a70f-f4f7-50c6-bedf-9a44b4cf6a92",
              "name": "ki_modell",
              "value": "gpt-5-mini",
              "type": "string"
            },
            {
              "id": "90143e94-eccd-5610-a9d4-d2a33cfdfd90",
              "name": "absender",
              "value": "automation@ihre-firma.de",
              "type": "string"
            },
            {
              "id": "e514962e-9b93-5886-b69b-147320ff739b",
              "name": "vertrieb_an",
              "value": "vertrieb@ihre-firma.de",
              "type": "string"
            },
            {
              "id": "3fabcd5e-da5a-59e6-a947-9adf3af4c00f",
              "name": "sammel_an",
              "value": "info@ihre-firma.de",
              "type": "string"
            }
          ]
        },
        "includeOtherFields": true,
        "options": {
          "includeBinary": true
        }
      },
      "id": "9905151f-78b2-5354-a48f-1ab0c3501b58",
      "name": "Konfiguration",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        -200,
        0
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "={{ $('Konfiguration').first().json.ki_endpunkt }}",
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "openAiApi",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ model: $('Konfiguration').first().json.ki_modell, response_format: { type: 'json_object' }, messages: [ { role: 'system', content: \"Du sortierst Kundenanfragen eines deutschen Betriebs. Antworte nur mit JSON: {thema, kundentyp (privat|gewerblich|unklar), dringlichkeit (hoch|normal|niedrig), zusammenfassung (max. 3 S\\u00e4tze), fehlende_angaben (Liste), antwortentwurf (freundlich, Sie-Form, max. 120 W\\u00f6rter, keine Preise zusagen)}.\" }, { role: 'user', content: 'Anfrage:\\n' + JSON.stringify($('Formular-Webhook').first().json.body ?? $('Formular-Webhook').first().json) } ] }) }}",
        "options": {
          "timeout": 60000
        }
      },
      "id": "7e1b72ad-ad25-54a3-b29b-bbe3696c88b3",
      "name": "KI: Anfrage einordnen",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        40,
        0
      ]
    },
    {
      "parameters": {
        "jsCode": "// Antwort des Sprachmodells (JSON) auslesen\nreturn $input.all().map((item, i) => {\n  const raw = item.json.choices?.[0]?.message?.content ?? '{}';\n  let data = {};\n  try { data = JSON.parse(raw); } catch (e) { data = { fehler: 'Antwort war kein JSON', roh: raw }; }\n  return { json: { ...data } };\n});"
      },
      "id": "2ddc71b3-8064-58dd-a7fd-c49cfc893d42",
      "name": "Antwort auslesen",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        260,
        0
      ]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": false,
            "leftValue": "",
            "typeValidation": "loose"
          },
          "conditions": [
            {
              "id": "518e46d4-d2c2-59d9-ad47-acbf4653c305",
              "leftValue": "={{ $json.dringlichkeit }}",
              "rightValue": "hoch",
              "operator": {
                "type": "string",
                "operation": "equals"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "9a9d6071-c73f-5cb6-889a-4533f70589a2",
      "name": "Dringend?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2,
      "position": [
        480,
        0
      ]
    },
    {
      "parameters": {
        "fromEmail": "={{ $('Konfiguration').first().json.absender }}",
        "toEmail": "={{ $('Konfiguration').first().json.vertrieb_an }}",
        "subject": "=DRINGEND: {{ $json.thema }}",
        "emailFormat": "text",
        "text": "={{ $json.zusammenfassung }}\n\nKundentyp: {{ $json.kundentyp }}\nFehlende Angaben: {{ $json.fehlende_angaben }}\n\n--- Antwortentwurf ---\n{{ $json.antwortentwurf }}\n\n--- Original ---\n{{ JSON.stringify($('Formular-Webhook').first().json.body, null, 2) }}",
        "options": {}
      },
      "id": "012ae839-04d0-5d7e-9e97-d2bc33b50cfb",
      "name": "Sofort an Vertrieb",
      "type": "n8n-nodes-base.emailSend",
      "typeVersion": 2.1,
      "position": [
        720,
        -100
      ]
    },
    {
      "parameters": {
        "fromEmail": "={{ $('Konfiguration').first().json.absender }}",
        "toEmail": "={{ $('Konfiguration').first().json.sammel_an }}",
        "subject": "=Neue Anfrage: {{ $json.thema }} ({{ $json.dringlichkeit }})",
        "emailFormat": "text",
        "text": "={{ $json.zusammenfassung }}\n\nKundentyp: {{ $json.kundentyp }}\nFehlende Angaben: {{ $json.fehlende_angaben }}\n\n--- Antwortentwurf ---\n{{ $json.antwortentwurf }}",
        "options": {}
      },
      "id": "00f5ee45-53ff-5e96-805e-6f776d90cfd5",
      "name": "Ins Sammelpostfach",
      "type": "n8n-nodes-base.emailSend",
      "typeVersion": 2.1,
      "position": [
        720,
        100
      ]
    },
    {
      "parameters": {
        "content": "## Website-Anfragen vorqualifizieren\nVorlage von roiwerk.com\n\n1. Ihr Kontaktformular schickt die Felder per POST an die Webhook-URL (Produktions-URL aus dem Webhook-Node)\n2. KI-Zugang hinterlegen, Empfänger in **Konfiguration** anpassen\n3. Die KI schickt nur Entwürfe, gesendet wird von einem Menschen\n\nTipp: Statt E-Mail lässt sich der Entwurf auch als Aufgabe in Ihr CRM oder in einen Teams-Kanal schreiben.",
        "height": 340,
        "width": 420
      },
      "id": "ac5002a6-8941-5bfe-9c2c-fd70e6d1981c",
      "name": "Hinweis",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -260,
        -420
      ]
    }
  ],
  "connections": {
    "Formular-Webhook": {
      "main": [
        [
          {
            "node": "Konfiguration",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Konfiguration": {
      "main": [
        [
          {
            "node": "KI: Anfrage einordnen",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "KI: Anfrage einordnen": {
      "main": [
        [
          {
            "node": "Antwort auslesen",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Antwort auslesen": {
      "main": [
        [
          {
            "node": "Dringend?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Dringend?": {
      "main": [
        [
          {
            "node": "Sofort an Vertrieb",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Ins Sammelpostfach",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "meta": {
    "templateCredsSetupCompleted": false,
    "source": "https://roiwerk.com/vorlagen/n8n-workflow-vorlagen"
  },
  "tags": []
}