{ "name": "brief-vorbereiten", "nodes": [ { "parameters": {}, "type": "n8n-nodes-base.manualTrigger", "typeVersion": 1, "position": [ -460, 40 ], "id": "4fdca0a5-7851-4f7b-9f3c-276418464202", "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": "f9adf55b-7fff-42e9-b6da-d57af4835257", "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": "208692e2-bdc6-4d22-95e7-bad567ee6b74", "name": "Webhook Start", "webhookId": "75113a14-9f13-4021-a15d-db58b2a57fd8" }, { "parameters": { "mode": "manual", "assignments": { "assignments": [ { "id": "4ddbf6e7-68d3-4e8b-bb73-d1f63f26d6e2", "name": "nw_base", "value": "https://app.neuronwriter.com/neuron-api/0.5/writer", "type": "string" }, { "id": "a35095d9-6dfd-4f04-a506-d7694a65f570", "name": "nw_project", "value": "3da4d745e0e223cb", "type": "string" }, { "id": "24dcf02e-1af6-4275-bc00-f602b4b84356", "name": "nw_engine", "value": "google.de", "type": "string" }, { "id": "b35bfea0-9e67-4844-973d-a7ba42853675", "name": "nw_language", "value": "German", "type": "string" }, { "id": "399912b4-6998-4882-9dc6-da19fe6863a2", "name": "gitea_base", "value": "http://gitea:3000", "type": "string" }, { "id": "7729e907-6ba5-419e-b90d-82cba600bd1f", "name": "gitea_owner", "value": "lucas.orth", "type": "string" }, { "id": "0315283f-06eb-460b-af29-5ba407f35e5e", "name": "gitea_repo", "value": "Skrift-Auto-Article", "type": "string" }, { "id": "1bef1534-8459-4915-8b19-889c1103cf15", "name": "branch", "value": "main", "type": "string" }, { "id": "cf49930f-99c3-4889-9894-850a21c174b2", "name": "index_pfad", "value": "artikel-index.json", "type": "string" }, { "id": "2a3ab33d-64bf-466e-85f3-fafb1df95b4d", "name": "brief_ordner", "value": "briefe", "type": "string" }, { "id": "c8a33c09-b371-4fa6-adb8-1c4fb831739b", "name": "poll_max", "value": 30, "type": "number" }, { "id": "a2d67260-b199-4a4c-a2c2-5f32d93a80ff", "name": "poll_sekunden", "value": 20, "type": "number" }, { "id": "5bddb3d2-44c6-4a5a-987e-697a303d8ba7", "name": "pause_zwischen_artikeln", "value": 5, "type": "number" }, { "id": "bd4fd63e-5a72-4892-a2e0-481ed234ba11", "name": "benachrichtigung_an", "value": "privat@lucas-orth.de", "type": "string" } ] }, "options": {} }, "type": "n8n-nodes-base.set", "typeVersion": 3.4, "position": [ -240, 200 ], "id": "4e6479bc-7e41-432e-b38b-abd3905ded3a", "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": "748c30f8-635c-4f7a-9a7c-e2045e8ce423", "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": "5a72faa0-c8df-4a53-8981-aab5e7e1cf7e", "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": "30c7c0d8-e179-41b1-9291-6ca1e158f232", "name": "Tabelle auswerten" }, { "parameters": { "conditions": { "options": { "caseSensitive": true, "leftValue": "", "typeValidation": "loose", "version": 2 }, "conditions": [ { "id": "b8fe7382-0842-4295-b498-b0a9c7021226", "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": "42fa04a3-7b12-4a2e-b646-f22316415ac6", "name": "Offene Artikel vorhanden?" }, { "parameters": {}, "type": "n8n-nodes-base.noOp", "typeVersion": 1, "position": [ 640, 60 ], "id": "baa73a73-d519-4722-8a6f-22e17f37dcbb", "name": "Nichts zu tun" }, { "parameters": { "batchSize": 1, "options": { "reset": false } }, "type": "n8n-nodes-base.splitInBatches", "typeVersion": 3, "position": [ 640, 320 ], "id": "976aa62b-ce93-4677-88a4-48584933aad7", "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": "d0b0e12c-2e55-4e8b-abb9-678716695c6c", "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": "4d94bedf-6bbe-4f90-897d-2302a68c2abf", "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": "47460438-b146-4705-bf0a-3719ca66af05", "name": "Poll vorbereiten" }, { "parameters": { "amount": "={{ $('Konfiguration').first().json.poll_sekunden }}", "unit": "seconds" }, "type": "n8n-nodes-base.wait", "typeVersion": 1.1, "position": [ 1340, 420 ], "id": "4ec0f013-a163-46da-b7b1-02e4b73dd9dd", "name": "Warten", "webhookId": "ac9b591c-58ac-40b4-bd94-716826479d88" }, { "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": "aaa1c12a-7d47-41ef-903d-109f847ff356", "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": "23a1f2d5-49a3-4f69-85f3-456c0dcccaba", "name": "Fehler Analyse abfragen", "onError": "continueRegularOutput" }, { "parameters": { "conditions": { "options": { "caseSensitive": true, "leftValue": "", "typeValidation": "loose", "version": 2 }, "conditions": [ { "id": "4bb7114a-807a-4487-a612-0835fb9260ca", "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": "0d337016-36a1-492a-8b29-5e1d290be140", "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": "a22a0c31-e340-435d-8663-0ab865ebd394", "name": "Versuch zaehlen" }, { "parameters": { "conditions": { "options": { "caseSensitive": true, "leftValue": "", "typeValidation": "loose", "version": 2 }, "conditions": [ { "id": "1e0b93da-c082-406f-8642-56ff4a421c07", "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": "5603ea35-5166-4234-be4b-7791bcba1d95", "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": "96ab606e-48a9-400e-96e7-857b042acffb", "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 praxis: Array.isArray(a.praxis) ? a.praxis : [] },\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, immer inklusive MwSt.: '\n + '[skrift_preis key=\"SCHLUESSEL\" ab=\"0|1\" brutto=\"1\"]. '\n + 'key ist der Produktschluessel (briefe, postkarten). ab=1 liefert den guenstigsten Staffelpreis, '\n + 'ab=0 den Standardpreis. brutto ist immer 1. Hinter dem Preis steht immer \"inkl. 19 % MwSt.\", '\n + 'nie \"netto\", \"brutto\" oder \"zzgl.\". Das Wort \"ab\" gehoert in den Fliesstext. Beispiel: '\n + 'Handschriftliche Briefe ab [skrift_preis key=\"briefe\" ab=\"1\" brutto=\"1\"] pro Stueck inkl. 19 % MwSt.',\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 praxis: 'Der Artikel baut auf den Stichpunkten in artikel.praxis auf. Jeder Stichpunkt kommt '\n + 'erkennbar im Text vor, als Beispiel, Erfahrung oder klare Empfehlung. Ist die Liste leer, '\n + 'wird der Artikel nicht geschrieben, sondern zuerst Praxiswissen bei Lucas erfragt.',\n begriffe: 'begriffe_pflicht sind verbindlich. begriffe_erweitert nur verwenden, wenn der Satz '\n + 'dadurch nicht schlechter wird. Keine Saetze, die nur fuer den NeuronWriter-Score da sind. '\n + 'Keine Wettbewerbernamen. Zielwert im Import ist 65.',\n links: 'Interne Links primaer auf Business-Leistungsseiten: handgeschriebene-businessbriefe, '\n + 'handgeschriebene-postkarten, unterschriftenservice, automatisierte-follow-ups. '\n + 'artikel.cta_ziel mindestens einmal im Fliesstext verlinken, mindestens zwei Business-Links insgesamt. '\n + 'papier-schriftmuster nur ergaenzend. Keine Links auf Privatkunden-Seiten, review, agb, datenschutz, '\n + 'impressum, zahlungsmethoden, lieferung-versand.',\n bausteine: 'Kein Block \"Auch fuer Privatpersonen.\" und kein Abschnitt \"Kostenloses Handschriftmuster '\n + 'anfordern.\" im Artikeltext, beides liefert das Seitenlayout. Der Artikel endet mit dem letzten '\n + 'inhaltlichen Abschnitt, nie mit einer Zusammenfassung.',\n faq_ueberschrift: 'Eigene FAQ-Ueberschrift als Feld faq_ueberschrift, konkret zum Thema, z. B. '\n + '\"Fragen zu den Kosten\". Satzfall, ohne Punkt am Ende.',\n stil: 'Kurze und lange Saetze mischen. Absaetze unterschiedlich lang. Keine Formeln wie '\n + '\"Genau das\", \"Der Grund ist\", \"nicht nur, sondern auch\", \"entscheidend ist\", '\n + '\"der groesste Hebel\", \"macht den Unterschied\". Keine Aufzaehlung mit erstens, zweitens. '\n + 'Keine rhetorische Frage mit Sofortantwort. Keine Behauptung ohne Beleg, also kein '\n + '\"erfahrungsgemaess\" oder \"in aller Regel\". Wo es passt, auch abraten: wann sich '\n + 'Handschrift nicht lohnt.',\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": "19c85690-97f0-4eb7-b1e0-a83348ceefe1", "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": "c43d02ff-1236-45fc-bcb3-5098accee588", "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": "8d222315-472d-44f2-953b-494074b5d482", "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": "1a784408-d09d-420b-a6d3-7f808bbd806d", "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": "47ec95be-d567-4685-8ea7-aa447a91103d", "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": "07a1e471-d6bb-4327-a812-266bca634263", "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": "9e4fc985-8c3d-4736-9585-1ecaf29a4b01", "name": "Pause Rate Limit", "webhookId": "380a5713-2767-4992-aa4a-053605517480" }, { "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": "d80eaa2b-a228-4f93-a608-c4bc48804cea", "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": "f52ac21c-d921-4b65-b0ca-0232f6c212e6", "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": "ace29136-8155-46df-93d4-4ebba0b909eb", "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": "8cd217a6-ad58-44dd-bef9-7183c6a6ccad", "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": "b331d639-2de7-4329-8b11-350d227a59a5", "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": "8a6f1d29-5114-4e70-b539-18d50475ec94", "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" } }