{
  "name": "Veille — Queue API (webhooks)",
  "nodes": [
    {
      "parameters": {
        "httpMethod": "GET",
        "path": "veille-queue",
        "authentication": "headerAuth",
        "responseMode": "responseNode",
        "options": {}
      },
      "id": "a1111111-0000-0000-0000-000000000001",
      "name": "Webhook GET file",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        448,
        80
      ],
      "credentials": {
        "httpHeaderAuth": {
          "id": "REMPLACER_PAR_CRED_HEADER",
          "name": "Fidulia webhook token"
        }
      },
      "notes": "GET /webhook/veille-queue. Header Auth obligatoire (X-Fidulia-Token) — un webhook sans auth est une faille critique (UKP n8n Fondamentaux Axe 2). Renvoie les posts PENDING au format JSON pour la routine Claude Code."
    },
    {
      "parameters": {
        "documentId": {
          "__rl": true,
          "value": "1NvgtiwfgwKRjsm025O3qlXnUcw6QffZpVLI1_4IAHLc",
          "mode": "id"
        },
        "sheetName": {
          "__rl": true,
          "value": "File-à-traiter",
          "mode": "name"
        },
        "options": {}
      },
      "id": "a1111111-0000-0000-0000-000000000002",
      "name": "Lire File-à-traiter",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.5,
      "position": [
        672,
        80
      ],
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "EvORDqxqhAIKRlIW",
          "name": "Google Sheets account"
        }
      }
    },
    {
      "parameters": {
        "jsCode": "// Ne renvoyer que les lignes PENDING, projetées sur les champs utiles à la routine.\n// role (fix 2026-07-21) : ajouté à la projection — sans lui la routine ne peut pas pré-filtrer par rôle\n// et l'Agent 50 traite toute source comme influenceur (monitoring), jamais citable.\nconst pending = [];\nfor (const item of $input.all()) {\n  const r = item.json;\n  if (String(r.statut || '').toUpperCase() !== 'PENDING') continue;\n  pending.push({\n    postId: r.postId,\n    author: r.author,\n    profileUrl: r.profileUrl,\n    url: r.url,\n    text: r.text,\n    postedAt: r.postedAt,\n    likes: Number(r.likes) || 0,\n    comments: Number(r.comments) || 0,\n    role: r.role || ''\n  });\n}\nreturn [{ json: { posts: pending, count: pending.length } }];"
      },
      "id": "a1111111-0000-0000-0000-000000000003",
      "name": "Filtrer PENDING",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        896,
        80
      ]
    },
    {
      "parameters": {
        "respondWith": "json",
        "responseBody": "={{ JSON.stringify($json.posts) }}",
        "options": {}
      },
      "id": "a1111111-0000-0000-0000-000000000004",
      "name": "Répondre (posts JSON)",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1.1,
      "position": [
        1120,
        80
      ]
    },
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "veille-queue/done",
        "authentication": "headerAuth",
        "responseMode": "responseNode",
        "options": {}
      },
      "id": "b2222222-0000-0000-0000-000000000001",
      "name": "Webhook POST done",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        448,
        360
      ],
      "credentials": {
        "httpHeaderAuth": {
          "id": "REMPLACER_PAR_CRED_HEADER",
          "name": "Fidulia webhook token"
        }
      },
      "notes": "POST /webhook/veille-queue/done. Body : { postIds:[...], traitePar:'42,50' }. Marque chaque post DONE pour ne pas le reproposer demain."
    },
    {
      "parameters": {
        "jsCode": "// Transforme le body { postIds:[...], traitePar } en une ligne par postId à mettre à jour.\nconst body = $json.body || $json;\nconst ids = Array.isArray(body.postIds) ? body.postIds : [];\nconst traitePar = body.traitePar || '42,50';\nconst dateTraitement = new Date().toISOString();\nif (ids.length === 0) return [];\nreturn ids.map(id => ({ json: { postId: String(id), statut: 'DONE', traitePar, dateTraitement } }));"
      },
      "id": "b2222222-0000-0000-0000-000000000002",
      "name": "Préparer maj DONE",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        672,
        360
      ]
    },
    {
      "parameters": {
        "operation": "appendOrUpdate",
        "documentId": {
          "__rl": true,
          "value": "1NvgtiwfgwKRjsm025O3qlXnUcw6QffZpVLI1_4IAHLc",
          "mode": "id"
        },
        "sheetName": {
          "__rl": true,
          "value": "File-à-traiter",
          "mode": "name"
        },
        "columns": {
          "mappingMode": "autoMapInputData",
          "matchingColumns": [
            "postId"
          ],
          "value": {}
        },
        "options": {}
      },
      "id": "b2222222-0000-0000-0000-000000000003",
      "name": "Marquer DONE",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.5,
      "position": [
        896,
        360
      ],
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "EvORDqxqhAIKRlIW",
          "name": "Google Sheets account"
        }
      }
    },
    {
      "parameters": {
        "respondWith": "json",
        "responseBody": "={{ JSON.stringify({ ok: true, marques: $items().length }) }}",
        "options": {}
      },
      "id": "b2222222-0000-0000-0000-000000000004",
      "name": "Répondre (ok)",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1.1,
      "position": [
        1120,
        360
      ]
    }
  ],
  "connections": {
    "Webhook GET file": {
      "main": [
        [
          {
            "node": "Lire File-à-traiter",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Lire File-à-traiter": {
      "main": [
        [
          {
            "node": "Filtrer PENDING",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Filtrer PENDING": {
      "main": [
        [
          {
            "node": "Répondre (posts JSON)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Webhook POST done": {
      "main": [
        [
          {
            "node": "Préparer maj DONE",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Préparer maj DONE": {
      "main": [
        [
          {
            "node": "Marquer DONE",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Marquer DONE": {
      "main": [
        [
          {
            "node": "Répondre (ok)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  },
  "active": false,
  "pinData": {},
  "meta": {
    "instanceId": "4f1b23afe1c1f425a998bc69ab78d2ebd64d2175c452226921ae034356fabed4"
  }
}