{
  "name": "DzRouter · 06 · Commentaires → réponses suggérées",
  "nodes": [
    {
      "id": "a7c9278a-c94f-5840-ba97-6beb292d2edc",
      "name": "Note",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -520,
        -260
      ],
      "parameters": {
        "content": "## Commentaires → réponses\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\nLeçon : un nœud traite **chaque élément** automatiquement (ici, un appel par commentaire).\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### Comments → replies\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": "11cc1cd5-a615-548a-a92a-90741d3b4257",
      "name": "Form",
      "type": "n8n-nodes-base.formTrigger",
      "typeVersion": 2.3,
      "position": [
        0,
        0
      ],
      "parameters": {
        "formTitle": "💬 Analyse des commentaires",
        "formDescription": "Un commentaire par ligne (Facebook, Instagram, TikTok…)",
        "formFields": {
          "values": [
            {
              "fieldLabel": "Commentaires",
              "fieldType": "textarea",
              "requiredField": true
            },
            {
              "fieldLabel": "Nom de la page",
              "fieldType": "text",
              "placeholder": "ex : Bijoux Lina Oran"
            }
          ]
        },
        "responseMode": "lastNode",
        "options": {
          "appendAttribution": false
        }
      }
    },
    {
      "id": "dee32275-511d-5c73-84e5-af5826e6e686",
      "name": "One item per comment",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        260,
        0
      ],
      "parameters": {
        "jsCode": "const form = $input.first().json;\nreturn form.Commentaires.split(/\\r?\\n/).map((c) => c.trim()).filter(Boolean)\n  .map((comment) => ({ json: { comment, page: form['Nom de la page'] || 'notre page' } }));"
      }
    },
    {
      "id": "d7e929e8-293b-5e3d-80ec-2913e28e826a",
      "name": "Analyze & reply",
      "type": "n8n-nodes-dzrouter.dzRouter",
      "typeVersion": 1,
      "position": [
        520,
        0
      ],
      "parameters": {
        "resource": "chat",
        "operation": "message",
        "model": {
          "__rl": true,
          "mode": "id",
          "value": "openai/gpt-4o-mini"
        },
        "messages": {
          "values": [
            {
              "role": "system",
              "content": "=Tu gères la page « {{ $json.page }} » pour un public algérien. Pour le commentaire donné, réponds uniquement en JSON : {\"category\":\"question|compliment|complaint|order|spam\",\"sentiment\":\"positive|neutral|negative\",\"reply\":\"…\"}. La réponse est courte, polie, dans la même langue ou dialecte que le commentaire (darja en lettres latines si le client écrit ainsi). Pour le spam, reply est vide."
            },
            {
              "role": "user",
              "content": "={{ $json.comment }}"
            }
          ]
        },
        "simplify": true,
        "options": {
          "temperature": 0.4,
          "maxTokens": 400,
          "responseFormat": "json_object"
        }
      }
    },
    {
      "id": "440454d5-0b3a-58be-b44a-88edf7d8529d",
      "name": "Build page",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        780,
        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 rows = $input.all().map((it, i) => ({ comment: $('One item per comment').all()[i].json.comment, ...(it.json.json ?? {}) }));\nconst color = { positive: '#007f00', neutral: '#4f6158', negative: '#d0262c' };\nconst table = `<table style=\"width:100%;border-collapse:collapse\">${rows.map((r) => `<tr style=\"border-bottom:1px solid #d6e1d9\">\n<td style=\"padding:8px\" dir=\"auto\">${esc(r.comment)}</td><td style=\"padding:8px;white-space:nowrap\"><b>${esc(r.category)}</b><br><span style=\"color:${color[r.sentiment] ?? '#4f6158'}\">${esc(r.sentiment)}</span></td>\n<td style=\"padding:8px\" dir=\"auto\">${esc(r.reply)}</td></tr>`).join('')}</table>`;\nreturn [{ json: { html: page(`💬 ${rows.length} commentaires`, table), rows } }];"
      }
    },
    {
      "id": "1db1b8cb-8c50-53d3-9339-0d9ca0803824",
      "name": "Show result",
      "type": "n8n-nodes-base.form",
      "typeVersion": 2.3,
      "position": [
        1040,
        0
      ],
      "parameters": {
        "operation": "completion",
        "respondWith": "showText",
        "responseText": "={{ $json.html }}"
      }
    }
  ],
  "connections": {
    "Form": {
      "main": [
        [
          {
            "node": "One item per comment",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "One item per comment": {
      "main": [
        [
          {
            "node": "Analyze & reply",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Analyze & reply": {
      "main": [
        [
          {
            "node": "Build page",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Build page": {
      "main": [
        [
          {
            "node": "Show result",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "pinData": {
    "Form": [
      {
        "json": {
          "Commentaires": "Ch7al el prix svp ?\nTrès belle qualité, je recommande 👍\nDerna commande men 10 jours w mazal ma wselnach !!\nحابة نطلب 2 قطع، كاين التوصيل لسطيف؟\nGagnez un iPhone gratuit ici >> bit.ly/xxx",
          "Nom de la page": "Bijoux Lina Oran",
          "submittedAt": "2026-10-13T10:00:00.000+01:00",
          "formMode": "test"
        }
      }
    ]
  },
  "settings": {
    "executionOrder": "v1"
  },
  "meta": {
    "templateCredsSetupCompleted": false,
    "templateId": "dzrouter"
  }
}
