{
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "nodes": [
    {
      "id": "6fc2bb82-168e-4852-a904-525154d50fd8",
      "name": "Schedule Trigger",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        0,
        0
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "cronExpression",
              "expression": "30 7,10,12,16,18 * * *"
            }
          ]
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "e6664669-a580-4a13-8e50-694a4ab5715f",
      "name": "HTTP Request",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        208,
        0
      ],
      "parameters": {
        "url": "https://www.mortgagenewsdaily.com/",
        "options": {},
        "jsonHeaders": "{\n  \"User-Agent\": \"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/0.0.0.0 Safari/537.36\",\n  \"Accept\": \"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\",\n  \"Accept-Language\": \"en-US,en;q=0.9\",\n  \"Connection\": \"keep-alive\"\n}\n",
        "sendHeaders": true,
        "specifyHeaders": "json"
      },
      "typeVersion": 4.2
    },
    {
      "id": "a93e75cf-80f0-4df0-b74e-fc3fd34a417c",
      "name": "Code in JavaScript",
      "type": "n8n-nodes-base.code",
      "position": [
        416,
        0
      ],
      "parameters": {
        "jsCode": "const html = items[0].json.data || \"\";\n\n// Grab the last updated date\nconst updatedMatch = html.match(/Last Updated:\\s*([\\d/]+)/i);\nconst lastUpdated = updatedMatch ? updatedMatch[1] : \"Unknown\";\n\n// Match all rows in the mortgage table\nconst rowRegex = /<tr[^>]*>(.*?)<\\/tr>/gs;\nconst rows = [...html.matchAll(rowRegex)];\n\nconst rates = [];\n\nfor (const row of rows) {\n  const cells = [...row[1].matchAll(/<td[^>]*>(.*?)<\\/td>/gs)]\n    .map(m => m[1].replace(/<[^>]+>/g, '').trim());\n  if (cells.length === 4) {\n    rates.push({\n      product: cells[0],\n      rate: cells[1],\n      change: cells[2],\n      points: cells[3]\n    });\n  }\n}\n\n// Format into a Discord message\nlet message = `\ud83d\udcca **Daily Mortgage Rates** (Updated: ${lastUpdated})\\n\\n`;\n\nfor (const r of rates) {\n  message += `\ud83c\udfe0 ${r.product}: ${r.rate}  (${r.change}, pts: ${r.points})\\n`;\n}\n\nreturn [\n  {\n    json: {\n      content: message\n    }\n  }\n];\n"
      },
      "typeVersion": 2
    },
    {
      "id": "03ad32b4-a10b-40bb-8c82-df36afc1ece2",
      "name": "Discord",
      "type": "n8n-nodes-base.discord",
      "position": [
        928,
        0
      ],
      "parameters": {
        "content": "={{ $('Code in JavaScript').item.json.content }}\n\nCustom Client Messages:\n{{ $json.content.parts[0].text }}",
        "options": {},
        "authentication": "webhook"
      },
      "credentials": {
        "discordWebhookApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2
    },
    {
      "id": "c01f5aea-976b-4ac3-a17f-e8d51887d80d",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -304,
        -64
      ],
      "parameters": {
        "content": "## 1. Daily Rate Updates\n**Set your Trigger Times Here** Currently you will get a few updates every day!"
      },
      "typeVersion": 1
    },
    {
      "id": "553df342-b1b6-45e4-a988-1b76f4f39600",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        16,
        -336
      ],
      "parameters": {
        "height": 240,
        "content": "## 2. Get Mortgage Rates From Mortgage News Daily \n\nCan change Source if needed but haven't had any issues"
      },
      "typeVersion": 1
    },
    {
      "id": "67b4c32d-5556-455c-8927-63e35430b534",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        320,
        -336
      ],
      "parameters": {
        "height": 240,
        "content": "## 3. Clean up data for discord message\n\nMight need some updates if you wanted it to go to slack or something have not tested."
      },
      "typeVersion": 1
    },
    {
      "id": "d487c064-629a-4a52-ba47-622dffcdbc5b",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        912,
        -528
      ],
      "parameters": {
        "height": 432,
        "content": "## 4. Send cleaned mortgage rates and custom messages for lenders or real estate agents to send to their clients, delivered to Discord Webhook\n\nCould be changed to slack/telegram/whatsapp etc. "
      },
      "typeVersion": 1
    },
    {
      "id": "d4350624-6bdf-498a-a9b1-d5aa58330890",
      "name": "Message a model",
      "type": "@n8n/n8n-nodes-langchain.googleGemini",
      "position": [
        624,
        0
      ],
      "parameters": {
        "modelId": {
          "__rl": true,
          "mode": "list",
          "value": "models/gemini-2.0-flash-lite",
          "cachedResultName": "models/gemini-2.0-flash-lite"
        },
        "options": {},
        "messages": {
          "values": [
            {
              "content": "=Please look at the following mortgage rate updates and generate the viewer a message that can be sent to clients and what this could mean for them. Never include a name or things like client, just say something like hello or hi if needed. Give one formatted for Text, one formatted for email. Only output the messages.  Rates:  {{ $json.content }}"
            }
          ]
        }
      },
      "credentials": {
        "googlePalmApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "eb8139a3-7345-45c8-b01c-8cfed5003ff5",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        624,
        -448
      ],
      "parameters": {
        "height": 352,
        "content": "## 3. AI Magic to create Text/Emails to send to clients (Fee API Key at https://aistudio.google.com/api-keys)\n\nThis can be customized if you need different messaging style or if you want to include a name variable for a CRM etc."
      },
      "typeVersion": 1
    }
  ],
  "connections": {
    "HTTP Request": {
      "main": [
        [
          {
            "node": "Code in JavaScript",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Message a model": {
      "main": [
        [
          {
            "node": "Discord",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Schedule Trigger": {
      "main": [
        [
          {
            "node": "HTTP Request",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Code in JavaScript": {
      "main": [
        [
          {
            "node": "Message a model",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}