{
  "nodes": [
    {
      "id": "426f7eae-c881-4c95-b72d-c2c2b2464740",
      "name": "1. Daily Schedule Trigger",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        -368,
        0
      ],
      "parameters": {
        "rule": {
          "interval": [
            {}
          ]
        }
      },
      "typeVersion": 1.1
    },
    {
      "id": "f477ff06-dbc4-4273-b4a0-3fac0926864e",
      "name": "Workflow Configuration",
      "type": "n8n-nodes-base.set",
      "position": [
        -144,
        0
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "rss-url",
              "name": "rssUrl",
              "type": "string",
              "value": "https://news.google.com/rss/search?q=n8n+automation+OR+n8n+tutorial+OR+AI+agents&hl=en&gl=US&ceid=US:en"
            },
            {
              "id": "line-id",
              "name": "lineUserId",
              "type": "string",
              "value": "Uf837e8117c20ab4d62d749abf2e9c919"
            },
            {
              "id": "sheet-id",
              "name": "sheetId",
              "type": "string",
              "value": "1YwuSdXcUeYCHQfqi_iZU0Rip1CzeNP3DDpycChc0rfA"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "26e6e1c8-0ceb-40f8-b294-48fccbae141a",
      "name": "2. Get Latest News",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        80,
        0
      ],
      "parameters": {
        "url": "={{ $json.rssUrl }}",
        "options": {}
      },
      "typeVersion": 4.2
    },
    {
      "id": "afb608c8-1e8c-4a08-97d3-5d896d301cec",
      "name": "Parse RSS Feed",
      "type": "n8n-nodes-base.code",
      "position": [
        304,
        0
      ],
      "parameters": {
        "jsCode": "const rssData = $node[\"2. Get Latest News\"].json.data;\nconst titles = rssData.match(/<title>(.*?)<\\/title>/g) || [];\nconst links = rssData.match(/<link>(.*?)<\\/link>/g) || [];\nconst newsList = [];\n\nfor (let i = 1; i < Math.min(titles.length, 11); i++) {\n  const cleanTitle = titles[i].replace(/<\\/?title>/g, '');\n  const cleanLink = links[i].replace(/<\\/?link>/g, '');\n  newsList.push(`Title: ${cleanTitle} \\nURL: ${cleanLink}`);\n}\n\nreturn {\n  newsDataForAI: newsList.join('\\n---\\n')\n};"
      },
      "typeVersion": 2
    },
    {
      "id": "3baf96eb-d4e8-4311-9c4e-144d3154c6d5",
      "name": "3. AI: Keyword Selection",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        512,
        0
      ],
      "parameters": {
        "text": "=Analyze the following news items and propose 3 SEO keywords and 1 article title.\n\nLatest News:\n{{ $json.newsDataForAI }}",
        "options": {
          "systemMessage": "You are a technical writer expert in n8n and workflow automation. \nPick topics most relevant to business efficiency. \n\nOutput Rules:\n1. 3 Target Keywords.\n2. Brief reason why they are important.\n3. 1 Catchy Title.\nImportant: End your response with 'Title: [Your Proposed Title]'"
        },
        "promptType": "define"
      },
      "typeVersion": 1.7
    },
    {
      "id": "50b54f7b-3d83-42fd-be62-3847f117a208",
      "name": "Store Resume Key",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        816,
        0
      ],
      "parameters": {
        "columns": {
          "value": {
            "userId": "={{ $('Workflow Configuration').item.json.lineUserId }}",
            "resumeurl": "={{ $execution.resumeUrl }}"
          },
          "mappingMode": "defineBelow",
          "matchingColumns": [
            "userId"
          ]
        },
        "options": {},
        "operation": "appendOrUpdate",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0"
        },
        "documentId": {
          "__rl": true,
          "mode": "id",
          "value": "1YwuSdXcUeYCHQfqi_iZU0Rip1CzeNP3DDpycChc0rfA"
        }
      },
      "typeVersion": 4.7
    },
    {
      "id": "9d7bdaf6-2c86-4030-a013-5108ea2be3af",
      "name": "4. LINE: KW Approval Request",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        960,
        0
      ],
      "parameters": {
        "url": "https://api.line.me/v2/bot/message/push",
        "method": "POST",
        "options": {},
        "jsonBody": "={{\nJSON.stringify({\n  \"to\": $('Workflow Configuration').item.json.lineUserId,\n  \"messages\": [\n    {\n      \"type\": \"text\",\n      \"text\": \"\ud83d\udcdd Keyword proposal ready:\\n\\n\" + $('3. AI: Keyword Selection').item.json.output + \"\\n\\nReply with 'Create Article' to start writing!\"\n    }\n  ]\n})\n}}",
        "sendBody": true,
        "specifyBody": "json",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth"
      },
      "typeVersion": 4.3
    },
    {
      "id": "5cf2cf22-826a-4579-a04d-279586254b77",
      "name": "5. Wait: KW Approval",
      "type": "n8n-nodes-base.wait",
      "position": [
        1184,
        0
      ],
      "parameters": {
        "resume": "webhook",
        "options": {
          "responseData": "Approved. Generating outline..."
        }
      },
      "typeVersion": 1.1
    },
    {
      "id": "ba726804-4cd5-4bb7-a74b-98e59155d79a",
      "name": "6. AI: Outline Creation",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        1392,
        0
      ],
      "parameters": {
        "text": "=Create a detailed SEO article outline (H2 and H3 tags) based on these keywords:\n\nKeywords:\n{{ $('3. AI: Keyword Selection').item.json.output }}",
        "options": {
          "systemMessage": "Create a structured outline. Include 3-5 H2 sections with nested H3 sub-points."
        },
        "promptType": "define"
      },
      "typeVersion": 1.7
    },
    {
      "id": "1101f7c0-7856-4c5f-8010-faf823cd39cf",
      "name": "7. LINE: Outline Approval",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        1648,
        0
      ],
      "parameters": {
        "url": "https://api.line.me/v2/bot/message/push",
        "method": "POST",
        "options": {},
        "jsonBody": "={{\nJSON.stringify({\n  \"to\": $('Workflow Configuration').item.json.lineUserId,\n  \"messages\": [\n    {\n      \"type\": \"text\",\n      \"text\": \"\ud83d\udccb Outline is ready:\\n\\n\" + $json.output + \"\\n\\nReply with 'Create Article' to begin deep writing!\"\n    }\n  ]\n})\n}}",
        "sendBody": true,
        "specifyBody": "json"
      },
      "typeVersion": 4.3
    },
    {
      "id": "49a6c734-07b5-405b-b2a3-d0eb4d469d9b",
      "name": "8. Wait: Outline Approval",
      "type": "n8n-nodes-base.wait",
      "position": [
        1840,
        0
      ],
      "parameters": {
        "resume": "webhook",
        "options": {
          "responseData": "Approved. Starting deep-dive writing loop..."
        }
      },
      "typeVersion": 1.1
    },
    {
      "id": "445c720b-577a-4d18-829f-a88fdbf412e5",
      "name": "Create Google Doc",
      "type": "n8n-nodes-base.googleDocs",
      "position": [
        2064,
        0
      ],
      "parameters": {
        "title": "={{ $('3. AI: Keyword Selection').item.json.output.split('Title:')[1] || 'Untitled Article' }}",
        "folderId": "default"
      },
      "typeVersion": 2
    },
    {
      "id": "f24d24ab-fcaa-447e-a7c2-b66ffce5ba67",
      "name": "Split Outline to Chapters",
      "type": "n8n-nodes-base.code",
      "position": [
        2272,
        0
      ],
      "parameters": {
        "jsCode": "const outline = $node[\"6. AI: Outline Creation\"].json.output;\nconst sections = outline.split(/(?=##+ )/g).filter(s => s.trim() !== \"\");\nreturn sections.map(s => { return { json: { section_content: s.trim() } }; });"
      },
      "typeVersion": 2
    },
    {
      "id": "59bbf4b1-e3d7-4583-a3f9-5deb81b5d42f",
      "name": "Chapter Loop",
      "type": "n8n-nodes-base.splitInBatches",
      "position": [
        2496,
        0
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 3
    },
    {
      "id": "e0c490fd-cee2-48e5-a7a8-6d5f1722922a",
      "name": "9. AI: Chapter Writing",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        2720,
        0
      ],
      "parameters": {
        "text": "=Please write the full content for this specific chapter:\n{{ $json.section_content }}\n\nInclude examples and actionable advice in HTML format.",
        "options": {
          "systemMessage": "You are a professional SEO copywriter. Write 400-600 words for the provided heading. Use <p>, <strong>, and <ul> tags."
        },
        "promptType": "define"
      },
      "typeVersion": 1.7
    },
    {
      "id": "5fc58b93-c6a1-4fcc-a403-f78966de187f",
      "name": "Write Chapter to Docs",
      "type": "n8n-nodes-base.googleDocs",
      "position": [
        2992,
        0
      ],
      "parameters": {
        "actionsUi": {
          "actionFields": [
            {
              "action": "insert"
            }
          ]
        },
        "operation": "update"
      },
      "typeVersion": 2
    },
    {
      "id": "51607ce9-3a7d-4ec3-8b0b-5139a0ea5bb0",
      "name": "11. Log Final Article to Sheets",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        2704,
        -176
      ],
      "parameters": {
        "columns": {
          "value": {
            "URL": "=https://docs.google.com/document/d/{{ $('Create Google Doc').item.json.id }}/edit",
            "Date": "={{ $now.format('YYYY-MM-DD') }}",
            "Title": "={{ $('Create Google Doc').item.json.name }}"
          },
          "mappingMode": "defineBelow"
        },
        "options": {},
        "operation": "append",
        "sheetName": "Article_History",
        "documentId": "={{ $('Workflow Configuration').item.json.sheetId }}"
      },
      "typeVersion": 4.5
    },
    {
      "id": "8c313149-ebe5-407b-b76e-214bb6b1bbc9",
      "name": "12. LINE: Final Notification",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        2896,
        -176
      ],
      "parameters": {
        "url": "https://api.line.me/v2/bot/message/push",
        "method": "POST",
        "options": {},
        "jsonBody": "={{\nJSON.stringify({\n  \"to\": $('Workflow Configuration').item.json.lineUserId,\n  \"messages\": [\n    {\n      \"type\": \"text\",\n      \"text\": \"\u2705 Deep writing complete!\\n\\nTitle: \" + $('Create Google Doc').item.json.name + \"\\nURL: https://docs.google.com/document/d/\" + $('Create Google Doc').item.json.id + \"/edit\"\n    }\n  ]\n})\n}}",
        "sendBody": true,
        "specifyBody": "json"
      },
      "typeVersion": 4.2
    },
    {
      "id": "f6c37328-403b-4a18-b35c-d44bd9e78235",
      "name": "LINE Webhook Receiver",
      "type": "n8n-nodes-base.webhook",
      "position": [
        -368,
        512
      ],
      "parameters": {
        "path": "line-webhook-receiver",
        "options": {},
        "httpMethod": "POST"
      },
      "typeVersion": 2.1
    },
    {
      "id": "7c4a8fae-59fe-495c-85b3-46fd4b6a1a48",
      "name": "Check if 'Create Article'",
      "type": "n8n-nodes-base.if",
      "position": [
        -112,
        512
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "string": [
            {
              "value1": "={{ $json.body.events[0].message.text }}",
              "value2": "Create Article",
              "operation": "equals"
            }
          ]
        }
      },
      "typeVersion": 2
    },
    {
      "id": "67073a2b-d837-4cba-b6c6-65c5cc9c627c",
      "name": "Get Resume URL from Sheets",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        144,
        512
      ],
      "parameters": {
        "operation": "lookup",
        "documentId": "1YwuSdXcUeYCHQfqi_iZU0Rip1CzeNP3DDpycChc0rfA"
      },
      "typeVersion": 4.5
    },
    {
      "id": "007c2ec7-b914-4b82-b650-b5eada4e803c",
      "name": "Resume Main Workflow",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        384,
        512
      ],
      "parameters": {
        "url": "={{ $json.resumeurl }}",
        "options": {}
      },
      "typeVersion": 4.2
    },
    {
      "id": "39026ed1-db91-4cd4-8f23-bbf72e52ed2d",
      "name": "OpenAI Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        480,
        160
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4.1-mini"
        },
        "options": {},
        "builtInTools": {}
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.3
    },
    {
      "id": "2f35aa9f-e1bf-4987-bfa7-c4753a2a3a5a",
      "name": "OpenAI Chat Model1",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        1408,
        176
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4.1-mini"
        },
        "options": {},
        "builtInTools": {}
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.3
    },
    {
      "id": "acb45510-8229-4a8b-9f87-e10670710838",
      "name": "OpenAI Chat Model2",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        2672,
        160
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4.1-mini"
        },
        "options": {},
        "builtInTools": {}
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.3
    },
    {
      "id": "eea30e72-00a5-4001-9dfe-5301dfe24e62",
      "name": "Sticky Note - Overview",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1216,
        -128
      ],
      "parameters": {
        "width": 664,
        "height": 822,
        "content": "# \ud83e\udd16 AI-Powered SEO Content Factory (LINE Approval & Recursive Loop)\n\nThis high-end workflow automates the editorial pipeline from niche news discovery to long-form, deep-dive SEO articles.\n\n## \ud83d\ude80 Key Features\n1. **Smart Sourcing**: Aggregates trending news via Google News RSS.\n2. **AI Strategy**: Proposes SEO keywords and titles using OpenAI GPT-4o.\n3. **Human-in-the-Loop**: Two-stage manual approval via LINE mobile commands.\n4. **Recursive Loop Writing**: Splits articles into chapters for superior depth (400-600 words per section) instead of a single output.\n5. **Automated Archiving**: Finalizes content in Google Docs and logs metadata to Sheets.\n\n## \u2699\ufe0f Setup Steps\n1. **Configuration**: Fill in your `lineUserId` and `sheetId` in the 'Workflow Configuration' node.\n2. **Google Sheets**: Create a sheet with two tabs: `Approval_Keys` (userId, resumeurl) and `Article_History` (Title, URL, Date).\n3. **LINE Setup**: Set your n8n Production URL in the LINE Developers Console and enable Webhooks.\n4. **Activate**: Toggle to 'Active' to start the daily automation."
      },
      "typeVersion": 1
    },
    {
      "id": "caccb5ea-a83f-45f6-b7e7-d9c9c3ced543",
      "name": "Sticky Note - Phase 1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -400,
        -176
      ],
      "parameters": {
        "color": 7,
        "width": 1664,
        "height": 452,
        "content": "## 1\ufe0f\u20e3 News Discovery & AI Strategy\nMonitors your niche and triggers the AI to propose a content strategy.\n- **RSS**: Fetches the latest niche trends.\n- **AI**: Generates SEO Keywords and Title candidates.\n- **Bridge**: Stores the session URL in Google Sheets so you can approve via text message."
      },
      "typeVersion": 1
    },
    {
      "id": "2bba5fa5-84e2-4684-8d29-56c3ce5af9bf",
      "name": "Sticky Note - Phase 2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -416,
        336
      ],
      "parameters": {
        "color": 5,
        "width": 1022,
        "height": 450,
        "content": "## 2\ufe0f\u20e3 LINE Webhook & Resume Logic\nThis section acts as the receiver for your mobile commands.\n- **Trigger**: Listens for the text \"Create Article\" from your LINE.\n- **Lookup**: Retrieves the unique Resume URL from Google Sheets.\n- **Resume**: Signals the main workflow to continue the next phase."
      },
      "typeVersion": 1
    },
    {
      "id": "9d6f661b-8547-46ce-a38f-930a911cb946",
      "name": "Sticky Note - Phase 3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1312,
        -176
      ],
      "parameters": {
        "color": 2,
        "width": 1852,
        "height": 468,
        "content": "## 3\ufe0f\u20e3 Deep-Dive Recursive Writing Loop\nTo prevent \"AI Fatigue\" and surface-level content, this phase loops through the outline:\n- **Chapter Writing**: Focuses on one specific H2/H3 at a time.\n- **Google Docs**: Appends content progressively to a single document.\n- **Staggered Flow**: Ensures a high word count and quality structure."
      },
      "typeVersion": 1
    }
  ],
  "connections": {
    "Chapter Loop": {
      "main": [
        [
          {
            "node": "11. Log Final Article to Sheets",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "9. AI: Chapter Writing",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Parse RSS Feed": {
      "main": [
        [
          {
            "node": "3. AI: Keyword Selection",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Store Resume Key": {
      "main": [
        [
          {
            "node": "4. LINE: KW Approval Request",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create Google Doc": {
      "main": [
        [
          {
            "node": "Split Outline to Chapters",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "3. AI: Keyword Selection",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "2. Get Latest News": {
      "main": [
        [
          {
            "node": "Parse RSS Feed",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model1": {
      "ai_languageModel": [
        [
          {
            "node": "6. AI: Outline Creation",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model2": {
      "ai_languageModel": [
        [
          {
            "node": "9. AI: Chapter Writing",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "5. Wait: KW Approval": {
      "main": [
        [
          {
            "node": "6. AI: Outline Creation",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "LINE Webhook Receiver": {
      "main": [
        [
          {
            "node": "Check if 'Create Article'",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Write Chapter to Docs": {
      "main": [
        [
          {
            "node": "Chapter Loop",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "9. AI: Chapter Writing": {
      "main": [
        [
          {
            "node": "Write Chapter to Docs",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Workflow Configuration": {
      "main": [
        [
          {
            "node": "2. Get Latest News",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "6. AI: Outline Creation": {
      "main": [
        [
          {
            "node": "7. LINE: Outline Approval",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "3. AI: Keyword Selection": {
      "main": [
        [
          {
            "node": "Store Resume Key",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "1. Daily Schedule Trigger": {
      "main": [
        [
          {
            "node": "Workflow Configuration",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "7. LINE: Outline Approval": {
      "main": [
        [
          {
            "node": "8. Wait: Outline Approval",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "8. Wait: Outline Approval": {
      "main": [
        [
          {
            "node": "Create Google Doc",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check if 'Create Article'": {
      "main": [
        [
          {
            "node": "Get Resume URL from Sheets",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Split Outline to Chapters": {
      "main": [
        [
          {
            "node": "Chapter Loop",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Resume URL from Sheets": {
      "main": [
        [
          {
            "node": "Resume Main Workflow",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "4. LINE: KW Approval Request": {
      "main": [
        [
          {
            "node": "5. Wait: KW Approval",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "11. Log Final Article to Sheets": {
      "main": [
        [
          {
            "node": "12. LINE: Final Notification",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}