{
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "nodes": [
    {
      "id": "dc878070-ff34-420a-9dc1-fc424cff19a2",
      "name": "Typeform Trigger",
      "type": "n8n-nodes-base.typeformTrigger",
      "position": [
        18704,
        8864
      ],
      "parameters": {
        "formId": "UBdasOKD"
      },
      "typeVersion": 1.1
    },
    {
      "id": "c940fd71-1b77-4b79-9d96-304944ed1a4b",
      "name": "Create a record",
      "type": "n8n-nodes-base.airtable",
      "position": [
        19152,
        8864
      ],
      "parameters": {
        "base": {
          "__rl": true,
          "mode": "list",
          "value": "",
          "cachedResultUrl": "",
          "cachedResultName": ""
        },
        "table": {
          "__rl": true,
          "mode": "list",
          "value": "",
          "cachedResultUrl": "",
          "cachedResultName": ""
        },
        "columns": {
          "value": {
            "Name": "={{ $json.Name }}",
            "Email": "={{ $json.Email }}",
            "Status": "New",
            "Message": "={{ $json.Message }}"
          },
          "schema": [
            {
              "id": "Name",
              "type": "string",
              "display": true,
              "removed": false,
              "readOnly": false,
              "required": false,
              "displayName": "Name",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Email",
              "type": "string",
              "display": true,
              "removed": false,
              "readOnly": false,
              "required": false,
              "displayName": "Email",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Message",
              "type": "string",
              "display": true,
              "removed": false,
              "readOnly": false,
              "required": false,
              "displayName": "Message",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Status",
              "type": "options",
              "display": true,
              "options": [
                {
                  "name": "New",
                  "value": "New"
                },
                {
                  "name": "Done",
                  "value": "Done"
                }
              ],
              "removed": false,
              "readOnly": false,
              "required": false,
              "displayName": "Status",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "autoMapInputData",
          "matchingColumns": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "create"
      },
      "typeVersion": 2.1
    },
    {
      "id": "76196c55-0439-4cf6-a4e3-1e2a53e6ba5e",
      "name": "Send a message",
      "type": "n8n-nodes-base.gmail",
      "position": [
        20176,
        8576
      ],
      "parameters": {
        "sendTo": "={{ $json.fields.Email }}",
        "message": "=Hi {{$json.fields.Name}},\n\nThanks for your interest in working with us! \ud83d\ude80  \nWe reviewed your request and it looks exciting.\n\nOur team will reach out shortly with next steps.\n\nMeanwhile, check this:\n\ud83d\udc49 [Your Services Link]\n\n\u2013 Team",
        "options": {},
        "subject": "=\ud83d\udd25 Let's Build Something Great, {{$json.fields.Name}}"
      },
      "typeVersion": 2.2
    },
    {
      "id": "8c48b5f2-abac-4ea0-8be6-1125282b6812",
      "name": "Sanitize Lead Data",
      "type": "n8n-nodes-base.code",
      "position": [
        18928,
        8864
      ],
      "parameters": {
        "jsCode": "const name = $json[\"What is your full name?\"] || \"\";\nconst email = $json[\"What is your email address?\"] || \"\";\nconst message = $json[\"What project can we help you with today?\"] || \"\";\n\n// Title Case Name\nfunction toTitleCase(str) {\n  return str\n    .toLowerCase()\n    .split(\" \")\n    .map(word => word.charAt(0).toUpperCase() + word.slice(1))\n    .join(\" \");\n}\n\n// Extract domain\nconst domain = email.split(\"@\")[1] || \"\";\n\nreturn [\n  {\n    json: {\n      Name: toTitleCase(name.trim()),\n      Email: email.trim().toLowerCase(),\n      Message: message.trim(),\n      Domain: domain\n    }\n  }\n];"
      },
      "typeVersion": 2
    },
    {
      "id": "bdea441c-8727-4ec8-807e-a25a353ff112",
      "name": "AI Lead Analyzer",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "position": [
        19456,
        8800
      ],
      "parameters": {
        "modelId": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4.1-mini",
          "cachedResultName": "GPT-4.1-MINI"
        },
        "options": {},
        "responses": {
          "values": [
            {
              "content": "=You are an AI lead classification system for a business.\n\nYour task is to analyze a user's message and extract structured insights.\n\n------------------------\nINPUT:\nMessage: {{$json[\"Message\"]}}\n------------------------\n\nINSTRUCTIONS:\n\n1. Carefully read the message and understand the user's intent.\n\n2. Classify the message into ONE of the following categories:\n   - \"Sales\" \u2192 User is interested in buying, pricing, services, or hiring\n   - \"Support\" \u2192 User needs help, has an issue, bug, or question about usage\n   - \"Partnership\" \u2192 Collaboration, business proposal, joint venture\n   - \"Feedback\" \u2192 Suggestions, opinions, general comments\n   - \"Other\" \u2192 If unclear, vague, spammy, or does not fit above\n\n3. Assign a lead_score from 1 to 10:\n   - 9\u201310 \u2192 Highly valuable, strong intent, clear business opportunity\n   - 7\u20138 \u2192 Good potential lead, somewhat clear intent\n   - 4\u20136 \u2192 Moderate or unclear intent\n   - 1\u20133 \u2192 Low quality, vague, spam, or irrelevant\n\n4. Assign priority:\n   - \"High\" \u2192 urgent request, high lead_score (\u22658), or strong intent\n   - \"Medium\" \u2192 moderate intent or lead_score 5\u20137\n   - \"Low\" \u2192 weak, unclear, or low-value messages\n\n5. Handle edge cases:\n   - Empty or very short messages \u2192 category = \"Other\", score = 1, priority = \"Low\"\n   - Spam or promotional content \u2192 category = \"Other\"\n   - Multiple intents \u2192 choose the PRIMARY intent only\n\n6. Be strict and consistent. Do NOT guess beyond the message.\n\n------------------------\nOUTPUT FORMAT (STRICT JSON ONLY):\n------------------------\n\n{\n  \"category\": \"Sales | Support | Partnership | Feedback | Other\",\n  \"lead_score\": number,\n  \"priority\": \"Low | Medium | High\"\n}\n\n------------------------\nIMPORTANT RULES:\n- Output ONLY valid JSON (no text before or after)\n- Do NOT include explanations\n- Do NOT include markdown formatting\n- Do NOT include extra fields\n- Ensure JSON is always parsable\n"
            }
          ]
        },
        "builtInTools": {}
      },
      "typeVersion": 2.1
    },
    {
      "id": "0be203f6-8ec4-45ce-a4c8-f276cc16ced2",
      "name": "Merge",
      "type": "n8n-nodes-base.merge",
      "position": [
        19760,
        8928
      ],
      "parameters": {
        "mode": "combine",
        "options": {},
        "combineBy": "combineByPosition"
      },
      "typeVersion": 3.2
    },
    {
      "id": "e6e881fd-d725-4d3e-8395-86afac41cc21",
      "name": "Route by Category",
      "type": "n8n-nodes-base.switch",
      "position": [
        19952,
        8832
      ],
      "parameters": {
        "rules": {
          "values": [
            {
              "conditions": {
                "options": {
                  "version": 3,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "85b8796e-4064-4f8e-96ab-f0cdedcd515e",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{$json.fields.Category}}",
                    "rightValue": "=Sales"
                  }
                ]
              }
            },
            {
              "conditions": {
                "options": {
                  "version": 3,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "abaccc9d-b220-4efa-ad2c-532c8414130b",
                    "operator": {
                      "name": "filter.operator.equals",
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{$json.fields.Category}}",
                    "rightValue": "Support"
                  }
                ]
              }
            },
            {
              "conditions": {
                "options": {
                  "version": 3,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "df2a52be-9469-4a42-877f-53124eaec785",
                    "operator": {
                      "name": "filter.operator.equals",
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{$json.fields.Category}}",
                    "rightValue": "Partnership"
                  }
                ]
              }
            },
            {
              "conditions": {
                "options": {
                  "version": 3,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "5ff69906-7831-4b35-8561-ad0c2763bd96",
                    "operator": {
                      "name": "filter.operator.equals",
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{$json.fields.Category}}",
                    "rightValue": "Default"
                  }
                ]
              }
            }
          ]
        },
        "options": {}
      },
      "typeVersion": 3.4
    },
    {
      "id": "c3898c4d-52bf-4b41-9c3b-3a56369efa38",
      "name": "Send a message1",
      "type": "n8n-nodes-base.gmail",
      "position": [
        20176,
        8768
      ],
      "parameters": {
        "sendTo": "={{ $json.fields.Email }}",
        "message": "=<p>Hi <strong>{{ $json.fields.Name }}</strong>,</p>\n\n<p>Thank you for reaching out! We have successfully received your request regarding:</p>\n\n<blockquote style=\"background:#f9f9f9;border-left:5px solid #ccc;padding:10px;\">\n\"{{ $json.fields.Message }}\"\n</blockquote>\n\n<p>Our team will review your message and get back to you shortly. Your inquiry has been logged in our system with the status: <strong>NEW</strong>.</p>\n\n<p>Best regards,<br>\nYour Company Name</p>",
        "options": {},
        "subject": "We Got Your Request \ud83d\udc4d"
      },
      "typeVersion": 2.2
    },
    {
      "id": "1b995c4f-8cf5-40a0-af0c-a4a21a13f8cc",
      "name": "Send a message2",
      "type": "n8n-nodes-base.gmail",
      "position": [
        20176,
        8960
      ],
      "parameters": {
        "sendTo": "={{ $json.fields.Email }}",
        "message": "=Hi {{$json.fields.Name}},\n\nWe love collaboration! Our team will review your proposal and connect soon.\n\n\u2013 Partnerships Team",
        "options": {},
        "subject": "Partnership Opportunity \ud83d\ude80"
      },
      "typeVersion": 2.2
    },
    {
      "id": "d6ed4acf-4e8b-4030-a8f5-1aac44b80797",
      "name": "Send a message3",
      "type": "n8n-nodes-base.gmail",
      "position": [
        20176,
        9152
      ],
      "parameters": {
        "sendTo": "={{ $json.fields.Email }}",
        "message": "=<p>Hi <strong>{{ $json.fields.Name }}</strong>,</p>\n\n<p>Thank you for reaching out! We have successfully received your request regarding:</p>\n\n<blockquote style=\"background:#f9f9f9;border-left:5px solid #ccc;padding:10px;\">\n\"{{ $json.fields.Message }}\"\n</blockquote>\n\n<p>Our team will review your message and get back to you shortly. Your inquiry has been logged in our system with the status: <strong>NEW</strong>.</p>\n\n<p>Best regards,<br>\nYour Company Name</p>",
        "options": {},
        "subject": "=Hi {{ $json.fields.Name }}, thank you for your inquiry!"
      },
      "typeVersion": 2.2
    },
    {
      "id": "09140fcd-1e23-4b4b-9b79-39d64fb61157",
      "name": "Send a message4",
      "type": "n8n-nodes-base.discord",
      "position": [
        20400,
        8576
      ],
      "parameters": {
        "content": "=\ud83d\udea8 New Lead Received!\n\n\ud83d\udc64 Name: {{$json.fields.Name}}\n\ud83d\udce7 Email: {{$json.fields.Email}}\n\ud83d\udcca Score: {{$json.fields[\"Lead Score\"]}}\n\ud83d\udd25 Priority: {{$json.fields.Priority}}\n\n\ud83d\udcac Message:\n{{$json.fields.Message}}",
        "guildId": {
          "__rl": true,
          "mode": "list",
          "value": "",
          "cachedResultUrl": "",
          "cachedResultName": ""
        },
        "options": {},
        "resource": "message",
        "channelId": {
          "__rl": true,
          "mode": "list",
          "value": "",
          "cachedResultUrl": "",
          "cachedResultName": ""
        }
      },
      "typeVersion": 2
    },
    {
      "id": "ebb701ce-e6b3-4318-b582-ff6029ceb521",
      "name": "Sticky Note6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        17520,
        8256
      ],
      "parameters": {
        "width": 1072,
        "height": 1120,
        "content": "**Lead intake and AI intelligence with Typeform, Airtable, and OpenAI**\n\n**What this workflow does**\n\n* Captures new submissions from Typeform in real time\n* Cleans and standardizes lead data\n* Stores submissions in Airtable with status **NEW**\n* Uses OpenAI to classify leads, assign score, and set priority\n* Routes leads based on category\n* Sends email confirmations and Discord alerts for high-priority leads\n\n\n**How it works**\n\n1. Typeform Trigger receives a new submission\n2. Code node formats names and emails\n3. Airtable stores the lead as **NEW**\n4. OpenAI analyzes and assigns category, score, and priority\n5. Switch node routes leads by category\n6. Gmail sends confirmation email\n7. Discord sends alerts for high-priority sales leads\n\n\n**Setup notes**\n\n* Connect credentials: Typeform, Airtable, OpenAI, Gmail, Discord\n* Ensure Airtable fields: Name, Email, Message, Status, Category, Lead Score, Priority\n* Do not hardcode API keys\u2014use n8n credentials\n* Use a Set node for configurable values if needed"
      },
      "typeVersion": 1
    },
    {
      "id": "c2fde15d-58b6-45e8-9b18-c392b514cb59",
      "name": "Sticky Note7",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        18608,
        8256
      ],
      "parameters": {
        "color": 7,
        "width": 480,
        "height": 1120,
        "content": "# Step 1\nPhase: Inbound & Cleaning\nTypeform Trigger: Listens for the formId: UBdasOKD submission.\n\nSanitize Lead Data: Runs JavaScript to Title Case names, lowercase emails, and extract the domain for cleaner CRM entries."
      },
      "typeVersion": 1
    },
    {
      "id": "12af5fcf-3778-4ad6-a04f-a111343f3fb6",
      "name": "Sticky Note8",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        19104,
        8256
      ],
      "parameters": {
        "color": 7,
        "width": 272,
        "height": 1120,
        "content": "# Step 2\nPhase: The \"Source of Truth\"\nCreate a Record: Instantly pushes the sanitized data into Airtable. This ensures that even if the AI or Email steps fail later, you never lose the lead data."
      },
      "typeVersion": 1
    },
    {
      "id": "a324c214-c81d-41fe-899f-524ef83c76da",
      "name": "Sticky Note9",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        19392,
        8256
      ],
      "parameters": {
        "color": 7,
        "width": 480,
        "height": 1120,
        "content": "# Step 3\nPhase: AI Intelligence\nAI Lead Analyzer: Passes the message to GPT-4o-mini.\n\nLogic: The AI assigns a category, lead_score, and priority.\n\nMerge: The workflow combines the original Airtable record data with the new AI insights to prepare for routing."
      },
      "typeVersion": 1
    },
    {
      "id": "5bbd07ca-6765-460e-b4bf-c4759a1ef781",
      "name": "Sticky Note10",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        19888,
        8256
      ],
      "parameters": {
        "color": 7,
        "width": 816,
        "height": 1120,
        "content": "# Step 4\nPhase: Routing & Response\nRoute by Category: The Switch Node reads the AI's \"Category\" output.\n\nGmail (Branches):\n\nSales: Sends a high-energy \"Let's Build\" email.\n\nSupport/Partnership/Default: Sends tailored professional confirmations.\n\nDiscord Alert: A final notification is sent to the team (via the general channel) for Sales leads, including the AI-generated Lead Score and Priority."
      },
      "typeVersion": 1
    }
  ],
  "connections": {
    "Merge": {
      "main": [
        [
          {
            "node": "Route by Category",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send a message": {
      "main": [
        [
          {
            "node": "Send a message4",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create a record": {
      "main": [
        [
          {
            "node": "AI Lead Analyzer",
            "type": "main",
            "index": 0
          },
          {
            "node": "Merge",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "AI Lead Analyzer": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Typeform Trigger": {
      "main": [
        [
          {
            "node": "Sanitize Lead Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Route by Category": {
      "main": [
        [
          {
            "node": "Send a message",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Send a message1",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Send a message2",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Send a message3",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Sanitize Lead Data": {
      "main": [
        [
          {
            "node": "Create a record",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}