{
  "_superseded": "⚠️ Ancienne maquette non déployée. Le workflow réel est Clients/Fidulia/Automatisation/VEILLE-DIGEST-EMAIL.json (path veille-digest-fidulia, schéma {markdown, subject} — voir Agents/70-Agent-Automatisation/routine/ROUTINE-VEILLE-MATIN.md étape 5). Conservé ici pour référence historique uniquement.",
  "name": "Veille — Digest email (webhook)",
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "veille-digest",
        "authentication": "headerAuth",
        "responseMode": "responseNode",
        "options": {}
      },
      "id": "c1111111-0000-0000-0000-000000000001",
      "name": "Webhook POST digest",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        448,
        80
      ],
      "credentials": {
        "httpHeaderAuth": {
          "id": "REMPLACER_PAR_CRED_HEADER",
          "name": "Fidulia webhook token"
        }
      },
      "notes": "POST /webhook/veille-digest. Reçoit le résumé produit par l'étape 5 de ROUTINE-VEILLE-MATIN.md (sortie des VRAIS agents 42/50). Header Auth X-Fidulia-Token obligatoire."
    },
    {
      "parameters": {
        "jsCode": "// Construit l'email de synthèse du matin à partir du résumé envoyé par la routine Claude Code.\n// L'email est un TABLEAU DE BORD (compteurs + pointeurs vers les fichiers agents). Le détail\n// (brouillons, captures) vit dans les fichiers locaux, remontés par Kimi. L'email n'est PLUS\n// généré par un Claude généraliste : c'est le rendu de la sortie des vrais agents.\nfunction esc(s){return String(s==null?'':s).replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;');}\nconst b = $json.body || $json;\nconst d = {\n  runDate: b.runDate || new Date().toISOString().slice(0,10),\n  totalTraites: b.totalTraites || 0,\n  candidatsCommentaire: b.candidatsCommentaire || 0,\n  itemsVeille: b.itemsVeille || 0,\n  itemsNewsletter: b.itemsNewsletter || 0,\n  notifsEquipe: Array.isArray(b.notifsEquipe) ? b.notifsEquipe : [],\n  fichiers: b.fichiers || {}\n};\nconst agentNom = { '20':'Stratège (20)', '21':'Design System (21)', '31':'Graphiste (31)', '30':'Rédacteur (30)' };\nconst notifs = d.notifsEquipe.length\n  ? '<ul style=\"margin:6px 0;padding-left:18px;\">' + d.notifsEquipe.map(n => `<li style=\"margin:4px 0;\"><strong>${esc(agentNom[n.agent]||('Agent '+n.agent))}</strong> : ${esc(n.signal)}</li>`).join('') + '</ul>'\n  : '<p style=\"color:#999;margin:6px 0;\">Aucun signal à dispatcher aujourd\\'hui.</p>';\nconst fichiers = Object.keys(d.fichiers).length\n  ? '<ul style=\"margin:6px 0;padding-left:18px;font-size:13px;color:#555;\">' + Object.entries(d.fichiers).map(([k,v]) => `<li><strong>${esc(k)}</strong> : <code>${esc(v)}</code></li>`).join('') + '</ul>'\n  : '';\nconst html = `<div style=\"max-width:640px;margin:auto;font-family:Arial,Helvetica,sans-serif;color:#0C132A;\">\n  <h1 style=\"font-size:22px;margin-bottom:2px;\">Digest veille — ${esc(d.runDate)}</h1>\n  <p style=\"color:#666;margin-top:0;\">${d.totalTraites} posts traités par les agents 42 &amp; 50.</p>\n  <table style=\"width:100%;border-collapse:collapse;margin:16px 0;\">\n    <tr>\n      <td style=\"padding:14px;background:#f5f6fa;border-radius:12px;text-align:center;width:33%;\"><div style=\"font-size:28px;font-weight:900;color:#D70459;\">${d.candidatsCommentaire}</div><div style=\"font-size:13px;color:#555;\">à commenter</div></td>\n      <td style=\"width:12px;\"></td>\n      <td style=\"padding:14px;background:#f5f6fa;border-radius:12px;text-align:center;width:33%;\"><div style=\"font-size:28px;font-weight:900;color:#0C132A;\">${d.itemsVeille}</div><div style=\"font-size:13px;color:#555;\">en veille</div></td>\n      <td style=\"width:12px;\"></td>\n      <td style=\"padding:14px;background:#f5f6fa;border-radius:12px;text-align:center;width:33%;\"><div style=\"font-size:28px;font-weight:900;color:#0C132A;\">${d.itemsNewsletter}</div><div style=\"font-size:13px;color:#555;\">newsletter</div></td>\n    </tr>\n  </table>\n  <h2 style=\"font-size:17px;color:#D70459;\">🔔 À dispatcher à l'équipe</h2>\n  ${notifs}\n  <h2 style=\"font-size:17px;color:#0C132A;\">📁 Fichiers produits</h2>\n  <p style=\"font-size:13px;color:#555;margin-top:4px;\">Le détail (brouillons de commentaires, captures) est dans ces fichiers, remontés par Kimi au programme du jour :</p>\n  ${fichiers}\n  <p style=\"font-size:12px;color:#aaa;margin-top:24px;\">Généré par les agents 42 &amp; 50 · routine Claude Code · Linked Connexion</p>\n</div>`;\nconst subject = `Digest veille ${d.runDate} — ${d.candidatsCommentaire} à commenter, ${d.itemsVeille} en veille`;\nreturn [{ json: { html, subject } }];"
      },
      "id": "c1111111-0000-0000-0000-000000000002",
      "name": "Construire l'email HTML",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        672,
        80
      ]
    },
    {
      "parameters": {
        "sendTo": "fabien@fabien-massavie.com",
        "subject": "={{ $json.subject }}",
        "emailType": "html",
        "message": "={{ $json.html }}",
        "options": {}
      },
      "id": "c1111111-0000-0000-0000-000000000003",
      "name": "Envoyer le digest (Gmail)",
      "type": "n8n-nodes-base.gmail",
      "typeVersion": 2.1,
      "position": [
        896,
        80
      ],
      "webhookId": "fc06f178-d3c7-477a-9ac3-bed6f6a6ef31"
    },
    {
      "parameters": {
        "respondWith": "json",
        "responseBody": "={{ JSON.stringify({ ok: true, sent: true }) }}",
        "options": {}
      },
      "id": "c1111111-0000-0000-0000-000000000004",
      "name": "Répondre (ok)",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1.1,
      "position": [
        1120,
        80
      ]
    }
  ],
  "connections": {
    "Webhook POST digest": {
      "main": [
        [
          {
            "node": "Construire l'email HTML",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Construire l'email HTML": {
      "main": [
        [
          {
            "node": "Envoyer le digest (Gmail)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Envoyer le digest (Gmail)": {
      "main": [
        [
          {
            "node": "Répondre (ok)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  },
  "active": false,
  "pinData": {},
  "meta": {
    "instanceId": "4f1b23afe1c1f425a998bc69ab78d2ebd64d2175c452226921ae034356fabed4"
  }
}
