{
  "name": "n8n workflow",
  "nodes": [
    {
      "id": "060d1587-2460-4658-b2fa-429639e6da83",
      "name": "Weekly Monday 9AM Trigger",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        320,
        64
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "weeks",
              "triggerAtDay": [
                1
              ],
              "triggerAtHour": 9
            }
          ]
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "93a5b983-221c-49eb-afc9-d5bf323cc225",
      "name": "Workflow Configuration",
      "type": "n8n-nodes-base.set",
      "position": [
        544,
        64
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "id-1",
              "name": "searchKeyword",
              "type": "string",
              "value": "2025年 AIツール"
            },
            {
              "id": "id-2",
              "name": "apifyActorId",
              "type": "string",
              "value": "apify/google-search-scraper"
            },
            {
              "id": "id-3",
              "name": "notionDatabaseId",
              "type": "string",
              "value": "<__PLACEHOLDER_VALUE__Notion Database ID__>"
            },
            {
              "id": "id-4",
              "name": "slackChannel",
              "type": "string",
              "value": "<__PLACEHOLDER_VALUE__Slack Channel ID or Name__>"
            }
          ]
        },
        "includeOtherFields": true
      },
      "typeVersion": 3.4
    },
    {
      "id": "9a32f684-f69e-4e71-a6e1-8a540267aa30",
      "name": "AI Editorial Meeting - Generate 3 Article Ideas",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "position": [
        992,
        64
      ],
      "parameters": {
        "modelId": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o",
          "cachedResultName": "GPT-4O"
        },
        "options": {},
        "responses": {
          "values": [
            {
              "content": "=あなたはWebメディアの編集長です。\n以下のGoogle検索結果の情報を元に、3つの異なる切り口でブログ記事の企画を立ててください。\n\n【検索結果データ】\n{{ JSON.stringify($input.all()) }}\n\n【条件】\n必ず以下のJSON形式の配列のみを出力してください。余計な会話や挨拶は一切不要です。\n\n[\n  {\n    \"angle\": \"初心者向け\",\n    \"title\": \"記事タイトル\",\n    \"outline\": \"記事の構成案\",\n    \"image_prompt\": \"Image generation prompt in English\"\n  },\n  {\n    \"angle\": \"辛口レビュー\",\n    \"title\": \"記事タイトル\",\n    \"outline\": \"記事の構成案\",\n    \"image_prompt\": \"Image generation prompt in English\"\n  },\n  {\n    \"angle\": \"ビジネス活用\",\n    \"title\": \"記事タイトル\",\n    \"outline\": \"記事の構成案\",\n    \"image_prompt\": \"Image generation prompt in English\"\n  }\n]"
            }
          ]
        },
        "builtInTools": {}
      },
      "typeVersion": 2
    },
    {
      "id": "58c39f28-8e89-4fa2-b971-b42e4bea5438",
      "name": "Parse Article Ideas JSON",
      "type": "n8n-nodes-base.code",
      "position": [
        1344,
        64
      ],
      "parameters": {
        "jsCode": "const items = $input.all();\nif (items.length === 0) return [];\nconst item = items[0].json;\n\n// スクリーンショットの構造に合わせてデータを取得\nlet content = \"\";\n\n// パターンA: 今回のあなたの環境の構造\nif (item.output && item.output[0] && item.output[0].content && item.output[0].content[0]) {\n   content = item.output[0].content[0].text;\n} \n// パターンB: 別のパターンの構造（念のため）\nelse if (item.message && item.message.content) {\n   content = item.message.content;\n}\nelse {\n   // 見つからない場合は強制的に文字列化して探す\n   content = JSON.stringify(item);\n}\n\n// [ ] で囲まれたJSON部分を探して切り出す\nconst startIndex = content.indexOf('[');\nconst endIndex = content.lastIndexOf(']') + 1;\n\nlet ideas = [];\nif (startIndex !== -1 && endIndex !== 0) {\n  const jsonString = content.substring(startIndex, endIndex);\n  try {\n    ideas = JSON.parse(jsonString);\n  } catch (e) {\n    console.log(\"Parse Error\");\n  }\n}\n\nreturn ideas.map(idea => ({ json: idea }));"
      },
      "typeVersion": 2
    },
    {
      "id": "f940701e-d03e-4cc6-9898-615fe7ccaa41",
      "name": "AI Writer - Generate Article Content",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "position": [
        1568,
        64
      ],
      "parameters": {
        "options": {},
        "messages": {
          "values": [
            {
              "content": "=あなたはプロのライターです。以下のタイトルと構成案に基づき、ブログ記事の本文を執筆してください。\nHTMLタグは使わず、Markdown形式（見出しは ## など）で書いてください。\n\n【タイトル】\n{{ $('Parse Article Ideas JSON').item.json.title }}\n\n【構成案】\n{{ $('Parse Article Ideas JSON').item.json.outline }}"
            }
          ]
        },
        "resource": "conversation"
      },
      "typeVersion": 2
    },
    {
      "id": "0cfedf3a-64c2-4a6a-ab56-ad01e0a05321",
      "name": "DALL-E Generate Cover Image",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "position": [
        1792,
        64
      ],
      "parameters": {
        "prompt": "={{ $('Parse Article Ideas JSON').item.json.image_prompt }}",
        "options": {
          "size": "1024x1024",
          "dalleQuality": "standard",
          "returnImageUrls": true
        },
        "resource": "image"
      },
      "typeVersion": 2
    },
    {
      "id": "febe370c-ec23-41c9-a156-9620d3567d9b",
      "name": "Save Article to Notion",
      "type": "n8n-nodes-base.notion",
      "position": [
        2016,
        64
      ],
      "parameters": {
        "title": "={{ $('Parse Article Ideas JSON').item.json.title }}",
        "blockUi": {
          "blockValues": [
            {
              "url": "={{ $json.url }}",
              "type": "image"
            },
            {
              "text": {
                "text": [
                  {
                    "text": "={{ $('AI Editorial Meeting - Generate 3 Article Ideas').item.json.output[0].content[0].text }}",
                    "annotationUi": {}
                  }
                ]
              },
              "richText": true
            }
          ]
        },
        "options": {},
        "resource": "databasePage",
        "databaseId": {
          "__rl": true,
          "mode": "list",
          "value": "2b264f81-26ed-8066-8b2b-c37250fae0bf",
          "cachedResultUrl": "https://www.notion.so/2b264f8126ed80668b2bc37250fae0bf",
          "cachedResultName": "n8n sigodeki"
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "a98d8a71-b35b-4d9e-b2d9-ce039f55aa81",
      "name": "Aggregate All Articles",
      "type": "n8n-nodes-base.aggregate",
      "position": [
        2240,
        64
      ],
      "parameters": {
        "include": "specifiedFields",
        "options": {},
        "aggregate": "aggregateAllItemData",
        "fieldsToInclude": "url"
      },
      "typeVersion": 1
    },
    {
      "id": "2abfa925-0ef4-4937-a1ad-b5ad1e1127f1",
      "name": "Send Completion Notification to Slack",
      "type": "n8n-nodes-base.slack",
      "position": [
        2464,
        64
      ],
      "parameters": {
        "text": "=✅ *AI編集部レポート*\n\n3本の記事案をNotionに格納しました！\n\n{{ $json.url.map((url, i) => `${i+1}. ${url}`).join('\\n') }}\n\n確認してください 📝",
        "select": "channel",
        "channelId": {
          "__rl": true,
          "mode": "name",
          "value": "=all-n8n-shigodeki"
        },
        "otherOptions": {},
        "authentication": "oAuth2"
      },
      "typeVersion": 2.3
    },
    {
      "id": "e9a0f716-2ced-412b-9226-0e562eed6fee",
      "name": "Run an Actor and get dataset",
      "type": "@apify/n8n-nodes-apify.apify",
      "position": [
        768,
        64
      ],
      "parameters": {
        "actorId": {
          "__rl": true,
          "mode": "list",
          "value": "nFJndFXA5zjCTuudP",
          "cachedResultUrl": "https://console.apify.com/actors/nFJndFXA5zjCTuudP/input",
          "cachedResultName": "Google Search Results Scraper (apify/google-search-scraper)"
        },
        "operation": "Run actor and get dataset",
        "customBody": "={\n  \"queries\": \"{{ $('Workflow Configuration').item.json.searchKeyword }}\",\n  \"maxPagesPerQuery\": 1,\n  \"resultsPerPage\": 5,\n  \"countryCode\": \"jp\",\n  \"languageCode\": \"ja\"\n}"
      },
      "typeVersion": 1
    },
    {
      "id": "51134bd2-393a-47b4-b653-c797a90c16ac",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -400,
        -144
      ],
      "parameters": {
        "width": 640,
        "height": 368,
        "content": "##  How it works\nThis workflow automates the process of creating trend-based blog posts.\n1. **Schedule & Config**: Triggers weekly and defines the search keyword.\n2. **Research**: Scrapes Google/Social trends via Apify and analyzes them with AI.\n3. **Drafting**: Generates a full article and a DALL-E 3 cover image based on the analysis.\n4. **Publishing**: Saves the draft to Notion and notifies the team on Slack.\n\n## Setup steps\n1. **Credentials**: Configure your credentials for **Apify**, **OpenAI**, **Notion**, and **Slack**.\n2. **Configuration**: Open the **'Workflow Configuration'** node and set your target `Keyword`.\n3. **Apify Actor**: Ensure you have the Google Search Scraper actor available in your Apify account.\n4. **Notion**: Select your target Database in the Notion node."
      },
      "typeVersion": 1
    },
    {
      "id": "e1d1e49c-6ab2-44be-bb1a-ca400319d861",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        272,
        -144
      ],
      "parameters": {
        "color": 7,
        "width": 400,
        "height": 368,
        "content": "## 1. Configuration\nSet the schedule and target keywords here."
      },
      "typeVersion": 1
    },
    {
      "id": "8c44a4f7-2553-4ee4-9e4e-d4cbfb52f946",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        704,
        -144
      ],
      "parameters": {
        "color": 7,
        "width": 768,
        "height": 368,
        "content": "## 2. Research & Analysis\nScrapes trend data via Apify and structures the article plan using AI."
      },
      "typeVersion": 1
    },
    {
      "id": "948e68e7-8f68-4e1d-bb3d-75c7d336e6a7",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1504,
        -144
      ],
      "parameters": {
        "color": 7,
        "width": 432,
        "height": 368,
        "content": "## 3. Content Creation\nWrites the article body and generates a cover image."
      },
      "typeVersion": 1
    },
    {
      "id": "9fd4835a-b845-4084-8b63-e08fe5765617",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1968,
        -144
      ],
      "parameters": {
        "color": 7,
        "width": 624,
        "height": 368,
        "content": "## 4. Save & Notify\nSaves the draft to Notion and sends a report to Slack."
      },
      "typeVersion": 1
    }
  ],
  "connections": {
    "Aggregate All Articles": {
      "main": [
        [
          {
            "node": "Send Completion Notification to Slack",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Save Article to Notion": {
      "main": [
        [
          {
            "node": "Aggregate All Articles",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Workflow Configuration": {
      "main": [
        [
          {
            "node": "Run an Actor and get dataset",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Parse Article Ideas JSON": {
      "main": [
        [
          {
            "node": "AI Writer - Generate Article Content",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Weekly Monday 9AM Trigger": {
      "main": [
        [
          {
            "node": "Workflow Configuration",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "DALL-E Generate Cover Image": {
      "main": [
        [
          {
            "node": "Save Article to Notion",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Run an Actor and get dataset": {
      "main": [
        [
          {
            "node": "AI Editorial Meeting - Generate 3 Article Ideas",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI Writer - Generate Article Content": {
      "main": [
        [
          {
            "node": "DALL-E Generate Cover Image",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI Editorial Meeting - Generate 3 Article Ideas": {
      "main": [
        [
          {
            "node": "Parse Article Ideas JSON",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {},
  "active": false
}
