{
  "id": "y0Yk7da21T4u9zlp",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "Breaking News Aggregator with SendGrid and PostgreSQL",
  "tags": [],
  "nodes": [
    {
      "id": "554daf32-f153-40b2-bc21-473cc9f3d25a",
      "name": "Daily Regulatory Check",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        288,
        352
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "hours",
              "hoursInterval": 24
            }
          ]
        }
      },
      "typeVersion": 1.1
    },
    {
      "id": "0b55fbab-42f0-43a7-8d26-d9027c80a577",
      "name": "Define Regulatory Sources",
      "type": "n8n-nodes-base.code",
      "position": [
        480,
        352
      ],
      "parameters": {
        "jsCode": "// Add or remove sources as needed\nreturn [\n  {json: {url: 'https://www.sec.gov/news/pressreleases.rss'}},\n  {json: {url: 'https://www.federalregister.gov/' }},\n  {json: {url: 'https://www.fca.org.uk/news' }}\n];"
      },
      "typeVersion": 2
    },
    {
      "id": "1c959531-610e-4c02-bfa8-b811aa7d7f4b",
      "name": "Loop Through Sources",
      "type": "n8n-nodes-base.splitInBatches",
      "position": [
        688,
        352
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 3
    },
    {
      "id": "d81bc838-c7ba-45af-a225-04a9bcb18190",
      "name": "Scrape Regulatory Page",
      "type": "n8n-nodes-scrapegraphai.scrapegraphAi",
      "position": [
        864,
        352
      ],
      "parameters": {
        "userPrompt": "Extract regulatory updates. For each update return: {\"title\":\"string\",\"summary\":\"string\",\"date\":\"string\",\"link\":\"string\",\"impactLevel\":\"string\"}. If impact cannot be inferred set impactLevel to \"Normal\".",
        "websiteUrl": "={{ $json.url }}"
      },
      "typeVersion": 1
    },
    {
      "id": "c7e1818b-982e-417b-bdb7-615eab88dbc9",
      "name": "Normalize & Score Impact",
      "type": "n8n-nodes-base.code",
      "position": [
        1120,
        352
      ],
      "parameters": {
        "jsCode": "// Normalise and score impact\nconst keywordRegex = /(effective immediately|compliance deadline|penalty|must comply|urgent)/i;\nconst results = [];\n$input.all().forEach(item => {\n  const data = item.json;\n  const highImpact = keywordRegex.test(data.summary || '') || (data.impactLevel || '').toLowerCase() === 'high';\n  results.push({\n    json: {\n      title: data.title || 'Untitled',\n      summary: data.summary || '',\n      date: data.date || new Date().toISOString(),\n      link: data.link || '',\n      impactLevel: data.impactLevel || (highImpact ? 'High' : 'Normal'),\n      highImpact\n    }\n  });\n});\nreturn results;"
      },
      "typeVersion": 2
    },
    {
      "id": "76b17ea8-abe5-45cb-be56-297deeca2ab1",
      "name": "Add Timestamp & Metadata",
      "type": "n8n-nodes-base.set",
      "position": [
        1312,
        352
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 3.4
    },
    {
      "id": "ff52ab33-e23f-49ac-85da-c850873f53ff",
      "name": "High Impact?",
      "type": "n8n-nodes-base.if",
      "position": [
        1584,
        352
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "boolean": [
            {
              "value1": "={{ $json.highImpact }}",
              "operator": {
                "type": "boolean",
                "operation": "true"
              }
            }
          ]
        }
      },
      "typeVersion": 2
    },
    {
      "id": "d2c2d27a-28d4-4915-a934-d02c2dc8d151",
      "name": "Prepare Email Content",
      "type": "n8n-nodes-base.set",
      "position": [
        1776,
        448
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 3.4
    },
    {
      "id": "980ee3ec-ab9c-4d18-89ed-2afcb1c27a24",
      "name": "SendGrid Alert",
      "type": "n8n-nodes-base.sendGrid",
      "position": [
        1968,
        416
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "91770e6e-9e4d-4147-8c1a-b570ad1f9b34",
      "name": "Store Regulation Record",
      "type": "n8n-nodes-base.postgres",
      "position": [
        2160,
        400
      ],
      "parameters": {
        "table": "regulatory_updates",
        "schema": "public",
        "columns": {
          "value": {
            "title": "={{ $json.title }}",
            "summary": "={{ $json.summary }}",
            "high_impact": "={{ $json.highImpact }}",
            "inserted_at": "={{ $json.timestamp }}",
            "source_link": "={{ $json.link }}",
            "impact_level": "={{ $json.impactLevel }}",
            "effective_date": "={{ $json.date }}"
          },
          "mappingMode": "defineBelow"
        },
        "options": {}
      },
      "typeVersion": 2.5
    },
    {
      "id": "0ffcb627-4a4d-4429-b3ed-b86aed44b31e",
      "name": "Workflow Overview",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -224,
        80
      ],
      "parameters": {
        "width": 420,
        "height": 620,
        "content": "## How it works\n\nThis workflow runs every morning to keep compliance teams on top of newly-published regulations. The Schedule Trigger wakes the workflow and feeds a short list of government and regulatory URLs into ScrapeGraphAI one at a time. ScrapeGraphAI reads each page or RSS feed, returning a clean JSON object that contains the headline, summary, date, link and an AI-estimated impact level. A Code node double-checks the text for urgent keywords and flags the record as high-impact when appropriate. An IF node then decides what to do next. Routine changes are simply written to PostgreSQL for later reporting, while anything flagged as high-impact takes an extra branch that builds an email and pushes it through SendGrid before being stored in the same table. In less than a minute the team's inbox and database are completely up to date.\n\n## Setup steps\n\n1. Add ScrapeGraphAI credentials in n8n\n2. Create \"regulatory_updates\" table in PostgreSQL\n3. Add PostgreSQL credentials to the workflow\n4. Insert your SendGrid API credentials\n5. Replace example recipient email with your team address\n6. Adjust the URL list in the first Code node\n7. Activate and let the schedule run"
      },
      "typeVersion": 1
    },
    {
      "id": "bccf65a9-de59-4106-af00-03ee3c05f154",
      "name": "Section - Data Collection",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        240,
        208
      ],
      "parameters": {
        "color": 7,
        "width": 780,
        "height": 340,
        "content": "## Data Collection\n\nTriggers daily and loops through regulatory URLs. ScrapeGraphAI extracts headlines, summaries, dates, and impact levels from each source."
      },
      "typeVersion": 1
    },
    {
      "id": "f31bb6c1-8fd8-4a5f-9b62-d4bc28296495",
      "name": "Section - Processing",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1056,
        208
      ],
      "parameters": {
        "color": 7,
        "width": 420,
        "height": 340,
        "content": "## Processing\n\nNormalizes data, scores impact using keyword detection, and adds timestamps before routing."
      },
      "typeVersion": 1
    },
    {
      "id": "54fe0eb9-56a0-4d6b-8d4c-f2b6e3618ca3",
      "name": "Section - Alerts & Storage",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1520,
        208
      ],
      "parameters": {
        "color": 7,
        "width": 884,
        "height": 452,
        "content": "## Alerts & Storage\n\nHigh-impact updates trigger SendGrid email alerts. All records are stored in PostgreSQL for reporting."
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "e419e7e4-db76-435d-9f96-eca412d3e385",
  "connections": {
    "High Impact?": {
      "main": [
        [
          {
            "node": "Prepare Email Content",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Store Regulation Record",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "SendGrid Alert": {
      "main": [
        [
          {
            "node": "Store Regulation Record",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Loop Through Sources": {
      "main": [
        [
          {
            "node": "Scrape Regulatory Page",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Prepare Email Content": {
      "main": [
        [
          {
            "node": "SendGrid Alert",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Daily Regulatory Check": {
      "main": [
        [
          {
            "node": "Define Regulatory Sources",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Scrape Regulatory Page": {
      "main": [
        [
          {
            "node": "Normalize & Score Impact",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Add Timestamp & Metadata": {
      "main": [
        [
          {
            "node": "High Impact?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Normalize & Score Impact": {
      "main": [
        [
          {
            "node": "Add Timestamp & Metadata",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Define Regulatory Sources": {
      "main": [
        [
          {
            "node": "Loop Through Sources",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}