{
  "name": "How to Make Money With n8n Using a Free Local Proposal Engine",
  "nodes": [
    {
      "name": "Proposal Request Form",
      "type": "n8n-nodes-base.formTrigger",
      "typeVersion": 2.6,
      "position": [
        0,
        0
      ],
      "parameters": {
        "formTitle": "Request a proposal",
        "formDescription": "Enter the client brief and attach any scope documents. A priced draft proposal is generated locally for your review.",
        "formFields": {
          "values": [
            {
              "fieldLabel": "Client Name",
              "fieldType": "text",
              "requiredField": true
            },
            {
              "fieldLabel": "Client Email",
              "fieldType": "email",
              "requiredField": true
            },
            {
              "fieldLabel": "Brief",
              "fieldType": "textarea",
              "requiredField": true,
              "placeholder": "Paste the client's brief"
            },
            {
              "fieldLabel": "Scope Files",
              "fieldType": "file",
              "multipleFiles": true,
              "requiredField": false,
              "acceptFileTypes": ".pdf,.docx,.doc,.txt"
            }
          ]
        },
        "responseMode": "onReceived",
        "options": {
          "path": "proposal-request",
          "appendAttribution": false,
          "respondWithOptions": {
            "values": {
              "respondWith": "text",
              "formSubmittedText": "Got it. The draft proposal will appear in Discord for your review."
            }
          }
        }
      }
    },
    {
      "name": "Split Scope Files",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        240,
        0
      ],
      "parameters": {
        "jsCode": "// One item per uploaded scope file so Tika sees one file at a time\nconst form = $input.first();\nconst files = Object.entries(form.binary || {});\nif (!files.length) {\n  // No attachments: pass a marker item so the brief still goes through\n  return [{ json: { fileName: '', noFile: true } }];\n}\nreturn files.map(([key, bin]) => ({\n  json: { fileName: bin.fileName || key, noFile: false },\n  binary: { data: bin },\n}));"
      }
    },
    {
      "name": "Extract Text (Tika)",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.3,
      "onError": "continueRegularOutput",
      "position": [
        480,
        0
      ],
      "parameters": {
        "method": "PUT",
        "url": "http://tika:9998/tika",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Accept",
              "value": "text/plain"
            }
          ]
        },
        "sendBody": true,
        "contentType": "binaryData",
        "inputDataFieldName": "data",
        "options": {
          "timeout": 60000,
          "response": {
            "response": {
              "responseFormat": "text"
            }
          }
        }
      }
    },
    {
      "name": "Build Prompt",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        720,
        0
      ],
      "parameters": {
        "jsCode": "// Combine the written brief and the Tika text into one prompt\nconst form = $('Proposal Request Form').first().json;\nconst items = $input.all();\nconst docs = [];\nconst notes = [];\nitems.forEach((it, i) => {\n  const src = $('Split Scope Files').all()[i]?.json || {};\n  if (src.noFile) return;\n  const text = (typeof it.json.data === 'string' ? it.json.data : '').replace(/\\s+\\n/g, '\\n').trim();\n  if (text.length < 40) {\n    notes.push(`${src.fileName || 'file'}: little or no text extracted (scanned PDF?), brief only`);\n  } else {\n    docs.push(`--- ${src.fileName} ---\\n${text.slice(0, 6000)}`);\n  }\n});\nconst docText = docs.length ? docs.join('\\n\\n') : '(no usable scope documents attached)';\nreturn [{ json: {\n  clientName: form['Client Name'],\n  clientEmail: form['Client Email'],\n  brief: form['Brief'],\n  documentText: docText,\n  extractionNotes: notes,\n  documentCount: docs.length,\n} }];"
      }
    },
    {
      "name": "Draft Proposal",
      "type": "@n8n/n8n-nodes-langchain.chainLlm",
      "typeVersion": 1.9,
      "position": [
        960,
        0
      ],
      "parameters": {
        "promptType": "define",
        "text": "=You are a freelance automation consultant writing a client proposal. Use ONLY the facts in the CLIENT BRIEF and SCOPE DOCUMENTS. Do not invent company details.\n\nReturn ONLY JSON in exactly this shape:\n{\"summary\":\"2-3 sentence overview of the project\",\"deliverables\":[{\"name\":\"...\",\"description\":\"...\"}],\"pricing_tiers\":[{\"name\":\"Starter\",\"price\":0,\"includes\":[\"...\"]},{\"name\":\"Standard\",\"price\":0,\"includes\":[\"...\"]},{\"name\":\"Premium\",\"price\":0,\"includes\":[\"...\"]}]}\n\nRules:\n- 3 to 6 deliverables, each tied to something in the brief or documents.\n- Exactly 3 pricing tiers named Starter, Standard and Premium. price is a whole number in USD (no symbols), rising with scope. These are rough placeholder estimates for the freelancer to review.\n- includes lists 2 to 4 short items per tier.\n\nCLIENT NAME: {{ $json.clientName }}\n\nCLIENT BRIEF:\n{{ $json.brief }}\n\nSCOPE DOCUMENTS:\n{{ $json.documentText }}"
      }
    },
    {
      "name": "Ollama qwen2.5 14B",
      "type": "@n8n/n8n-nodes-langchain.lmChatOllama",
      "typeVersion": 1,
      "position": [
        960,
        220
      ],
      "parameters": {
        "model": "qwen2.5:14b-instruct-q4_K_M",
        "options": {
          "temperature": 0.3,
          "numCtx": 8192,
          "format": "json",
          "keepAlive": "10m"
        }
      }
    },
    {
      "name": "Validate Proposal",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1320,
        0
      ],
      "parameters": {
        "jsCode": "// Parse the model output, check the structure, and format the review message\nconst prep = $('Build Prompt').first().json;\nconst out = $input.first().json;\n// The chain returns either a text string or an already-parsed JSON object\nconst raw = typeof out.text === 'string' ? out.text : JSON.stringify(out);\nconst errors = [];\nlet p = null;\ntry {\n  p = typeof out.text === 'string'\n    ? JSON.parse(out.text.replace(/^```(?:json)?\\s*|\\s*```$/g, '').trim())\n    : out;\n} catch (e) {\n  errors.push('Output is not valid JSON');\n}\nif (p) {\n  if (typeof p.summary !== 'string' || p.summary.trim().length < 20) errors.push('Missing summary');\n  if (!Array.isArray(p.deliverables) || p.deliverables.length < 1) errors.push('Missing deliverables');\n  else p.deliverables.forEach((d, i) => { if (!d?.name || !d?.description) errors.push(`Deliverable ${i + 1} needs name and description`); });\n  if (!Array.isArray(p.pricing_tiers) || p.pricing_tiers.length !== 3) errors.push('Need exactly 3 pricing tiers');\n  else p.pricing_tiers.forEach((t, i) => {\n    if (!t?.name) errors.push(`Tier ${i + 1} missing name`);\n    if (typeof t?.price !== 'number' || !(t.price > 0)) errors.push(`Tier ${i + 1} price must be a positive number`);\n    if (!Array.isArray(t?.includes) || !t.includes.length) errors.push(`Tier ${i + 1} missing includes`);\n  });\n}\nconst valid = errors.length === 0;\nlet proposalText = '';\nlet discordMessage = '';\nif (valid) {\n  const tiers = p.pricing_tiers.map(t => `**${t.name}: $${t.price}**\\n${t.includes.map(x => '- ' + x).join('\\n')}`).join('\\n\\n');\n  const dels = p.deliverables.map(d => `- **${d.name}**: ${d.description}`).join('\\n');\n  proposalText = `Proposal for ${prep.clientName}\\n\\nSummary\\n${p.summary}\\n\\nDeliverables\\n${dels}\\n\\nPricing\\n${tiers}`;\n  discordMessage = (`**Proposal draft ready for review** (not sent to the client)\\nClient: ${prep.clientName}\\n\\n${proposalText}\\n\\n_Prices are AI estimates. Review before sending._`).slice(0, 1900);\n} else {\n  discordMessage = (`**Proposal failed validation** for ${prep.clientName}\\nProblems: ${errors.join('; ')}\\n\\nRaw model output:\\n${String(raw).slice(0, 1200)}`).slice(0, 1900);\n}\nreturn [{ json: { valid, errors, clientName: prep.clientName, clientEmail: prep.clientEmail, summary: p?.summary ?? '', proposal: p, proposalText, discordMessage } }];"
      }
    },
    {
      "name": "Structure Valid?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        1560,
        0
      ],
      "parameters": {
        "conditions": {
          "options": {
            "version": 2,
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "c1",
              "leftValue": "={{ $json.valid }}",
              "rightValue": "",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              }
            }
          ]
        },
        "options": {}
      }
    },
    {
      "name": "Create Tracker Table",
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 2.5,
      "position": [
        1800,
        -100
      ],
      "parameters": {
        "operation": "executeQuery",
        "query": "CREATE TABLE IF NOT EXISTS proposals (\n  id serial PRIMARY KEY,\n  client_name text NOT NULL,\n  client_email text,\n  proposal_date date DEFAULT CURRENT_DATE,\n  summary text,\n  proposal_details text,\n  status text DEFAULT 'Draft - awaiting review'\n);",
        "options": {}
      }
    },
    {
      "name": "Log to Tracker",
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 2.5,
      "position": [
        2040,
        -100
      ],
      "parameters": {
        "schema": {
          "__rl": true,
          "mode": "list",
          "value": "public"
        },
        "table": {
          "__rl": true,
          "mode": "list",
          "value": "proposals"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "client_name": "={{ $('Validate Proposal').first().json.clientName }}",
            "client_email": "={{ $('Validate Proposal').first().json.clientEmail }}",
            "summary": "={{ $('Validate Proposal').first().json.summary }}",
            "proposal_details": "={{ $('Validate Proposal').first().json.proposalText }}"
          },
          "matchingColumns": [],
          "schema": []
        },
        "options": {}
      }
    },
    {
      "name": "Send Proposal to Discord",
      "type": "n8n-nodes-base.discord",
      "typeVersion": 2,
      "position": [
        2280,
        -100
      ],
      "parameters": {
        "authentication": "webhook",
        "resource": "message",
        "operation": "sendLegacy",
        "content": "={{ $('Validate Proposal').first().json.discordMessage }}"
      }
    },
    {
      "name": "Alert Invalid Output",
      "type": "n8n-nodes-base.discord",
      "typeVersion": 2,
      "position": [
        1800,
        140
      ],
      "parameters": {
        "authentication": "webhook",
        "resource": "message",
        "operation": "sendLegacy",
        "content": "={{ $json.discordMessage }}"
      }
    }
  ],
  "connections": {
    "Proposal Request Form": {
      "main": [
        [
          {
            "node": "Split Scope Files",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Split Scope Files": {
      "main": [
        [
          {
            "node": "Extract Text (Tika)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract Text (Tika)": {
      "main": [
        [
          {
            "node": "Build Prompt",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Build Prompt": {
      "main": [
        [
          {
            "node": "Draft Proposal",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Draft Proposal": {
      "main": [
        [
          {
            "node": "Validate Proposal",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Validate Proposal": {
      "main": [
        [
          {
            "node": "Structure Valid?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Structure Valid?": {
      "main": [
        [
          {
            "node": "Create Tracker Table",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Alert Invalid Output",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create Tracker Table": {
      "main": [
        [
          {
            "node": "Log to Tracker",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Log to Tracker": {
      "main": [
        [
          {
            "node": "Send Proposal to Discord",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Ollama qwen2.5 14B": {
      "ai_languageModel": [
        [
          {
            "node": "Draft Proposal",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  }
}