{
  "name": "n8n Automation Business: 5 Local Workflows That Save Hours Every Week",
  "nodes": [
    {
      "id": "node-1",
      "name": "Every 15 Minutes",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.4,
      "position": [
        0,
        400
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "minutes",
              "minutesInterval": 15
            }
          ]
        }
      }
    },
    {
      "id": "node-2",
      "name": "Prepare Task Table",
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 2.8,
      "position": [
        240,
        400
      ],
      "parameters": {
        "resource": "database",
        "operation": "executeQuery",
        "query": "CREATE TABLE IF NOT EXISTS tasks (id serial PRIMARY KEY, type text NOT NULL, status text NOT NULL DEFAULT 'pending', input text, output text, ts timestamptz DEFAULT now());\nINSERT INTO tasks (type, status, input) SELECT v.type, 'pending', v.input FROM (VALUES ('triage', 'Hi, my invoice from last week shows the wrong amount and I need it corrected before Friday please.'), ('summarise', 'Quarterly report. Revenue grew steadily across all three product lines this quarter, driven mainly by the subscription plan. Support tickets fell by a third after the new help centre launched, while onboarding time for new customers stayed flat. The main risks are rising hosting costs and a delay in the mobile app release. The team recommends hiring one more support engineer and moving the app release to next quarter.'), ('research', 'self-hosted workflow automation tools'), ('digest', 'daily'), ('ideas', 'local AI automation')) AS v(type, input) WHERE NOT EXISTS (SELECT 1 FROM tasks);",
        "options": {}
      }
    },
    {
      "id": "node-3",
      "name": "Claim Pending Tasks",
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 2.8,
      "position": [
        480,
        400
      ],
      "parameters": {
        "resource": "database",
        "operation": "executeQuery",
        "query": "UPDATE tasks SET status = 'running', ts = now() WHERE id IN (SELECT id FROM tasks WHERE status = 'pending' ORDER BY id LIMIT 10) RETURNING id, type, input;",
        "options": {}
      }
    },
    {
      "id": "node-4",
      "name": "Route by Task Type",
      "typeVersion": 3.2,
      "position": [
        720,
        400
      ],
      "parameters": {
        "mode": "rules",
        "rules": {
          "values": [
            {
              "outputKey": "triage",
              "renameOutput": true,
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict"
                },
                "conditions": [
                  {
                    "leftValue": "={{ $json.type }}",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    },
                    "rightValue": "triage"
                  }
                ],
                "combinator": "and"
              }
            },
            {
              "outputKey": "summarise",
              "renameOutput": true,
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict"
                },
                "conditions": [
                  {
                    "leftValue": "={{ $json.type }}",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    },
                    "rightValue": "summarise"
                  }
                ],
                "combinator": "and"
              }
            },
            {
              "outputKey": "research",
              "renameOutput": true,
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict"
                },
                "conditions": [
                  {
                    "leftValue": "={{ $json.type }}",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    },
                    "rightValue": "research"
                  }
                ],
                "combinator": "and"
              }
            },
            {
              "outputKey": "digest",
              "renameOutput": true,
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict"
                },
                "conditions": [
                  {
                    "leftValue": "={{ $json.type }}",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    },
                    "rightValue": "digest"
                  }
                ],
                "combinator": "and"
              }
            },
            {
              "outputKey": "ideas",
              "renameOutput": true,
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict"
                },
                "conditions": [
                  {
                    "leftValue": "={{ $json.type }}",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    },
                    "rightValue": "ideas"
                  }
                ],
                "combinator": "and"
              }
            }
          ]
        },
        "options": {}
      }
    },
    {
      "id": "node-5",
      "name": "New Message Webhook",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2.1,
      "position": [
        0,
        700
      ],
      "parameters": {
        "httpMethod": "POST",
        "path": "inbox-triage",
        "responseMode": "onReceived"
      }
    },
    {
      "id": "node-6",
      "name": "Queue Message as Task",
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 2.8,
      "position": [
        240,
        700
      ],
      "parameters": {
        "resource": "database",
        "operation": "executeQuery",
        "query": "INSERT INTO tasks (type, status, input) VALUES ('triage', 'pending', $1) RETURNING id;",
        "options": {
          "queryReplacement": "={{ [$json.body.message] }}"
        }
      }
    },
    {
      "id": "node-7",
      "name": "Gemma4 12b (Triage)",
      "type": "@n8n/n8n-nodes-langchain.lmChatOllama",
      "typeVersion": 1,
      "parameters": {
        "model": "gemma4:12b-it-qat",
        "options": {
          "temperature": 0.1
        }
      }
    },
    {
      "id": "node-8",
      "name": "Classify Message",
      "type": "@n8n/n8n-nodes-langchain.chainLlm",
      "typeVersion": 1.9,
      "position": [
        960,
        0
      ],
      "parameters": {
        "promptType": "define",
        "text": "=Classify this inbound message into exactly one label: billing, support, sales or spam. Answer with the single label word only.\n\nMessage:\n{{ $json.input }}"
      }
    },
    {
      "id": "node-9",
      "name": "Pick Label",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1200,
        0
      ],
      "parameters": {
        "mode": "runOnceForEachItem",
        "language": "javaScript",
        "jsCode": "const labels = ['billing', 'support', 'sales', 'spam'];\nconst answer = String($json.text || '').toLowerCase();\nconst found = labels.find(l => answer.includes(l));\nconst src = $('Route by Task Type').item.json;\nreturn { json: { taskId: src.id, message: src.input, label: found || 'needs review', status: found ? 'done' : 'needs_review' } };"
      }
    },
    {
      "id": "node-10",
      "name": "Log Triage to Sheets",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.7,
      "position": [
        1440,
        0
      ],
      "parameters": {
        "resource": "sheet",
        "operation": "append",
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "",
          "cachedResultName": "Local Automation Business"
        },
        "sheetName": {
          "__rl": true,
          "mode": "name",
          "value": "triage"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "taskId": "={{ $json.taskId }}",
            "label": "={{ $json.label }}",
            "message": "={{ $json.message }}",
            "loggedAt": "={{ $now.toISO() }}"
          },
          "schema": [
            {
              "id": "taskId",
              "displayName": "taskId",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": false
            },
            {
              "id": "label",
              "displayName": "label",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": false
            },
            {
              "id": "message",
              "displayName": "message",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": false
            },
            {
              "id": "loggedAt",
              "displayName": "loggedAt",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": false
            }
          ]
        },
        "options": {}
      }
    },
    {
      "id": "node-11",
      "name": "Post Triage to Discord",
      "type": "n8n-nodes-base.discord",
      "typeVersion": 2,
      "position": [
        1680,
        0
      ],
      "parameters": {
        "authentication": "webhook",
        "resource": "message",
        "operation": "sendLegacy",
        "content": "=**Inbox triage: {{ $('Pick Label').item.json.label }}**\n> {{ $('Pick Label').item.json.message }}"
      }
    },
    {
      "id": "node-12",
      "name": "Mark Triage Done",
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 2.8,
      "position": [
        1920,
        0
      ],
      "parameters": {
        "resource": "database",
        "operation": "executeQuery",
        "query": "UPDATE tasks SET status = $2, output = $3, ts = now() WHERE id = $1::int RETURNING id, type, status;",
        "options": {
          "queryReplacement": "={{ [$('Pick Label').item.json.taskId, $('Pick Label').item.json.status, $('Pick Label').item.json.label] }}"
        }
      }
    },
    {
      "id": "node-13",
      "name": "Prepare Document",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        960,
        200
      ],
      "parameters": {
        "mode": "runOnceForEachItem",
        "language": "javaScript",
        "jsCode": "const bin = await this.helpers.prepareBinaryData(Buffer.from(String($json.input), 'utf8'), 'document.txt', 'text/plain');\nreturn { json: { taskId: $json.id }, binary: { data: bin } };"
      }
    },
    {
      "id": "node-14",
      "name": "Extract Text (Tika)",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.4,
      "position": [
        1200,
        200
      ],
      "parameters": {
        "method": "PUT",
        "url": "http://tika:9998/tika",
        "sendHeaders": true,
        "specifyHeaders": "keypair",
        "headerParameters": {
          "parameters": [
            {
              "name": "Accept",
              "value": "text/plain"
            }
          ]
        },
        "sendBody": true,
        "contentType": "binaryData",
        "inputDataFieldName": "data",
        "options": {
          "response": {
            "response": {
              "responseFormat": "text"
            }
          },
          "timeout": 60000
        }
      }
    },
    {
      "id": "node-15",
      "name": "Gemma4 12b (Summary)",
      "type": "@n8n/n8n-nodes-langchain.lmChatOllama",
      "typeVersion": 1,
      "parameters": {
        "model": "gemma4:12b-it-qat",
        "options": {
          "temperature": 0.2
        }
      }
    },
    {
      "id": "node-16",
      "name": "Summarise Document",
      "type": "@n8n/n8n-nodes-langchain.chainLlm",
      "typeVersion": 1.9,
      "position": [
        1440,
        200
      ],
      "parameters": {
        "promptType": "define",
        "text": "=Summarise this document in 3 short bullet points for a busy manager. Use only facts from the text.\n\nDocument:\n{{ String($json.data).slice(0, 6000) }}"
      }
    },
    {
      "id": "node-17",
      "name": "Check Summary",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1680,
        200
      ],
      "parameters": {
        "mode": "runOnceForEachItem",
        "language": "javaScript",
        "jsCode": "const s = String($json.text || '').trim();\nconst ok = s.length >= 80 && s.length <= 1500;\nreturn { json: { taskId: $('Prepare Document').item.json.taskId, summary: s, chars: s.length, status: ok ? 'done' : 'needs_review' } };"
      }
    },
    {
      "id": "node-18",
      "name": "Log Summary to Sheets",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.7,
      "position": [
        1920,
        200
      ],
      "parameters": {
        "resource": "sheet",
        "operation": "append",
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "",
          "cachedResultName": "Local Automation Business"
        },
        "sheetName": {
          "__rl": true,
          "mode": "name",
          "value": "summaries"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "taskId": "={{ $json.taskId }}",
            "summary": "={{ $json.summary }}",
            "quality": "={{ $json.status }}",
            "loggedAt": "={{ $now.toISO() }}"
          },
          "schema": [
            {
              "id": "taskId",
              "displayName": "taskId",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": false
            },
            {
              "id": "summary",
              "displayName": "summary",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": false
            },
            {
              "id": "quality",
              "displayName": "quality",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": false
            },
            {
              "id": "loggedAt",
              "displayName": "loggedAt",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": false
            }
          ]
        },
        "options": {}
      }
    },
    {
      "id": "node-19",
      "name": "Send Summary to Telegram",
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [
        2160,
        200
      ],
      "parameters": {
        "resource": "message",
        "operation": "sendMessage",
        "chatId": "YOUR_TELEGRAM_CHAT_ID",
        "text": "=Document summary:\n{{ $('Check Summary').item.json.summary }}",
        "additionalFields": {
          "appendAttribution": false
        }
      }
    },
    {
      "id": "node-20",
      "name": "Mark Summary Done",
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 2.8,
      "position": [
        2400,
        200
      ],
      "parameters": {
        "resource": "database",
        "operation": "executeQuery",
        "query": "UPDATE tasks SET status = $2, output = $3, ts = now() WHERE id = $1::int RETURNING id, type, status;",
        "options": {
          "queryReplacement": "={{ [$('Check Summary').item.json.taskId, $('Check Summary').item.json.status, $('Check Summary').item.json.summary] }}"
        }
      }
    },
    {
      "id": "node-21",
      "name": "Search SearXNG",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.4,
      "position": [
        960,
        400
      ],
      "parameters": {
        "method": "GET",
        "url": "http://searxng:8080/search",
        "sendQuery": true,
        "specifyQuery": "keypair",
        "queryParameters": {
          "parameters": [
            {
              "name": "q",
              "value": "={{ $json.input }}"
            },
            {
              "name": "format",
              "value": "json"
            }
          ]
        },
        "options": {
          "timeout": 30000
        }
      }
    },
    {
      "id": "node-22",
      "name": "Pick Top Results",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1200,
        400
      ],
      "parameters": {
        "mode": "runOnceForAllItems",
        "language": "javaScript",
        "jsCode": "const taskId = $('Route by Task Type').first().json.id;\nconst results = ($input.first().json.results || []).filter(r => r.url).slice(0, 3);\nreturn results.map(r => ({ json: { taskId, url: r.url, title: r.title || '' } }));"
      }
    },
    {
      "id": "node-23",
      "name": "Fetch Page (Browserless)",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.4,
      "position": [
        1440,
        400
      ],
      "parameters": {
        "method": "POST",
        "url": "http://browserless:3000/function",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpCustomAuth",
        "sendBody": true,
        "contentType": "json",
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ code: \"export default async function ({ page }) { await page.goto(\" + JSON.stringify($json.url) + \", { waitUntil: 'domcontentloaded', timeout: 30000 }); return { data: await page.content(), type: 'text/html' }; }\" }) }}",
        "options": {
          "timeout": 60000
        }
      },
      "onError": "continueRegularOutput"
    },
    {
      "id": "node-24",
      "name": "Check Sources",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1680,
        400
      ],
      "parameters": {
        "mode": "runOnceForAllItems",
        "language": "javaScript",
        "jsCode": "const picked = $('Pick Top Results').all();\nconst pages = $input.all().map((it, i) => {\n  const html = String((it.json && it.json.data) || '');\n  const text = html.replace(/<(script|style|noscript|svg|head)[\\s\\S]*?<\\/\\1>/gi, ' ').replace(/<[^>]+>/g, ' ').replace(/\\s+/g, ' ').trim();\n  const p = picked[i] ? picked[i].json : {};\n  return { url: p.url || '', title: p.title || '', text: text.slice(0, 2500) };\n}).filter(p => p.text.length > 300);\nconst enough = pages.length >= 2;\nconst material = pages.map((p, n) => 'SOURCE ' + (n + 1) + ': ' + p.title + ' (' + p.url + ')\\n' + p.text).join('\\n\\n');\nreturn [{ json: { taskId: picked.length ? picked[0].json.taskId : $('Route by Task Type').first().json.id, topic: $('Route by Task Type').first().json.input, sourceCount: pages.length, enough, status: enough ? 'done' : 'needs_review', sources: pages.map(p => p.url).join(' ; '), material } }];"
      }
    },
    {
      "id": "node-25",
      "name": "Gemma4 12b (Research)",
      "type": "@n8n/n8n-nodes-langchain.lmChatOllama",
      "typeVersion": 1,
      "parameters": {
        "model": "gemma4:12b-it-qat",
        "options": {
          "temperature": 0.2,
          "numCtx": 8192
        }
      }
    },
    {
      "id": "node-26",
      "name": "Write Research Brief",
      "type": "@n8n/n8n-nodes-langchain.chainLlm",
      "typeVersion": 1.9,
      "position": [
        1920,
        400
      ],
      "parameters": {
        "promptType": "define",
        "text": "=Topic: {{ $json.topic }}\n\n{{ $json.enough ? 'Using only the sources below, write a short research brief: 4 bullet points of key findings, then one line on what is still unclear.' : 'Fewer than two usable sources were found. Reply with one sentence saying there was not enough source material.' }}\n\n{{ $json.material }}"
      }
    },
    {
      "id": "node-27",
      "name": "Save Brief to Sheets",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.7,
      "position": [
        2160,
        400
      ],
      "parameters": {
        "resource": "sheet",
        "operation": "append",
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "",
          "cachedResultName": "Local Automation Business"
        },
        "sheetName": {
          "__rl": true,
          "mode": "name",
          "value": "research"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "taskId": "={{ $('Check Sources').item.json.taskId }}",
            "topic": "={{ $('Check Sources').item.json.topic }}",
            "sources": "={{ $('Check Sources').item.json.sourceCount }}",
            "brief": "={{ $json.text }}",
            "loggedAt": "={{ $now.toISO() }}"
          },
          "schema": [
            {
              "id": "taskId",
              "displayName": "taskId",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": false
            },
            {
              "id": "topic",
              "displayName": "topic",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": false
            },
            {
              "id": "sources",
              "displayName": "sources",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": false
            },
            {
              "id": "brief",
              "displayName": "brief",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": false
            },
            {
              "id": "loggedAt",
              "displayName": "loggedAt",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": false
            }
          ]
        },
        "options": {}
      }
    },
    {
      "id": "node-28",
      "name": "Mark Research Done",
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 2.8,
      "position": [
        2400,
        400
      ],
      "parameters": {
        "resource": "database",
        "operation": "executeQuery",
        "query": "UPDATE tasks SET status = $2, output = $3, ts = now() WHERE id = $1::int RETURNING id, type, status;",
        "options": {
          "queryReplacement": "={{ [$('Check Sources').item.json.taskId, $('Check Sources').item.json.status, $('Write Research Brief').item.json.text] }}"
        }
      }
    },
    {
      "id": "node-29",
      "name": "Get Today's Rows",
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 2.8,
      "position": [
        960,
        600
      ],
      "parameters": {
        "resource": "database",
        "operation": "executeQuery",
        "query": "SELECT id, type, status, left(coalesce(output, ''), 160) AS output FROM tasks WHERE ts::date = current_date AND status IN ('done', 'needs_review') AND type <> 'digest' ORDER BY id;",
        "options": {}
      },
      "executeOnce": true,
      "alwaysOutputData": true
    },
    {
      "id": "node-30",
      "name": "Build Digest Prompt",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1200,
        600
      ],
      "parameters": {
        "mode": "runOnceForAllItems",
        "language": "javaScript",
        "jsCode": "const rows = $input.all().map(i => i.json).filter(r => r.id !== undefined);\nconst lines = rows.length ? rows.map(r => '- ' + r.type + ' (' + r.status + '): ' + r.output).join('\\n') : '- No finished tasks yet today.';\nreturn [{ json: { taskId: $('Route by Task Type').first().json.id, rowCount: rows.length, prompt: 'Write a friendly daily digest of 4 lines or fewer from these automation results:\\n' + lines } }];"
      }
    },
    {
      "id": "node-31",
      "name": "Gemma4 12b (Digest)",
      "type": "@n8n/n8n-nodes-langchain.lmChatOllama",
      "typeVersion": 1,
      "parameters": {
        "model": "gemma4:12b-it-qat",
        "options": {
          "temperature": 0.4
        }
      }
    },
    {
      "id": "node-32",
      "name": "Write Digest",
      "type": "@n8n/n8n-nodes-langchain.chainLlm",
      "typeVersion": 1.9,
      "position": [
        1440,
        600
      ],
      "parameters": {
        "promptType": "define",
        "text": "={{ $json.prompt }}"
      }
    },
    {
      "id": "node-33",
      "name": "Send Digest to Telegram",
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [
        1680,
        600
      ],
      "parameters": {
        "resource": "message",
        "operation": "sendMessage",
        "chatId": "YOUR_TELEGRAM_CHAT_ID",
        "text": "=Daily digest:\n{{ $json.text }}",
        "additionalFields": {
          "appendAttribution": false
        }
      }
    },
    {
      "id": "node-34",
      "name": "Send Digest to Discord",
      "type": "n8n-nodes-base.discord",
      "typeVersion": 2,
      "position": [
        1920,
        600
      ],
      "parameters": {
        "authentication": "webhook",
        "resource": "message",
        "operation": "sendLegacy",
        "content": "=**Daily digest**\n{{ $('Write Digest').item.json.text }}"
      }
    },
    {
      "id": "node-35",
      "name": "Mark Digest Done",
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 2.8,
      "position": [
        2160,
        600
      ],
      "parameters": {
        "resource": "database",
        "operation": "executeQuery",
        "query": "UPDATE tasks SET status = $2, output = $3, ts = now() WHERE id = $1::int RETURNING id, type, status;",
        "options": {
          "queryReplacement": "={{ [$('Build Digest Prompt').item.json.taskId, 'done', $('Write Digest').item.json.text] }}"
        }
      }
    },
    {
      "id": "node-36",
      "name": "Gemma4 12b (Ideas)",
      "type": "@n8n/n8n-nodes-langchain.lmChatOllama",
      "typeVersion": 1,
      "parameters": {
        "model": "gemma4:12b-it-qat",
        "options": {
          "temperature": 0.8
        }
      }
    },
    {
      "id": "node-37",
      "name": "Generate Ideas",
      "type": "@n8n/n8n-nodes-langchain.chainLlm",
      "typeVersion": 1.9,
      "position": [
        960,
        800
      ],
      "parameters": {
        "promptType": "define",
        "text": "=Give 6 short video or post ideas about: {{ $json.input }}. One idea per line, no numbering, no extra text."
      }
    },
    {
      "id": "node-38",
      "name": "Get Past Ideas",
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 2.8,
      "position": [
        1200,
        800
      ],
      "parameters": {
        "resource": "database",
        "operation": "executeQuery",
        "query": "SELECT output FROM tasks WHERE type = 'ideas' AND status = 'done' AND output IS NOT NULL;",
        "options": {}
      },
      "executeOnce": true,
      "alwaysOutputData": true
    },
    {
      "id": "node-39",
      "name": "Filter Duplicates",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1440,
        800
      ],
      "parameters": {
        "mode": "runOnceForAllItems",
        "language": "javaScript",
        "jsCode": "const taskId = $('Route by Task Type').first().json.id;\nconst past = $input.all().map(i => String(i.json.output || '').toLowerCase()).join('\\n');\nconst seen = [];\nconst kept = [];\nfor (const line of String($('Generate Ideas').first().json.text || '').split('\\n')) {\n  const idea = line.replace(/^[-*0-9. ]+/, '').trim();\n  const key = idea.toLowerCase();\n  if (idea.length < 5 || seen.includes(key) || past.includes(key)) continue;\n  seen.push(key);\n  kept.push(idea);\n}\nif (!kept.length) kept.push('(no new ideas - all were duplicates)');\nreturn kept.map(idea => ({ json: { taskId, idea } }));"
      }
    },
    {
      "id": "node-40",
      "name": "Save Ideas to Sheets",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.7,
      "position": [
        1680,
        800
      ],
      "parameters": {
        "resource": "sheet",
        "operation": "append",
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "",
          "cachedResultName": "Local Automation Business"
        },
        "sheetName": {
          "__rl": true,
          "mode": "name",
          "value": "ideas"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "taskId": "={{ $json.taskId }}",
            "idea": "={{ $json.idea }}",
            "loggedAt": "={{ $now.toISO() }}"
          },
          "schema": [
            {
              "id": "taskId",
              "displayName": "taskId",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": false
            },
            {
              "id": "idea",
              "displayName": "idea",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": false
            },
            {
              "id": "loggedAt",
              "displayName": "loggedAt",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": false
            }
          ]
        },
        "options": {}
      }
    },
    {
      "id": "node-41",
      "name": "Mark Ideas Done",
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 2.8,
      "position": [
        1920,
        800
      ],
      "parameters": {
        "resource": "database",
        "operation": "executeQuery",
        "query": "UPDATE tasks SET status = $2, output = $3, ts = now() WHERE id = $1::int RETURNING id, type, status;",
        "options": {
          "queryReplacement": "={{ [$('Filter Duplicates').first().json.taskId, 'done', $('Filter Duplicates').all().map(i => i.json.idea).join('\\n')] }}"
        }
      },
      "executeOnce": true
    }
  ],
  "connections": {
    "Every 15 Minutes": {
      "main": [
        [
          {
            "node": "Prepare Task Table",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Prepare Task Table": {
      "main": [
        [
          {
            "node": "Claim Pending Tasks",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Claim Pending Tasks": {
      "main": [
        [
          {
            "node": "Route by Task Type",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Route by Task Type": {
      "main": [
        [
          {
            "node": "Classify Message",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Prepare Document",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Search SearXNG",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Get Today's Rows",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Generate Ideas",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Classify Message": {
      "main": [
        [
          {
            "node": "Pick Label",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Pick Label": {
      "main": [
        [
          {
            "node": "Log Triage to Sheets",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Log Triage to Sheets": {
      "main": [
        [
          {
            "node": "Post Triage to Discord",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Post Triage to Discord": {
      "main": [
        [
          {
            "node": "Mark Triage Done",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Prepare Document": {
      "main": [
        [
          {
            "node": "Extract Text (Tika)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract Text (Tika)": {
      "main": [
        [
          {
            "node": "Summarise Document",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Summarise Document": {
      "main": [
        [
          {
            "node": "Check Summary",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check Summary": {
      "main": [
        [
          {
            "node": "Log Summary to Sheets",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Log Summary to Sheets": {
      "main": [
        [
          {
            "node": "Send Summary to Telegram",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send Summary to Telegram": {
      "main": [
        [
          {
            "node": "Mark Summary Done",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Search SearXNG": {
      "main": [
        [
          {
            "node": "Pick Top Results",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Pick Top Results": {
      "main": [
        [
          {
            "node": "Fetch Page (Browserless)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch Page (Browserless)": {
      "main": [
        [
          {
            "node": "Check Sources",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check Sources": {
      "main": [
        [
          {
            "node": "Write Research Brief",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Write Research Brief": {
      "main": [
        [
          {
            "node": "Save Brief to Sheets",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Save Brief to Sheets": {
      "main": [
        [
          {
            "node": "Mark Research Done",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Today's Rows": {
      "main": [
        [
          {
            "node": "Build Digest Prompt",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Build Digest Prompt": {
      "main": [
        [
          {
            "node": "Write Digest",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Write Digest": {
      "main": [
        [
          {
            "node": "Send Digest to Telegram",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send Digest to Telegram": {
      "main": [
        [
          {
            "node": "Send Digest to Discord",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send Digest to Discord": {
      "main": [
        [
          {
            "node": "Mark Digest Done",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Generate Ideas": {
      "main": [
        [
          {
            "node": "Get Past Ideas",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Past Ideas": {
      "main": [
        [
          {
            "node": "Filter Duplicates",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Filter Duplicates": {
      "main": [
        [
          {
            "node": "Save Ideas to Sheets",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Save Ideas to Sheets": {
      "main": [
        [
          {
            "node": "Mark Ideas Done",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Gemma4 12b (Triage)": {
      "ai_languageModel": [
        [
          {
            "node": "Classify Message",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Gemma4 12b (Summary)": {
      "ai_languageModel": [
        [
          {
            "node": "Summarise Document",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Gemma4 12b (Research)": {
      "ai_languageModel": [
        [
          {
            "node": "Write Research Brief",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Gemma4 12b (Digest)": {
      "ai_languageModel": [
        [
          {
            "node": "Write Digest",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Gemma4 12b (Ideas)": {
      "ai_languageModel": [
        [
          {
            "node": "Generate Ideas",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "New Message Webhook": {
      "main": [
        [
          {
            "node": "Queue Message as Task",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  }
}
