{
  "name": "01 - Lead-gen: Form -> Sheet + Notifica",
  "nodes": [
    {
      "parameters": {
        "content": "## 01 - Lead-gen: form -> arricchimento -> Sheet + notifica\n\n**Setup (10 min):**\n1. Apri il nodo *Nuovo lead (form)* e copia l'URL del form (Production URL)\n2. Collega credenziali Google Sheets e Telegram\n3. Sostituisci `INSERISCI_ID_GOOGLE_SHEET` e `INSERISCI_CHAT_ID`\n4. L'arricchimento via microlink.io e' opzionale: se fallisce, il flusso continua\n\nColonne attese nel foglio *Lead*: nome, email, azienda, sito, fonte, data, descrizione_azienda",
        "width": 520,
        "height": 320
      },
      "id": "98b4cf41-de49-4c8d-a926-5190614e20bb",
      "name": "Nota setup",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -780,
        -220
      ]
    },
    {
      "parameters": {
        "formTitle": "Contattaci",
        "formDescription": "Lascia i tuoi dati: ti ricontattiamo entro 24 ore.",
        "formFields": {
          "values": [
            {
              "fieldLabel": "Nome",
              "requiredField": true
            },
            {
              "fieldLabel": "Email",
              "fieldType": "email",
              "requiredField": true
            },
            {
              "fieldLabel": "Azienda"
            },
            {
              "fieldLabel": "Sito web"
            },
            {
              "fieldLabel": "Messaggio",
              "fieldType": "textarea"
            }
          ]
        },
        "options": {}
      },
      "id": "8d48a71b-b533-4bd3-8c3d-de2d3372e487",
      "name": "Nuovo lead (form)",
      "type": "n8n-nodes-base.formTrigger",
      "typeVersion": 2.2,
      "position": [
        -600,
        120
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "56b8712c-79df-4adc-a021-d2484e5806d7",
              "name": "nome",
              "value": "={{ ($json.Nome || '').trim() }}",
              "type": "string"
            },
            {
              "id": "937ecb1e-08fb-425a-ab0c-c788ca1d9e54",
              "name": "email",
              "value": "={{ ($json.Email || '').trim().toLowerCase() }}",
              "type": "string"
            },
            {
              "id": "00f4862f-29a5-4c24-b46c-b5498eb417a9",
              "name": "azienda",
              "value": "={{ ($json.Azienda || '').trim() }}",
              "type": "string"
            },
            {
              "id": "8e6b0713-8e5c-4e4d-a73f-fbd0669efd53",
              "name": "sito",
              "value": "={{ ($json['Sito web'] || '').trim().replace(/^https?:\\/\\//, '') }}",
              "type": "string"
            },
            {
              "id": "839d433b-6922-4c3f-8879-7fb5a9a51794",
              "name": "messaggio",
              "value": "={{ $json.Messaggio || '' }}",
              "type": "string"
            },
            {
              "id": "c3588510-62d5-4082-94e2-9c3168e3d4b4",
              "name": "fonte",
              "value": "form-sito",
              "type": "string"
            },
            {
              "id": "68f08a43-fbc1-400a-a18c-3bd3b83e4580",
              "name": "data",
              "value": "={{ $now.toISO() }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "id": "f6d22b82-7d24-4285-8558-d9f9deefa2ef",
      "name": "Normalizza dati",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        -380,
        120
      ]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": false,
            "leftValue": "",
            "typeValidation": "loose"
          },
          "conditions": [
            {
              "id": "9b0e1396-3bc5-4d9d-b0d7-8d93ff437d15",
              "leftValue": "={{ $json.email }}",
              "rightValue": "^[^@\\s]+@[^@\\s]+\\.[^@\\s]+$",
              "operator": {
                "type": "string",
                "operation": "regex"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "28b1b3ba-c1e1-44b6-b26e-056be5c59d4e",
      "name": "Email valida?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        -160,
        120
      ]
    },
    {
      "parameters": {
        "method": "GET",
        "url": "=https://api.microlink.io/?url=https://{{ $json.sito }}",
        "options": {
          "timeout": 10000
        }
      },
      "id": "87d98544-366a-4eef-91ac-1c7d83bfbe24",
      "name": "Arricchimento sito (opzionale)",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        80,
        20
      ],
      "onError": "continueRegularOutput"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "2928bb04-9d4d-4ef2-b180-62e6ae27ac66",
              "name": "descrizione_azienda",
              "value": "={{ $json.data?.description || '' }}",
              "type": "string"
            },
            {
              "id": "cdcd2943-196a-4354-8937-c2ca36fb0d46",
              "name": "nome",
              "value": "={{ $('Normalizza dati').item.json.nome }}",
              "type": "string"
            },
            {
              "id": "f66e4fac-4ddd-4c3a-9bd5-ce144d4c15f2",
              "name": "email",
              "value": "={{ $('Normalizza dati').item.json.email }}",
              "type": "string"
            },
            {
              "id": "58b2c123-57a6-4152-8042-ad7854345d7d",
              "name": "azienda",
              "value": "={{ $('Normalizza dati').item.json.azienda }}",
              "type": "string"
            },
            {
              "id": "2172b833-32c5-472e-9661-f0c4cc70f830",
              "name": "sito",
              "value": "={{ $('Normalizza dati').item.json.sito }}",
              "type": "string"
            },
            {
              "id": "d0033b11-f61d-4e65-9c34-6664fcbfe0ef",
              "name": "messaggio",
              "value": "={{ $('Normalizza dati').item.json.messaggio }}",
              "type": "string"
            },
            {
              "id": "eb34e4d9-219c-4f0b-9740-f02515a9191f",
              "name": "fonte",
              "value": "form-sito",
              "type": "string"
            },
            {
              "id": "69a7ab1f-2404-4795-b3ab-e17e69ef85e3",
              "name": "data",
              "value": "={{ $('Normalizza dati').item.json.data }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "id": "949cdc16-169e-49b0-a044-0178bd12913d",
      "name": "Unisci dati",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        300,
        20
      ]
    },
    {
      "parameters": {
        "operation": "append",
        "documentId": {
          "__rl": true,
          "mode": "id",
          "value": "INSERISCI_ID_GOOGLE_SHEET"
        },
        "sheetName": {
          "__rl": true,
          "mode": "name",
          "value": "Lead"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "nome": "={{ $json.nome }}",
            "email": "={{ $json.email }}",
            "azienda": "={{ $json.azienda }}",
            "sito": "={{ $json.sito }}",
            "fonte": "={{ $json.fonte }}",
            "data": "={{ $json.data }}",
            "descrizione_azienda": "={{ $json.descrizione_azienda }}"
          },
          "matchingColumns": [],
          "schema": []
        },
        "options": {}
      },
      "id": "6d67f985-94e4-4b3e-b543-2c0a54859fb4",
      "name": "Salva su Google Sheet (CRM)",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.5,
      "position": [
        520,
        20
      ]
    },
    {
      "parameters": {
        "chatId": "INSERISCI_CHAT_ID",
        "text": "=Nuovo lead dal sito!\nNome: {{ $json.nome }}\nEmail: {{ $json.email }}\nAzienda: {{ $json.azienda || '-' }}\nMessaggio: {{ $json.messaggio || '-' }}",
        "additionalFields": {}
      },
      "id": "b71fca1c-a994-433b-8b35-3e3b291c03ba",
      "name": "Notifica Telegram",
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [
        740,
        20
      ]
    },
    {
      "parameters": {},
      "id": "15964122-b970-4740-970f-5e47c0267fc9",
      "name": "Scartato (email non valida)",
      "type": "n8n-nodes-base.noOp",
      "typeVersion": 1,
      "position": [
        80,
        260
      ]
    }
  ],
  "connections": {
    "Nuovo lead (form)": {
      "main": [
        [
          {
            "node": "Normalizza dati",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Normalizza dati": {
      "main": [
        [
          {
            "node": "Email valida?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Email valida?": {
      "main": [
        [
          {
            "node": "Arricchimento sito (opzionale)",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Scartato (email non valida)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Arricchimento sito (opzionale)": {
      "main": [
        [
          {
            "node": "Unisci dati",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Unisci dati": {
      "main": [
        [
          {
            "node": "Salva su Google Sheet (CRM)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Salva su Google Sheet (CRM)": {
      "main": [
        [
          {
            "node": "Notifica Telegram",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "tags": []
}