{
  "name": "🗞️ AI-Powered Sustainability Newsletter for Marketing with Gmail, GPT-4o",
  "nodes": [
    {
      "parameters": {
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "7f8ac804-088d-4dfa-a661-8b6b09a6e340",
              "operator": {
                "name": "filter.operator.equals",
                "type": "string",
                "operation": "equals"
              },
              "leftValue": "={{ $json.date }}",
              "rightValue": "={{ $now.minus(5,\"day\").day }} {{ $now.minus(5,\"day\").monthLong }} {{ $now.minus(5,\"day\").year }}"
            },
            {
              "id": "094bd21e-1d23-4f06-a286-501045a53c9b",
              "operator": {
                "name": "filter.operator.equals",
                "type": "string",
                "operation": "equals"
              },
              "leftValue": "={{ $json.type }}",
              "rightValue": "News article"
            }
          ]
        },
        "options": {}
      },
      "id": "07aad9fd-18dd-4e1d-9f84-a37a5c91e6d4",
      "name": "If",
      "type": "n8n-nodes-base.if",
      "position": [
        1024,
        560
      ],
      "typeVersion": 2.2
    },
    {
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o-mini"
        },
        "options": {}
      },
      "id": "e331e6c8-5a57-475d-8db3-3991af026446",
      "name": "OpenAI Chat Model3",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        1440,
        544
      ],
      "typeVersion": 1.2
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "=Title: {{$json.title}}\nDescription: {{$json.description}}\n\nIs this article about sustainability? Return only: true or false\n",
        "hasOutputParser": true,
        "options": {
          "systemMessage": "=You are a classification assistant. \n\nYour role is to analyze the title and description of an article and determine if it is related to sustainability. \n\nYou must only return {\"answer\": true} if the article is clearly related to sustainability (e.g., environmental protection, renewable energy, sustainable development, climate action, green economy, etc.). \n\nIf it is not clearly related, return {\"answer\": false}.\n\nIf the description is empty or missing, rely only on the title. Your response must be only one of the two JSON options: {\"answer\": true} or {\"answer\": false}. Do not provide explanations.\n"
        }
      },
      "id": "1d6b1257-d28f-4b77-a255-ac1f571a5843",
      "name": "Agent Classification",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        1456,
        368
      ],
      "typeVersion": 1.8
    },
    {
      "parameters": {
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "=",
          "cachedResultUrl": "=",
          "cachedResultName": "="
        },
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0",
          "cachedResultUrl": "=",
          "cachedResultName": "="
        },
        "filtersUI": {
          "values": [
            {
              "lookupColumn": "sustainability",
              "lookupValue": "true"
            }
          ]
        },
        "options": {}
      },
      "id": "c675a902-b8aa-499e-934e-da643fb53fb9",
      "name": "Get Sustainability News",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        176,
        944
      ],
      "notesInFlow": true,
      "typeVersion": 4.5
    },
    {
      "parameters": {
        "sendTo": "email@gmail.com",
        "subject": "Your Sustainability News Digest from LogiGreen",
        "message": "={{ $json.email_body }}",
        "options": {
          "appendAttribution": false
        }
      },
      "id": "6c3316bd-2763-4a77-aa01-ce60fd80910c",
      "name": "Send to your mailing list",
      "type": "n8n-nodes-base.gmail",
      "position": [
        544,
        944
      ],
      "webhookId": "=",
      "notesInFlow": true,
      "typeVersion": 2.1
    },
    {
      "parameters": {
        "jsCode": "const summary = `Welcome to the EU Sustainability News Digest provided by <a href=\"https://logi-green.com\" style=\"color: #0077cc; text-decoration: none;\">LogiGreen Consulting</a>.`;\n\nconst articles = items.map(item => item.json);  // each item is an article\n\nlet html = `\n<div style=\"font-family: Arial, sans-serif; max-width: 700px; margin: auto;\">\n  <h2 style=\"color: #2c3e50;\">🌍 EU News Digest – ${new Date().toLocaleDateString('en-GB', { day: 'numeric', month: 'long', year: 'numeric' })}</h2>\n  <p style=\"font-size: 16px; color: #333;\">${summary}</p>\n  <hr style=\"border: 1px solid #eee;\" />\n`;\n\nfor (const article of articles) {\n  const link = article.link.startsWith(\"http\") ? article.link : `https://ec.europa.eu${article.link}`;\n  html += `\n    <div style=\"display: flex; margin: 20px 0; border-bottom: 1px solid #ddd; padding-bottom: 15px;\">\n      ${article.image ? `<img src=\"${article.image}\" alt=\"\" width=\"150\" style=\"margin-right: 15px; border-radius: 6px; object-fit: cover;\" />` : ''}\n      <div>\n        <p style=\"margin: 0; font-size: 12px; color: #888;\">${article.type} | ${article.date}</p>\n        <h3 style=\"margin: 5px 0;\">\n          <a href=\"${link}\" style=\"text-decoration: none; color: #0077cc;\">${article.title}</a>\n        </h3>\n        <p style=\"margin: 5px 0; color: #333;\">${article.description || ''}</p>\n        ${article.read_time ? `<p style=\"font-size: 12px; color: gray;\">${article.read_time}</p>` : ''}\n      </div>\n    </div>\n  `;\n}\n\nhtml += `\n  <div style=\"margin-top: 40px; padding-top: 20px; border-top: 1px solid #eee; text-align: center;\">\n    <p style=\"font-size: 12px; color: #999;\">You received this email as part of the EU Sustainability News Digest project.</p>\n    <a href=\"https://logi-green.com\" target=\"_blank\">\n      <img src=\"https://www.logi-green.com/web/image/website/1/logo/LogiGreen%20Consulting?unique=e2af3c6\" alt=\"LogiGreen Consulting Logo\" style=\"height: 40px; margin-top: 10px;\" />\n    </a>\n  </div>\n</div>\n`;\n\n\nreturn [{ json: { email_body: html } }];\n"
      },
      "id": "4d666ab3-5750-4098-b3e5-44ea3f5c87e3",
      "name": "Generate Email HTML",
      "type": "n8n-nodes-base.code",
      "position": [
        368,
        944
      ],
      "notesInFlow": true,
      "typeVersion": 2
    },
    {
      "parameters": {
        "operation": "extractHtmlContent",
        "dataPropertyName": "articles",
        "extractionValues": {
          "values": [
            {
              "key": "type",
              "cssSelector": "ul.ecl-content-block__primary-meta-container li:nth-child(1)"
            },
            {
              "key": "date",
              "cssSelector": "ul.ecl-content-block__primary-meta-container li:nth-child(2) time\t"
            },
            {
              "key": "title",
              "cssSelector": "div.ecl-content-block__title a\t"
            },
            {
              "key": "link",
              "cssSelector": "div.ecl-content-block__title a\t",
              "returnValue": "attribute",
              "attribute": "href"
            },
            {
              "key": "description",
              "cssSelector": "div.ecl-content-block__description p\t"
            },
            {
              "key": "image",
              "cssSelector": "picture img",
              "returnValue": "attribute",
              "attribute": "src"
            },
            {
              "key": "read_time",
              "cssSelector": "ul.ecl-content-block__secondary-meta-container span.ecl-content-block__secondary-meta-label\t"
            }
          ]
        },
        "options": {}
      },
      "id": "9b4a5a80-c005-4875-9fed-988c2a3f89c4",
      "name": "Parse Article Blocks",
      "type": "n8n-nodes-base.html",
      "position": [
        800,
        560
      ],
      "notesInFlow": true,
      "typeVersion": 1.2
    },
    {
      "parameters": {
        "operation": "extractHtmlContent",
        "extractionValues": {
          "values": [
            {
              "key": "articles",
              "cssSelector": "div.ecl-content-item-block__item",
              "returnValue": "html",
              "returnArray": true
            }
          ]
        },
        "options": {}
      },
      "id": "7b83131e-4d98-49b6-b957-8de11f84fa3b",
      "name": "Extract Articles Blocks",
      "type": "n8n-nodes-base.html",
      "position": [
        368,
        560
      ],
      "notesInFlow": true,
      "typeVersion": 1.2
    },
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "triggerAtHour": 8,
              "triggerAtMinute": 30
            }
          ]
        }
      },
      "id": "d599f4a5-1816-4963-bd64-649bb34eb5ae",
      "name": "Trigger at 08:30 am",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        -80,
        560
      ],
      "typeVersion": 1.2
    },
    {
      "parameters": {
        "url": "https://commission.europa.eu/news-and-media/news_en",
        "options": {}
      },
      "id": "f0964113-af3a-4588-93c8-cdf83df3ab16",
      "name": "Query EU News Website",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        128,
        560
      ],
      "notesInFlow": true,
      "typeVersion": 4.2
    },
    {
      "parameters": {
        "fieldToSplitOut": "articles",
        "options": {}
      },
      "id": "c258eed9-51fe-4522-828c-5dbbcc2e348f",
      "name": "Split Out by Article Block",
      "type": "n8n-nodes-base.splitOut",
      "position": [
        576,
        560
      ],
      "typeVersion": 1
    },
    {
      "parameters": {
        "options": {}
      },
      "id": "4d9c0c86-2776-4d2f-ac68-cc69f4e363f5",
      "name": "Loop Over Articles",
      "type": "n8n-nodes-base.splitInBatches",
      "position": [
        1248,
        560
      ],
      "typeVersion": 3
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "dcfc8260-1125-4883-8895-8a5f55d09341",
              "name": "sustainability",
              "type": "string",
              "value": "={{ $json.output.answer }}"
            }
          ]
        },
        "options": {}
      },
      "id": "535ab5f2-04d4-49b7-b00b-fbe069e3da71",
      "name": "Sustainability Flag",
      "type": "n8n-nodes-base.set",
      "position": [
        1840,
        368
      ],
      "notesInFlow": true,
      "retryOnFail": false,
      "typeVersion": 3.4
    },
    {
      "parameters": {
        "mode": "combineBySql"
      },
      "id": "aa7885a1-e7d3-453b-b5cc-c43cba8f64e8",
      "name": "Merge Article + Flag",
      "type": "n8n-nodes-base.merge",
      "position": [
        2064,
        416
      ],
      "notesInFlow": true,
      "typeVersion": 3.1
    },
    {
      "parameters": {
        "operation": "append",
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "=",
          "cachedResultUrl": "=",
          "cachedResultName": "="
        },
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0",
          "cachedResultUrl": "=",
          "cachedResultName": "="
        },
        "columns": {
          "value": {
            "date": "={{ $json.date }}",
            "link": "={{ $json.link }}",
            "type": "={{ $json.type }}",
            "image": "={{ $json.image }}",
            "title": "={{ $json.title }}",
            "read_time": "={{ $json.read_time }}",
            "description": "={{ $json.description }}",
            "sustainability": "={{ $json.sustainability }}"
          },
          "schema": [
            {
              "id": "sustainability",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "sustainability",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "type",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "type",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "date",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "date",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "title",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "title",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "link",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "link",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "description",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "description",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "image",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "image",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "read_time",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "read_time",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {}
      },
      "id": "014fe94f-b469-4b14-b3f8-f495b6fed9c4",
      "name": "Record Results",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        2288,
        496
      ],
      "notesInFlow": true,
      "typeVersion": 4.5
    },
    {
      "parameters": {
        "jsonSchemaExample": "{\n  \"answer\": \"boolean | null\"\n}\n"
      },
      "id": "2943600b-3233-4095-ad86-f022da9574a6",
      "name": "Structured Output Parser",
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "position": [
        1728,
        544
      ],
      "typeVersion": 1.2
    },
    {
      "parameters": {
        "content": "### 1. Workflow Trigger with Cron Job\nThe workflow is triggered every morning at 08:30 am (local time)\n\n#### How to setup?\n- Select the time you want to set it up\n",
        "height": 680,
        "width": 220,
        "color": 7
      },
      "id": "19b8d0ee-7d46-46dc-9a2d-b0ff8491881e",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -144,
        16
      ],
      "typeVersion": 1
    },
    {
      "parameters": {
        "content": "### 4. Generate HTML page and send by email\nThis block collects all the articles of the day to create a prettified HTML page that is sent using the Gmail node.\n#### How to setup?\n- **Gmail Node:** set up your Gmail API credentials\n[Learn more about the Gmail Trigger Node]\n",
        "height": 380,
        "width": 620,
        "color": 7
      },
      "id": "4704fae8-341f-4c39-92d9-99c0bd9b0d1d",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        96,
        736
      ],
      "typeVersion": 1
    },
    {
      "parameters": {
        "content": "### 2. Scrapping and Parsing of Articles blocks\nThis starts with the HTTP node collecting HTML code that is parsed to extract Article Titles, Link, Image Cover and Reading time.\n\n#### How to setup?\n*Nothing to do*",
        "height": 700,
        "width": 840,
        "color": 7
      },
      "id": "c5d497f1-e62f-48e6-a457-ed6cebbe9caf",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        96,
        16
      ],
      "typeVersion": 1
    },
    {
      "parameters": {
        "content": "### 3. Classifiy all the articles (Sustainability: true or false)\nThis starts with the If node that filters based on the scope date fixed by you. Through the loop, the AI Agent classify the articles using the title and description.\nThe ones that are flagged as \"sustainability\" are recorded in a Google Sheet.\n\n#### How to setup?\n- **Record results in the Google Sheet Node**:\n   1. Add your Google Sheet API credentials to access the Google Sheet file\n   2. Select the file using the list, an URL or an ID\n   3. Select the sheet in which you want to record the articles\n   4. Map the fields: **sustainability, type, date, title, link, description, image, read time**\n  [Learn more about the Google Sheet Node](https://docs.n8n.io/integrations/builtin/app-nodes/n8n-nodes-base.googlesheets)\n- **AI Agent with the Chat Model**:\n   1. Add a chat model with the required credentials *(Example: Open AI 4o-mini)*",
        "height": 700,
        "width": 1440,
        "color": 7
      },
      "id": "4c2a8401-4c98-4ec7-a728-ec50a26db06f",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1024,
        16
      ],
      "typeVersion": 1
    },
    {
      "parameters": {
        "content": "### [Check the Tutorial](https://www.youtube.com/watch?v=q8VCAUbuat8)\n![Thumbnail](https://www.samirsaci.com/content/images/2025/04/temp-10.png)",
        "height": 380,
        "width": 580
      },
      "id": "e551e7d1-43c8-4e9e-a458-860123f41e85",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        768,
        736
      ],
      "typeVersion": 1
    }
  ],
  "pinData": {},
  "connections": {
    "If": {
      "main": [
        [
          {
            "node": "Loop Over Articles",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model3": {
      "ai_languageModel": [
        [
          {
            "node": "Agent Classification",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Agent Classification": {
      "main": [
        [
          {
            "node": "Sustainability Flag",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Sustainability News": {
      "main": [
        [
          {
            "node": "Generate Email HTML",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Generate Email HTML": {
      "main": [
        [
          {
            "node": "Send to your mailing list",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Parse Article Blocks": {
      "main": [
        [
          {
            "node": "If",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract Articles Blocks": {
      "main": [
        [
          {
            "node": "Split Out by Article Block",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Trigger at 08:30 am": {
      "main": [
        [
          {
            "node": "Query EU News Website",
            "type": "main",
            "index": 0
          },
          {
            "node": "Get Sustainability News",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Query EU News Website": {
      "main": [
        [
          {
            "node": "Extract Articles Blocks",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Split Out by Article Block": {
      "main": [
        [
          {
            "node": "Parse Article Blocks",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Loop Over Articles": {
      "main": [
        [],
        [
          {
            "node": "Agent Classification",
            "type": "main",
            "index": 0
          },
          {
            "node": "Merge Article + Flag",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Sustainability Flag": {
      "main": [
        [
          {
            "node": "Merge Article + Flag",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Merge Article + Flag": {
      "main": [
        [
          {
            "node": "Record Results",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Record Results": {
      "main": [
        [
          {
            "node": "Loop Over Articles",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Structured Output Parser": {
      "ai_outputParser": [
        [
          {
            "node": "Agent Classification",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1",
    "availableInMCP": false
  },
  "versionId": "ca3fb620-022c-4264-b278-63beb80b9996",
  "meta": {
    "instanceId": "5ff5a5992c4c72af22abbdcfa574d8cdf93dc14d57eb9f66e3d9ef2a3e2dbb6c"
  },
  "id": "WFTjsLo3SlyEcjyI",
  "tags": []
}