{
  "id": "QNx37JKLOCGmSd31",
  "name": "Gold SIP Tracker with Monthly Investment Logging & AI Insights",
  "tags": [],
  "nodes": [
    {
      "id": "2b243ea4-9009-418a-aff7-aa9f9191f164",
      "name": "Sticky Note 6060f0b5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        224,
        304
      ],
      "parameters": {
        "width": 612,
        "height": 552,
        "content": "## Overview\nThis workflow runs on a scheduled basis, fetches real-time gold prices, calculates portfolio performance, stores historical investment data, generates AI-driven insights, and delivers actionable reports through multiple communication channels.\n\n## How to Setup \n1. Set Google Sheet with column Date, SIP Amount, Gold Price (1 gm)\n2. Set recipient email address\n3. Create Slack channel: #gold-sip-tracker\n\n## Credentials needed:\n- Google Sheets OAuth2\n- Gmail OAuth2\n- Slack Bot Token\n- Groq API / Other LLM Token"
      },
      "typeVersion": 1
    },
    {
      "id": "007ca48c-66af-4243-8ff4-8e1ceab17d5f",
      "name": "Groq Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatGroq",
      "position": [
        2880,
        912
      ],
      "parameters": {
        "model": "allam-2-7b",
        "options": {}
      },
      "typeVersion": 1
    },
    {
      "id": "cf958e2e-4bfb-428f-b322-c36058a5514a",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1040,
        304
      ],
      "parameters": {
        "color": 7,
        "width": 560,
        "height": 848,
        "content": "## Data ingestion layer\n\nThis group is responsible for triggering the workflow, fetching latest gold price from api, and reading user sip data from google sheets.\n\nFlow:\n- monthly trigger starts execution\n- http request fetches real-time gold price (inr/xau)\n- google sheets node loads historical sip transactions\n- error branch handles api failure and sends slack alert"
      },
      "typeVersion": 1
    },
    {
      "id": "cd373d62-b631-4fce-8e59-71726d664ff9",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1664,
        304
      ],
      "parameters": {
        "color": 7,
        "width": 512,
        "height": 848,
        "content": "## SIP Calculation & Decision engine\n\nThis group calculates the complete gold sip portfolio and determines action based on performance.\n\nLogic:\n- calculate grams acquired for each transaction using historical gold price\n- aggregate total investment and total gold held\n- compute current portfolio value using latest gold price\n- calculate pnl (amount + percentage)\n- derive average buy price\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nDecision rules:\n- pnl <= -10% \u2192 loss alert (accumulation opportunity)\n- pnl >= 25% \u2192 profit booking suggestion\n- otherwise \u2192 neutral monthly update\n"
      },
      "typeVersion": 1
    },
    {
      "id": "f27ad39d-1569-44bc-87e6-2fe39dca3877",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2752,
        304
      ],
      "parameters": {
        "color": 7,
        "width": 848,
        "height": 848,
        "content": "## AI insights & Notification layer\n\nThis group enhances portfolio data with ai-generated insights and delivers final report to users.\n- AI agent analyzes portfolio and generates actionable insights\n- combine ai insights with portfolio metrics\n- send formatted notification via slack (and email if enabled)\n\nFeatures:\n- natural language investment advice\n- decision-based messaging (loss / profit / neutral)\n- automated monthly reporting\n"
      },
      "typeVersion": 1
    },
    {
      "id": "f561c904-0938-4c44-b14d-6015e58de595",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2224,
        304
      ],
      "parameters": {
        "color": 7,
        "width": 464,
        "height": 848,
        "content": "## Decision Routing Layer\n\nRoutes decision output (loss / profit / neutral) into specific branches and prepares structured input for the ai agent.\n\ngoal: ensure clean, scenario-ready data for accurate ai insights."
      },
      "typeVersion": 1
    },
    {
      "id": "ef5e93d2-09ea-432a-b8cd-ab14c6ab95b4",
      "name": "Monthly SIP Trigger",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        896,
        880
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "months",
              "triggerAtHour": 9
            }
          ]
        }
      },
      "typeVersion": 1.3
    },
    {
      "id": "821355d6-64cf-433b-890b-2f3f01262add",
      "name": "Fetch Gold Price",
      "type": "n8n-nodes-base.httpRequest",
      "onError": "continueErrorOutput",
      "position": [
        1152,
        880
      ],
      "parameters": {
        "url": "https://api.metalpriceapi.com/v1/latest",
        "options": {},
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "api_key",
              "value": "29ce26bdb53d106c78d1dfa1aee7893a"
            },
            {
              "name": "base",
              "value": "INR"
            },
            {
              "name": "currencies",
              "value": "XAU"
            }
          ]
        }
      },
      "retryOnFail": true,
      "typeVersion": 4.3
    },
    {
      "id": "61b5a6f8-cf7f-4f2f-af71-ff0181b4b632",
      "name": "Read Investment History",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        1376,
        784
      ],
      "parameters": {
        "options": {},
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/11IOzzXH40FqUPBH6AmEKl-lNdF1GKMVZzEkRu7icXf8/edit#gid=0",
          "cachedResultName": "Sheet1"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "11IOzzXH40FqUPBH6AmEKl-lNdF1GKMVZzEkRu7icXf8",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/11IOzzXH40FqUPBH6AmEKl-lNdF1GKMVZzEkRu7icXf8/edit?usp=drivesdk",
          "cachedResultName": "Gold SIP data"
        }
      },
      "executeOnce": true,
      "typeVersion": 4.7
    },
    {
      "id": "2e55db24-e9b6-43a1-951b-dc9b05907dbd",
      "name": "Alert Gold Fetch Error",
      "type": "n8n-nodes-base.slack",
      "position": [
        1376,
        976
      ],
      "parameters": {
        "text": "=*SIP Automation Error* - Failed to fetch gold price on {{ $now.toFormat(\"dd MMM yyyy\") }}. Manual intervention required.",
        "select": "channel",
        "channelId": {
          "__rl": true,
          "mode": "list",
          "value": "C0AP6AD7069",
          "cachedResultName": "all-group-d"
        },
        "otherOptions": {
          "includeLinkToWorkflow": false
        }
      },
      "typeVersion": 2.4
    },
    {
      "id": "364d8237-3f83-482c-9ad5-c9ecc70510d0",
      "name": "SIP Calculations",
      "type": "n8n-nodes-base.code",
      "position": [
        1744,
        784
      ],
      "parameters": {
        "jsCode": "// Get SIP sheet data\nconst transactions = $input.all().map(i => i.json);\n\n// Latest gold price (for valuation ONLY)\nconst pricePerOunceINR = $('Fetch Gold Price').first().json.rates.INRXAU || 400000;\nconst currentPricePerGram = pricePerOunceINR / 31.1035;\n\n// Aggregation\nlet totalInvested = 0;\nlet totalGrams = 0;\n\nconst detailed = [];\n\ntransactions.forEach(txn => {\n  const amount = parseFloat(txn[\"SIPAmount\"]) || 0;\n  const price = parseFloat(txn[\"Gold Price(1 gm)\"]) || 0;\n\n  if (amount > 0 && price > 0) {\n    const grams = amount / price;\n\n    totalInvested += amount;\n    totalGrams += grams;\n\n    detailed.push({\n      date: txn.Date,\n      amount,\n      pricePerGram: price,\n      grams: parseFloat(grams.toFixed(6))\n    });\n  }\n});\n\n// Current portfolio value (use latest price)\nconst currentValue = totalGrams * currentPricePerGram;\n\n// Profit / Loss\nconst pnlAmount = currentValue - totalInvested;\nconst pnlPercent = totalInvested > 0\n  ? (pnlAmount / totalInvested) * 100\n  : 0;\n\n// Avg buy price\nconst avgBuyPrice = totalGrams > 0\n  ? totalInvested / totalGrams\n  : 0;\n\n// Final output\nreturn [{\n  json: {\n    totalTransactions: transactions.length,\n\n    totalInvested: parseFloat(totalInvested.toFixed(2)),\n    totalGrams: parseFloat(totalGrams.toFixed(6)),\n\n    currentPricePerGram: parseFloat(currentPricePerGram.toFixed(2)),\n\n    currentValue: parseFloat(currentValue.toFixed(2)),\n\n    pnlAmount: parseFloat(pnlAmount.toFixed(2)),\n    pnlPercent: parseFloat(pnlPercent.toFixed(2)),\n\n    avgBuyPrice: parseFloat(avgBuyPrice.toFixed(2)),\n\n    breakdown: detailed\n  }\n}];"
      },
      "typeVersion": 2
    },
    {
      "id": "fd92a969-d487-4b0e-9ef5-89865eebf767",
      "name": "Decision Engine",
      "type": "n8n-nodes-base.switch",
      "position": [
        1936,
        768
      ],
      "parameters": {
        "rules": {
          "values": [
            {
              "outputKey": "Loss Alert",
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "loss-check",
                    "operator": {
                      "type": "number",
                      "operation": "lte"
                    },
                    "leftValue": "={{ $json.pnlPercent }}",
                    "rightValue": -10
                  }
                ]
              },
              "renameOutput": true
            },
            {
              "outputKey": "Profit Booking",
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "profit-check",
                    "operator": {
                      "type": "number",
                      "operation": "gte"
                    },
                    "leftValue": "={{ $json.pnlPercent }}",
                    "rightValue": 25
                  }
                ]
              },
              "renameOutput": true
            },
            {
              "outputKey": "Neutral Update",
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "neutral-check",
                    "operator": {
                      "type": "number",
                      "operation": "gt"
                    },
                    "leftValue": "={{ $json.pnlPercent }}",
                    "rightValue": -10
                  }
                ]
              },
              "renameOutput": true
            }
          ]
        },
        "options": {}
      },
      "typeVersion": 3.2
    },
    {
      "id": "3aef1b48-66ce-4782-82b4-5d762eca450a",
      "name": "Prepare Loss Alert",
      "type": "n8n-nodes-base.set",
      "position": [
        2304,
        608
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "1",
              "name": "alertType",
              "type": "string",
              "value": "LOSS_ALERT"
            },
            {
              "id": "3",
              "name": "alertTitle",
              "type": "string",
              "value": "GOLD SIP \u2014 LOSS ALERT (>10%)"
            },
            {
              "id": "4",
              "name": "decisionMessage",
              "type": "string",
              "value": "=Portfolio is down {{ $json.pnlPercent }}%. Consider increasing SIP to lower average cost, or review strategy."
            },
            {
              "id": "5",
              "name": "pnlPercent",
              "type": "number",
              "value": "={{ $json.pnlPercent }}"
            },
            {
              "id": "6",
              "name": "pnlAmount",
              "type": "number",
              "value": "={{ $json.pnlAmount }}"
            },
            {
              "id": "7",
              "name": "currentValue",
              "type": "number",
              "value": "={{ $json.currentValue }}"
            },
            {
              "id": "8",
              "name": "totalInvested",
              "type": "number",
              "value": "={{ $json.totalInvested }}"
            },
            {
              "id": "9",
              "name": "goldPriceINR",
              "type": "number",
              "value": "={{ $json.goldPriceINR }}"
            },
            {
              "id": "10",
              "name": "monthYear",
              "type": "string",
              "value": "={{ $json.monthYear }}"
            },
            {
              "id": "11",
              "name": "sipAmountINR",
              "type": "number",
              "value": "={{ $json.sipAmountINR }}"
            },
            {
              "id": "12",
              "name": "avgBuyPriceINR",
              "type": "number",
              "value": "={{ $json.avgBuyPriceINR }}"
            },
            {
              "id": "13",
              "name": "totalGrams",
              "type": "number",
              "value": "={{ $json.totalGrams }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "6072e5c5-a981-4080-a9dc-e1ebc62a63b0",
      "name": "Prepare Profit Booking",
      "type": "n8n-nodes-base.set",
      "position": [
        2304,
        784
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "1",
              "name": "alertType",
              "type": "string",
              "value": "PROFIT_BOOKING"
            },
            {
              "id": "3",
              "name": "alertTitle",
              "type": "string",
              "value": "GOLD SIP \u2014 PROFIT BOOKING SUGGESTION (>25%)"
            },
            {
              "id": "4",
              "name": "decisionMessage",
              "type": "string",
              "value": "=Excellent! Portfolio is up {{ $json.pnlPercent }}%. Consider booking 25-30% of profits and reinvesting at lower levels."
            },
            {
              "id": "5",
              "name": "pnlPercent",
              "type": "number",
              "value": "={{ $json.pnlPercent }}"
            },
            {
              "id": "6",
              "name": "pnlAmount",
              "type": "number",
              "value": "={{ $json.pnlAmount }}"
            },
            {
              "id": "7",
              "name": "currentValue",
              "type": "number",
              "value": "={{ $json.currentValue }}"
            },
            {
              "id": "8",
              "name": "totalInvested",
              "type": "number",
              "value": "={{ $json.totalInvested }}"
            },
            {
              "id": "9",
              "name": "goldPriceINR",
              "type": "number",
              "value": "={{ $json.currentPricePerGram }}"
            },
            {
              "id": "12",
              "name": "avgBuyPriceINR",
              "type": "number",
              "value": "={{ $json.avgBuyPrice }}"
            },
            {
              "id": "13",
              "name": "totalGrams",
              "type": "number",
              "value": "={{ $json.totalGrams }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "48c1a602-4900-4860-8c09-653fdf26973a",
      "name": "Prepare Neutral Status",
      "type": "n8n-nodes-base.set",
      "position": [
        2304,
        976
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "1",
              "name": "alertType",
              "type": "string",
              "value": "MONTHLY_UPDATE"
            },
            {
              "id": "3",
              "name": "alertTitle",
              "type": "string",
              "value": "GOLD SIP \u2014 Monthly Portfolio Update"
            },
            {
              "id": "4",
              "name": "decisionMessage",
              "type": "string",
              "value": "=Portfolio is tracking at {{ $json.pnlPercent }}%. Continue your SIP schedule consistently."
            },
            {
              "id": "5",
              "name": "pnlPercent",
              "type": "number",
              "value": "={{ $json.pnlPercent }}"
            },
            {
              "id": "6",
              "name": "pnlAmount",
              "type": "number",
              "value": "={{ $json.pnlAmount }}"
            },
            {
              "id": "7",
              "name": "currentValue",
              "type": "number",
              "value": "={{ $json.currentValue }}"
            },
            {
              "id": "8",
              "name": "totalInvested",
              "type": "number",
              "value": "={{ $json.totalInvested }}"
            },
            {
              "id": "9",
              "name": "goldPriceINR",
              "type": "number",
              "value": "={{ $json.currentPricePerGram }}"
            },
            {
              "id": "12",
              "name": "avgBuyPriceINR",
              "type": "number",
              "value": "={{ $json.avgBuyPrice }}"
            },
            {
              "id": "13",
              "name": "totalGrams",
              "type": "number",
              "value": "={{ $json.totalGrams }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "36c5bce6-b0a7-4afe-945a-c08561beb4e5",
      "name": "AI Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        2800,
        688
      ],
      "parameters": {
        "text": "=You are a gold investment advisor. Analyze this monthly SIP data and provide 3-4 concise actionable insights in plain text (no markdown, no bullet symbols).\n\nPortfolio Summary:\n- Month: {{ $json.monthYear }}\n- Gold Price INR (per troy oz): {{ $json.goldPriceINR }}\n- Monthly SIP: Rs {{ $json.sipAmountINR }}\n- Total Invested: Rs {{ $json.totalInvested }}\n- Current Value: Rs {{ $json.currentValue }}\n- P&L: Rs {{ $json.pnlAmount }} ({{ $json.pnlPercent }}%)\n- Avg Buy Price per gram: Rs {{ $json.avgBuyPriceINR }}\n- Total Grams Held: {{ $json.totalGrams }}\n- Alert Status: {{ $json.alertType }}\n- Decision: {{ $json.decisionMessage }}\n\nProvide insights on: market trend, cost averaging effectiveness, risk assessment, and a 3-month outlook. Max 180 words.",
        "options": {},
        "promptType": "define"
      },
      "typeVersion": 3.1
    },
    {
      "id": "e11346d3-6c0b-4cce-8325-f3f4984a0d97",
      "name": "Prepare Final Notification",
      "type": "n8n-nodes-base.set",
      "position": [
        3152,
        688
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "1",
              "name": "aiInsights",
              "type": "string",
              "value": "={{ $json.output }}"
            },
            {
              "id": "2",
              "name": "alertType",
              "type": "string",
              "value": "={{ $('Merge Decision Branches').item.json.alertType }}"
            },
            {
              "id": "4",
              "name": "alertTitle",
              "type": "string",
              "value": "={{ $('Merge Decision Branches').item.json.alertTitle }}"
            },
            {
              "id": "5",
              "name": "decisionMessage",
              "type": "string",
              "value": "={{ $('Merge Decision Branches').item.json.decisionMessage }}"
            },
            {
              "id": "6",
              "name": "pnlPercent",
              "type": "number",
              "value": "={{ $('Merge Decision Branches').item.json.pnlPercent }}"
            },
            {
              "id": "7",
              "name": "pnlAmount",
              "type": "number",
              "value": "={{ $('Merge Decision Branches').item.json.pnlAmount }}"
            },
            {
              "id": "8",
              "name": "currentValue",
              "type": "number",
              "value": "={{ $('Merge Decision Branches').item.json.currentValue }}"
            },
            {
              "id": "9",
              "name": "totalInvested",
              "type": "number",
              "value": "={{ $('Merge Decision Branches').item.json.totalInvested }}"
            },
            {
              "id": "10",
              "name": "goldPriceINR",
              "type": "number",
              "value": "={{ $('Merge Decision Branches').item.json.goldPriceINR }}"
            },
            {
              "id": "11",
              "name": "monthYear",
              "type": "string",
              "value": "={{ $('Merge Decision Branches').item.json.monthYear }}"
            },
            {
              "id": "12",
              "name": "sipAmountINR",
              "type": "number",
              "value": "={{ $('Merge Decision Branches').item.json.sipAmountINR }}"
            },
            {
              "id": "13",
              "name": "avgBuyPriceINR",
              "type": "number",
              "value": "={{ $('Merge Decision Branches').item.json.avgBuyPriceINR }}"
            },
            {
              "id": "14",
              "name": "totalGrams",
              "type": "number",
              "value": "={{ $('Merge Decision Branches').item.json.totalGrams }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "baee7244-c125-4e1b-9462-3a0dfe3951d3",
      "name": "Send Slack Notification",
      "type": "n8n-nodes-base.slack",
      "position": [
        3376,
        688
      ],
      "parameters": {
        "text": "={{ $json.alertTitle }}* | {{ $json.monthYear }}\n\n*Portfolio Snapshot:*\nGold Price: Rs {{ $json.goldPriceINR }}\nTotal Invested: Rs {{ $json.totalInvested }}\nCurrent Value: Rs {{ $json.currentValue }}\nP&L: Rs {{ $json.pnlAmount }} ({{ $json.pnlPercent }}%)\nAvg Buy Price/gram: Rs {{ $json.avgBuyPriceINR }}\n\n*Decision:* {{ $json.decisionMessage }}\n\n*AI Insights:*\n{{ $json.aiInsights }}",
        "select": "channel",
        "channelId": {
          "__rl": true,
          "mode": "list",
          "value": "C0APDQMMZUL",
          "cachedResultName": "support"
        },
        "otherOptions": {
          "mrkdwn": true,
          "includeLinkToWorkflow": false
        }
      },
      "typeVersion": 2.4
    },
    {
      "id": "654ec165-ddd7-415d-9b9d-c03f7f251542",
      "name": "Send Email Report",
      "type": "n8n-nodes-base.gmail",
      "position": [
        3376,
        880
      ],
      "parameters": {
        "sendTo": "<__PLACEHOLDER_VALUE__recipient@example.com__>",
        "message": "=<html><body style=\"font-family:Arial,sans-serif;max-width:620px;margin:auto;padding:24px;color:#333\">\n<h2 style=\"color:#B8860B;border-bottom:2px solid #B8860B;padding-bottom:8px\">{{ $json.alertEmoji }} {{ $json.alertTitle }}</h2>\n<p style=\"color:#666\">Period: <strong>{{ $json.monthYear }}</strong></p>\n<table style=\"width:100%;border-collapse:collapse;margin:16px 0;font-size:14px\">\n<tr style=\"background:#fdf8ec\"><td style=\"padding:10px;border:1px solid #e0d5b0\"><strong>Gold Price (per troy oz)</strong></td><td style=\"padding:10px;border:1px solid #e0d5b0\">Rs {{ $json.goldPriceINR }}</td></tr>\n<tr><td style=\"padding:10px;border:1px solid #e0d5b0\"><strong>Monthly SIP</strong></td><td style=\"padding:10px;border:1px solid #e0d5b0\">Rs {{ $json.sipAmountINR }}</td></tr>\n<tr style=\"background:#fdf8ec\"><td style=\"padding:10px;border:1px solid #e0d5b0\"><strong>Total Invested</strong></td><td style=\"padding:10px;border:1px solid #e0d5b0\">Rs {{ $json.totalInvested }}</td></tr>\n<tr><td style=\"padding:10px;border:1px solid #e0d5b0\"><strong>Current Value</strong></td><td style=\"padding:10px;border:1px solid #e0d5b0\">Rs {{ $json.currentValue }}</td></tr>\n<tr style=\"background:#fdf8ec\"><td style=\"padding:10px;border:1px solid #e0d5b0\"><strong>P&amp;L Amount</strong></td><td style=\"padding:10px;border:1px solid #e0d5b0\"><strong>Rs {{ $json.pnlAmount }} ({{ $json.pnlPercent }}%)</strong></td></tr>\n<tr><td style=\"padding:10px;border:1px solid #e0d5b0\"><strong>Avg Buy Price per gram</strong></td><td style=\"padding:10px;border:1px solid #e0d5b0\">Rs {{ $json.avgBuyPriceINR }}</td></tr>\n<tr style=\"background:#fdf8ec\"><td style=\"padding:10px;border:1px solid #e0d5b0\"><strong>Total Gold Held</strong></td><td style=\"padding:10px;border:1px solid #e0d5b0\">{{ $json.totalGrams }} grams</td></tr>\n</table>\n<div style=\"background:#fff8e1;border-left:4px solid #B8860B;padding:12px;margin:16px 0\">\n<strong>Decision:</strong> {{ $json.decisionMessage }}\n</div>\n<h3 style=\"color:#B8860B\">AI Insights</h3>\n<div style=\"background:#f5f5f5;padding:14px;border-radius:6px;font-size:13px;line-height:1.6\">{{ $json.aiInsights }}</div>\n<p style=\"color:#aaa;font-size:11px;margin-top:20px;border-top:1px solid #eee;padding-top:12px\">Automated by n8n Gold SIP Tracker. This is not financial advice.</p>\n</body></html>",
        "options": {
          "appendAttribution": false
        },
        "subject": "=Gold SIP Report {{ $json.monthYear }} | P&L: {{ $json.pnlPercent }}%",
        "authentication": "serviceAccount"
      },
      "typeVersion": 2.2
    },
    {
      "id": "5006ddd0-9322-4218-a6ce-0cb0598cec63",
      "name": "Merge Decision Branches",
      "type": "n8n-nodes-base.merge",
      "position": [
        2496,
        672
      ],
      "parameters": {
        "numberInputs": 3
      },
      "typeVersion": 3.2
    }
  ],
  "active": false,
  "settings": {
    "binaryMode": "separate",
    "executionOrder": "v1"
  },
  "versionId": "23f473fa-14f9-441f-9f90-29d56ae58c03",
  "nodeGroups": [],
  "connections": {
    "AI Agent": {
      "main": [
        [
          {
            "node": "Prepare Final Notification",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Decision Engine": {
      "main": [
        [
          {
            "node": "Prepare Loss Alert",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Prepare Profit Booking",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Prepare Neutral Status",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Groq Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Fetch Gold Price": {
      "main": [
        [
          {
            "node": "Read Investment History",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Alert Gold Fetch Error",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "SIP Calculations": {
      "main": [
        [
          {
            "node": "Decision Engine",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Prepare Loss Alert": {
      "main": [
        [
          {
            "node": "Merge Decision Branches",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Monthly SIP Trigger": {
      "main": [
        [
          {
            "node": "Fetch Gold Price",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Prepare Neutral Status": {
      "main": [
        [
          {
            "node": "Merge Decision Branches",
            "type": "main",
            "index": 2
          }
        ]
      ]
    },
    "Prepare Profit Booking": {
      "main": [
        [
          {
            "node": "Merge Decision Branches",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Merge Decision Branches": {
      "main": [
        [
          {
            "node": "AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Read Investment History": {
      "main": [
        [
          {
            "node": "SIP Calculations",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Prepare Final Notification": {
      "main": [
        [
          {
            "node": "Send Slack Notification",
            "type": "main",
            "index": 0
          },
          {
            "node": "Send Email Report",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}