{
  "name": "Formdall lead triage",
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "formdall-leads",
        "authentication": "headerAuth",
        "options": {
          "rawBody": true
        }
      },
      "name": "Formdall Webhook",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2.1,
      "position": [
        0,
        0
      ],
      "id": "e123ceb9-2a2c-4dea-adc2-4fe4351aab5f"
    },
    {
      "parameters": {
        "jsCode": "// Formdall signs the raw body with the action's secret. Compare in constant\n// time, and against the raw bytes - a re-serialised JSON object will not match.\nconst crypto = require('crypto');\nconst secret = $env.FORMDALL_SIGNING_SECRET;\nconst item = $input.first();\nconst raw = Buffer.from(item.binary.data.data, 'base64');\nconst header = item.json.headers['x-formdall-signature'] ?? '';\nconst expected = 'sha256=' + crypto.createHmac('sha256', secret).update(raw).digest('hex');\nconst ok =\n  expected.length === header.length &&\n  crypto.timingSafeEqual(Buffer.from(expected), Buffer.from(header));\nif (!ok) throw new Error('Invalid Formdall signature');\n// Keep the webhook's item shape, so the agent's $json.body.data paths work\n// whether this node is enabled or not. Only the body is swapped for the\n// verified bytes.\nreturn [{ json: { ...item.json, body: JSON.parse(raw.toString('utf8')) } }];\n"
      },
      "name": "Verify signature",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        240,
        0
      ],
      "id": "b3002ad8-b187-42ac-ae3c-37acaa967c5d",
      "disabled": true
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "=New inquiry from the contact form on our website.\n\nName: {{ $json.body.data.name }}\nEmail: {{ $json.body.data.email }}\nCompany: {{ $json.body.data.company }}\nMessage:\n{{ $json.body.data.message }}",
        "hasOutputParser": true,
        "options": {
          "systemMessage": "You triage inbound inquiries for a small web agency that builds websites and web apps for businesses.\n\nClassify the inquiry into exactly one score:\n- \"hot\": a concrete project or budget, a deadline, or a direct request for a quote or call.\n- \"warm\": a genuine prospect who is still vague, exploring, or asking general questions.\n- \"junk\": not a prospect. This includes vendor and agency pitches (SEO, marketing, lead lists, outsourcing), partnership or link-building offers, job applications, and requests unrelated to our services.\n\nAlso return:\n- category: a 1-3 word label for what the inquiry is about.\n- summary: one sentence a salesperson can read in two seconds.\n- reply_draft: for \"warm\" only, a short, friendly reply in the language of the inquiry that answers what can be answered and asks one question to move forward. Empty string otherwise.\n\nNever invent facts about our prices or availability."
        }
      },
      "name": "Lead triage agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "typeVersion": 3.1,
      "position": [
        480,
        0
      ],
      "id": "d32ba025-1791-44a6-87ef-9c436eaf89e4"
    },
    {
      "parameters": {
        "model": "ministral-14b-latest",
        "options": {}
      },
      "name": "Mistral Cloud Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatMistralCloud",
      "typeVersion": 1,
      "position": [
        432,
        240
      ],
      "id": "cb5a248a-0e43-483a-8993-07dbf88487bc"
    },
    {
      "parameters": {
        "schemaType": "manual",
        "inputSchema": "{\n  \"type\": \"object\",\n  \"properties\": {\n    \"score\": { \"type\": \"string\", \"enum\": [\"hot\", \"warm\", \"junk\"] },\n    \"category\": { \"type\": \"string\" },\n    \"summary\": { \"type\": \"string\" },\n    \"reply_draft\": { \"type\": \"string\" }\n  },\n  \"required\": [\"score\", \"category\", \"summary\", \"reply_draft\"]\n}"
      },
      "name": "Lead schema",
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "typeVersion": 1.3,
      "position": [
        640,
        240
      ],
      "id": "c728d2e5-67c6-4d03-8e04-ede97876f53a"
    },
    {
      "parameters": {
        "rules": {
          "values": [
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 3
                },
                "conditions": [
                  {
                    "id": "fc77151e-2a59-4b4a-8805-70792d13b3d8",
                    "leftValue": "={{ $json.output.score }}",
                    "rightValue": "hot",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "hot"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 3
                },
                "conditions": [
                  {
                    "id": "3fe9c88c-a210-4908-b031-be7c617232e8",
                    "leftValue": "={{ $json.output.score }}",
                    "rightValue": "warm",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "warm"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 3
                },
                "conditions": [
                  {
                    "id": "990c3355-8f23-4749-9109-76bf328476c9",
                    "leftValue": "={{ $json.output.score }}",
                    "rightValue": "junk",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "junk"
            }
          ]
        },
        "options": {}
      },
      "name": "Route by score",
      "type": "n8n-nodes-base.switch",
      "typeVersion": 3.4,
      "position": [
        880,
        0
      ],
      "id": "2e36e54a-a15a-4490-ad35-62cf81fa5327"
    },
    {
      "parameters": {
        "select": "channel",
        "channelId": {
          "__rl": true,
          "mode": "name",
          "value": "#sales"
        },
        "text": "=:fire: {{ $json.output.summary }} - {{ $('Formdall Webhook').item.json.body.data.email }}",
        "otherOptions": {}
      },
      "name": "Notify sales",
      "type": "n8n-nodes-base.slack",
      "typeVersion": 2.7,
      "position": [
        1152,
        -208
      ],
      "id": "db31b60a-5749-42a8-9348-3e3ca4760efd"
    },
    {
      "parameters": {
        "operation": "append",
        "documentId": {
          "__rl": true,
          "mode": "id",
          "value": "YOUR_SHEET_ID"
        },
        "sheetName": {
          "__rl": true,
          "mode": "name",
          "value": "Leads"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "date": "={{ $('Formdall Webhook').item.json.body.submitted_at }}",
            "name": "={{ $('Formdall Webhook').item.json.body.data.name }}",
            "email": "={{ $('Formdall Webhook').item.json.body.data.email }}",
            "category": "={{ $('Lead triage agent').item.json.output.category }}",
            "summary": "={{ $('Lead triage agent').item.json.output.summary }}"
          },
          "matchingColumns": [],
          "schema": [
            {
              "id": "date",
              "displayName": "date",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "name",
              "displayName": "name",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "email",
              "displayName": "email",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "category",
              "displayName": "category",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "summary",
              "displayName": "summary",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            }
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {}
      },
      "name": "Log lead",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.7,
      "position": [
        1392,
        -208
      ],
      "id": "77b180ba-c944-4573-bed7-55b18e4a45b9"
    },
    {
      "parameters": {
        "resource": "draft",
        "subject": "Re: your inquiry",
        "message": "={{ $json.output.reply_draft }}",
        "options": {
          "sendTo": "={{ $('Formdall Webhook').item.json.body.data.email }}"
        }
      },
      "name": "Draft reply",
      "type": "n8n-nodes-base.gmail",
      "typeVersion": 2.2,
      "position": [
        1152,
        0
      ],
      "id": "3d376550-cbe3-4e2c-8da7-6e5acb479bce"
    },
    {
      "parameters": {},
      "name": "Drop",
      "type": "n8n-nodes-base.noOp",
      "typeVersion": 1,
      "position": [
        1152,
        208
      ],
      "id": "f6ea36f8-0381-40e2-a334-4a36e2274470"
    }
  ],
  "connections": {
    "Formdall Webhook": {
      "main": [
        [
          {
            "node": "Verify signature",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Verify signature": {
      "main": [
        [
          {
            "node": "Lead triage agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Mistral Cloud Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "Lead triage agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Lead schema": {
      "ai_outputParser": [
        [
          {
            "node": "Lead triage agent",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    },
    "Lead triage agent": {
      "main": [
        [
          {
            "node": "Route by score",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Route by score": {
      "main": [
        [
          {
            "node": "Notify sales",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Draft reply",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Drop",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Notify sales": {
      "main": [
        [
          {
            "node": "Log lead",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  },
  "active": false
}
