{
  "name": "新着情報から必要なものだけ知らせる（役立ち情報館のテンプレート）",
  "nodes": [
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "days",
              "daysInterval": 1,
              "triggerAtHour": 8
            }
          ]
        }
      },
      "name": "毎朝8時に確認する",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.2,
      "position": [
        0,
        0
      ]
    },
    {
      "parameters": {
        "url": "https://www.chusho.meti.go.jp/rss/index.xml",
        "options": {}
      },
      "name": "新着情報を読む",
      "type": "n8n-nodes-base.rssFeedRead",
      "typeVersion": 1.1,
      "position": [
        220,
        0
      ]
    },
    {
      "parameters": {
        "jsCode": "// 「公募」「補助金」などの言葉を含む新着だけを残し、前回までに知らせたものは除く。\n// あわせて、RSSの最新の日付が古すぎる（更新が止まっている）ときは警告を出す。\nconst KEYWORDS = ['公募', '補助金', '採択', '支援策'];\nconst STALE_DAYS = 14;\nconst store = $getWorkflowStaticData('global');\nconst seen = new Set(store.seen ?? []);\nconst first = store.seen === undefined;\nconst all = $input.all().map(i => i.json);\nconst items = all.filter(j => KEYWORDS.some(k => (j.title ?? '').includes(k)));\nconst fresh = items.filter(j => !seen.has(j.link));\nfor (const j of items) seen.add(j.link);\nstore.seen = [...seen].slice(-300);\nconst send = first ? fresh.slice(0, 5) : fresh;\nconst dates = all.map(j => new Date(j.isoDate ?? j.pubDate ?? j['dc:date'] ?? 0)).filter(d => !isNaN(d));\nconst latest = dates.length ? new Date(Math.max(...dates)) : null;\nconst ageDays = latest ? Math.floor((Date.now() - latest) / 86400000) : null;\nconst lines = [];\nif (send.length) lines.push('中小企業庁の新着（補助金・公募）', ...send.map(j => `・${j.title}\\n  ${j.link}`));\nconst today = new Date().toISOString().slice(0, 10);\nif (ageDays !== null && ageDays > STALE_DAYS && store.warnedOn !== today) {\n  lines.push(`⚠ RSSの最新の記事が${ageDays}日前（${latest.toISOString().slice(0, 10)}）です。RSSの更新が止まっている可能性があるので、サイトの新着情報のページも確認してください：https://www.chusho.meti.go.jp/`);\n  store.warnedOn = today;\n}\nif (!lines.length) return [];\nreturn [{ json: { text: lines.join('\\n'), count: send.length, ageDays } }];"
      },
      "name": "新しいものだけ残す",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        440,
        0
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://hooks.slack.com/services/XXXX/XXXX/XXXX",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ text: $json.text }) }}",
        "options": {}
      },
      "name": "Slackに知らせる",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        660,
        0
      ]
    }
  ],
  "connections": {
    "新着情報を読む": {
      "main": [
        [
          {
            "node": "新しいものだけ残す",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "新しいものだけ残す": {
      "main": [
        [
          {
            "node": "Slackに知らせる",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "毎朝8時に確認する": {
      "main": [
        [
          {
            "node": "新着情報を読む",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  }
}