{
  "name": "Daily News Alert with Keyword Detection",
  "nodes": [
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "cronExpression",
              "expression": "0 9 * * *"
            }
          ]
        }
      },
      "id": "schedule-node",
      "name": "Каждый день в 9:00",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        256,
        304
      ],
      "typeVersion": 1.3
    },
    {
      "parameters": {
        "url": "https://[domain]/rbcnews/news/30/full.rss",
        "options": {}
      },
      "id": "rss-rbc",
      "name": "RSS — RBC",
      "type": "n8n-nodes-base.rssFeedRead",
      "position": [
        512,
        208
      ],
      "typeVersion": 1.2
    },
    {
      "parameters": {
        "url": "https://[domain]/RSS/news.xml",
        "options": {}
      },
      "id": "rss-kommersant",
      "name": "RSS — Коммерсант",
      "type": "n8n-nodes-base.rssFeedRead",
      "position": [
        512,
        400
      ],
      "typeVersion": 1.2
    },
    {
      "parameters": {},
      "id": "merge-node",
      "name": "Объединить новости",
      "type": "n8n-nodes-base.merge",
      "position": [
        752,
        304
      ],
      "typeVersion": 3
    },
    {
      "parameters": {
        "jsCode": "const keywords = [\n  'Копылов Иван',\n  'Копылов И.С.',\n  'MWS AI',\n  'лаборатория робототехники ФКН',\n  'НИУ ВШЭ робототехника'\n];\n\nconst allItems = $input.all();\nconst mentions = [];\nconst topNews = [];\n\nfor (const item of allItems) {\n  const title = (item.json.title || '').toLowerCase();\n  const content = (item.json.content || item.json.description || item.json['content:encoded'] || '').toLowerCase();\n  const text = title + ' ' + content;\n\n  const isMention = keywords.some(kw => text.includes(kw.toLowerCase()));\n\n  if (isMention) {\n    mentions.push({\n      title: item.json.title || 'Без заголовка',\n      link: item.json.link || item.json.url || '',\n      source: item.json.feed?.url?.includes('rbc') ? 'RBC' : 'Коммерсант',\n      date: item.json.pubDate || item.json.isoDate || ''\n    });\n  } else {\n    topNews.push({\n      title: item.json.title || 'Без заголовка',\n      link: item.json.link || item.json.url || '',\n      source: item.json.feed?.url?.includes('rbc') ? 'RBC' : 'Коммерсант'\n    });\n  }\n}\n\nreturn [{\n  json: {\n    hasMentions: mentions.length > 0,\n    mentions: mentions,\n    topNews: topNews.slice(0, 5)\n  }\n}];"
      },
      "id": "filter-code",
      "name": "Поиск упоминаний",
      "type": "n8n-nodes-base.code",
      "position": [
        1008,
        304
      ],
      "typeVersion": 2
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "leftValue": "",
            "caseSensitive": false,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "cond-1",
              "operator": {
                "type": "boolean",
                "operation": "true"
              },
              "leftValue": "={{ $json.hasMentions }}",
              "rightValue": true
            }
          ]
        },
        "options": {}
      },
      "id": "if-node",
      "name": "Есть упоминания?",
      "type": "n8n-nodes-base.if",
      "position": [
        1264,
        304
      ],
      "typeVersion": 2
    },
    {
      "parameters": {
        "jsCode": "const data = $input.first().json;\nconst mentions = data.mentions;\n\nlet msg = '🔔 <b>Упоминания о вас за сегодня</b>\\n';\nmsg += `📅 ${new Date().toLocaleDateString('ru-RU')}\\n\\n`;\n\nfor (const m of mentions) {\n  msg += `📰 <b>${m.source}</b>\\n`;\n  msg += `${m.title}\\n`;\n  if (m.link) msg += `🔗 <a href=\"${m.link}\">Читать</a>\\n`;\n  msg += '\\n';\n}\n\nmsg += `Найдено упоминаний: <b>${mentions.length}</b>`;\n\nreturn [{ json: { message: msg } }];"
      },
      "id": "format-mentions",
      "name": "Форматировать упоминания",
      "type": "n8n-nodes-base.code",
      "position": [
        1504,
        160
      ],
      "typeVersion": 2
    },
    {
      "parameters": {
        "jsCode": "const data = $input.first().json;\nconst top = data.topNews;\n\nlet msg = '📭 <b>Упоминаний не найдено</b>\\n';\nmsg += `📅 ${new Date().toLocaleDateString('ru-RU')}\\n\\n`;\nmsg += '📌 <b>Топ новостей за сегодня:</b>\\n\\n';\n\nfor (const n of top) {\n  msg += `📰 <b>${n.source}</b>\\n`;\n  msg += `${n.title}\\n`;\n  if (n.link) msg += `🔗 <a href=\"${n.link}\">Читать</a>\\n`;\n  msg += '\\n';\n}\n\nreturn [{ json: { message: msg } }];"
      },
      "id": "format-topnews",
      "name": "Форматировать топ новостей",
      "type": "n8n-nodes-base.code",
      "position": [
        1504,
        464
      ],
      "typeVersion": 2
    },
    {
      "parameters": {
        "chatId": "354631489",
        "text": "={{ $json.message }}",
        "additionalFields": {
          "disable_web_page_preview": true,
          "parse_mode": "HTML"
        }
      },
      "id": "telegram-mentions",
      "name": "Telegram — упоминания",
      "type": "n8n-nodes-base.telegram",
      "position": [
        1760,
        160
      ],
      "typeVersion": 1.2,
      "webhookId": "7178c57c-a94f-4888-abaf-8391904dc165",
      "credentials": {
        "telegramApi": {
          "id": "0vnrBUm3coYjYkdp",
          "name": "Telegram account"
        }
      }
    },
    {
      "parameters": {
        "chatId": "354631489",
        "text": "={{ $json.message }}",
        "additionalFields": {
          "disable_web_page_preview": true,
          "parse_mode": "HTML"
        }
      },
      "id": "telegram-topnews",
      "name": "Telegram — топ новостей",
      "type": "n8n-nodes-base.telegram",
      "position": [
        1760,
        464
      ],
      "typeVersion": 1.2,
      "webhookId": "ba24db24-3c50-4eb8-a401-5e5a0b3a2afb",
      "credentials": {
        "telegramApi": {
          "id": "0vnrBUm3coYjYkdp",
          "name": "Telegram account"
        }
      }
    }
  ],
  "pinData": {},
  "connections": {
    "RSS — RBC": {
      "main": [
        [
          {
            "node": "Объединить новости",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "RSS — Коммерсант": {
      "main": [
        [
          {
            "node": "Объединить новости",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Каждый день в 9:00": {
      "main": [
        [
          {
            "node": "RSS — RBC",
            "type": "main",
            "index": 0
          },
          {
            "node": "RSS — Коммерсант",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Есть упоминания?": {
      "main": [
        [
          {
            "node": "Форматировать упоминания",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Форматировать топ новостей",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Поиск упоминаний": {
      "main": [
        [
          {
            "node": "Есть упоминания?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Объединить новости": {
      "main": [
        [
          {
            "node": "Поиск упоминаний",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Форматировать упоминания": {
      "main": [
        [
          {
            "node": "Telegram — упоминания",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Форматировать топ новостей": {
      "main": [
        [
          {
            "node": "Telegram — топ новостей",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1",
    "saveDataErrorExecution": "all",
    "saveDataSuccessExecution": "all",
    "saveManualExecutions": true,
    "saveExecutionProgress": true,
    "callerPolicy": "workflowsFromSameOwner",
    "availableInMCP": false
  },
  "versionId": "0edd552a-1ab6-4850-8ae0-bb689b55ac08",
  "meta": {
    "templateCredsSetupCompleted": true,
    "instanceId": "e09d1f0f8b9f78e80ac70b6dc8726dd263b0b6ffc4300b0eee3b58f6da316f29"
  },
  "id": "SiatxqTMNcjzXArk",
  "tags": []
}