{
 "id": "FLUXIEL-DEMO1-SUPPORT",
 "name": "Fluxiel Démo 1 — Agent IA support e-commerce",
 "nodes": [
  {
   "parameters": {
    "content": "## Démo 1 — Agent IA support client e-commerce\n\n1. Requête POST sur le webhook (`message`, `email` et/ou `order_id`).\n2. Validation et nettoyage de l'entrée.\n3. **shop-api** (`SHOP_API_URL/repondre`) : contexte commande + FAQ, appel LLM local (Ollama), détection d'escalade.\n4. Escalade → alerte humaine enregistrée.\n5. Réponse JSON renvoyée au caller.\n\nEn test, `SHOP_API_URL` peut pointer vers le service avec `OLLAMA_URL` = llm-mock (voir README).\nVariables : voir `.env.example`.",
    "height": 400,
    "width": 400
   },
   "id": "note-intro",
   "name": "Note explicative",
   "type": "n8n-nodes-base.stickyNote",
   "typeVersion": 1,
   "position": [
    200,
    60
   ]
  },
  {
   "parameters": {
    "httpMethod": "POST",
    "path": "support-demo",
    "responseMode": "responseNode",
    "options": {}
   },
   "id": "webhook-support",
   "name": "Webhook support",
   "type": "n8n-nodes-base.webhook",
   "typeVersion": 2,
   "position": [
    240,
    300
   ],
   "webhookId": "fluxiel-demo1-support"
  },
  {
   "parameters": {
    "jsCode": "// Validation et nettoyage de l'entrée\nconst body = $json.body || $json;\nconst message = String(body.message || '').trim();\nif (!message) {\n  throw new Error('Champ \"message\" requis et non vide.');\n}\nif (message.length > 2000) {\n  throw new Error('Message trop long (max 2000 caractères).');\n}\nconst email = body.email ? String(body.email).trim() : null;\nif (email && !/^[^@\\s]+@[^@\\s]+\\.[^@\\s]+$/.test(email)) {\n  throw new Error('E-mail invalide.');\n}\nconst orderId = body.order_id ? String(body.order_id).trim() : null;\nreturn [{ json: { message, email, order_id: orderId } }];"
   },
   "id": "valider-entree",
   "name": "Valider l'entrée",
   "type": "n8n-nodes-base.code",
   "typeVersion": 2,
   "position": [
    460,
    300
   ]
  },
  {
   "parameters": {
    "method": "POST",
    "url": "={{ $env.SHOP_API_URL || 'http://127.0.0.1:8101' }}/repondre",
    "sendBody": true,
    "specifyBody": "json",
    "jsonBody": "={{ { message: $json.message, email: $json.email, order_id: $json.order_id } }}",
    "options": {
     "timeout": 90000
    }
   },
   "id": "appeler-agent",
   "name": "Appeler l'agent (shop-api)",
   "type": "n8n-nodes-base.httpRequest",
   "typeVersion": 4.2,
   "position": [
    680,
    300
   ]
  },
  {
   "parameters": {
    "conditions": {
     "options": {
      "caseSensitive": true,
      "leftValue": "",
      "typeValidation": "loose"
     },
     "conditions": [
      {
       "id": "cond-escalade",
       "leftValue": "={{ $json.escalation }}",
       "rightValue": true,
       "operator": {
        "type": "boolean",
        "operation": "true",
        "singleValue": true
       }
      }
     ],
     "combinator": "and"
    },
    "options": {}
   },
   "id": "si-escalade",
   "name": "Escalade humaine ?",
   "type": "n8n-nodes-base.if",
   "typeVersion": 2.2,
   "position": [
    900,
    300
   ]
  },
  {
   "parameters": {
    "method": "POST",
    "url": "={{ $env.SHOP_API_URL || 'http://127.0.0.1:8101' }}/alertes",
    "sendBody": true,
    "specifyBody": "json",
    "jsonBody": "={{ { sujet: 'Escalade support (via n8n)', detail: ($json.motif_escalade || 'non précisé') + ' — message client : ' + $(\"Valider l'entrée\").item.json.message } }}",
    "options": {}
   },
   "id": "alerter-humain",
   "name": "Alerter un humain",
   "type": "n8n-nodes-base.httpRequest",
   "typeVersion": 4.2,
   "position": [
    1120,
    200
   ]
  },
  {
   "parameters": {
    "respondWith": "json",
    "responseBody": "={{ { reponse: $('Appeler l\\'agent (shop-api)').item.json.reponse, escalation: true, motif_escalade: $('Appeler l\\'agent (shop-api)').item.json.motif_escalade || null } }}",
    "options": {}
   },
   "id": "repondre-escalade",
   "name": "Répondre (escalade)",
   "type": "n8n-nodes-base.respondToWebhook",
   "typeVersion": 1.4,
   "position": [
    1340,
    200
   ]
  },
  {
   "parameters": {
    "respondWith": "json",
    "responseBody": "={{ { reponse: $json.reponse, escalation: false, sources: $json.sources } }}",
    "options": {}
   },
   "id": "repondre-ok",
   "name": "Répondre (auto)",
   "type": "n8n-nodes-base.respondToWebhook",
   "typeVersion": 1.4,
   "position": [
    1120,
    420
   ]
  }
 ],
 "connections": {
  "Webhook support": {
   "main": [
    [
     {
      "node": "Valider l'entrée",
      "type": "main",
      "index": 0
     }
    ]
   ]
  },
  "Valider l'entrée": {
   "main": [
    [
     {
      "node": "Appeler l'agent (shop-api)",
      "type": "main",
      "index": 0
     }
    ]
   ]
  },
  "Appeler l'agent (shop-api)": {
   "main": [
    [
     {
      "node": "Escalade humaine ?",
      "type": "main",
      "index": 0
     }
    ]
   ]
  },
  "Escalade humaine ?": {
   "main": [
    [
     {
      "node": "Alerter un humain",
      "type": "main",
      "index": 0
     }
    ],
    [
     {
      "node": "Répondre (auto)",
      "type": "main",
      "index": 0
     }
    ]
   ]
  },
  "Alerter un humain": {
   "main": [
    [
     {
      "node": "Répondre (escalade)",
      "type": "main",
      "index": 0
     }
    ]
   ]
  }
 },
 "settings": {
  "errorWorkflow": "WF-ERREUR-DEMO1",
  "timezone": "Europe/Paris",
  "saveDataErrorExecution": "all"
 },
 "tags": [
  {
   "name": "fluxiel-demo"
  }
 ]
}