{
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "nodes": [
    {
      "id": "15528050-2707-48e2-94a4-193e4a1294bd",
      "name": "Daily Schedule Trigger",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        -16,
        816
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "triggerAtHour": 10
            }
          ]
        }
      },
      "typeVersion": 1.3
    },
    {
      "id": "f019e429-4053-4b2d-90b7-7320d1e7bf8a",
      "name": "GNews API",
      "type": "n8n-nodes-base.httpRequest",
      "onError": "continueRegularOutput",
      "position": [
        384,
        640
      ],
      "parameters": {
        "url": "https://gnews.io/api/v4/search",
        "options": {
          "timeout": 10000
        },
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "q",
              "value": "cybersecurity OR cyber attack OR data breach OR vulnerability"
            },
            {
              "name": "lang",
              "value": "en"
            },
            {
              "name": "max",
              "value": "20"
            },
            {
              "name": "apikey",
              "value": "f01c51e789cb83eafeca20025ccd44ce"
            }
          ]
        }
      },
      "typeVersion": 4.3,
      "continueOnFail": true
    },
    {
      "id": "70fd3b63-a38c-47cd-a2d9-d1ceaf5a23f5",
      "name": "NewsAPI",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        384,
        816
      ],
      "parameters": {
        "url": "https://newsapi.org/v2/everything",
        "options": {
          "timeout": 10000
        },
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "q",
              "value": "cybersecurity OR \"data breach\" OR \"security vulnerability\""
            },
            {
              "name": "pageSize",
              "value": "20"
            },
            {
              "name": "sortBy",
              "value": "publishedAt"
            },
            {
              "name": "apikey",
              "value": "8b1896e394d74847adb2603a4ec74b5b"
            }
          ]
        }
      },
      "typeVersion": 4.3,
      "continueOnFail": true
    },
    {
      "id": "5cebb572-1f03-4eff-b316-866c2ebca86b",
      "name": "AI Threat Analysis Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        2480,
        720
      ],
      "parameters": {
        "text": "=Articles:\n{{ JSON.stringify($json.articles) }}\n\nErrors:\n{{ JSON.stringify($json.errors) }}\n\nTasks:\n1. Select the 5 most important cybersecurity stories\n2. Write a concise summary for each (2\u20133 lines)\n3. Add a short headline per story\n4. End with a one-line note if any data sources failed\n",
        "options": {
          "systemMessage": "You are a professional cybersecurity news analyst.\n\nYou receive:\n\u2022 A list of normalized cybersecurity news articles\n\u2022 A list of API errors (if any)\n\nYour job is to produce a clear, concise, factual daily cybersecurity news digest.\n\nRules:\n- Focus on impact, severity, and relevance\n- Prefer data breaches, ransomware, nation-state attacks, and critical vulnerabilities\n- Ignore marketing fluff or low-impact news\n- Do NOT hallucinate facts\n- If some sources failed, mention it briefly at the end\n- Maintain a professional tone\n\nMust Must Must Rank stories by severity: Critical, High, Medium."
        }
      },
      "typeVersion": 1
    },
    {
      "id": "7a6e6022-1d0a-4842-a31b-fed226020f83",
      "name": "OpenAI GPT-4",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        2432,
        944
      ],
      "parameters": {
        "model": "gpt-4-turbo-preview",
        "options": {
          "maxTokens": 2000,
          "temperature": 0.3
        }
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "07e8cf7a-6e57-45b1-8be9-1ca319ba19cb",
      "name": "Send to Telegram",
      "type": "n8n-nodes-base.telegram",
      "position": [
        3072,
        336
      ],
      "parameters": {
        "text": "={{ $json.textMessage }}",
        "chatId": "YOUR_TELEGRAM_CHAT_ID",
        "additionalFields": {
          "parse_mode": "Markdown",
          "appendAttribution": false
        }
      },
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "52879507-58ca-4ace-aaf7-55c3e2eaf37b",
      "name": "Send to Slack",
      "type": "n8n-nodes-base.slack",
      "position": [
        3072,
        544
      ],
      "parameters": {
        "text": "={{ $json.digest }}",
        "select": "channel",
        "channelId": {
          "__rl": true,
          "mode": "list",
          "value": "YOUR_SLACK_CHANNEL_ID"
        },
        "otherOptions": {},
        "authentication": "oAuth2"
      },
      "typeVersion": 2.2
    },
    {
      "id": "e513106f-1677-4f82-a9c5-684a3fbdc540",
      "name": "Archive to Google Sheets",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        3088,
        976
      ],
      "parameters": {
        "columns": {
          "value": {
            "Date": "={{ $now.format('yyyy-MM-dd') }}",
            "Digest": "={{ $json.digest }}",
            "Timestamp": "={{ $now.format('yyyy-MM-dd HH:mm:ss') }}",
            "Article Count": "={{ $('Prepare Data for AI').item.json.articleCount }}",
            "Character Count": "={{ $json.digestLength }}"
          },
          "mappingMode": "defineBelow"
        },
        "options": {},
        "operation": "append",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "Sheet1"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "YOUR_GOOGLE_SHEET_ID"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.5
    },
    {
      "id": "a3ff18c2-7429-4754-9b02-1bf0d0bbfc49",
      "name": "Sources Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        272,
        544
      ],
      "parameters": {
        "color": 4,
        "width": 768,
        "height": 616,
        "content": "##  News Sources\nFetching from multiple APIs with error handling"
      },
      "typeVersion": 1
    },
    {
      "id": "f4f85638-5e78-40e1-ac95-0c4b1333bc7f",
      "name": "Processing Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1056,
        544
      ],
      "parameters": {
        "color": 5,
        "width": 1324,
        "height": 616,
        "content": "##  Data Processing\nDeduplication, normalization & error handling"
      },
      "typeVersion": 1
    },
    {
      "id": "7159c15b-f467-4141-9663-23b832e8fdbc",
      "name": "AI Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2400,
        544
      ],
      "parameters": {
        "color": 6,
        "width": 544,
        "height": 616,
        "content": " AI Analysis\nGPT-4 powered threat intelligence analysis with categorization"
      },
      "typeVersion": 1
    },
    {
      "id": "5d5b275d-e1a6-4ac2-b51f-918eb9c1ee4d",
      "name": "Delivery Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2976,
        192
      ],
      "parameters": {
        "color": 3,
        "width": 316,
        "height": 972,
        "content": "## \ud83d\udce4 Multi-Channel Delivery\nTelegram, Slack, Email + Archive to Google Sheets"
      },
      "typeVersion": 1
    },
    {
      "id": "bc7d80ce-08f5-44c5-957f-4bf56d485584",
      "name": "Workflow Overview",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -864,
        -368
      ],
      "parameters": {
        "color": 7,
        "width": 720,
        "height": 1556,
        "content": "# Advanced Cyber Threat Intelligence Digest System\n\n**Created by: Abdullah Dilshad**\niamabdullahdishad@gmail.com\n\n##  Key Features\n\n###  **Multi-Source Aggregation**\n- GNews API for mainstream news\n- NewsAPI for comprehensive coverage\n- Reddit r/cybersecurity for community insights\n- Expandable to RSS feeds, CISA alerts, CVE databases\n\n###  **Smart Deduplication**\n- Levenshtein distance algorithm\n- 80% similarity threshold\n- Prevents duplicate stories from multiple sources\n\n###  **AI-Powered Analysis**\n- GPT-4 threat prioritization\n- Automatic categorization (Breach, Vulnerability, Tool, Research)\n- Severity rating (Critical, High, Medium)\n- Actionable summaries for security teams\n\n###  **Robust Error Handling**\n- Retry logic with continueOnFail\n- Admin alerts for failures\n- Timeout protection (10s)\n- Fallback mechanisms\n\n###  **Multi-Channel Distribution**\n- **Telegram**: Instant mobile notifications\n- **Slack**: Team collaboration channels\n- **Email**: Executive-friendly HTML format\n- **Google Sheets**: Searchable historical archive\n\n###  **Quality Assurance**\n- Message length validation\n- Character count monitoring\n- Warning alerts for oversized digests\n- Source count tracking\n\n---\n\n##  Perfect For\n\n **Security Operations Centers (SOCs)**\n **Cybersecurity Teams**\n **IT Security Managers**\n **Incident Response Teams**\n **CISOs & Security Leadership**\n **Security Researchers**\n **Penetration Testers**\n\n Time: ~20 minutes\n\n**Requirements**:\n- n8n instance (cloud or self-hosted)\n- OpenAI API key\n- GNews API key (free tier available)\n- NewsAPI key (free tier available)\n- Telegram Bot Token\n- (Optional) Slack workspace access\n- (Optional) Google Sheets for archiving\n- (Optional) Email SMTP credentials"
      },
      "typeVersion": 1
    },
    {
      "id": "124bdd41-e279-4309-b5ec-ebc149b08d2f",
      "name": "Reddit Cybersecurity",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        384,
        1008
      ],
      "parameters": {
        "url": "https://api.worldnewsapi.com/search-news",
        "options": {
          "timeout": 10000
        },
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "text",
              "value": "cybersecurity OR \"data breach\" OR \"security vulnerability\""
            },
            {
              "name": "language",
              "value": "en"
            },
            {
              "name": "api-key",
              "value": "c574a03e9f694107b581f614b1761333"
            }
          ]
        }
      },
      "typeVersion": 4.3,
      "continueOnFail": true
    },
    {
      "id": "10948406-b0ae-44b8-8e37-3fc3677ab6da",
      "name": "Merge",
      "type": "n8n-nodes-base.merge",
      "position": [
        1264,
        800
      ],
      "parameters": {
        "numberInputs": 3
      },
      "typeVersion": 3.2
    },
    {
      "id": "351c3659-f6e0-46f1-8208-cf21fffd9a88",
      "name": "If1",
      "type": "n8n-nodes-base.if",
      "position": [
        752,
        816
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 3,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "or",
          "conditions": [
            {
              "id": "3a787eeb-576d-41b4-9f85-196e1e19fc3d",
              "operator": {
                "type": "string",
                "operation": "exists",
                "singleValue": true
              },
              "leftValue": "={{ $json.error }}",
              "rightValue": ""
            },
            {
              "id": "4c53315c-a83f-451e-963a-97cb775ec69d",
              "operator": {
                "type": "number",
                "operation": "gte"
              },
              "leftValue": "={{ $json.statusCode }}",
              "rightValue": 400
            }
          ]
        }
      },
      "typeVersion": 2.3
    },
    {
      "id": "b17da31b-4bd1-4cbe-888e-0d9098fb6cdc",
      "name": "If",
      "type": "n8n-nodes-base.if",
      "position": [
        736,
        640
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 3,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "or",
          "conditions": [
            {
              "id": "3a787eeb-576d-41b4-9f85-196e1e19fc3d",
              "operator": {
                "type": "string",
                "operation": "exists",
                "singleValue": true
              },
              "leftValue": "={{ $json.error }}",
              "rightValue": ""
            },
            {
              "id": "4c53315c-a83f-451e-963a-97cb775ec69d",
              "operator": {
                "type": "number",
                "operation": "gte"
              },
              "leftValue": "={{ $json.statusCode }}",
              "rightValue": 400
            }
          ]
        }
      },
      "typeVersion": 2.3
    },
    {
      "id": "4844174b-9c00-4d43-8751-348e848ce1b9",
      "name": "If2",
      "type": "n8n-nodes-base.if",
      "position": [
        752,
        1008
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 3,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "or",
          "conditions": [
            {
              "id": "3a787eeb-576d-41b4-9f85-196e1e19fc3d",
              "operator": {
                "type": "string",
                "operation": "exists",
                "singleValue": true
              },
              "leftValue": "={{ $json.error }}",
              "rightValue": ""
            },
            {
              "id": "4c53315c-a83f-451e-963a-97cb775ec69d",
              "operator": {
                "type": "number",
                "operation": "gte"
              },
              "leftValue": "={{ $json.statusCode }}",
              "rightValue": 400
            }
          ]
        }
      },
      "typeVersion": 2.3
    },
    {
      "id": "83c11b26-7d84-4686-8bdf-8eeff43f144d",
      "name": "Code in JavaScript",
      "type": "n8n-nodes-base.code",
      "position": [
        1200,
        32
      ],
      "parameters": {
        "jsCode": "return [{\n  json: {\n    source: 'GNews',\n    error: $json.error?.message || 'Request failed',\n    statusCode: $json.statusCode || null,\n    timestamp: new Date().toISOString()\n  }\n}];"
      },
      "typeVersion": 2
    },
    {
      "id": "94188453-31b5-4114-9a26-e271e9e8ba9b",
      "name": "Code in JavaScript1",
      "type": "n8n-nodes-base.code",
      "position": [
        1200,
        192
      ],
      "parameters": {
        "jsCode": "return [{\n  json: {\n    source: 'NewsAPI',\n    error: $json.error?.message || 'Request failed',\n    statusCode: $json.statusCode || null,\n    timestamp: new Date().toISOString()\n  }\n}];"
      },
      "typeVersion": 2
    },
    {
      "id": "7eafd036-aa31-49ac-aa86-521e71a6fcf2",
      "name": "Code in JavaScript2",
      "type": "n8n-nodes-base.code",
      "position": [
        1200,
        352
      ],
      "parameters": {
        "jsCode": "return [{\n  json: {\n    source: 'World News',\n    error: $json.error?.message || 'Request failed',\n    statusCode: $json.statusCode || null,\n    timestamp: new Date().toISOString()\n  }\n}];"
      },
      "typeVersion": 2
    },
    {
      "id": "75dcf7b4-3372-48a1-bc3a-d4322cacb7de",
      "name": "Merge1",
      "type": "n8n-nodes-base.merge",
      "position": [
        1568,
        128
      ],
      "parameters": {
        "numberInputs": 3
      },
      "typeVersion": 3.2
    },
    {
      "id": "154c384c-9410-4935-93e4-b4c7de035128",
      "name": "Normalize Articles",
      "type": "n8n-nodes-base.code",
      "position": [
        1536,
        816
      ],
      "parameters": {
        "jsCode": "const normalized = [];\n\nfor (const item of items) {\n  const source =\n    item.json.source ||\n    item.json.provider ||\n    item.json.news ||\n    'Unknown';\n\n  const articles = item.json.articles || [];\n\n  for (const article of articles) {\n    normalized.push({\n      json: {\n        source,\n        title: article.title || '',\n        description: article.description || '',\n        content: article.content || '',\n        url: article.url || '',\n        image: article.image || null\n      }\n    });\n  }\n}\n\nreturn normalized;"
      },
      "typeVersion": 2
    },
    {
      "id": "f2b43de5-ea1e-4b2a-a890-903a769ab249",
      "name": "Final Context Builder",
      "type": "n8n-nodes-base.code",
      "position": [
        2144,
        800
      ],
      "parameters": {
        "jsCode": "const articles = [];\nconst errors = [];\n\nfor (const item of items) {\n  if (item.json.title) {\n    articles.push(item.json);\n  } else if (item.json.error) {\n    errors.push(item.json);\n  }\n}\n\nreturn [{\n  json: {\n    articles,\n    errors,\n    generatedAt: new Date().toISOString()\n  }\n}];\n"
      },
      "typeVersion": 2
    },
    {
      "id": "1d8fdda6-3e84-4887-a2cd-681819992d78",
      "name": "Merge Articles + Errors",
      "type": "n8n-nodes-base.merge",
      "position": [
        1872,
        800
      ],
      "parameters": {},
      "typeVersion": 3.2
    },
    {
      "id": "5ae19667-b8f5-4eb6-81c7-fca6d6b714ab",
      "name": "Manipulating Outputs",
      "type": "n8n-nodes-base.code",
      "position": [
        2768,
        720
      ],
      "parameters": {
        "jsCode": "const aiText = items[0].json.output;\n\n// 1\ufe0f\u20e3 Unified text message (Telegram / Slack / Email)\nconst message =\n`\ud83d\udee1\ufe0f Daily Cybersecurity Brief\n\n${aiText}\n\n\ud83d\udd52 Generated: ${new Date().toLocaleString()}`;\n\n// 2\ufe0f\u20e3 Basic row format for Sheets (1 row per digest)\nconst sheetRow = {\n  date: new Date().toISOString(),\n  content: aiText\n};\n\nreturn [{\n  json: {\n    textMessage: message,\n    sheetRow,\n    metadata: {\n      generatedAt: new Date().toISOString(),\n      length: aiText.length\n    }\n  }\n}];\n"
      },
      "typeVersion": 2
    },
    {
      "id": "00647085-0652-4429-8774-bd5090b29c20",
      "name": "AI Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1056,
        -80
      ],
      "parameters": {
        "color": 6,
        "width": 688,
        "height": 616,
        "content": "## Handeling Errors\n"
      },
      "typeVersion": 1
    },
    {
      "id": "e2e8e939-6455-4634-a353-6b814e41a3b3",
      "name": "Send a message",
      "type": "n8n-nodes-base.gmail",
      "position": [
        3088,
        752
      ],
      "parameters": {
        "message": "Hello",
        "options": {},
        "subject": "Hello"
      },
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.2
    }
  ],
  "connections": {
    "If": {
      "main": [
        [
          {
            "node": "Code in JavaScript",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If1": {
      "main": [
        [
          {
            "node": "Code in JavaScript1",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "If2": {
      "main": [
        [
          {
            "node": "Code in JavaScript2",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 2
          }
        ]
      ]
    },
    "Merge": {
      "main": [
        [
          {
            "node": "Normalize Articles",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Merge1": {
      "main": [
        [
          {
            "node": "Merge Articles + Errors",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "NewsAPI": {
      "main": [
        [
          {
            "node": "If1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "GNews API": {
      "main": [
        [
          {
            "node": "If",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI GPT-4": {
      "ai_languageModel": [
        [
          {
            "node": "AI Threat Analysis Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Code in JavaScript": {
      "main": [
        [
          {
            "node": "Merge1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Normalize Articles": {
      "main": [
        [
          {
            "node": "Merge Articles + Errors",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Code in JavaScript1": {
      "main": [
        [
          {
            "node": "Merge1",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Code in JavaScript2": {
      "main": [
        [
          {
            "node": "Merge1",
            "type": "main",
            "index": 2
          }
        ]
      ]
    },
    "Manipulating Outputs": {
      "main": [
        [
          {
            "node": "Send to Telegram",
            "type": "main",
            "index": 0
          },
          {
            "node": "Send to Slack",
            "type": "main",
            "index": 0
          },
          {
            "node": "Archive to Google Sheets",
            "type": "main",
            "index": 0
          },
          {
            "node": "Send a message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Reddit Cybersecurity": {
      "main": [
        [
          {
            "node": "If2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Final Context Builder": {
      "main": [
        [
          {
            "node": "AI Threat Analysis Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Daily Schedule Trigger": {
      "main": [
        [
          {
            "node": "GNews API",
            "type": "main",
            "index": 0
          },
          {
            "node": "NewsAPI",
            "type": "main",
            "index": 0
          },
          {
            "node": "Reddit Cybersecurity",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Merge Articles + Errors": {
      "main": [
        [
          {
            "node": "Final Context Builder",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI Threat Analysis Agent": {
      "main": [
        [
          {
            "node": "Manipulating Outputs",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}