{
  "name": "Inbound lead responder (Agent Routines)",
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "inbound-lead",
        "responseMode": "onReceived",
        "options": {}
      },
      "id": "de68c37b-3d81-58df-bb79-db2650596c05",
      "name": "Form webhook",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        250,
        300
      ],
      "webhookId": "d045e20c-d095-5e3d-bb9f-58106cdb5357"
    },
    {
      "parameters": {
        "method": "GET",
        "url": "=https://YOUR_ENRICHMENT_API/companies?domain={{ $json.body.email.split('@')[1] }}",
        "options": {
          "response": {
            "response": {
              "fullResponse": true,
              "neverError": true
            }
          },
          "timeout": 10000
        }
      },
      "id": "a8f04f06-e194-5f07-b454-cdb28a70e513",
      "name": "Enrich company",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        490,
        300
      ]
    },
    {
      "parameters": {
        "modelId": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o-mini"
        },
        "messages": {
          "values": [
            {
              "role": "system",
              "content": "You are a sales assistant. ICP: <DESCRIBE YOUR IDEAL CUSTOMER>. Booking link: <YOUR_BOOKING_LINK>. Return JSON only. Keys: score (1-5 number), reason, reply_subject, reply_body."
            },
            {
              "content": "=Lead form: {{ JSON.stringify($('Form webhook').item.json.body) }}\nEnrichment: {{ JSON.stringify($json.body) }}\n\nWorkflow: Webhook trigger from your website form -> enrich the email domain (company name, size) -> AI node scores the lead 1-5 against your ICP and drafts a tailored reply with a booking link -> if score >= 4 notify sales in Slack immediately -> save everything to the CRM. Keep the draft for human approval before send."
            }
          ]
        },
        "jsonOutput": true,
        "options": {}
      },
      "id": "b710f6c2-2746-5a4b-a151-a4951f43ddeb",
      "name": "Score and draft reply",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "typeVersion": 1.8,
      "position": [
        730,
        300
      ],
      "credentials": {
        "openAiApi": {
          "id": "REPLACE_ME",
          "name": "OpenAI account"
        }
      }
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "loose"
          },
          "conditions": [
            {
              "id": "492ce14b-4a13-5a50-bfa3-971ec26ccab6",
              "leftValue": "={{ $json.message.content.score }}",
              "rightValue": 4,
              "operator": {
                "type": "number",
                "operation": "gte"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "742723f8-49fa-5432-9ea0-f008cb922531",
      "name": "Score 4 or higher?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2,
      "position": [
        970,
        300
      ]
    },
    {
      "parameters": {
        "select": "channel",
        "channelId": {
          "__rl": true,
          "mode": "name",
          "value": "#sales"
        },
        "text": "=Hot lead ({{ $json.message.content.score }}/5): {{ $('Form webhook').item.json.body.email }}\n{{ $json.message.content.reason }}",
        "otherOptions": {}
      },
      "id": "5f508ded-6f2b-58bc-91fb-45c96e5c53d5",
      "name": "Notify sales",
      "type": "n8n-nodes-base.slack",
      "typeVersion": 2.2,
      "position": [
        1210,
        300
      ],
      "credentials": {
        "slackApi": {
          "id": "REPLACE_ME",
          "name": "Slack account"
        }
      }
    },
    {
      "parameters": {
        "resource": "draft",
        "subject": "={{ $('Score and draft reply').item.json.message.content.reply_subject }}",
        "message": "={{ $('Score and draft reply').item.json.message.content.reply_body }}",
        "options": {
          "sendTo": "={{ $('Form webhook').item.json.body.email }}"
        }
      },
      "id": "61dd1e18-1c6c-5e81-82ab-0e5fce4b2f25",
      "name": "Draft reply for approval",
      "type": "n8n-nodes-base.gmail",
      "typeVersion": 2.1,
      "position": [
        1210,
        460
      ],
      "credentials": {
        "gmailOAuth2": {
          "id": "REPLACE_ME",
          "name": "Gmail account"
        }
      }
    },
    {
      "parameters": {
        "operation": "append",
        "documentId": {
          "__rl": true,
          "mode": "id",
          "value": "YOUR_SHEET_ID"
        },
        "sheetName": {
          "__rl": true,
          "mode": "name",
          "value": "Leads"
        },
        "columns": {
          "mappingMode": "autoMapInputData",
          "value": {},
          "matchingColumns": [],
          "schema": []
        },
        "options": {}
      },
      "id": "7c67c740-6dc8-52fe-ba90-7ddf3b6a8837",
      "name": "Save to CRM sheet",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.5,
      "position": [
        970,
        460
      ],
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "REPLACE_ME",
          "name": "Google Sheets account"
        }
      }
    }
  ],
  "connections": {
    "Form webhook": {
      "main": [
        [
          {
            "node": "Enrich company",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Enrich company": {
      "main": [
        [
          {
            "node": "Score and draft reply",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Score and draft reply": {
      "main": [
        [
          {
            "node": "Score 4 or higher?",
            "type": "main",
            "index": 0
          },
          {
            "node": "Save to CRM sheet",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Score 4 or higher?": {
      "main": [
        [
          {
            "node": "Notify sales",
            "type": "main",
            "index": 0
          },
          {
            "node": "Draft reply for approval",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Draft reply for approval",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "pinData": {},
  "meta": {
    "templateCredsSetupCompleted": false,
    "source": "https://agentroutines.si/r/inbound-lead-responder/"
  },
  "tags": []
}