{
  "name": "Lead Form to Email and Spreadsheet. A template by The Gridline Company",
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "new-lead",
        "responseMode": "responseNode",
        "options": {}
      },
      "id": "webhook-101",
      "name": "Lead Form Submission",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 1.1,
      "position": [240, 300],
      "webhookId": "gridline-lead-webhook"
    },
    {
      "parameters": {
        "resource": "chat",
        "operation": "message",
        "modelId": {
          "__rl": true,
          "value": "gpt-4o-mini",
          "mode": "list"
        },
        "messages": {
          "values": [
            {
              "content": "You write one-line email subject lines that summarize a customer inquiry. Be specific. Include the customer's name and what they want. No more than 80 characters. Example: 'Sarah at Westside Bakery wants a website rebuild quote'.",
              "role": "system"
            },
            {
              "content": "Name: {{ $json.body.name }}\nBusiness: {{ $json.body.business }}\nMessage: {{ $json.body.message }}",
              "role": "user"
            }
          ]
        },
        "options": {}
      },
      "id": "openai-102",
      "name": "Write Subject Line",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "typeVersion": 1.4,
      "position": [460, 300],
      "credentials": {
        "openAiApi": {
          "id": "REPLACE_WITH_YOUR_OPENAI_CREDENTIAL_ID",
          "name": "OpenAI account"
        }
      }
    },
    {
      "parameters": {
        "sendTo": "REPLACE_WITH_YOUR_EMAIL@example.com",
        "subject": "=New Lead: {{ $json.message.content }}",
        "emailType": "html",
        "message": "=<h2>New lead received</h2>\n<p><strong>Name:</strong> {{ $('Lead Form Submission').item.json.body.name }}</p>\n<p><strong>Email:</strong> {{ $('Lead Form Submission').item.json.body.email }}</p>\n<p><strong>Business:</strong> {{ $('Lead Form Submission').item.json.body.business }}</p>\n<p><strong>Message:</strong></p>\n<p>{{ $('Lead Form Submission').item.json.body.message }}</p>\n<hr>\n<p><a href=\"mailto:{{ $('Lead Form Submission').item.json.body.email }}\">Reply directly</a></p>",
        "options": {}
      },
      "id": "gmail-103",
      "name": "Send Email to You",
      "type": "n8n-nodes-base.gmail",
      "typeVersion": 2.1,
      "position": [680, 200],
      "credentials": {
        "gmailOAuth2": {
          "id": "REPLACE_WITH_YOUR_GMAIL_CREDENTIAL_ID",
          "name": "Gmail account"
        }
      }
    },
    {
      "parameters": {
        "operation": "append",
        "documentId": {
          "__rl": true,
          "value": "REPLACE_WITH_YOUR_GOOGLE_SHEET_ID",
          "mode": "id"
        },
        "sheetName": {
          "__rl": true,
          "value": "Sheet1",
          "mode": "list"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "Date": "={{ $now.toISO() }}",
            "Name": "={{ $('Lead Form Submission').item.json.body.name }}",
            "Email": "={{ $('Lead Form Submission').item.json.body.email }}",
            "Business": "={{ $('Lead Form Submission').item.json.body.business }}",
            "Message": "={{ $('Lead Form Submission').item.json.body.message }}",
            "AI Summary": "={{ $json.message.content }}"
          }
        },
        "options": {}
      },
      "id": "sheets-104",
      "name": "Add to Spreadsheet",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.4,
      "position": [680, 400],
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "REPLACE_WITH_YOUR_GOOGLE_SHEETS_CREDENTIAL_ID",
          "name": "Google Sheets account"
        }
      }
    },
    {
      "parameters": {
        "respondWith": "json",
        "responseBody": "={{ { success: true, message: 'Thanks! We\\'ll be in touch within 1 business day.' } }}",
        "options": {}
      },
      "id": "respond-105",
      "name": "Confirm to Visitor",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1.1,
      "position": [900, 300]
    }
  ],
  "connections": {
    "Lead Form Submission": {
      "main": [
        [{ "node": "Write Subject Line", "type": "main", "index": 0 }]
      ]
    },
    "Write Subject Line": {
      "main": [
        [
          { "node": "Send Email to You", "type": "main", "index": 0 },
          { "node": "Add to Spreadsheet", "type": "main", "index": 0 }
        ]
      ]
    },
    "Send Email to You": {
      "main": [
        [{ "node": "Confirm to Visitor", "type": "main", "index": 0 }]
      ]
    },
    "Add to Spreadsheet": {
      "main": [
        [{ "node": "Confirm to Visitor", "type": "main", "index": 0 }]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "gridline-002",
  "meta": {
    "templateCredsSetupCompleted": false,
    "instanceId": "gridline-company-templates"
  },
  "tags": [
    { "name": "Gridline Company", "id": "gridline" },
    { "name": "Lead Capture", "id": "leads" }
  ]
}
