{
  "nodes": [
    {
      "id": "9860881a-543c-443e-81ea-f5064fa7d0eb",
      "name": "Send Email",
      "type": "n8n-nodes-base.emailSend",
      "onError": "continueErrorOutput",
      "position": [
        864,
        288
      ],
      "parameters": {
        "html": "={ {$json[\"htmlBody\"]} }",
        "options": {},
        "subject": "={ {$json[\"subject\"]} }",
        "toEmail": "$env.RECEIVER_EMAIL",
        "fromEmail": "$env.SENDER_EMAIL"
      },
      "typeVersion": 1
    },
    {
      "id": "d64002f0-aa87-4a4c-9131-69ef1229d2a8",
      "name": "AI Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "onError": "continueErrorOutput",
      "position": [
        -112,
        736
      ],
      "parameters": {
        "text": "=You are a strict relevance filter for news articles.\n\nINSTRUCTIONS:\n- Reply only with: true or false\n- No explanations, no punctuation, no newlines, no extra text\n\nRELEVANT TOPICS:\n- Brand or product launches\n- New or upcoming advertising/marketing campaigns\n- Digital media changes (strategies, platforms, or tools)\n\nEvaluate the following article:\n\nTitle: { { $json.title } }\nContent: { { $json.content } }\nSnippet: { { $json.contentSnippet } }\n\nIs this article relevant? Respond with true or false only.",
        "options": {},
        "promptType": "define"
      },
      "executeOnce": true,
      "typeVersion": 1.9
    },
    {
      "id": "698a5769-e902-4f59-a447-dbb1e930f5b9",
      "name": "Loop Over Items",
      "type": "n8n-nodes-base.splitInBatches",
      "position": [
        -400,
        720
      ],
      "parameters": {
        "options": {
          "reset": false
        }
      },
      "typeVersion": 3
    },
    {
      "id": "ec67c0f9-6f6d-46e6-825a-2809d2dea323",
      "name": "Merge",
      "type": "n8n-nodes-base.merge",
      "position": [
        288,
        864
      ],
      "parameters": {
        "mode": "combine",
        "options": {},
        "combineBy": "combineByPosition"
      },
      "typeVersion": 3.1
    },
    {
      "id": "c5fcc084-98a2-414b-b3df-4f08a5a9bae3",
      "name": "If",
      "type": "n8n-nodes-base.if",
      "position": [
        496,
        864
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "2f473722-ac3b-485f-b3de-6d4406b75e12",
              "operator": {
                "type": "string",
                "operation": "contains"
              },
              "leftValue": "={ { $json.output } }",
              "rightValue": "true"
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "df59dde2-6b31-42b6-90ae-e73bf46226ef",
      "name": "Schedule Trigger",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        -1904,
        736
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "cronExpression",
              "expression": "30 19 * * *"
            }
          ]
        }
      },
      "notesInFlow": false,
      "typeVersion": 1.2
    },
    {
      "id": "ae210423-1e58-4cfb-acb0-999fb25e9c0a",
      "name": "Code",
      "type": "n8n-nodes-base.code",
      "position": [
        416,
        208
      ],
      "parameters": {
        "jsCode": "const tz = \"Asia/Kolkata\";\nconst now = new Date().toLocaleString(\"en-IN\", { timeZone: tz });\n\nconst articles = items.map(it => {\n  const j = it.json;\n\n  return `\n    <div style=\"padding:16px; border:1px solid #eee; border-radius:8px; margin-bottom:20px; background-color:#f9f9f9;\">\n      <h3 style=\"margin-top:0; margin-bottom:8px;\">\n        <a href=\"${j.Link}\" target=\"_blank\" style=\"color:#0077cc; text-decoration:none;\">\n          ${j.Title}\n        </a>\n      </h3>\n      <p style=\"margin:0 0 6px 0; font-size:13px; color:#888;\">\n        Published on: ${new Date(j.IsoDate).toLocaleDateString(\"en-IN\", { day: 'numeric', month: 'short', year: 'numeric' })}\n      </p>\n      <p style=\"margin:0; font-size:15px; line-height:1.6; color:#333;\">\n        ${j.ContentSnippet || ''}\n      </p>\n    </div>\n  `;\n}).join(\"\");\n\nreturn [{\n  json: {\n    subject: `XYZ Marketing NewsLetter – ${now}`,\n    htmlBody: `\n      <div style=\"font-family:'Segoe UI', Roboto, sans-serif; padding:24px; background-color:#ffffff; color:#333; max-width:700px; margin:auto;\">\n        <h2 style=\"color:#111; margin-top:0;\">📢 Latest Brand & Campaign Updates</h2>\n        ${articles}\n        <hr style=\"border:none; border-top:1px solid #ddd; margin:24px 0;\">\n        <p style=\"font-size:12px; color:#999; text-align:center;\">\n          Sent automatically by our XYZ newsletter assistant from Delhi.\n        </p>\n      </div>\n    `\n  }\n}];\n"
      },
      "typeVersion": 2
    },
    {
      "id": "d7f68c7f-92cb-45cc-aef6-42112ba5cd85",
      "name": "EconomicTimes Top Stories1",
      "type": "n8n-nodes-base.rssFeedRead",
      "onError": "continueRegularOutput",
      "position": [
        -1376,
        608
      ],
      "parameters": {
        "url": "https://brandequity.economictimes.indiatimes.com/rss/topstories",
        "options": {
          "ignoreSSL": false
        }
      },
      "typeVersion": 1
    },
    {
      "id": "3926fa32-ed62-4248-96c6-e2562512d52a",
      "name": "EconomicTimes Business of Brands",
      "type": "n8n-nodes-base.rssFeedRead",
      "onError": "continueRegularOutput",
      "position": [
        -1360,
        864
      ],
      "parameters": {
        "url": "https://brandequity.economictimes.indiatimes.com/rss/business-of-brands",
        "options": {}
      },
      "typeVersion": 1
    },
    {
      "id": "9f1eaf64-d570-49f7-868a-6d8228503d21",
      "name": "EconomicTimes Digital Marketing",
      "type": "n8n-nodes-base.rssFeedRead",
      "onError": "continueRegularOutput",
      "position": [
        -1568,
        896
      ],
      "parameters": {
        "url": "https://brandequity.economictimes.indiatimes.com/rss/digital",
        "options": {}
      },
      "typeVersion": 1
    },
    {
      "id": "ae122e32-bca0-4123-99f5-31ad16e8a6c7",
      "name": "Campaign India",
      "type": "n8n-nodes-base.rssFeedRead",
      "onError": "continueRegularOutput",
      "position": [
        -1568,
        576
      ],
      "parameters": {
        "url": "https://www.campaignindia.in/rss/rss.ashx",
        "options": {
          "ignoreSSL": false
        }
      },
      "typeVersion": 1
    },
    {
      "id": "44fafce1-d0c3-4abd-9f51-73efdcc5da7b",
      "name": "Send a message",
      "type": "n8n-nodes-base.gmail",
      "onError": "continueErrorOutput",
      "position": [
        640,
        208
      ],
      "parameters": {
        "sendTo": "$env.RECEIVER_EMAIL",
        "message": "={ { $json.htmlBody } }",
        "options": {},
        "subject": "={ { $json.subject } }"
      },
      "typeVersion": 2.1,
      "alwaysOutputData": false
    },
    {
      "id": "79280bbc-5bfe-47cf-8c6c-f0565394598c",
      "name": "OpenAI Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        -112,
        912
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-5-mini",
          "cachedResultName": "gpt-5-mini"
        },
        "options": {}
      },
      "typeVersion": 1.2
    },
    {
      "id": "de716d41-c201-483e-bccd-12eb4a58ed3e",
      "name": "Insert row",
      "type": "n8n-nodes-base.dataTable",
      "position": [
        768,
        848
      ],
      "parameters": {
        "columns": {
          "value": {
            "Guid": "={ { $json.guid } }",
            "Link": "={ { $json.link } }",
            "Title": "={ { $json.title } }",
            "Output": "={ { $json.output } }",
            "Content": "={ { $json.content } }",
            "IsoDate": "={ { $json.isoDate } }",
            "PubDate": "={ { $json.pubDate } }",
            "ContentSnippet": "={ { $json.contentSnippet } }"
          },
          "schema": [
            {
              "id": "Output",
              "type": "string",
              "display": true,
              "removed": false,
              "readOnly": false,
              "required": false,
              "displayName": "Output",
              "defaultMatch": false
            },
            {
              "id": "Title",
              "type": "string",
              "display": true,
              "removed": false,
              "readOnly": false,
              "required": false,
              "displayName": "Title",
              "defaultMatch": false
            },
            {
              "id": "Link",
              "type": "string",
              "display": true,
              "removed": false,
              "readOnly": false,
              "required": false,
              "displayName": "Link",
              "defaultMatch": false
            },
            {
              "id": "PubDate",
              "type": "string",
              "display": true,
              "removed": false,
              "readOnly": false,
              "required": false,
              "displayName": "PubDate",
              "defaultMatch": false
            },
            {
              "id": "Content",
              "type": "string",
              "display": true,
              "removed": false,
              "readOnly": false,
              "required": false,
              "displayName": "Content",
              "defaultMatch": false
            },
            {
              "id": "ContentSnippet",
              "type": "string",
              "display": true,
              "removed": false,
              "readOnly": false,
              "required": false,
              "displayName": "ContentSnippet",
              "defaultMatch": false
            },
            {
              "id": "Guid",
              "type": "string",
              "display": true,
              "removed": false,
              "readOnly": false,
              "required": false,
              "displayName": "Guid",
              "defaultMatch": false
            },
            {
              "id": "IsoDate",
              "type": "string",
              "display": true,
              "removed": false,
              "readOnly": false,
              "required": false,
              "displayName": "IsoDate",
              "defaultMatch": false
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "dataTableId": {
          "__rl": true,
          "mode": "list",
          "value": "1VUgEWZhtGRgWRc4",
          "cachedResultUrl": "/projects/wdXsYqO0TAnlH2nc/datatables/1VUgEWZhtGRgWRc4",
          "cachedResultName": "Newsletter"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "260dacc0-2ee8-4b74-a9b3-c9c65274de24",
      "name": "Get row(s)",
      "type": "n8n-nodes-base.dataTable",
      "position": [
        208,
        208
      ],
      "parameters": {
        "limit": 30,
        "operation": "get",
        "dataTableId": {
          "__rl": true,
          "mode": "list",
          "value": "1VUgEWZhtGRgWRc4",
          "cachedResultUrl": "/projects/wdXsYqO0TAnlH2nc/datatables/1VUgEWZhtGRgWRc4",
          "cachedResultName": "Newsletter"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "2cbe39ed-8e7e-4bee-9dc8-c349a1284d98",
      "name": "Delete row(s)",
      "type": "n8n-nodes-base.dataTable",
      "position": [
        1168,
        112
      ],
      "parameters": {
        "filters": {
          "conditions": [
            {
              "keyName": "Output",
              "keyValue": "true"
            }
          ]
        },
        "options": {},
        "operation": "deleteRows",
        "dataTableId": {
          "__rl": true,
          "mode": "list",
          "value": "1VUgEWZhtGRgWRc4",
          "cachedResultUrl": "/projects/wdXsYqO0TAnlH2nc/datatables/1VUgEWZhtGRgWRc4",
          "cachedResultName": "Newsletter"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "b6ecb2d9-b2cb-4dc2-a696-dc0944a89430",
      "name": "Limit",
      "type": "n8n-nodes-base.limit",
      "position": [
        0,
        208
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "ef55d92a-d724-4b72-9682-128df5923d12",
      "name": "Merge Feeds-1",
      "type": "n8n-nodes-base.merge",
      "position": [
        -976,
        592
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "66d0fb2d-de49-47f7-866e-199fc3f8e0a5",
      "name": "Merge Feeds-2",
      "type": "n8n-nodes-base.merge",
      "position": [
        -976,
        880
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "c428f9bf-b7fe-43d1-8198-0ff2f494da89",
      "name": "Merge Feeds-All",
      "type": "n8n-nodes-base.merge",
      "position": [
        -736,
        720
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "f3bec180-9231-49fa-84a2-8e22f609e08d",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -2544,
        432
      ],
      "parameters": {
        "width": 420,
        "height": 704,
        "content": "## Set up steps - What this workflow does!\n\nThis flow pulls the latest marketing news from Campaign India and ET BrandEquity, filters the useful stories with an AI relevance check, saves them to a Data Table, and sends a daily newsletter at 7:30 PM IST."
      },
      "typeVersion": 1
    }
  ],
  "connections": {
    "If": {
      "main": [
        [
          {
            "node": "Insert row",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Code": {
      "main": [
        [
          {
            "node": "Send a message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Limit": {
      "main": [
        [
          {
            "node": "Get row(s)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Merge": {
      "main": [
        [
          {
            "node": "If",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI Agent": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get row(s)": {
      "main": [
        [
          {
            "node": "Code",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Insert row": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send Email": {
      "main": [
        [
          {
            "node": "Delete row(s)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Merge Feeds-1": {
      "main": [
        [
          {
            "node": "Merge Feeds-All",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Merge Feeds-2": {
      "main": [
        [
          {
            "node": "Merge Feeds-All",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Campaign India": {
      "main": [
        [
          {
            "node": "Merge Feeds-1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send a message": {
      "main": [
        [
          {
            "node": "Delete row(s)",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Send Email",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Loop Over Items": {
      "main": [
        [
          {
            "node": "Limit",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "AI Agent",
            "type": "main",
            "index": 0
          },
          {
            "node": "Merge",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Merge Feeds-All": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Schedule Trigger": {
      "main": [
        [
          {
            "node": "EconomicTimes Top Stories1",
            "type": "main",
            "index": 0
          },
          {
            "node": "EconomicTimes Business of Brands",
            "type": "main",
            "index": 0
          },
          {
            "node": "EconomicTimes Digital Marketing",
            "type": "main",
            "index": 0
          },
          {
            "node": "Campaign India",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "EconomicTimes Top Stories1": {
      "main": [
        [
          {
            "node": "Merge Feeds-1",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "EconomicTimes Digital Marketing": {
      "main": [
        [
          {
            "node": "Merge Feeds-2",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "EconomicTimes Business of Brands": {
      "main": [
        [
          {
            "node": "Merge Feeds-2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}