{
  "name": "DzRouter · 10 · Avis clients → synthèse et plan d'action",
  "nodes": [
    {
      "id": "882cb1f6-1946-5457-b408-0a52487f51d4",
      "name": "Note",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -520,
        -260
      ],
      "parameters": {
        "content": "## Avis clients → plan d'action\n\n1. Installez le nœud communautaire **n8n-nodes-dzrouter** (Paramètres → Community nodes).\n2. Ouvrez chaque nœud DzRouter et choisissez votre identifiant **DzRouter API** (clé `sk-dz-…`).\n3. Cliquez **Test workflow** : un exemple algérien est déjà chargé.\n\n---\n\n<div dir=\"rtl\">\n\n### آراء الزبائن\n\n1. ثبّت العقدة **n8n-nodes-dzrouter** (الإعدادات ← Community nodes).\n2. افتح كل عقدة DzRouter واختر بيانات اعتماد **DzRouter API** (مفتاح `sk-dz-…`).\n3. اضغط **Test workflow**: مثال جزائري جاهز للتجربة.\n\n</div>\n\n---\n\n### Customer reviews\n\n1. Install the **n8n-nodes-dzrouter** community node (Settings → Community nodes).\n2. Open each DzRouter node and pick your **DzRouter API** credential (`sk-dz-…` key).\n3. Click **Test workflow**: an Algerian sample is already loaded.",
        "height": 560,
        "width": 440,
        "color": 4
      }
    },
    {
      "id": "f53d48f6-9941-54b2-b3fb-38677c00a07d",
      "name": "Form",
      "type": "n8n-nodes-base.formTrigger",
      "typeVersion": 2.3,
      "position": [
        0,
        0
      ],
      "parameters": {
        "formTitle": "⭐ Analyse des avis clients",
        "formDescription": "Un avis par ligne",
        "formFields": {
          "values": [
            {
              "fieldLabel": "Avis",
              "fieldType": "textarea",
              "requiredField": true
            },
            {
              "fieldLabel": "Commerce",
              "fieldType": "text",
              "placeholder": "ex : Restaurant Le Tlemcenien"
            }
          ]
        },
        "responseMode": "lastNode",
        "options": {
          "appendAttribution": false
        }
      }
    },
    {
      "id": "46e23bea-3759-5792-b21b-457f78a028ce",
      "name": "One item per review",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        260,
        0
      ],
      "parameters": {
        "jsCode": "const form = $input.first().json;\nreturn form.Avis.split(/\\r?\\n/).map((s) => s.trim()).filter(Boolean).map((review) => ({ json: { review } }));"
      }
    },
    {
      "id": "22054f2a-54a6-5c93-a348-2fb500d7e727",
      "name": "Sentiment",
      "type": "n8n-nodes-dzrouter.dzRouter",
      "typeVersion": 1,
      "position": [
        520,
        0
      ],
      "parameters": {
        "resource": "text",
        "operation": "sentiment",
        "model": {
          "__rl": true,
          "mode": "id",
          "value": "openai/gpt-4o-mini"
        },
        "text": "={{ $json.review }}",
        "options": {
          "includeEmotions": true
        }
      }
    },
    {
      "id": "1564884c-04ce-5545-ad50-4747fd822ded",
      "name": "Gather",
      "type": "n8n-nodes-base.aggregate",
      "typeVersion": 1,
      "position": [
        780,
        0
      ],
      "parameters": {
        "aggregate": "aggregateAllItemData",
        "destinationFieldName": "results",
        "options": {}
      }
    },
    {
      "id": "d564da5d-756d-5844-8e5b-eafbd3bc33c4",
      "name": "Action plan",
      "type": "n8n-nodes-dzrouter.dzRouter",
      "typeVersion": 1,
      "position": [
        1040,
        0
      ],
      "parameters": {
        "resource": "chat",
        "operation": "message",
        "model": {
          "__rl": true,
          "mode": "id",
          "value": "openai/gpt-4o-mini"
        },
        "messages": {
          "values": [
            {
              "role": "system",
              "content": "Tu conseilles un commerce algérien. À partir des avis et de leur sentiment, réponds uniquement en JSON : {\"average_score\":0.0,\"strengths\":[\"…\"],\"weaknesses\":[\"…\"],\"actions\":[\"…\"],\"reply_template\":\"…\"}. actions = exactement 3 actions concrètes et peu coûteuses. reply_template = réponse type aux avis négatifs, en français."
            },
            {
              "role": "user",
              "content": "=Commerce : {{ $('Form').item.json.Commerce }}\nAvis analysés :\n{{ $json.results.map((r, i) => `- ${$('One item per review').all()[i].json.review} → ${r.sentiment} (${r.score})`).join('\\n') }}"
            }
          ]
        },
        "simplify": true,
        "options": {
          "temperature": 0.3,
          "maxTokens": 1500,
          "responseFormat": "json_object"
        }
      }
    },
    {
      "id": "85c86ca6-4fae-5c79-91d7-f32abebcca1d",
      "name": "Build page",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1300,
        0
      ],
      "parameters": {
        "jsCode": "const esc = (s) => String(s ?? '').replace(/[&<>\"]/g, (c) => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '\"': '&quot;' }[c]));\nconst page = (title, body) => `<div style=\"font-family:system-ui,Segoe UI,Tahoma,sans-serif;max-width:720px;margin:0 auto;line-height:1.6;color:#0f1c16\">\n<h2 style=\"color:#007f00;margin:0 0 12px\">${esc(title)}</h2>${body}\n<p style=\"color:#4f6158;font-size:13px;margin-top:24px\">Généré avec DzRouter · dzrouter.com</p></div>`;\n\nconst r = $('Action plan').first().json.json ?? {};\nconst list = (t, a) => `<h3>${t}</h3><ul dir=\"auto\">${(a ?? []).map((x) => `<li>${esc(x)}</li>`).join('')}</ul>`;\nconst body = `<p>Score moyen : <b>${esc(r.average_score)}</b> (de -1 à 1)</p>` + list('Points forts', r.strengths) + list('Points faibles', r.weaknesses) +\n  list('3 actions', r.actions) + `<h3>Réponse type aux avis négatifs</h3><p dir=\"auto\">${esc(r.reply_template)}</p>`;\nreturn [{ json: { html: page('⭐ ' + ($('Form').first().json.Commerce || 'Vos avis'), body) } }];"
      }
    },
    {
      "id": "818a1bd2-be60-573e-80eb-8ada8079aa23",
      "name": "Show result",
      "type": "n8n-nodes-base.form",
      "typeVersion": 2.3,
      "position": [
        1560,
        0
      ],
      "parameters": {
        "operation": "completion",
        "respondWith": "showText",
        "responseText": "={{ $json.html }}"
      }
    }
  ],
  "connections": {
    "Form": {
      "main": [
        [
          {
            "node": "One item per review",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "One item per review": {
      "main": [
        [
          {
            "node": "Sentiment",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Sentiment": {
      "main": [
        [
          {
            "node": "Gather",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Gather": {
      "main": [
        [
          {
            "node": "Action plan",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Action plan": {
      "main": [
        [
          {
            "node": "Build page",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Build page": {
      "main": [
        [
          {
            "node": "Show result",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "pinData": {
    "Form": [
      {
        "json": {
          "Avis": "Couscous excellent, comme chez ma grand-mère !\nService très lent le vendredi soir, 45 minutes d'attente.\nالمكان نظيف والأسعار معقولة\nBon mais un peu cher pour une chorba.\nPersonnel souriant, parking introuvable.",
          "Commerce": "Restaurant Le Tlemcenien",
          "submittedAt": "2026-10-13T10:00:00.000+01:00",
          "formMode": "test"
        }
      }
    ]
  },
  "settings": {
    "executionOrder": "v1"
  },
  "meta": {
    "templateCredsSetupCompleted": false,
    "templateId": "dzrouter"
  }
}
