{
  "name": "CRM Lead Routing mit Slack Alert",
  "nodes": [
    {
      "parameters": {
        "path": "crm-lead-routing",
        "httpMethod": "POST",
        "responseMode": "responseNode",
        "options": {}
      },
      "id": "lead-webhook-empfangen",
      "name": "Lead Webhook empfangen",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        0,
        0
      ]
    },
    {
      "parameters": {
        "mode": "manual",
        "duplicateItem": false,
        "assignments": {
          "assignments": [
            {
              "id": "email",
              "name": "email",
              "value": "={{ $json.email || \"kunde@example.com\" }}",
              "type": "string"
            },
            {
              "id": "quelle",
              "name": "quelle",
              "value": "={{ $json.source || \"Website\" }}",
              "type": "string"
            },
            {
              "id": "budget",
              "name": "budget",
              "value": "={{ Number($json.budget || 0) }}",
              "type": "number"
            }
          ]
        },
        "options": {}
      },
      "id": "lead-daten-normalisieren",
      "name": "Lead Daten normalisieren",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        260,
        0
      ]
    },
    {
      "parameters": {
        "method": "GET",
        "url": "https://example.com/api/crm/contacts",
        "sendBody": true,
        "contentType": "json",
        "jsonBody": "={{ $json }}",
        "options": {},
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "email",
              "value": "={{ $json.email }}"
            }
          ]
        }
      },
      "id": "crm-kontakt-suchen",
      "name": "CRM Kontakt suchen",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        520,
        -90
      ]
    },
    {
      "parameters": {
        "jsCode": "return items.map((item) => ({ json: { ...item.json, score: Number(item.json.budget || 0) >= 5000 ? 85 : 45 } }));"
      },
      "id": "lead-score-berechnen",
      "name": "Lead Score berechnen",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        520,
        120
      ]
    },
    {
      "parameters": {
        "mode": "combine",
        "combineBy": "combineByPosition",
        "options": {}
      },
      "id": "kontakt-und-score-verbinden",
      "name": "Kontakt und Score verbinden",
      "type": "n8n-nodes-base.merge",
      "typeVersion": 3.2,
      "position": [
        780,
        0
      ]
    },
    {
      "parameters": {
        "conditions": {
          "conditions": [
            {
              "leftValue": "={{ $json.score }}",
              "rightValue": 70,
              "operator": {
                "type": "number",
                "operation": "gte"
              }
            }
          ]
        },
        "options": {}
      },
      "id": "a-lead-erkennen",
      "name": "A-Lead erkennen",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        1040,
        0
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://example.com/api/crm/deals",
        "sendBody": true,
        "contentType": "json",
        "jsonBody": "={\"email\":\"{{$json.email}}\",\"phase\":\"Beratung\",\"score\":{{$json.score}}}",
        "options": {}
      },
      "id": "a-lead-im-crm-anlegen",
      "name": "A-Lead im CRM anlegen",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1300,
        -150
      ]
    },
    {
      "parameters": {
        "resource": "message",
        "operation": "post",
        "channel": "#sales",
        "text": "={{ \"Neuer A-Lead: \" + $json.email + \" mit Score \" + $json.score }}"
      },
      "id": "sales-in-slack-informieren",
      "name": "Sales in Slack informieren",
      "type": "n8n-nodes-base.slack",
      "typeVersion": 2.3,
      "position": [
        1560,
        -150
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://example.com/api/crm/tasks",
        "sendBody": true,
        "contentType": "json",
        "jsonBody": "={\"email\":\"{{$json.email}}\",\"typ\":\"Nachfassen\"}",
        "options": {}
      },
      "id": "b-lead-als-aufgabe-speichern",
      "name": "B-Lead als Aufgabe speichern",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1300,
        150
      ]
    },
    {
      "parameters": {
        "respondWith": "json",
        "responseBody": "={\"status\":\"angenommen\",\"email\":\"{{$json.email}}\"}",
        "options": {}
      },
      "id": "webhook-bestaetigen",
      "name": "Webhook bestaetigen",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1.4,
      "position": [
        1820,
        0
      ]
    }
  ],
  "connections": {
    "Lead Webhook empfangen": {
      "main": [
        [
          {
            "node": "Lead Daten normalisieren",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Lead Daten normalisieren": {
      "main": [
        [
          {
            "node": "CRM Kontakt suchen",
            "type": "main",
            "index": 0
          },
          {
            "node": "Lead Score berechnen",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "CRM Kontakt suchen": {
      "main": [
        [
          {
            "node": "Kontakt und Score verbinden",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Lead Score berechnen": {
      "main": [
        [
          {
            "node": "Kontakt und Score verbinden",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Kontakt und Score verbinden": {
      "main": [
        [
          {
            "node": "A-Lead erkennen",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "A-Lead erkennen": {
      "main": [
        [
          {
            "node": "A-Lead im CRM anlegen",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "B-Lead als Aufgabe speichern",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "A-Lead im CRM anlegen": {
      "main": [
        [
          {
            "node": "Sales in Slack informieren",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Sales in Slack informieren": {
      "main": [
        [
          {
            "node": "Webhook bestaetigen",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "B-Lead als Aufgabe speichern": {
      "main": [
        [
          {
            "node": "Webhook bestaetigen",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  }
}
