{
  "id": "cao-campagne-envergure-01",
  "name": "Campagne CAO envergure — Synergieloc",
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "campagne-cao",
        "responseMode": "onReceived",
        "options": {}
      },
      "id": "c0a00001-0001-4000-8000-000000000001",
      "name": "Webhook prospects CAO",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [0, 80],
      "webhookId": "campagne-cao",
      "notes": "POST JSON : un prospect {prospect_email, prospect_nom, prospect_entreprise, cible?} ou {prospects: [...]}."
    },
    {
      "parameters": {
        "jsCode": "const raw = $input.first().json;\nconst list = Array.isArray(raw.prospects) ? raw.prospects\n  : (Array.isArray(raw) ? raw : [raw]);\nreturn list.filter(p => p && (p.prospect_email || p.email)).map(p => ({\n  json: {\n    prospect_email: String(p.prospect_email || p.email || '').trim(),\n    prospect_nom: String(p.prospect_nom || p.nom || '').trim(),\n    prospect_entreprise: String(p.prospect_entreprise || p.entreprise || '').trim(),\n    cible: String(p.cible || 'architecte').trim() || 'architecte',\n    campagne: 'cao',\n    contexte: String(p.contexte || 'moteur CAO JSON vers IFC DXF visite 4K').trim(),\n    produit: String(p.produit || 'CAO 3D hebergee').trim()\n  }\n}));"
      },
      "id": "c0a00001-0002-4000-8000-000000000002",
      "name": "Normaliser la liste",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [240, 80]
    },
    {
      "parameters": {
        "batchSize": 8,
        "options": {}
      },
      "id": "c0a00001-0003-4000-8000-000000000003",
      "name": "Lots de 8 (plafond 30/min)",
      "type": "n8n-nodes-base.splitInBatches",
      "typeVersion": 3,
      "position": [480, 80]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://synergieloc.fr/api/v1/agent/decide",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            { "name": "Content-Type", "value": "application/json" },
            { "name": "X-Make-Secret", "value": "VOTRE_MAKE_DEMARCHAGE_SECRET" }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ prospect_email: $json.prospect_email, prospect_nom: $json.prospect_nom, prospect_entreprise: $json.prospect_entreprise, contexte: $json.contexte, cible: $json.cible, campagne: 'cao', produit: $json.produit }) }}",
        "options": { "timeout": 30000 }
      },
      "id": "c0a00001-0004-4000-8000-000000000004",
      "name": "Synergieloc décide",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [720, 80],
      "notes": "Synergieloc décide l'offre. n8n n'invente ni tarif ni CTA."
    },
    {
      "parameters": {
        "conditions": {
          "options": { "caseSensitive": true, "leftValue": "", "typeValidation": "strict" },
          "conditions": [
            {
              "id": "ok-offre",
              "leftValue": "={{ $json.actions[0].type }}",
              "rightValue": "envoyer_offre",
              "operator": { "type": "string", "operation": "equals" }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "c0a00001-0005-4000-8000-000000000005",
      "name": "Offre autorisée ?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [960, 80]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://synergieloc.fr/api/v1/agent/demarchage",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            { "name": "Content-Type", "value": "application/json" },
            { "name": "X-Make-Secret", "value": "VOTRE_MAKE_DEMARCHAGE_SECRET" }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify($json.actions[0].body) }}",
        "options": { "timeout": 30000 }
      },
      "id": "c0a00001-0006-4000-8000-000000000006",
      "name": "Envoyer l'offre CAO",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [1200, 0],
      "notes": "SMTP Synergieloc + file de reprise. Opt-out STOP dans l'email."
    },
    {
      "parameters": {
        "amount": 3,
        "unit": "seconds"
      },
      "id": "c0a00001-0007-4000-8000-000000000007",
      "name": "Pause 3 s",
      "type": "n8n-nodes-base.wait",
      "typeVersion": 1.1,
      "position": [1440, 80],
      "webhookId": "wait-cao"
    }
  ],
  "connections": {
    "Webhook prospects CAO": {
      "main": [[{ "node": "Normaliser la liste", "type": "main", "index": 0 }]]
    },
    "Normaliser la liste": {
      "main": [[{ "node": "Lots de 8 (plafond 30/min)", "type": "main", "index": 0 }]]
    },
    "Lots de 8 (plafond 30/min)": {
      "main": [[{ "node": "Synergieloc décide", "type": "main", "index": 0 }]]
    },
    "Synergieloc décide": {
      "main": [[{ "node": "Offre autorisée ?", "type": "main", "index": 0 }]]
    },
    "Offre autorisée ?": {
      "main": [
        [{ "node": "Envoyer l'offre CAO", "type": "main", "index": 0 }],
        [{ "node": "Pause 3 s", "type": "main", "index": 0 }]
      ]
    },
    "Envoyer l'offre CAO": {
      "main": [[{ "node": "Pause 3 s", "type": "main", "index": 0 }]]
    },
    "Pause 3 s": {
      "main": [[{ "node": "Lots de 8 (plafond 30/min)", "type": "main", "index": 0 }]]
    }
  },
  "settings": { "executionOrder": "v1" },
  "_synergieloc_notes": {
    "import": "n8n → Workflows → Import from File → n8n-campagne-cao.json",
    "secret": "Remplacer VOTRE_MAKE_DEMARCHAGE_SECRET (même secret que Make).",
    "volume": "Branchez Google Sheets / Airtable / Postgres à la place du webhook. 8 par lot + pause 3 s ≈ 20/min, sous le plafond 30/min.",
    "relance": "Pour J+3 : dupliquez le workflow, source = prospects sans clic, même campagne=cao, contexte='relance CAO J+3'.",
    "legal": "B2B, listes légitimes, STOP. Pas d'achat de fichiers emails.",
    "guide": "https://synergieloc.fr/guides/campagne-cao-make-n8n"
  }
}
