{
  "name": "AI Form Lead Extractor — Structured Fields with Confidence Routing",
  "flow": [
    {
      "id": 1,
      "module": "gateway:CustomWebHook",
      "version": 1,
      "parameters": {
        "hook": "YOUR_WEBHOOK_ID",
        "maxResults": 1
      },
      "mapper": {},
      "metadata": {
        "designer": {
          "x": 0,
          "y": 0,
          "name": "Form submission webhook"
        },
        "restore": {
          "parameters": {
            "hook": {
              "label": "Form submission webhook"
            }
          }
        },
        "parameters": [
          {
            "name": "hook",
            "type": "hook:gateway-webhook",
            "label": "Webhook",
            "required": true
          }
        ],
        "interface": [
          {
            "name": "raw_submission",
            "type": "text"
          },
          {
            "name": "form_name",
            "type": "text"
          }
        ]
      }
    },
    {
      "id": 2,
      "module": "openai-gpt-3:CreateCompletion",
      "version": 1,
      "parameters": {
        "__IMTCONN__": "YOUR_OPENAI_CONNECTION"
      },
      "mapper": {
        "select": "chat",
        "model": "gpt-4o-mini",
        "max_tokens": "700",
        "temperature": "0",
        "n_completions": "1",
        "response_format": "json_object",
        "messages": [
          {
            "role": "system",
            "content": "You extract structured lead data from messy form submissions (free-text fields, mixed languages, typos).\n\nRules:\n- full_name: properly capitalized. company: official-looking name without legal suffix noise unless meaningful.\n- email: lowercase; null if invalid. phone: E.164 if country can be inferred, otherwise as written.\n- intent: one of \"demo_request\", \"pricing_question\", \"support\", \"partnership\", \"other\".\n- budget_hint: any budget/price signal quoted from the text, else null.\n- confidence: 0.0-1.0 overall confidence that ALL extracted fields are correct. Lower it when fields are ambiguous, contradictory, or missing.\n\nRespond ONLY with valid JSON, no markdown fences, exactly this shape:\n{\"full_name\": string|null, \"email\": string|null, \"phone\": string|null, \"company\": string|null, \"intent\": string, \"budget_hint\": string|null, \"summary\": string, \"confidence\": number}"
          },
          {
            "role": "user",
            "content": "Form: {{1.form_name}}\nRaw submission:\n{{1.raw_submission}}"
          }
        ]
      },
      "metadata": {
        "designer": {
          "x": 300,
          "y": 0,
          "name": "Extract lead fields"
        },
        "restore": {
          "parameters": {
            "__IMTCONN__": {
              "label": "My OpenAI connection"
            }
          }
        },
        "parameters": [
          {
            "name": "__IMTCONN__",
            "type": "account:openai-gpt-3",
            "label": "Connection",
            "required": true
          }
        ]
      }
    },
    {
      "id": 3,
      "module": "json:ParseJSON",
      "version": 1,
      "parameters": {},
      "mapper": {
        "json": "{{2.result}}"
      },
      "metadata": {
        "designer": {
          "x": 600,
          "y": 0,
          "name": "Parse extraction JSON"
        },
        "restore": {},
        "parameters": []
      }
    },
    {
      "id": 4,
      "module": "builtin:BasicRouter",
      "version": 1,
      "parameters": {},
      "mapper": null,
      "metadata": {
        "designer": {
          "x": 900,
          "y": 0
        }
      },
      "routes": [
        {
          "flow": [
            {
              "id": 5,
              "module": "hubspotcrm:createContact",
              "version": 1,
              "parameters": {
                "__IMTCONN__": "YOUR_HUBSPOT_CONNECTION"
              },
              "filter": {
                "name": "High confidence (>= 0.8)",
                "conditions": [
                  [
                    {
                      "a": "{{3.confidence}}",
                      "b": "0.8",
                      "o": "number:greaterorequal"
                    }
                  ]
                ]
              },
              "mapper": {
                "email": "{{3.email}}",
                "firstname": "{{first(split(3.full_name; \" \"))}}",
                "lastname": "{{join(slice(split(3.full_name; \" \"); 1); \" \")}}",
                "company": "{{3.company}}",
                "phone": "{{3.phone}}",
                "hs_lead_status": "NEW",
                "message": "{{3.summary}} | Intent: {{3.intent}} | Budget hint: {{3.budget_hint}}"
              },
              "metadata": {
                "designer": {
                  "x": 1200,
                  "y": -150,
                  "name": "Create CRM contact"
                },
                "restore": {},
                "parameters": [
                  {
                    "name": "__IMTCONN__",
                    "type": "account:hubspotcrm",
                    "label": "Connection",
                    "required": true
                  }
                ]
              }
            },
            {
              "id": 6,
              "module": "google-sheets:addRow",
              "version": 2,
              "parameters": {
                "__IMTCONN__": "YOUR_GOOGLE_SHEETS_CONNECTION",
                "mode": "select",
                "spreadsheetId": "YOUR_SPREADSHEET_ID",
                "sheetId": "Leads",
                "includesHeaders": true,
                "insertDataOption": "INSERT_ROWS",
                "valueInputOption": "USER_ENTERED"
              },
              "mapper": {
                "values": {
                  "0": "{{formatDate(now; \"YYYY-MM-DD HH:mm\")}}",
                  "1": "{{3.full_name}}",
                  "2": "{{3.email}}",
                  "3": "{{3.company}}",
                  "4": "{{3.intent}}",
                  "5": "{{3.confidence}}",
                  "6": "{{3.summary}}"
                }
              },
              "metadata": {
                "designer": {
                  "x": 1500,
                  "y": -150,
                  "name": "Log lead to Sheets"
                },
                "restore": {},
                "parameters": [
                  {
                    "name": "__IMTCONN__",
                    "type": "account:google",
                    "label": "Connection",
                    "required": true
                  }
                ]
              }
            }
          ]
        },
        {
          "flow": [
            {
              "id": 7,
              "module": "slack:CreateMessage",
              "version": 4,
              "parameters": {
                "__IMTCONN__": "YOUR_SLACK_CONNECTION"
              },
              "filter": {
                "name": "Low confidence (< 0.8)",
                "conditions": [
                  [
                    {
                      "a": "{{3.confidence}}",
                      "b": "0.8",
                      "o": "number:less"
                    }
                  ]
                ]
              },
              "mapper": {
                "channel": "#lead-review",
                "channelType": "publicChannel",
                "text": ":mag: *Lead needs manual review* (confidence {{3.confidence}})\nName: {{3.full_name}} | Email: {{3.email}} | Company: {{3.company}}\nIntent: {{3.intent}} | Budget: {{ifempty(3.budget_hint; \"—\")}}\nSummary: {{3.summary}}\n\nRaw submission:\n```{{1.raw_submission}}```"
              },
              "metadata": {
                "designer": {
                  "x": 1200,
                  "y": 150,
                  "name": "Slack review alert"
                },
                "restore": {},
                "parameters": [
                  {
                    "name": "__IMTCONN__",
                    "type": "account:slack",
                    "label": "Connection",
                    "required": true
                  }
                ]
              }
            }
          ]
        }
      ]
    }
  ],
  "metadata": {
    "version": 1,
    "scenario": {
      "roundtrips": 1,
      "maxErrors": 3,
      "autoCommit": true,
      "autoCommitTriggerLast": true,
      "sequential": false,
      "confidential": false,
      "dataloss": false,
      "dlq": false,
      "freshVariables": false
    },
    "designer": {
      "orphans": []
    },
    "zone": "eu1.make.com"
  }
}
