{ "name": "brief-vorbereiten", "nodes": [ { "parameters": {}, "type": "n8n-nodes-base.manualTrigger", "typeVersion": 1, "position": [ -460, 40 ], "id": "5ad6950e-a5e9-4d1c-9f45-64e7f40c1345", "name": "Manuell starten" }, { "parameters": { "rule": { "interval": [ { "field": "weeks", "triggerAtDay": [ 1 ], "triggerAtHour": 7, "triggerAtMinute": 0 } ] } }, "type": "n8n-nodes-base.scheduleTrigger", "typeVersion": 1.2, "position": [ -460, 200 ], "id": "55fa4d8d-8362-4662-b422-5cf03694b4f8", "name": "Zeitplan Montag 07:00", "disabled": true }, { "parameters": { "httpMethod": "POST", "path": "brief-vorbereiten", "responseMode": "onReceived", "options": {} }, "type": "n8n-nodes-base.webhook", "typeVersion": 2.1, "position": [ -460, 360 ], "id": "675b0a53-a893-40ef-99d6-fafaa8ac0792", "name": "Webhook Start", "webhookId": "2de1c213-4fb5-4e91-8b5c-9ce69ef25ca3" }, { "parameters": { "mode": "manual", "assignments": { "assignments": [ { "id": "d43ddbb3-2514-41c6-b888-02abc4e15d41", "name": "nw_base", "value": "https://app.neuronwriter.com/neuron-api/0.5/writer", "type": "string" }, { "id": "bd516db2-6009-4bba-99d2-189750fc1cd2", "name": "nw_project", "value": "3da4d745e0e223cb", "type": "string" }, { "id": "7ec57b28-ee76-4fdb-87e6-5e07c56cdd4d", "name": "nw_engine", "value": "google.de", "type": "string" }, { "id": "e670bd6a-6327-4570-ac3b-09baff9dc81a", "name": "nw_language", "value": "German", "type": "string" }, { "id": "c5671976-8b69-4788-9e36-86165d5e97f4", "name": "gitea_base", "value": "http://gitea:3000", "type": "string" }, { "id": "17ab5e1f-db56-45ad-8392-ff0dfed8a965", "name": "gitea_owner", "value": "lucas.orth", "type": "string" }, { "id": "3a233c4d-69b7-47cc-97f6-0dc06c2923f6", "name": "gitea_repo", "value": "Skrift-Auto-Article", "type": "string" }, { "id": "83e56d69-847f-485c-9331-acffd8390fda", "name": "branch", "value": "main", "type": "string" }, { "id": "9ddffd30-8245-4e0e-85c6-4ef350dc45d9", "name": "index_pfad", "value": "artikel-index.json", "type": "string" }, { "id": "47ac93b9-529b-43a4-a3d1-76d83f056827", "name": "brief_ordner", "value": "briefe", "type": "string" }, { "id": "67d79c76-ca3a-4066-97a8-6d135f55244e", "name": "poll_max", "value": 30, "type": "number" }, { "id": "0766321e-b286-48b9-90c3-63b0f9d22a82", "name": "poll_sekunden", "value": 20, "type": "number" }, { "id": "9effca14-631e-419d-8dba-4e5c44c1b817", "name": "pause_zwischen_artikeln", "value": 5, "type": "number" }, { "id": "4cf2db61-c55a-43d1-8d7b-427e35ac703e", "name": "benachrichtigung_an", "value": "privat@lucas-orth.de", "type": "string" } ] }, "options": {} }, "type": "n8n-nodes-base.set", "typeVersion": 3.4, "position": [ -240, 200 ], "id": "aba36956-c83a-44c4-9012-fe80979f8545", "name": "Konfiguration" }, { "parameters": { "method": "GET", "url": "={{ $json.gitea_base }}/api/v1/repos/{{ $json.gitea_owner }}/{{ $json.gitea_repo }}/contents/{{ $json.index_pfad }}?ref={{ $json.branch }}", "authentication": "genericCredentialType", "genericAuthType": "httpHeaderAuth", "options": { "response": { "response": { "neverError": false } }, "timeout": 60000 } }, "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.3, "position": [ -20, 200 ], "id": "0ebb8bf1-d129-4066-8c59-2b4c3b27cd52", "name": "Artikeltabelle lesen", "credentials": { "httpHeaderAuth": { "id": "VOD4JM5zwpSC8wAr", "name": "Gitea Skrift Auto Article" } }, "onError": "continueErrorOutput", "retryOnFail": true, "maxTries": 3, "waitBetweenTries": 3000 }, { "parameters": { "mode": "runOnceForAllItems", "jsCode": "\nconst e = $input.first().json;\nthrow new Error(\n 'Artikeltabelle konnte nicht gelesen werden. Pruefen: Gitea-Token-Scope (write:repository noetig), '\n + 'Pfad artikel-index.json im Branch main, Repo-Name. Antwort: '\n + JSON.stringify(e).slice(0, 600)\n);\n" }, "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ -20, 420 ], "id": "5093a5ca-b790-459f-bf12-5e221431323f", "name": "Fehler Artikeltabelle" }, { "parameters": { "mode": "runOnceForAllItems", "jsCode": "\n// Gitea liefert den Dateiinhalt base64-kodiert.\nconst antwort = $input.first().json;\nif (!antwort.content) {\n throw new Error('Gitea-Antwort enthaelt kein Feld \"content\". Erhalten: ' + JSON.stringify(antwort).slice(0,400));\n}\nconst roh = Buffer.from(antwort.content, 'base64').toString('utf8');\nlet tabelle;\ntry { tabelle = JSON.parse(roh); }\ncatch (e) { throw new Error('artikel-index.json ist kein gueltiges JSON: ' + e.message); }\nif (!Array.isArray(tabelle)) {\n throw new Error('artikel-index.json muss ein Array sein, ist aber: ' + typeof tabelle);\n}\n\nconst konf = $('Konfiguration').first().json;\nconst pflicht = ['slug','titel','keyword','kategorie','cta_ziel','status'];\n\nconst offen = [];\ntabelle.forEach((zeile, i) => {\n if (zeile.status !== 'offen') return;\n const fehlt = pflicht.filter(f => !zeile[f]);\n if (fehlt.length) {\n throw new Error(`Zeile ${i} (slug: ${zeile.slug || '?'}) fehlen Pflichtfelder: ${fehlt.join(', ')}`);\n }\n offen.push({ json: { ...zeile, zeilen_index: i } });\n});\n\n// Kontext fuer spaetere Nodes einmal ablegen\nconst kontext = { index_sha: antwort.sha, tabelle_gesamt: tabelle, anzahl_offen: offen.length };\n$getWorkflowStaticData('global').lauf = kontext;\n\nif (offen.length === 0) return [{ json: { ...kontext, leer: true } }];\nreturn offen.map(o => ({ json: { ...o.json, index_sha: antwort.sha } }));\n" }, "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 200, 200 ], "id": "335206d7-0cd9-4e66-9534-bdf52618deac", "name": "Tabelle auswerten" }, { "parameters": { "conditions": { "options": { "caseSensitive": true, "leftValue": "", "typeValidation": "loose", "version": 2 }, "conditions": [ { "id": "90341bb9-1b82-49ee-8a6e-3351c7140dbe", "leftValue": "={{ $json.leer === true }}", "rightValue": "", "operator": { "type": "boolean", "operation": "true", "singleValue": true } } ], "combinator": "and" }, "looseTypeValidation": true, "options": {} }, "type": "n8n-nodes-base.if", "typeVersion": 2.2, "position": [ 420, 200 ], "id": "74528ffd-5113-4ada-a8a9-aa4e1e8a5309", "name": "Offene Artikel vorhanden?" }, { "parameters": {}, "type": "n8n-nodes-base.noOp", "typeVersion": 1, "position": [ 640, 60 ], "id": "c7123211-a46c-4446-a10d-5ba1083b05b2", "name": "Nichts zu tun" }, { "parameters": { "batchSize": 1, "options": { "reset": false } }, "type": "n8n-nodes-base.splitInBatches", "typeVersion": 3, "position": [ 640, 320 ], "id": "b690989b-0358-43aa-b7e3-efd5511b3d58", "name": "Artikel nacheinander" }, { "parameters": { "method": "POST", "url": "={{ $('Konfiguration').first().json.nw_base }}/new-query", "authentication": "genericCredentialType", "genericAuthType": "httpHeaderAuth", "options": { "response": { "response": { "neverError": false } }, "timeout": 60000 }, "sendBody": true, "specifyBody": "json", "jsonBody": "={{ JSON.stringify({ project: $('Konfiguration').first().json.nw_project, keyword: $json.keyword, engine: $('Konfiguration').first().json.nw_engine, language: $('Konfiguration').first().json.nw_language }) }}", "sendHeaders": true, "specifyHeaders": "json", "jsonHeaders": "={\"Content-Type\":\"application/json\"}" }, "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.3, "position": [ 900, 420 ], "id": "95a1f069-15c6-405e-888e-2d317891b28c", "name": "Analyse starten", "credentials": { "httpHeaderAuth": { "id": "U23n2O980GKWocWq", "name": "NeuronWriter API" } }, "onError": "continueErrorOutput", "retryOnFail": true, "maxTries": 3, "waitBetweenTries": 3000 }, { "parameters": { "mode": "runOnceForAllItems", "jsCode": "\nconst artikel = $('Artikel nacheinander').first().json;\nconst e = $input.first().json;\nreturn [{ json: {\n slug: artikel.slug, keyword: artikel.keyword, ergebnis: 'fehler',\n stufe: 'new-query',\n meldung: 'NeuronWriter /new-query fehlgeschlagen fuer Keyword \"' + artikel.keyword\n + '\". Haeufige Ursachen: Query-Kontingent erschoepft, falsche Projekt-ID, API-Key ungueltig. Antwort: '\n + JSON.stringify(e).slice(0, 500)\n}}];\n" }, "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 900, 640 ], "id": "bb797361-40f3-46da-b359-c2ce94ad3bec", "name": "Fehler Analyse starten", "onError": "continueRegularOutput" }, { "parameters": { "mode": "runOnceForAllItems", "jsCode": "\nconst artikel = $('Artikel nacheinander').first().json;\nconst neu = $input.first().json;\nif (!neu.query) {\n throw new Error('NeuronWriter lieferte kein Feld \"query\". Antwort: ' + JSON.stringify(neu).slice(0,400));\n}\nreturn [{ json: { ...artikel, query: neu.query, query_url: neu.query_url,\n share_url: neu.share_url, versuch: 0 } }];\n" }, "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 1120, 420 ], "id": "5320b757-5a3f-465e-9b3f-3da46b590824", "name": "Poll vorbereiten" }, { "parameters": { "amount": "={{ $('Konfiguration').first().json.poll_sekunden }}", "unit": "seconds" }, "type": "n8n-nodes-base.wait", "typeVersion": 1.1, "position": [ 1340, 420 ], "id": "0b0db985-8687-4b8a-b183-7a1072d8180f", "name": "Warten", "webhookId": "dcd62081-3c28-4b1c-87b1-058ee2e774fc" }, { "parameters": { "method": "POST", "url": "={{ $('Konfiguration').first().json.nw_base }}/get-query", "authentication": "genericCredentialType", "genericAuthType": "httpHeaderAuth", "options": { "response": { "response": { "neverError": false } }, "timeout": 60000 }, "sendBody": true, "specifyBody": "json", "jsonBody": "={{ JSON.stringify({ query: $json.query }) }}", "sendHeaders": true, "specifyHeaders": "json", "jsonHeaders": "={\"Content-Type\":\"application/json\"}" }, "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.3, "position": [ 1560, 420 ], "id": "c2d91e7a-97cd-446d-9f59-973d2fd2e872", "name": "Analyse abfragen", "credentials": { "httpHeaderAuth": { "id": "U23n2O980GKWocWq", "name": "NeuronWriter API" } }, "onError": "continueErrorOutput", "retryOnFail": true, "maxTries": 3, "waitBetweenTries": 3000 }, { "parameters": { "mode": "runOnceForAllItems", "jsCode": "\nconst a = $('Poll vorbereiten').first().json;\nreturn [{ json: { slug: a.slug, keyword: a.keyword, query: a.query, ergebnis: 'fehler',\n stufe: 'get-query',\n meldung: 'NeuronWriter /get-query fehlgeschlagen fuer query ' + a.query + '. Antwort: '\n + JSON.stringify($input.first().json).slice(0, 500) }}];\n" }, "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 1560, 640 ], "id": "32ea6fc9-45ad-4e9c-86db-5eda4a369308", "name": "Fehler Analyse abfragen", "onError": "continueRegularOutput" }, { "parameters": { "conditions": { "options": { "caseSensitive": true, "leftValue": "", "typeValidation": "loose", "version": 2 }, "conditions": [ { "id": "540396ef-e549-47e4-aab0-2658f397d1b0", "leftValue": "={{ $json.status }}", "rightValue": "ready", "operator": { "type": "string", "operation": "equals" } } ], "combinator": "and" }, "looseTypeValidation": true, "options": {} }, "type": "n8n-nodes-base.if", "typeVersion": 2.2, "position": [ 1780, 420 ], "id": "3611443b-1e91-4241-8c61-3c18e3a6a3d2", "name": "Analyse fertig?" }, { "parameters": { "mode": "runOnceForAllItems", "jsCode": "\nconst poll = $('Poll vorbereiten').first().json;\nconst antwort = $input.first().json;\nconst versuch = (poll.versuch || 0) + $runIndex + 1;\nreturn [{ json: { ...poll, versuch, letzter_status: antwort.status || 'unbekannt' } }];\n" }, "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 1780, 660 ], "id": "524f0b05-2fce-4223-9974-dbfd9571e9ac", "name": "Versuch zaehlen" }, { "parameters": { "conditions": { "options": { "caseSensitive": true, "leftValue": "", "typeValidation": "loose", "version": 2 }, "conditions": [ { "id": "f6a87ddd-b2da-4164-90ff-159bf3d0e33e", "leftValue": "={{ $json.versuch }}", "rightValue": "={{ $('Konfiguration').first().json.poll_max }}", "operator": { "type": "number", "operation": "gte" } } ], "combinator": "and" }, "looseTypeValidation": true, "options": {} }, "type": "n8n-nodes-base.if", "typeVersion": 2.2, "position": [ 2000, 660 ], "id": "5bcea09f-ad45-4347-ad0d-fcefbbae7b50", "name": "Poll-Limit erreicht?" }, { "parameters": { "mode": "runOnceForAllItems", "jsCode": "\nconst a = $input.first().json;\nreturn [{ json: { slug: a.slug, keyword: a.keyword, query: a.query, ergebnis: 'fehler',\n stufe: 'poll-timeout',\n meldung: 'NeuronWriter-Analyse fuer \"' + a.keyword + '\" war nach ' + a.versuch\n + ' Versuchen noch nicht fertig (letzter Status: ' + a.letzter_status\n + '). Analyse laeuft ggf. weiter, query merken: ' + a.query }}];\n" }, "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 2220, 780 ], "id": "f2b2da7e-2014-460f-af19-d9d08c1c8516", "name": "Timeout melden" }, { "parameters": { "mode": "runOnceForAllItems", "jsCode": "\n// Feldnamen stammen aus einer echten /get-query-Antwort, siehe docs/feldnachweis.md\nconst a = $('Poll vorbereiten').first().json;\nconst n = $input.first().json;\n\nconst liste = (arr) => (arr || []).map(x => ({\n begriff: x.t,\n min: Array.isArray(x.sugg_usage) ? x.sugg_usage[0] : null,\n max: Array.isArray(x.sugg_usage) ? x.sugg_usage[1] : null,\n bei_wettbewerbern_pc: x.usage_pc ?? null,\n}));\n\nconst fragen = [];\nconst gesehen = new Set();\nconst addFrage = (q, quelle, gewicht) => {\n if (!q) return;\n const k = q.trim().toLowerCase();\n if (gesehen.has(k)) return;\n gesehen.add(k);\n fragen.push({ frage: q.trim(), quelle, gewicht });\n};\nObject.entries((n.ideas && n.ideas.topic_matrix) || {})\n .sort((x, y) => (y[1].importance || 0) - (x[1].importance || 0))\n .forEach(([q, v]) => addFrage(q, 'topic_matrix', v.importance || null));\n((n.ideas || {}).people_also_ask || []).forEach(x => addFrage(x.q, 'people_also_ask', null));\n((n.ideas || {}).suggest_questions || []).forEach(x => addFrage(x.q, 'suggest_questions', null));\n((n.ideas || {}).content_questions || []).forEach(x => addFrage(x.q, 'content_questions', null));\n\nconst brief = {\n // --- die vom Auftrag geforderten Felder ---\n query_id: n.query,\n keyword: n.keyword,\n begriffe_pflicht: liste((n.terms || {}).content_basic),\n begriffe_erweitert: liste((n.terms || {}).content_extended),\n fragen,\n wortzahl_ziel: ((n.metrics || {}).word_count || {}).target ?? null,\n\n // --- Artikelkontext aus der Tabelle ---\n artikel: { slug: a.slug, titel: a.titel, kategorie: a.kategorie, cta_ziel: a.cta_ziel },\n\n // --- Zusatz fuer die Schreibvorlage ---\n zusatz: {\n wortzahl_median: ((n.metrics || {}).word_count || {}).median ?? null,\n lesbarkeit_ziel: ((n.metrics || {}).readability || {}).target ?? null,\n begriffe_titel: ((n.terms || {}).title || []).map(x => x.t),\n begriffe_description: ((n.terms || {}).desc || []).map(x => x.t),\n begriffe_h1: ((n.terms || {}).h1 || []).map(x => x.t),\n begriffe_h2: ((n.terms || {}).h2 || []).map(x => x.t),\n entitaeten: ((n.terms || {}).entities || []).slice(0, 15).map(x => ({ name: x.t, wichtigkeit: x.importance })),\n suchintention: (n.serp_summary || {}).top_intent ?? null,\n haeufigster_inhaltstyp: (n.serp_summary || {}).top_content_type ?? null,\n gliederungen_top5: (n.competitors || []).slice(0, 5).map(c => ({\n rang: c.rank, url: c.url, score: c.content_score, wortzahl: c.word_count,\n ueberschriften: (c.headers || []).map(h => `${h[0]}: ${h[1]}`).slice(0, 25),\n })),\n terms_txt_content_basic: ((n.terms_txt || {}).content_basic_w_ranges) ?? null,\n },\n\n schreibregeln: {\n preise: 'Preise niemals ausschreiben. Immer den Shortcode einsetzen: '\n + '[skrift_preis key=\"SCHLUESSEL\" ab=\"0|1\" brutto=\"0|1\"]. '\n + 'key ist der Produktschluessel (z. B. briefe, postkarten, porto_inland). '\n + 'ab=1 liefert den guenstigsten Staffelpreis, ab=0 den Standardpreis. '\n + 'brutto=1 inkl. MwSt., brutto=0 netto. Das Wort \"ab\" selbst gehoert in den Fliesstext, '\n + 'der Shortcode liefert nur die Zahl. Beispiel: '\n + 'Handschriftliche Briefe ab [skrift_preis key=\"briefe\" ab=\"1\"] pro Stueck. '\n + 'Ein unbekannter key ergibt eine leere Ausgabe, keinen Fehler.',\n faq: 'FAQ nicht in content_html schreiben, sondern als Feld faq mit Frage-Antwort-Paaren. '\n + 'Die Ausgabe im Beitrag uebernimmt der Shortcode [skrift_faq].',\n kurzantwort: 'Ein Absatz, der die Hauptfrage direkt beantwortet, als eigenes Feld kurzantwort.',\n },\n\n meta: {\n erzeugt_am: new Date().toISOString(),\n analyse_url: n.query_url || a.query_url || null,\n freigabe_url: n.share_url || a.share_url || null,\n sprache: n.language, suchmaschine: n.engine, projekt: n.project,\n },\n};\n\nreturn [{ json: { slug: a.slug, zeilen_index: a.zeilen_index, query: n.query,\n keyword: n.keyword, brief } }];\n" }, "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 2220, 300 ], "id": "e7c0babd-988d-4a5a-9cdd-ba6de4ecf07e", "name": "Brief bauen" }, { "parameters": { "method": "GET", "url": "={{ $('Konfiguration').first().json.gitea_base }}/api/v1/repos/{{ $('Konfiguration').first().json.gitea_owner }}/{{ $('Konfiguration').first().json.gitea_repo }}/contents/{{ $('Konfiguration').first().json.brief_ordner }}/brief-{{ $json.slug }}.json?ref={{ $('Konfiguration').first().json.branch }}", "authentication": "genericCredentialType", "genericAuthType": "httpHeaderAuth", "options": { "response": { "response": { "neverError": true, "fullResponse": true } }, "timeout": 60000 } }, "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.3, "position": [ 2440, 300 ], "id": "537e73ab-e8a5-44a5-b88d-1052ccd1bc61", "name": "Brief vorhanden?", "credentials": { "httpHeaderAuth": { "id": "VOD4JM5zwpSC8wAr", "name": "Gitea Skrift Auto Article" } } }, { "parameters": { "mode": "runOnceForAllItems", "jsCode": "\nconst b = $('Brief bauen').first().json;\nconst p = $input.first().json;\n// n8n liefert den Koerper bei fullResponse je nach Version als body oder data.\nconst K = (r) => (r && r.body !== undefined) ? r.body : ((r || {}).data);\nconst kp = K(p);\nconst vorhanden = p.statusCode === 200 && kp && kp.sha;\n\nconst inhalt = Buffer.from(JSON.stringify(b.brief, null, 2), 'utf8').toString('base64');\nconst konf = $('Konfiguration').first().json;\n\nreturn [{ json: {\n ...b,\n methode: vorhanden ? 'PUT' : 'POST',\n pfad: `${konf.brief_ordner}/brief-${b.slug}.json`,\n commit_body: JSON.stringify({\n content: inhalt,\n message: `Brief ${vorhanden ? 'aktualisiert' : 'erzeugt'}: ${b.slug} (${b.keyword})`,\n branch: konf.branch,\n ...(vorhanden ? { sha: kp.sha } : {}),\n }),\n}}];\n" }, "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 2660, 300 ], "id": "8a18d86d-fda2-4f65-bed9-7deda83a1acb", "name": "Commit vorbereiten" }, { "parameters": { "method": "={{ $json.methode }}", "url": "={{ $('Konfiguration').first().json.gitea_base }}/api/v1/repos/{{ $('Konfiguration').first().json.gitea_owner }}/{{ $('Konfiguration').first().json.gitea_repo }}/contents/{{ $json.pfad }}", "authentication": "genericCredentialType", "genericAuthType": "httpHeaderAuth", "options": { "response": { "response": { "neverError": false } }, "timeout": 60000 }, "sendBody": true, "specifyBody": "json", "jsonBody": "={{ $json.commit_body }}", "sendHeaders": true, "specifyHeaders": "json", "jsonHeaders": "={\"Content-Type\":\"application/json\"}" }, "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.3, "position": [ 2880, 300 ], "id": "db44ac17-59f2-437a-bb7d-94aa4da5a074", "name": "Brief committen", "credentials": { "httpHeaderAuth": { "id": "VOD4JM5zwpSC8wAr", "name": "Gitea Skrift Auto Article" } }, "onError": "continueErrorOutput", "retryOnFail": true, "maxTries": 3, "waitBetweenTries": 3000 }, { "parameters": { "mode": "runOnceForAllItems", "jsCode": "\nconst b = $('Brief bauen').first().json;\nreturn [{ json: { slug: b.slug, keyword: b.keyword, query: b.query, ergebnis: 'fehler',\n stufe: 'gitea-commit',\n meldung: 'Brief konnte nicht ins Repo geschrieben werden. Haeufigste Ursache: Gitea-Token ohne '\n + 'Scope write:repository. Antwort: ' + JSON.stringify($input.first().json).slice(0, 500) }}];\n" }, "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 2880, 520 ], "id": "31a3c38b-c79a-42cb-9ac1-6710deb2fd02", "name": "Fehler Brief committen", "onError": "continueRegularOutput" }, { "parameters": { "mode": "runOnceForAllItems", "jsCode": "\nconst b = $('Brief bauen').first().json;\nreturn [{ json: {\n slug: b.slug, keyword: b.keyword, query: b.query, zeilen_index: b.zeilen_index,\n ergebnis: 'ok', neuer_status: 'brief_bereit',\n pfad: $('Commit vorbereiten').first().json.pfad,\n wortzahl_ziel: b.brief.wortzahl_ziel,\n anzahl_pflichtbegriffe: b.brief.begriffe_pflicht.length,\n anzahl_fragen: b.brief.fragen.length,\n analyse_url: b.brief.meta.analyse_url,\n}}];\n" }, "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 3100, 300 ], "id": "5d243ba5-1e7e-4f16-8037-9eed05687643", "name": "Erfolg merken" }, { "parameters": { "amount": "={{ $('Konfiguration').first().json.pause_zwischen_artikeln }}", "unit": "seconds" }, "type": "n8n-nodes-base.wait", "typeVersion": 1.1, "position": [ 3320, 400 ], "id": "997a2d3f-ddca-4081-9ded-2eb521163b1b", "name": "Pause Rate Limit", "webhookId": "3f510a7a-22c1-4248-a7c1-60fe57786eb2" }, { "parameters": { "mode": "runOnceForAllItems", "jsCode": "\nconst alle = $input.all().map(i => i.json);\nconst tabelle = $('Tabelle auswerten').first().json.tabelle_gesamt\n || $getWorkflowStaticData('global').lauf.tabelle_gesamt;\nconst index_sha = $('Artikeltabelle lesen').first().json.sha;\n\nconst kopie = JSON.parse(JSON.stringify(tabelle));\nlet geaendert = 0;\nalle.filter(r => r.ergebnis === 'ok').forEach(r => {\n const i = kopie.findIndex(z => z.slug === r.slug);\n if (i >= 0) { kopie[i].status = 'brief_bereit'; kopie[i].query_id = r.query; geaendert++; }\n});\n\nconst ok = alle.filter(r => r.ergebnis === 'ok');\nconst fehler = alle.filter(r => r.ergebnis === 'fehler');\n\nreturn [{ json: {\n index_sha, geaendert,\n neue_tabelle: JSON.stringify(kopie, null, 2),\n ok, fehler,\n anzahl_ok: ok.length, anzahl_fehler: fehler.length,\n}}];\n" }, "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 900, 140 ], "id": "8f0de534-6cea-40af-bf64-e63651648df7", "name": "Ergebnisse sammeln" }, { "parameters": { "mode": "runOnceForAllItems", "jsCode": "\nconst s = $input.first().json;\nconst konf = $('Konfiguration').first().json;\nreturn [{ json: { ...s, commit_body: JSON.stringify({\n content: Buffer.from(s.neue_tabelle, 'utf8').toString('base64'),\n message: `Status auf brief_bereit gesetzt (${s.geaendert} Artikel)`,\n branch: konf.branch,\n sha: s.index_sha,\n})}}];\n" }, "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 1120, 140 ], "id": "9597c915-36d3-4f94-af9d-60351fa4ac41", "name": "Statusupdate vorbereiten" }, { "parameters": { "method": "PUT", "url": "={{ $('Konfiguration').first().json.gitea_base }}/api/v1/repos/{{ $('Konfiguration').first().json.gitea_owner }}/{{ $('Konfiguration').first().json.gitea_repo }}/contents/{{ $('Konfiguration').first().json.index_pfad }}", "authentication": "genericCredentialType", "genericAuthType": "httpHeaderAuth", "options": { "response": { "response": { "neverError": false } }, "timeout": 60000 }, "sendBody": true, "specifyBody": "json", "jsonBody": "={{ $json.commit_body }}", "sendHeaders": true, "specifyHeaders": "json", "jsonHeaders": "={\"Content-Type\":\"application/json\"}" }, "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.3, "position": [ 1340, 140 ], "id": "a81137d7-c063-4f56-ac56-2ac6fffa9560", "name": "Status zurueckschreiben", "credentials": { "httpHeaderAuth": { "id": "VOD4JM5zwpSC8wAr", "name": "Gitea Skrift Auto Article" } }, "onError": "continueErrorOutput", "retryOnFail": true, "maxTries": 3, "waitBetweenTries": 3000 }, { "parameters": { "mode": "runOnceForAllItems", "jsCode": "\nthrow new Error('Status konnte nicht zurueckgeschrieben werden. Die Briefe sind erzeugt, aber die '\n + 'Artikeltabelle steht noch auf \"offen\". Vor dem naechsten Lauf pruefen, sonst werden Analysen '\n + 'doppelt erzeugt. Antwort: ' + JSON.stringify($input.first().json).slice(0, 500));\n" }, "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 1340, -60 ], "id": "35cff298-1691-452f-bc25-a225ee241a6e", "name": "Fehler Statusupdate" }, { "parameters": { "mode": "runOnceForAllItems", "jsCode": "\nconst s = $('Ergebnisse sammeln').first().json;\nconst z = [];\nz.push(`Briefe vorbereitet: ${s.anzahl_ok}, Fehler: ${s.anzahl_fehler}`);\nz.push('');\nif (s.ok.length) {\n z.push('Fertig:');\n s.ok.forEach(r => z.push(\n ` ${r.slug} | Zielwortzahl ${r.wortzahl_ziel} | ${r.anzahl_pflichtbegriffe} Pflichtbegriffe, `\n + `${r.anzahl_fragen} Fragen\\n Datei: ${r.pfad}\\n Analyse: ${r.analyse_url}`));\n z.push('');\n}\nif (s.fehler.length) {\n z.push('Fehler:');\n s.fehler.forEach(r => z.push(` ${r.slug || '?'} [${r.stufe}]: ${r.meldung}`));\n z.push('');\n}\nz.push('Naechster Schritt: git pull, dann die Briefe in Cowork als Schreibvorlage nutzen.');\nreturn [{ json: {\n betreff: `Skrift Ratgeber: ${s.anzahl_ok} Brief(e) bereit` + (s.anzahl_fehler ? `, ${s.anzahl_fehler} Fehler` : ''),\n text: z.join('\\n'),\n}}];\n" }, "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 1560, 140 ], "id": "ad2d0735-fd21-4181-bb7f-8bc51bd01435", "name": "Meldung formulieren" }, { "parameters": { "fromEmail": "", "toEmail": "={{ $('Konfiguration').first().json.benachrichtigung_an }}", "subject": "={{ $json.betreff }}", "emailFormat": "text", "text": "={{ $json.text }}", "options": {} }, "type": "n8n-nodes-base.emailSend", "typeVersion": 2.1, "position": [ 1780, 140 ], "id": "03d899b0-4d69-4105-a755-eaa1792d7497", "name": "Benachrichtigung", "disabled": true, "notes": "SMTP-Credential zuweisen, Absender eintragen, dann Node aktivieren." } ], "connections": { "Manuell starten": { "main": [ [ { "node": "Konfiguration", "type": "main", "index": 0 } ] ] }, "Zeitplan Montag 07:00": { "main": [ [ { "node": "Konfiguration", "type": "main", "index": 0 } ] ] }, "Webhook Start": { "main": [ [ { "node": "Konfiguration", "type": "main", "index": 0 } ] ] }, "Konfiguration": { "main": [ [ { "node": "Artikeltabelle lesen", "type": "main", "index": 0 } ] ] }, "Artikeltabelle lesen": { "main": [ [ { "node": "Tabelle auswerten", "type": "main", "index": 0 } ], [ { "node": "Fehler Artikeltabelle", "type": "main", "index": 0 } ] ] }, "Tabelle auswerten": { "main": [ [ { "node": "Offene Artikel vorhanden?", "type": "main", "index": 0 } ] ] }, "Offene Artikel vorhanden?": { "main": [ [ { "node": "Nichts zu tun", "type": "main", "index": 0 } ], [ { "node": "Artikel nacheinander", "type": "main", "index": 0 } ] ] }, "Artikel nacheinander": { "main": [ [ { "node": "Ergebnisse sammeln", "type": "main", "index": 0 } ], [ { "node": "Analyse starten", "type": "main", "index": 0 } ] ] }, "Analyse starten": { "main": [ [ { "node": "Poll vorbereiten", "type": "main", "index": 0 } ], [ { "node": "Fehler Analyse starten", "type": "main", "index": 0 } ] ] }, "Poll vorbereiten": { "main": [ [ { "node": "Warten", "type": "main", "index": 0 } ] ] }, "Warten": { "main": [ [ { "node": "Analyse abfragen", "type": "main", "index": 0 } ] ] }, "Analyse abfragen": { "main": [ [ { "node": "Analyse fertig?", "type": "main", "index": 0 } ], [ { "node": "Fehler Analyse abfragen", "type": "main", "index": 0 } ] ] }, "Analyse fertig?": { "main": [ [ { "node": "Brief bauen", "type": "main", "index": 0 } ], [ { "node": "Versuch zaehlen", "type": "main", "index": 0 } ] ] }, "Versuch zaehlen": { "main": [ [ { "node": "Poll-Limit erreicht?", "type": "main", "index": 0 } ] ] }, "Poll-Limit erreicht?": { "main": [ [ { "node": "Timeout melden", "type": "main", "index": 0 } ], [ { "node": "Warten", "type": "main", "index": 0 } ] ] }, "Brief bauen": { "main": [ [ { "node": "Brief vorhanden?", "type": "main", "index": 0 } ] ] }, "Brief vorhanden?": { "main": [ [ { "node": "Commit vorbereiten", "type": "main", "index": 0 } ] ] }, "Commit vorbereiten": { "main": [ [ { "node": "Brief committen", "type": "main", "index": 0 } ] ] }, "Brief committen": { "main": [ [ { "node": "Erfolg merken", "type": "main", "index": 0 } ], [ { "node": "Fehler Brief committen", "type": "main", "index": 0 } ] ] }, "Erfolg merken": { "main": [ [ { "node": "Pause Rate Limit", "type": "main", "index": 0 } ] ] }, "Fehler Brief committen": { "main": [ [ { "node": "Pause Rate Limit", "type": "main", "index": 0 } ] ] }, "Fehler Analyse starten": { "main": [ [ { "node": "Pause Rate Limit", "type": "main", "index": 0 } ] ] }, "Fehler Analyse abfragen": { "main": [ [ { "node": "Pause Rate Limit", "type": "main", "index": 0 } ] ] }, "Timeout melden": { "main": [ [ { "node": "Pause Rate Limit", "type": "main", "index": 0 } ] ] }, "Pause Rate Limit": { "main": [ [ { "node": "Artikel nacheinander", "type": "main", "index": 0 } ] ] }, "Ergebnisse sammeln": { "main": [ [ { "node": "Statusupdate vorbereiten", "type": "main", "index": 0 } ] ] }, "Statusupdate vorbereiten": { "main": [ [ { "node": "Status zurueckschreiben", "type": "main", "index": 0 } ] ] }, "Status zurueckschreiben": { "main": [ [ { "node": "Meldung formulieren", "type": "main", "index": 0 } ], [ { "node": "Fehler Statusupdate", "type": "main", "index": 0 } ] ] }, "Meldung formulieren": { "main": [ [ { "node": "Benachrichtigung", "type": "main", "index": 0 } ] ] } }, "settings": { "executionOrder": "v1", "saveManualExecutions": true, "callerPolicy": "workflowsFromSameOwner" } }