{
  "name": "Agentic Architect · Pre-Call Lead Dossier + Draft-First Gmail Brief",
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "cal-scoping-booking",
        "responseMode": "onReceived"
      },
      "id": "cal-webhook",
      "name": "Cal.com Booking Webhook",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [220, 300]
    },
    {
      "parameters": {
        "jsCode": "const payload = $input.first().json.body?.payload || $input.first().json;\nconst attendee = (payload.attendees && payload.attendees[0]) || { email: 'lead@example.com', name: 'Prospect' };\nconst domain = (attendee.email.split('@')[1] || 'example.com').toLowerCase();\nconst bottleneck = payload.responses?.bottleneck?.value || 'recurring workflow bottleneck';\nreturn [{ json: { attendeeName: attendee.name, attendeeEmail: attendee.email, domain, bottleneck, startTime: payload.startTime } }];"
      },
      "id": "extract-lead",
      "name": "Extract Attendee, Domain & Bottleneck",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [450, 300]
    },
    {
      "parameters": {
        "url": "=https://r.jina.ai/https://{{ $json.domain }}",
        "options": { "timeout": 10000 }
      },
      "id": "fetch-company-site",
      "name": "Fetch Company Website Markdown",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [680, 300]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.openai.com/v1/chat/completions",
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "openAiApi",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n  \"model\": \"gpt-4o-mini\",\n  \"temperature\": 0.2,\n  \"response_format\": { \"type\": \"json_object\" },\n  \"messages\": [\n    {\n      \"role\": \"system\",\n      \"content\": \"You prepare concise pre-call workflow dossiers. Return strict JSON with keys: companySummary, twoAssumptionsToVerify (array of 2 strings), and warmDraftEmail (under 110 words, zero em-dashes).\"\n    },\n    {\n      \"role\": \"user\",\n      \"content\": \"Attendee: \" + $('Extract Attendee, Domain & Bottleneck').item.json.attendeeName + \" (\" + $('Extract Attendee, Domain & Bottleneck').item.json.domain + \")\\nStated bottleneck: \" + $('Extract Attendee, Domain & Bottleneck').item.json.bottleneck + \"\\nWebsite text:\\n\" + String($json.data || $json.body || '').slice(0, 6000)\n    }\n  ]\n}"
      },
      "id": "llm-synthesize-dossier",
      "name": "Synthesize Dossier & Assumption Check (LLM)",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [920, 300]
    },
    {
      "parameters": {
        "jsCode": "const lead = $('Extract Attendee, Domain & Bottleneck').first().json;\nconst raw = $input.first().json.choices?.[0]?.message?.content || '{}';\nconst parsed = JSON.parse(raw);\nconst assumptions = (parsed.twoAssumptionsToVerify || []).map((a, i) => `${i + 1}. ${a}`).join('\\n');\nreturn [{ json: {\n  toEmail: lead.attendeeEmail,\n  subject: `Quick note ahead of our 20-min workflow chat (${lead.domain})`,\n  draftBody: `[REVIEWER CHECK - 2 ASSUMPTIONS TO VERIFY BEFORE SENDING]\\n${assumptions}\\n\\n---\\n${parsed.warmDraftEmail || ''}`\n} }];"
      },
      "id": "format-draft-gate",
      "name": "Prepend 2-Assumption Human Review Gate",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [1160, 300]
    },
    {
      "parameters": {
        "resource": "draft",
        "subject": "={{ $json.subject }}",
        "message": "={{ $json.draftBody }}",
        "options": {
          "sendTo": "={{ $json.toEmail }}"
        }
      },
      "id": "stage-gmail-draft",
      "name": "Stage in Gmail Drafts (Human Sign-Off Gate)",
      "type": "n8n-nodes-base.gmail",
      "typeVersion": 2.1,
      "position": [1400, 300]
    }
  ],
  "connections": {
    "Cal.com Booking Webhook": {
      "main": [[{ "node": "Extract Attendee, Domain & Bottleneck", "type": "main", "index": 0 }]]
    },
    "Extract Attendee, Domain & Bottleneck": {
      "main": [[{ "node": "Fetch Company Website Markdown", "type": "main", "index": 0 }]]
    },
    "Fetch Company Website Markdown": {
      "main": [[{ "node": "Synthesize Dossier & Assumption Check (LLM)", "type": "main", "index": 0 }]]
    },
    "Synthesize Dossier & Assumption Check (LLM)": {
      "main": [[{ "node": "Prepend 2-Assumption Human Review Gate", "type": "main", "index": 0 }]]
    },
    "Prepend 2-Assumption Human Review Gate": {
      "main": [[{ "node": "Stage in Gmail Drafts (Human Sign-Off Gate)", "type": "main", "index": 0 }]]
    }
  }
}
