{
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "nodes": [
    {
      "id": "5e76ec22-b1d9-4873-90dc-e60547e1ad87",
      "name": "Receive Financial Input",
      "type": "n8n-nodes-base.webhook",
      "position": [
        -640,
        48
      ],
      "parameters": {
        "path": "28d783ca-9a99-43a5-9399-ed98f0237cd9",
        "options": {},
        "httpMethod": "POST",
        "responseMode": "responseNode"
      },
      "typeVersion": 2.1
    },
    {
      "id": "061a183c-1d8e-425f-8e04-c4c7cbf632c6",
      "name": "Normalize Input Data",
      "type": "n8n-nodes-base.set",
      "position": [
        -416,
        48
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "835ed8de-669e-4f04-86f2-02feff4ff34f",
              "name": "Income",
              "type": "number",
              "value": "={{ $json.body.Income || 0 }}"
            },
            {
              "id": "51c85f99-4f60-43fd-a5a1-6e04b11ba5e2",
              "name": "Goal",
              "type": "string",
              "value": "={{ $json.body.Goal || \"\"}}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "10776f6b-30ec-4283-9459-94f1ac822e28",
      "name": "Validate Income & Goal",
      "type": "n8n-nodes-base.if",
      "position": [
        -192,
        48
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 3,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "loose"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "f1c32250-14db-4186-9dd0-f224f98cb4d6",
              "operator": {
                "type": "number",
                "operation": "gte"
              },
              "leftValue": "={{ $json.Income }}",
              "rightValue": 0
            },
            {
              "id": "e219f7bb-23a4-4176-adeb-d141b147e8df",
              "operator": {
                "type": "string",
                "operation": "notEmpty",
                "singleValue": true
              },
              "leftValue": "={{ $json.Goal }}",
              "rightValue": ""
            }
          ]
        },
        "looseTypeValidation": true
      },
      "typeVersion": 2.3
    },
    {
      "id": "2f9c84e3-0dac-46d0-8510-1983969269ea",
      "name": "Return Validation Error",
      "type": "n8n-nodes-base.respondToWebhook",
      "position": [
        32,
        144
      ],
      "parameters": {
        "options": {},
        "respondWith": "json",
        "responseBody": "{\n  \"error\": \"income should not be in negative integer and goal should be not empty.\"\n}"
      },
      "typeVersion": 1.5
    },
    {
      "id": "4e8a675d-f5df-4dce-87e9-49d3fdf21ca2",
      "name": "Enrich Financial Metrics",
      "type": "n8n-nodes-base.set",
      "position": [
        32,
        -48
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "012349f1-ef19-401b-8569-2e95999c4364",
              "name": "Income",
              "type": "number",
              "value": "={{ $json.Income }}"
            },
            {
              "id": "f6e165ec-183b-4edc-a6d2-39ada7d37ee3",
              "name": "Goal",
              "type": "string",
              "value": "={{ $json.Goal }}"
            },
            {
              "id": "680bc71f-a1bc-4a83-98ec-a1e36c66cff9",
              "name": "Timestamp",
              "type": "string",
              "value": "={{ new Date().toISOString() }}"
            },
            {
              "id": "81c81411-3f6a-44be-b557-1529e765cf9b",
              "name": "RecommendedMonthlySaving",
              "type": "string",
              "value": "={{ Math.round($json.Income * 0.20) }}"
            },
            {
              "id": "8bdcffb5-30b9-495c-b6ad-53ab7e123feb",
              "name": "IncomeCategory",
              "type": "string",
              "value": "={{ $json.Income < 30000 ? \"Low\" : $json.Income < 100000 ? \"Mid\" : \"High\" }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "8452fb64-5669-4142-b17e-236586752977",
      "name": "Store User Data (Google Sheets)",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        256,
        -48
      ],
      "parameters": {
        "columns": {
          "value": {
            "Goal": "={{ $json.Goal }}",
            "Income": "={{ $json.Income }}",
            "Timestamp": "={{ $json.Timestamp }}",
            "IncomeCategory": "={{ $json.IncomeCategory }}",
            "RecommendedMonthlySaving": "={{ $json.RecommendedMonthlySaving }}"
          },
          "schema": [
            {
              "id": "Income",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Income",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Goal",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Goal",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Timestamp",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Timestamp",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "RecommendedMonthlySaving",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "RecommendedMonthlySaving",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "IncomeCategory",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "IncomeCategory",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "append",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": 36031943,
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1fwvOWtXwLzgx1FF_v1FaxTMDEiIN0qPF_zE1uFJj1Q8/edit#gid=36031943",
          "cachedResultName": "Income-Goal"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1fwvOWtXwLzgx1FF_v1FaxTMDEiIN0qPF_zE1uFJj1Q8",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1fwvOWtXwLzgx1FF_v1FaxTMDEiIN0qPF_zE1uFJj1Q8/edit?usp=drivesdk",
          "cachedResultName": "N8N - PRACTICE"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.7
    },
    {
      "id": "16ebaef7-cd7e-42f1-acc9-7300bca35ae3",
      "name": "Route by Income Category",
      "type": "n8n-nodes-base.switch",
      "position": [
        480,
        -64
      ],
      "parameters": {
        "rules": {
          "values": [
            {
              "conditions": {
                "options": {
                  "version": 3,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "loose"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "97f56d2d-3883-46c3-882f-35579dfdff98",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $json.IncomeCategory }}",
                    "rightValue": "Mid"
                  }
                ]
              }
            },
            {
              "conditions": {
                "options": {
                  "version": 3,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "loose"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "80a62502-3b3a-4e13-a389-b139c85ea524",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $json.IncomeCategory }}",
                    "rightValue": "Low"
                  }
                ]
              }
            },
            {
              "conditions": {
                "options": {
                  "version": 3,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "loose"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "d412ac45-d910-4d36-890e-5f15a6ee356d",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $json.IncomeCategory }}",
                    "rightValue": "High"
                  }
                ]
              }
            }
          ]
        },
        "options": {},
        "looseTypeValidation": true
      },
      "typeVersion": 3.4
    },
    {
      "id": "b2afa7b7-41c9-40bd-912c-fa2e2f15adcc",
      "name": "Generate Plan (Low Income)1",
      "type": "@n8n/n8n-nodes-langchain.googleGemini",
      "position": [
        704,
        -144
      ],
      "parameters": {
        "modelId": {
          "__rl": true,
          "mode": "list",
          "value": "models/gemini-flash-lite-latest",
          "cachedResultName": "models/gemini-flash-lite-latest"
        },
        "options": {},
        "messages": {
          "values": [
            {
              "content": "=You are a certified financial planner and wealth advisor.\n\nA user has submitted their financial details through a webhook. Your task is to analyze the data and generate a personalized, practical, and easy-to-understand investment strategy.\n\n### User Data:\n- Monthly Income: {{ $json.Income }}\n- Financial Goal: {{ $json.Goal }}\n\nThe user is in a low income bracket. \nPrioritize: building an emergency fund (3 months expenses), \nstarting a \u20b9500\u2013\u20b91000/month SIP in a large-cap index fund, \nand avoiding debt traps. Keep advice extremely practical and minimal-risk.\n\n### Instructions:\n\n1. Analyze the user\u2019s income and stated goal.\n2. Assume the user is a beginner investor unless stated otherwise.\n3. Create a structured financial plan that includes:\n\n#### 1. Goal Breakdown\n- Explain the goal in financial terms\n- Estimate required corpus (if possible)\n- Suggest a realistic timeline\n\n#### 2. Monthly Investment Plan\n- Recommend how much to invest monthly\n- Suggest allocation (e.g., equity, debt, savings, emergency fund)\n\n#### 3. Investment Strategy\n- Recommend suitable instruments (e.g., mutual funds, index funds, fixed deposits, ETFs)\n- Explain why each is suitable\n- Adjust risk level based on goal type (e.g., house = moderate, retirement = long-term growth)\n\n#### 4. Example Portfolio Allocation\n- Provide percentage split (e.g., 60% equity, 30% debt, 10% cash)\n\n#### 5. Actionable Steps\n- Clear next steps the user should take\n- Keep it practical and beginner-friendly\n\n#### 6. Tips & Warnings\n- Include 2\u20133 smart financial tips\n- Mention risks or common mistakes to avoid\n\n### Output Format:\n- Use clean headings\n- Keep tone professional but simple\n- Avoid jargon\n- Max 400\u2013600 words\n\n### Important:\n- Do NOT ask follow-up questions\n- Make reasonable assumptions if data is missing\n- Tailor advice specifically to the goal"
            }
          ]
        },
        "builtInTools": {}
      },
      "credentials": {
        "googlePalmApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.1
    },
    {
      "id": "4454844b-9ccc-42fb-9069-bd8544b51abb",
      "name": "Generate Plan (Mid Income)",
      "type": "@n8n/n8n-nodes-langchain.googleGemini",
      "position": [
        704,
        -336
      ],
      "parameters": {
        "modelId": {
          "__rl": true,
          "mode": "list",
          "value": "models/gemini-flash-lite-latest",
          "cachedResultName": "models/gemini-flash-lite-latest"
        },
        "options": {},
        "messages": {
          "values": [
            {
              "content": "=You are a certified financial planner and wealth advisor.\n\nA user has submitted their financial details through a webhook. Your task is to analyze the data and generate a personalized, practical, and easy-to-understand investment strategy.\n\n### User Data:\n- Monthly Income: {{ $json.Income }}\n- Financial Goal: {{ $json.Goal }}\n\nThe user is in a mid income bracket. \nRecommend a balanced approach: emergency fund + SIP in diversified \nmutual funds (equity + debt mix) + basic tax-saving via ELSS. \nIntroduce the concept of goal-based investing.\n\n### Instructions:\n\n1. Analyze the user\u2019s income and stated goal.\n2. Assume the user is a beginner investor unless stated otherwise.\n3. Create a structured financial plan that includes:\n\n#### 1. Goal Breakdown\n- Explain the goal in financial terms\n- Estimate required corpus (if possible)\n- Suggest a realistic timeline\n\n#### 2. Monthly Investment Plan\n- Recommend how much to invest monthly\n- Suggest allocation (e.g., equity, debt, savings, emergency fund)\n\n#### 3. Investment Strategy\n- Recommend suitable instruments (e.g., mutual funds, index funds, fixed deposits, ETFs)\n- Explain why each is suitable\n- Adjust risk level based on goal type (e.g., house = moderate, retirement = long-term growth)\n\n#### 4. Example Portfolio Allocation\n- Provide percentage split (e.g., 60% equity, 30% debt, 10% cash)\n\n#### 5. Actionable Steps\n- Clear next steps the user should take\n- Keep it practical and beginner-friendly\n\n#### 6. Tips & Warnings\n- Include 2\u20133 smart financial tips\n- Mention risks or common mistakes to avoid\n\n### Output Format:\n- Use clean headings\n- Keep tone professional but simple\n- Avoid jargon\n- Max 400\u2013600 words\n\n### Important:\n- Do NOT ask follow-up questions\n- Make reasonable assumptions if data is missing\n- Tailor advice specifically to the goal"
            }
          ]
        },
        "builtInTools": {}
      },
      "credentials": {
        "googlePalmApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.1
    },
    {
      "id": "de319540-a4ae-44b3-9f6d-0a6401a7fc5b",
      "name": "Generate Plan (High Income)",
      "type": "@n8n/n8n-nodes-langchain.googleGemini",
      "position": [
        704,
        48
      ],
      "parameters": {
        "modelId": {
          "__rl": true,
          "mode": "list",
          "value": "models/gemini-flash-lite-latest",
          "cachedResultName": "models/gemini-flash-lite-latest"
        },
        "options": {},
        "messages": {
          "values": [
            {
              "content": "=You are a certified financial planner and wealth advisor.\n\nA user has submitted their financial details through a webhook. Your task is to analyze the data and generate a personalized, practical, and easy-to-understand investment strategy.\n\n### User Data:\n- Monthly Income: {{ $json.Income }}\n- Financial Goal: {{ $json.Goal }}\n\nThe user is in a high income bracket. \nRecommend a sophisticated portfolio: index funds, NPS for retirement, \nELSS for tax saving, and optionally REITs or international ETFs. \nDiscuss asset allocation and rebalancing strategies.\n\n### Instructions:\n\n1. Analyze the user\u2019s income and stated goal.\n2. Assume the user is a beginner investor unless stated otherwise.\n3. Create a structured financial plan that includes:\n\n#### 1. Goal Breakdown\n- Explain the goal in financial terms\n- Estimate required corpus (if possible)\n- Suggest a realistic timeline\n\n#### 2. Monthly Investment Plan\n- Recommend how much to invest monthly\n- Suggest allocation (e.g., equity, debt, savings, emergency fund)\n\n#### 3. Investment Strategy\n- Recommend suitable instruments (e.g., mutual funds, index funds, fixed deposits, ETFs)\n- Explain why each is suitable\n- Adjust risk level based on goal type (e.g., house = moderate, retirement = long-term growth)\n\n#### 4. Example Portfolio Allocation\n- Provide percentage split (e.g., 60% equity, 30% debt, 10% cash)\n\n#### 5. Actionable Steps\n- Clear next steps the user should take\n- Keep it practical and beginner-friendly\n\n#### 6. Tips & Warnings\n- Include 2\u20133 smart financial tips\n- Mention risks or common mistakes to avoid\n\n### Output Format:\n- Use clean headings\n- Keep tone professional but simple\n- Avoid jargon\n- Max 400\u2013600 words\n\n### Important:\n- Do NOT ask follow-up questions\n- Make reasonable assumptions if data is missing\n- Tailor advice specifically to the goal"
            }
          ]
        },
        "builtInTools": {}
      },
      "credentials": {
        "googlePalmApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.1
    },
    {
      "id": "8f047b70-5964-4ff5-9f44-c92ee96e28d0",
      "name": "Merge AI Responses",
      "type": "n8n-nodes-base.merge",
      "position": [
        1056,
        -160
      ],
      "parameters": {
        "numberInputs": 3
      },
      "typeVersion": 3.2
    },
    {
      "id": "c4668b98-0818-4dd2-a642-af53df310d78",
      "name": "Generate HTML Report",
      "type": "n8n-nodes-base.set",
      "position": [
        1280,
        -144
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "84725477-6353-4a05-ae12-a9414d4ad874",
              "name": "=html_body",
              "type": "string",
              "value": "=<!DOCTYPE html>\n<html>\n<head>\n  <meta charset=\"UTF-8\">\n  <style>\n    body { font-family: Arial, sans-serif; padding: 40px; color: #1a1a1a; line-height: 1.7; }\n    h1 { color: #1a3c5e; border-bottom: 2px solid #1a3c5e; padding-bottom: 8px; }\n    h2, h3, h4 { color: #2c5f8a; margin-top: 24px; }\n    p { margin: 10px 0; }\n    .badge { background: #e8f4fd; border-left: 4px solid #2c5f8a;\n             padding: 10px 16px; margin: 16px 0; border-radius: 4px; }\n    .footer { margin-top: 40px; font-size: 12px; color: #888;\n              border-top: 1px solid #ddd; padding-top: 12px; }\n  </style>\n</head>\n<body>\n  <h1>Your Personalized Financial Plan</h1>\n  <div class=\"badge\">\n    <strong>Goal:</strong> {{ $('Store User Data (Google Sheets)').item.json.Goal }}<br>\n    <strong>Monthly Income:</strong> \u20b9{{ $('Store User Data (Google Sheets)').item.json.Income }}<br>\n    <strong>Recommended Monthly Saving:</strong> \u20b9{{ $('Store User Data (Google Sheets)').item.json.RecommendedMonthlySaving }}<br>\n    <strong>Income Category:</strong> {{ $('Store User Data (Google Sheets)').item.json.IncomeCategory }}<br>\n    <strong>Generated On:</strong> {{ $('Store User Data (Google Sheets)').item.json.Timestamp }}\n  </div>\n  <hr>\n  {{ $json.content.parts[0].text.replace(/\\n/g, '<br>').replace(/#{1,6} (.+)/g, '<h3>$1</h3>') }}\n  <div class=\"footer\">\n    This plan was auto-generated based on the data you provided.\n    It is for informational purposes only and not formal financial advice.\n  </div>\n</body>\n</html>"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "84594cd0-5edf-4c39-9dee-cf3befe9ff1b",
      "name": "Convert HTML to PDF",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        1504,
        -144
      ],
      "parameters": {
        "url": "https://api.pdfshift.io/v3/convert/pdf",
        "method": "POST",
        "options": {
          "response": {
            "response": {}
          }
        },
        "sendBody": true,
        "sendHeaders": true,
        "bodyParameters": {
          "parameters": [
            {
              "name": "source",
              "value": "={{ $json.html_body }}"
            },
            {
              "name": "filename",
              "value": "export.pdf"
            }
          ]
        },
        "headerParameters": {
          "parameters": [
            {
              "name": "X-API-key",
              "value": ""
            }
          ]
        }
      },
      "typeVersion": 4.4
    },
    {
      "id": "8c70feff-fba7-4186-a631-82818428a719",
      "name": "Fetch Generated PDF",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        1728,
        -144
      ],
      "parameters": {
        "url": "={{ $json.url }}",
        "options": {}
      },
      "typeVersion": 4.4
    },
    {
      "id": "0f34ef8f-494b-4734-9566-dbe08e5ce02e",
      "name": "Check PDF Generation Status",
      "type": "n8n-nodes-base.if",
      "position": [
        1952,
        -144
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 3,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "f2051cf4-3839-4b20-a572-cefec40b1cd8",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              },
              "leftValue": "={{ !!$binary.data }}",
              "rightValue": ""
            }
          ]
        }
      },
      "typeVersion": 2.3
    },
    {
      "id": "b4519523-5b1d-4345-9a3b-3fff937c145c",
      "name": "Upload PDF to Google Drive",
      "type": "n8n-nodes-base.googleDrive",
      "position": [
        2176,
        -336
      ],
      "parameters": {
        "name": "=Financial_Plan_{{ $('Store User Data (Google Sheets)').item.json.Goal.replace(/ /g,'_') }}_{{ new Date().toISOString().slice(0,10) }}.pdf",
        "driveId": {
          "__rl": true,
          "mode": "list",
          "value": "My Drive"
        },
        "options": {},
        "folderId": {
          "__rl": true,
          "mode": "list",
          "value": "root",
          "cachedResultName": "/ (Root folder)"
        },
        "inputDataFieldName": "={{ $binary.data }}"
      },
      "credentials": {
        "googleDriveOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 3
    },
    {
      "id": "573c49a2-8e98-402e-9a59-7813893ebd45",
      "name": "Send Email with PDF",
      "type": "n8n-nodes-base.gmail",
      "position": [
        2176,
        48
      ],
      "parameters": {
        "sendTo": "",
        "message": "=Hi there,\n\nPlease find your personalized financial plan attached as a PDF.\n\nHere's a quick summary:\n- Goal: {{ $('Route by Income Category').item.json.Goal }}\n- Monthly Income: \u20b9{{ $('Route by Income Category').item.json.Income }}\n- Recommended Monthly Saving: \u20b9{{ $('Route by Income Category').item.json.RecommendedMonthlySaving }}\n- Income Category: {{ $('Route by Income Category').item.json.IncomeCategory }}\n\nYou can also view your plan anytime here:\n{{ $json.webViewLink }}\n\nStart small, stay consistent.\n\n\u2014 Your AI Financial Planner",
        "options": {
          "attachmentsUi": {
            "attachmentsBinary": [
              {}
            ]
          },
          "appendAttribution": false
        },
        "subject": "=Your {{ $('Route by Income Category').item.json.IncomeCategory }} Income Financial Plan \u2014 {{ $('Route by Income Category').item.json.Goal }}",
        "emailType": "text"
      },
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "1d45ad6c-ee7d-4bc1-827f-cfccf71a310b",
      "name": "Return HTML Response",
      "type": "n8n-nodes-base.respondToWebhook",
      "position": [
        2176,
        -144
      ],
      "parameters": {
        "options": {
          "responseHeaders": {
            "entries": [
              {
                "name": "Content-Type",
                "value": "text/html"
              }
            ]
          }
        },
        "respondWith": "text",
        "responseBody": "={{ $('Generate HTML Report').item.json.html_body }}"
      },
      "typeVersion": 1.5
    },
    {
      "id": "7d1419c3-63cc-4b93-a676-4cc3671853fb",
      "name": "Return PDF Failure Response",
      "type": "n8n-nodes-base.respondToWebhook",
      "position": [
        2176,
        240
      ],
      "parameters": {
        "options": {},
        "respondWith": "json",
        "responseBody": "{\n  \"error\": \"PDF generation failed. Plain email sent instead.\"\n}"
      },
      "typeVersion": 1.5
    },
    {
      "id": "3f254143-019a-40ed-b794-9d7f93f908fb",
      "name": "Send Plain Text Email (Fallback)",
      "type": "n8n-nodes-base.gmail",
      "position": [
        2400,
        240
      ],
      "parameters": {
        "sendTo": "",
        "message": "={{ $('Merge AI Responses').item.json.content.parts[0].text }}",
        "options": {
          "appendAttribution": false
        },
        "subject": "={{ $('Store User Data (Google Sheets)').item.json.IncomeCategory }} Income Plan: {{ $('Store User Data (Google Sheets)').item.json.Goal }}",
        "emailType": "text"
      },
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "8e41de58-23c9-47d4-936e-8b00e07fde3b",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1424,
        -736
      ],
      "parameters": {
        "width": 576,
        "height": 528,
        "content": "### AI Financial Planning Automation (End-to-End Flow)\n\nThis workflow collects a user\u2019s income and financial goal via webhook, validates the input, and generates a personalized financial plan using AI.\n\n### How it works:\nReceives user data (income + goal)\nValidates inputs (no negative income, goal required)\nEnriches data (savings %, income category)\nStores data in Google Sheets\nRoutes user to AI model based on income level\nGenerates a tailored financial plan\nConverts plan into HTML \u2192 PDF\nUploads PDF to Google Drive\nSends email with PDF + summary\nReturns HTML response via webhook\n\n### Setup Steps:\nConnect Google Sheets, Google Drive, and Gmail accounts\nAdd Gemini (PaLM) API credentials\nReplace PDFShift API key\nUpdate email recipient if needed\nTest webhook using POST request with JSON:\n{ \"Income\": 50000, \"Goal\": \"Buy a house\" }"
      },
      "typeVersion": 1
    },
    {
      "id": "e8af848d-b998-42c9-95d8-ac81432b9314",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -16,
        -240
      ],
      "parameters": {
        "color": "#D6D6D6",
        "width": 432,
        "height": 352,
        "content": "### Data Enrichment & Storage\nAdds timestamp, savings recommendation (20%), and income category. Stores all records in Google Sheets for tracking."
      },
      "typeVersion": 1
    },
    {
      "id": "4bd46fba-3fbe-4048-b3a2-31f43f342842",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -688,
        -96
      ],
      "parameters": {
        "color": "#D6D6D6",
        "width": 640,
        "height": 304,
        "content": "### Input & Validation\nHandles incoming webhook data. Ensures income is non-negative and goal is provided. Invalid inputs return an error immediately."
      },
      "typeVersion": 1
    },
    {
      "id": "6b5ec289-58ed-4e5f-8e1c-3ea30243cdfb",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        464,
        -480
      ],
      "parameters": {
        "color": "#D6D6D6",
        "width": 720,
        "height": 720,
        "content": "### AI Plan Generation\nRoutes users into Low, Mid, or High income paths. Each path uses a tailored prompt to generate relevant financial advice."
      },
      "typeVersion": 1
    },
    {
      "id": "039849dc-4463-4072-ae18-00e0e842e6a2",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1264,
        -288
      ],
      "parameters": {
        "color": "#D6D6D6",
        "width": 576,
        "height": 336,
        "content": "### PDF Generation\nConverts HTML into PDF using PDFShift API and fetches the binary file for further processing."
      },
      "typeVersion": 1
    },
    {
      "id": "10bc1c3d-d5f8-4d86-9d81-462b0a331604",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1936,
        -576
      ],
      "parameters": {
        "color": "#D6D6D6",
        "width": 672,
        "height": 1008,
        "content": "### Delivery & Fallback\nUploads PDF to Google Drive, emails it to the user, and returns HTML response. If PDF fails, sends plain text email instead."
      },
      "typeVersion": 1
    }
  ],
  "connections": {
    "Merge AI Responses": {
      "main": [
        [
          {
            "node": "Generate HTML Report",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Convert HTML to PDF": {
      "main": [
        [
          {
            "node": "Fetch Generated PDF",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch Generated PDF": {
      "main": [
        [
          {
            "node": "Check PDF Generation Status",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send Email with PDF": {
      "main": [
        []
      ]
    },
    "Generate HTML Report": {
      "main": [
        [
          {
            "node": "Convert HTML to PDF",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Normalize Input Data": {
      "main": [
        [
          {
            "node": "Validate Income & Goal",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Return HTML Response": {
      "main": [
        []
      ]
    },
    "Validate Income & Goal": {
      "main": [
        [
          {
            "node": "Enrich Financial Metrics",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Return Validation Error",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Receive Financial Input": {
      "main": [
        [
          {
            "node": "Normalize Input Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Enrich Financial Metrics": {
      "main": [
        [
          {
            "node": "Store User Data (Google Sheets)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Route by Income Category": {
      "main": [
        [
          {
            "node": "Generate Plan (Mid Income)",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Generate Plan (Low Income)1",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Generate Plan (High Income)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Generate Plan (Mid Income)": {
      "main": [
        [
          {
            "node": "Merge AI Responses",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Upload PDF to Google Drive": {
      "main": [
        []
      ]
    },
    "Check PDF Generation Status": {
      "main": [
        [
          {
            "node": "Upload PDF to Google Drive",
            "type": "main",
            "index": 0
          },
          {
            "node": "Send Email with PDF",
            "type": "main",
            "index": 0
          },
          {
            "node": "Return HTML Response",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Return PDF Failure Response",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Generate Plan (High Income)": {
      "main": [
        [
          {
            "node": "Merge AI Responses",
            "type": "main",
            "index": 2
          }
        ]
      ]
    },
    "Generate Plan (Low Income)1": {
      "main": [
        [
          {
            "node": "Merge AI Responses",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Return PDF Failure Response": {
      "main": [
        [
          {
            "node": "Send Plain Text Email (Fallback)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Store User Data (Google Sheets)": {
      "main": [
        [
          {
            "node": "Route by Income Category",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send Plain Text Email (Fallback)": {
      "main": [
        []
      ]
    }
  }
}