{
  "name": "ADIK-02 Web Scraping + AI Analysis",
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "scrape-analyze",
        "responseMode": "lastNode",
        "options": {}
      },
      "id": "trigger-02",
      "name": "Webhook",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [240, 300],
      "webhookId": "adik-scrape-analyze"
    },
    {
      "parameters": {
        "url": "={{ $json.body.url || $json.url }}",
        "options": {
          "response": { "response": { "responseFormat": "text" } },
          "timeout": 20000
        }
      },
      "id": "fetch-url",
      "name": "Fetch HTML",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [460, 300]
    },
    {
      "parameters": {
        "jsCode": "const html = $input.first().json.data || $input.first().json.body || '';\nconst text = html\n  .replace(/<script[\\s\\S]*?<\\/script>/gi, ' ')\n  .replace(/<style[\\s\\S]*?<\\/style>/gi, ' ')\n  .replace(/<[^>]+>/g, ' ')\n  .replace(/\\s+/g, ' ')\n  .trim()\n  .slice(0, 6000);\nreturn [{ json: { url: $('Webhook').first().json.body?.url, text } }];"
      },
      "id": "extract-text",
      "name": "Strip HTML",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [680, 300]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "http://127.0.0.1:7860/api/hf/inference",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n  \"model\": \"facebook/bart-large-cnn\",\n  \"inputs\": {{ JSON.stringify($json.text) }},\n  \"parameters\": { \"max_length\": 200, \"min_length\": 60 }\n}",
        "options": {}
      },
      "id": "summarize",
      "name": "Summarize (BART)",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [900, 220]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "http://127.0.0.1:7860/api/hf/inference",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n  \"model\": \"cardiffnlp/twitter-roberta-base-sentiment-latest\",\n  \"inputs\": {{ JSON.stringify($('Strip HTML').first().json.text.slice(0,500)) }}\n}",
        "options": {}
      },
      "id": "sentiment",
      "name": "Sentiment",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [900, 380]
    },
    {
      "parameters": {
        "jsCode": "const sum = $('Summarize (BART)').first().json;\nconst sent = $('Sentiment').first().json;\nconst summary = Array.isArray(sum) ? sum[0]?.summary_text : sum.summary_text;\nlet sentLabel = 'unknown';\nif (Array.isArray(sent) && Array.isArray(sent[0])) {\n  sentLabel = sent[0].sort((a,b)=>b.score-a.score)[0]?.label || 'unknown';\n}\nreturn [{ json: {\n  url: $('Webhook').first().json.body?.url,\n  summary,\n  sentiment: sentLabel,\n  analyzed_at: new Date().toISOString()\n}}];"
      },
      "id": "merge",
      "name": "Merge Result",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [1120, 300]
    }
  ],
  "connections": {
    "Webhook":           { "main": [[{ "node": "Fetch HTML", "type": "main", "index": 0 }]] },
    "Fetch HTML":        { "main": [[{ "node": "Strip HTML", "type": "main", "index": 0 }]] },
    "Strip HTML":        { "main": [[{ "node": "Summarize (BART)", "type": "main", "index": 0 }, { "node": "Sentiment", "type": "main", "index": 0 }]] },
    "Summarize (BART)":  { "main": [[{ "node": "Merge Result", "type": "main", "index": 0 }]] },
    "Sentiment":         { "main": [[{ "node": "Merge Result", "type": "main", "index": 0 }]] }
  },
  "active": false,
  "settings": { "executionOrder": "v1" },
  "tags": [{ "name": "adik-os" }, { "name": "scraping" }]
}
