{
  "id": "leadflowPortfolioDemo",
  "name": "LeadFlow — Synthetic Portfolio Demo",
  "active": false,
  "nodes": [
    {
      "id": "4e375f0b-6e2d-4c6d-9d01-000000000001",
      "name": "Webhook",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [0, 0],
      "webhookId": "4e375f0b-6e2d-4c6d-9d01-000000000008",
      "parameters": {
        "httpMethod": "POST",
        "path": "leadflow-portfolio-demo",
        "authentication": "none",
        "responseMode": "responseNode",
        "options": {}
      },
      "notes": "Public synthetic example. Send only {scenario: 'website/high-budget'} or {scenario: 'email/small-budget'}. No real personal data, model calls, CRM writes, or message delivery.",
      "notesInFlow": true
    },
    {
      "id": "4e375f0b-6e2d-4c6d-9d01-000000000002",
      "name": "Normalize preset",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [260, 0],
      "parameters": {
        "mode": "runOnceForAllItems",
        "language": "javaScript",
        "jsCode": "const body = $input.first().json.body;\nconst presets = {\n  'website/high-budget': { source: 'website', budget: 250000 },\n  'email/small-budget': { source: 'email', budget: 25000 },\n};\nconst validBody = body !== null && typeof body === 'object' && !Array.isArray(body);\nconst valid = validBody && Object.keys(body).length === 1 && Object.prototype.hasOwnProperty.call(body, 'scenario') && typeof body.scenario === 'string' && Object.prototype.hasOwnProperty.call(presets, body.scenario);\nconst timestamp = new Date().toISOString();\nif (!valid) {\n  return [{ json: { valid: false, engine: 'n8n', mode: 'synthetic', timestamp, error: { code: 'INVALID_SCENARIO', message: 'Send only a scenario preset. Personal data and additional fields are not accepted.', allowedScenarios: Object.keys(presets) }, steps: [{ id: 'webhook', label: 'Webhook получен', status: 'completed' }, { id: 'normalize', label: 'Проверка пресета', status: 'failed' }, { id: 'priority', label: 'Определение приоритета', status: 'skipped' }, { id: 'draft', label: 'Подготовка примера ответа', status: 'skipped' }], sentToClient: false } }];\n}\nconst preset = presets[body.scenario];\nreturn [{ json: { valid: true, engine: 'n8n', mode: 'synthetic', timestamp, scenario: body.scenario, lead: { name: 'Демо-компания', source: preset.source, budget: preset.budget }, steps: [{ id: 'webhook', label: 'Webhook получен', status: 'completed' }, { id: 'normalize', label: 'Пресет проверен', status: 'completed' }], sentToClient: false } }];"
      }
    },
    {
      "id": "4e375f0b-6e2d-4c6d-9d01-000000000003",
      "name": "Preset is valid",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2,
      "position": [520, 0],
      "parameters": {
        "conditions": {
          "options": { "caseSensitive": true, "leftValue": "", "typeValidation": "strict", "version": 2 },
          "conditions": [
            {
              "id": "preset-validation",
              "leftValue": "={{ $json.valid }}",
              "rightValue": true,
              "operator": { "type": "boolean", "operation": "true", "singleValue": true }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      }
    },
    {
      "id": "4e375f0b-6e2d-4c6d-9d01-000000000004",
      "name": "Determine Priority",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [780, -120],
      "parameters": {
        "mode": "runOnceForAllItems",
        "language": "javaScript",
        "jsCode": "const item = $input.first().json;\nconst priority = item.lead.budget >= 100000 ? 'high' : 'normal';\nreturn [{ json: { ...item, lead: { ...item.lead, priority }, steps: [...item.steps, { id: 'priority', label: 'Приоритет определён правилом бюджета', status: 'completed' }] } }];"
      },
      "notes": "Deterministic rule: budget >= 100000 RUB → high; otherwise normal. No AI model is called.",
      "notesInFlow": true
    },
    {
      "id": "4e375f0b-6e2d-4c6d-9d01-000000000005",
      "name": "Prepare example draft (awaiting manager approval)",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [1040, -120],
      "parameters": {
        "mode": "runOnceForAllItems",
        "language": "javaScript",
        "jsCode": "const item = $input.first().json;\nconst bodies = {\n  'website/high-budget': 'Заранее подготовленный пример, не результат AI. Демо-компания, спасибо за заявку с сайта. Бюджет примера — 250 000 ₽. Предлагаем согласовать встречу для обсуждения проекта. Черновик ожидает одобрения менеджера и не отправлен клиенту.',\n  'email/small-budget': 'Заранее подготовленный пример, не результат AI. Демо-компания, спасибо за письмо. Бюджет примера — 25 000 ₽. Предлагаем уточнить объём работ и выбрать базовый пакет. Черновик ожидает одобрения менеджера и не отправлен клиенту.',\n};\nconst { valid, ...response } = item;\nreturn [{ json: { ...response, draft: { body: bodies[item.scenario], approved: false, kind: 'prepared-example' }, steps: [...item.steps, { id: 'draft', label: 'Подготовлен заранее написанный пример', status: 'completed' }, { id: 'approval', label: 'Ожидается одобрение менеджера; в демо недоступно', status: 'awaiting_approval' }, { id: 'delivery', label: 'Отправка клиенту отключена', status: 'skipped' }], sentToClient: false } }];"
      },
      "notes": "Prepared text, NOT real AI. awaiting_approval is a business status only: the execution finishes immediately; no approval/resume endpoint, CRM save, or outbound delivery exists.",
      "notesInFlow": true
    },
    {
      "id": "4e375f0b-6e2d-4c6d-9d01-000000000006",
      "name": "Respond JSON",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1.4,
      "position": [1360, -120],
      "parameters": {
        "respondWith": "json",
        "responseBody": "={{ JSON.stringify({ ...$json, executionId: $execution.id }) }}",
        "options": {
          "responseCode": 200,
          "responseHeaders": { "entries": [{ "name": "Cache-Control", "value": "no-store" }] }
        }
      }
    },
    {
      "id": "4e375f0b-6e2d-4c6d-9d01-000000000007",
      "name": "Respond invalid scenario",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1.4,
      "position": [780, 180],
      "parameters": {
        "respondWith": "json",
        "responseBody": "={{ JSON.stringify({ engine: $json.engine, mode: $json.mode, timestamp: $json.timestamp, executionId: $execution.id, error: $json.error, steps: $json.steps, sentToClient: false }) }}",
        "options": {
          "responseCode": 400,
          "responseHeaders": { "entries": [{ "name": "Cache-Control", "value": "no-store" }] }
        }
      }
    }
  ],
  "connections": {
    "Webhook": { "main": [[{ "node": "Normalize preset", "type": "main", "index": 0 }]] },
    "Normalize preset": { "main": [[{ "node": "Preset is valid", "type": "main", "index": 0 }]] },
    "Preset is valid": {
      "main": [
        [{ "node": "Determine Priority", "type": "main", "index": 0 }],
        [{ "node": "Respond invalid scenario", "type": "main", "index": 0 }]
      ]
    },
    "Determine Priority": { "main": [[{ "node": "Prepare example draft (awaiting manager approval)", "type": "main", "index": 0 }]] },
    "Prepare example draft (awaiting manager approval)": { "main": [[{ "node": "Respond JSON", "type": "main", "index": 0 }]] }
  },
  "settings": {
    "executionOrder": "v1",
    "executionTimeout": 20,
    "saveManualExecutions": false,
    "saveDataSuccessExecution": "none",
    "saveDataErrorExecution": "none",
    "saveExecutionProgress": false
  },
  "pinData": {},
  "tags": []
}
