Flujo de trabajo de n8n: agregación de noticias diaria y almacenamiento en MongoDB

Intermedio

Este es unMarket Research, Multimodal AIflujo de automatización del dominio deautomatización que contiene 11 nodos.Utiliza principalmente nodos como Code, Gmail, MongoDb, Perplexity, SplitInBatches. Agregación de noticias diaria con Perplexity AI y almacenamiento en MongoDB

Requisitos previos
  • Cuenta de Google y credenciales de API de Gmail
  • Cadena de conexión de MongoDB
Vista previa del flujo de trabajo
Visualización de las conexiones entre nodos, con soporte para zoom y panorámica
Exportar flujo de trabajo
Copie la siguiente configuración JSON en n8n para importar y usar este flujo de trabajo
{
  "id": "kpAcUnFPtxaqsGnZ",
  "meta": {
    "instanceId": "2726cca490aa82c0ebb012bdcdb3596cbc823e0d9b0e26be2ae4efed4df5b51c"
  },
  "name": "n8n Workflow: Daily News Aggregator & MongoDB Storage",
  "tags": [],
  "nodes": [
    {
      "id": "b00241ab-0355-4ada-acdb-56bea4f5d15a",
      "name": "Disparador programado",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        -80,
        64
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "triggerAtHour": 8
            }
          ]
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "d4b2cdc4-39ec-4d3c-9b76-684cb485540e",
      "name": "Nota adhesiva4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        778,
        -120
      ],
      "parameters": {
        "color": 3,
        "width": 508,
        "height": 200,
        "content": "Final Notification"
      },
      "typeVersion": 1
    },
    {
      "id": "caee7461-f2b4-46d6-ab86-110bd0d85fc4",
      "name": "Nota adhesiva3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        78,
        8
      ],
      "parameters": {
        "color": 6,
        "width": 228,
        "height": 216,
        "content": "News Perplexity"
      },
      "typeVersion": 1
    },
    {
      "id": "1a0c7dc3-dc3c-498b-8567-ae92e9176245",
      "name": "Perplexity",
      "type": "n8n-nodes-base.perplexity",
      "position": [
        144,
        64
      ],
      "parameters": {
        "model": "sonar-pro",
        "options": {
          "searchRecency": "day"
        },
        "messages": {
          "message": [
            {
              "content": "Fetch the latest breaking news from the past few hours, focusing on major headlines, current events, and urgent updates. Prioritize high-impact global news (politics, economics, disasters, technology, conflicts) from reputable sources (e.g., Reuters, AP, BBC, CNN).\n\nReturn the results as a valid JSON array with each article structured as follows:\n\njson\n{\n  \"headline\": \"Concise headline (under 120 chars)\",  \n  \"timestamp\": \"ISO 8601 format (e.g., 2024-03-15T14:30:00Z)\",  \n  \"source\": \"Trusted source name (e.g., BBC News)\",  \n  \"summary\": \"1-2 paragraph neutral summary (avoid opinionated language)\",  \n  \"url\": \"Direct link to the article\",  \n  \"category\": \"Topical category (e.g., politics, technology)\",  \n  \"language\": \"en\",  \n  \"metadata\": {\n    \"priority\": \"high/medium/low\",  \n    \"location\": \"Geo-tag if relevant (e.g., 'Ukraine')\"  \n  }\n}\nRequirements:\n\nExclude paywalled/promotional content.\n\nEnsure timestamps are UTC.\n\nInclude at least 5-10 diverse news items.\n\n\nKey Improvements:\nSpecificity – Clarifies content focus (global, high-impact) and credible sources.\n\nData Quality – Explicitly excludes paywalled content and mandates neutral summaries.\n\nStructure – Uses nested metadata for extensibility (e.g., adding tags later)."
            }
          ]
        },
        "simplify": true,
        "requestOptions": {}
      },
      "credentials": {
        "perplexityApi": {
          "id": "qKLBfuokGGYNrdJC",
          "name": "Perplexity account"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "eceb97dd-a30a-4237-a992-ebd7e38f67b5",
      "name": "Response Perplexity",
      "type": "n8n-nodes-base.code",
      "position": [
        368,
        64
      ],
      "parameters": {
        "jsCode": "// Get the string with the news array\nlet raw = $json[\"message\"];\n\n// Remove backticks and the ‘json’ tag if they exist\nraw = raw.replace(/```json|```/g, '').trim();\n\n// Parse the clean string into an array of objects\nconst noticias = JSON.parse(raw);\n\n// Returns each news item as an individual item for the Loop\nreturn noticias.map(noticia => ({ json: noticia }));"
      },
      "typeVersion": 2
    },
    {
      "id": "a77e0c7f-3597-4c98-8730-8af03a3a017b",
      "name": "News",
      "type": "n8n-nodes-base.code",
      "position": [
        816,
        -80
      ],
      "parameters": {
        "jsCode": "\nreturn [\n  {\n    json: {\n      noticias: items.map(item => item.json)\n    }\n  }\n];"
      },
      "typeVersion": 2
    },
    {
      "id": "49c51d23-2786-4005-8f99-3df1bd048dc3",
      "name": "Loop Over News",
      "type": "n8n-nodes-base.splitInBatches",
      "position": [
        592,
        64
      ],
      "parameters": {
        "options": {
          "reset": false
        }
      },
      "typeVersion": 3
    },
    {
      "id": "0051a6ef-16d8-489c-8ad9-b28191a88599",
      "name": "DB News",
      "type": "n8n-nodes-base.mongoDb",
      "notes": "Official Database",
      "position": [
        816,
        112
      ],
      "parameters": {
        "fields": "=headline,timestamp,source,summary,url,category,language,metadata",
        "options": {
          "dateFields": "={{ $json.headline }},{{ $json.timestamp }},{{ $json.source }},{{ $json.summary }},{{ $json.url }},{{ $json.category }},{{ $json.language }},{{ $json.metadata }}"
        },
        "operation": "insert",
        "collection": "news"
      },
      "credentials": {
        "mongoDb": {
          "id": "smjByRgHnSMlBLZV",
          "name": "MongoDB account"
        }
      },
      "notesInFlow": true,
      "typeVersion": 1.2
    },
    {
      "id": "c3cf8752-d188-44c5-8d85-762620670fe9",
      "name": "Send Message",
      "type": "n8n-nodes-base.gmail",
      "notes": "News registration confirmation",
      "position": [
        1040,
        -80
      ],
      "webhookId": "0ed03883-cced-4af4-a946-be91005b6108",
      "parameters": {
        "sendTo": "<YOUR EMAIL>",
        "message": "=<!DOCTYPE html> <html lang=\"es\">  <head>     <meta charset=\"UTF-8\">     <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">     <title>News</title>     <style>         body {             font-family: Arial, sans-serif;             background-color: #f4f4f4;             margin: 0;             padding: 0;         }          .container {             background-color: #ffffff;             width: 90%;             max-width: 600px;             margin: 20px auto;             padding: 20px;             border-radius: 5px;             box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);         }          h1 {             color: #333333;             font-size: 22px;         }          p {             color: #555555;             font-size: 16px;             line-height: 1.5;         }          .button {             display: inline-block;             padding: 10px 20px;             background-color: #007bff;             color: #ffffff;             text-decoration: none;             border-radius: 4px;             margin-top: 10px;         }          .footer {             font-size: 12px;             color: #888888;             text-align: center;             margin-top: 20px;         }     </style> </head>  <body>     <div class=\"container\">         <h1>Hi!!</h1>         <p>             We are pleased to inform you that the registration of news in MongoDB was successful!         </p>         <p>Thanks.</p>         <div class=\"footer\">             © 2025 News World.         </div>     </div> </body>  </html> ",
        "options": {
          "appendAttribution": false
        },
        "subject": "=[ News ] Record of all news items"
      },
      "credentials": {
        "gmailOAuth2": {
          "id": "Qq401GIyTl33eVdh",
          "name": "Gmail account 2"
        }
      },
      "notesInFlow": true,
      "typeVersion": 2.1,
      "alwaysOutputData": true
    },
    {
      "id": "da552b54-3fce-416e-bb6e-fcc5e5cacf4f",
      "name": "Nota adhesiva",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1184,
        -464
      ],
      "parameters": {
        "width": 1008,
        "height": 1632,
        "content": "## n8n Workflow: Daily News Aggregator & MongoDB Storage\n\n### **Objective**  \n### Automatically fetch global news from Perplexity once per day, format the data, store it in MongoDB, and send a confirmation email via Gmail.\n\n---\n\n## **Workflow Steps**\n\n### 1. **Trigger: Cron Node**\n- **Frequency**: Runs once daily (e.g., `0 8 * * *` for 8:00 AM UTC).\n- **Action**: Initiates the workflow.\n\n### 2. **Perplexity Node**\n- **Input**: Prompt that specifies the type of news you want along with the JSON format you expect to save in MongoDB with the news information.\n- **Output**: A string from a JSON file with the news obtained. Response containing news articles (headlines, sources, timestamps).\n\n### 3. **Code Node: Data Formatting**\n- **Purpose**: Transforms String Data into a loop-compatible array.\n- **Example Code**:\n  ```javascript\n  // Get the string with the news array\n  let raw = $json[\"message\"];\n  // Remove backticks and the ‘json’ tag if they exist\n  raw = raw.replace(/```json|```/g, '').trim();\n  // Parse the clean string into an array of objects\n  const noticias = JSON.parse(raw);\n  // Returns each news item as an individual item for the Loop\n  return noticias.map(noticia => ({ json: noticia }));\n\n## 4. Loop Node: MongoDB Insertion\n**Action**: Iterates over each news item and inserts into MongoDB.\n\n**Configuration**:\n- **Collection**: `daily_news`\n- **Operation**: `Insert`  \n- **Fields**: \n  ```json\n  {\n    \"headline\": \"\",\n    \"timestamp\": \"\",\n    \"source\": \"\",\n    \"url\": \"\",\n    \"category\": \"\",\n    \"metadata\": {}\n  }\n\n## 5. Code Node: Aggregation & Notification Prep\n\n- **Purpose**: Wait for the news to be posted and then send a single notification email.\n\n## 6. Email Node (Gmail)\n\n- **Purpose**: Notification email\n\nWorkFlow\n    A[Cron Trigger] --> B[Perplexity API]\n    B --> C[Format Data]\n    C --> D[Loop: MongoDB Insert]\n    D --> E[Aggregate Results]\n    E --> F[Send Email Notification]"
      },
      "typeVersion": 1
    },
    {
      "id": "5f8fde92-09a5-44a2-9e8e-efebfcb84fd9",
      "name": "Nota adhesiva1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -160,
        -256
      ],
      "parameters": {
        "color": 7,
        "width": 1504,
        "height": 672,
        "content": ""
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "a765923b-a9ab-4567-a08f-132d54451d50",
  "connections": {
    "a77e0c7f-3597-4c98-8730-8af03a3a017b": {
      "main": [
        [
          {
            "node": "c3cf8752-d188-44c5-8d85-762620670fe9",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "0051a6ef-16d8-489c-8ad9-b28191a88599": {
      "main": [
        [
          {
            "node": "49c51d23-2786-4005-8f99-3df1bd048dc3",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "1a0c7dc3-dc3c-498b-8567-ae92e9176245": {
      "main": [
        [
          {
            "node": "eceb97dd-a30a-4237-a992-ebd7e38f67b5",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "c3cf8752-d188-44c5-8d85-762620670fe9": {
      "main": [
        []
      ]
    },
    "49c51d23-2786-4005-8f99-3df1bd048dc3": {
      "main": [
        [
          {
            "node": "a77e0c7f-3597-4c98-8730-8af03a3a017b",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "0051a6ef-16d8-489c-8ad9-b28191a88599",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Schedule Trigger": {
      "main": [
        [
          {
            "node": "1a0c7dc3-dc3c-498b-8567-ae92e9176245",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "eceb97dd-a30a-4237-a992-ebd7e38f67b5": {
      "main": [
        [
          {
            "node": "49c51d23-2786-4005-8f99-3df1bd048dc3",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
Preguntas frecuentes

¿Cómo usar este flujo de trabajo?

Copie el código de configuración JSON de arriba, cree un nuevo flujo de trabajo en su instancia de n8n y seleccione "Importar desde JSON", pegue la configuración y luego modifique la configuración de credenciales según sea necesario.

¿En qué escenarios es adecuado este flujo de trabajo?

Intermedio - Investigación de mercado, IA Multimodal

¿Es de pago?

Este flujo de trabajo es completamente gratuito, puede importarlo y usarlo directamente. Sin embargo, tenga en cuenta que los servicios de terceros utilizados en el flujo de trabajo (como la API de OpenAI) pueden requerir un pago por su cuenta.

Información del flujo de trabajo
Nivel de dificultad
Intermedio
Número de nodos11
Categoría2
Tipos de nodos7
Descripción de la dificultad

Adecuado para usuarios con experiencia intermedia, flujos de trabajo de complejidad media con 6-15 nodos

Autor
Samuel Heredia

Samuel Heredia

@sheredia

I like to believe that I can contribute to creating a better world with the developments I make :)

Enlaces externos
Ver en n8n.io

Compartir este flujo de trabajo

Categorías

Categorías: 34