{
  "name": "Reddit High Score to Content Ideas",
  "nodes": [
    {
      "parameters": {
        "triggerTimes": {
          "item": [
            {
              "mode": "everyDay",
              "hour": 7,
              "minute": 35
            }
          ]
        }
      },
      "name": "Cron",
      "type": "n8n-nodes-base.cron",
      "typeVersion": 1,
      "position": [
        240,
        320
      ]
    },
    {
      "parameters": {
        "operation": "read",
        "documentId": "1n8TfxlswtIVqHgRg7JOkUri6BQa9NYrTTGqDZXOmGxY",
        "sheetName": "Reddit_Inbox"
      },
      "name": "Read Inbox",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4,
      "position": [
        440,
        320
      ],
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "functionCode": "const rows = $json.data || [];\nconst threshold = 25;\nconst picked = rows.filter(r => {\n  const s = Number(r.score || 0);\n  const st = (r.status || '').toLowerCase();\n  return s >= threshold && st !== 'ignored';\n});\nreturn picked.map(r => ({ json: r }));"
      },
      "name": "Filter High Score",
      "type": "n8n-nodes-base.function",
      "typeVersion": 2,
      "position": [
        640,
        320
      ]
    },
    {
      "parameters": {
        "operation": "lookup",
        "documentId": "1n8TfxlswtIVqHgRg7JOkUri6BQa9NYrTTGqDZXOmGxY",
        "sheetName": "Content_Ideas",
        "lookupColumn": "source_post_url",
        "lookupValue": "={{$json.post_url}}"
      },
      "name": "Dedup Content Ideas",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4,
      "position": [
        840,
        320
      ],
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "functionCode": "const found = $json?.matchedRow || $json?.data || null;\nif (found && Array.isArray(found) && found.length > 0) return [];\nreturn [{ json: $input.first().json }];"
      },
      "name": "If Not Already Added",
      "type": "n8n-nodes-base.function",
      "typeVersion": 2,
      "position": [
        1040,
        320
      ]
    },
    {
      "parameters": {
        "url": "={{$json.post_url.endsWith('/') ? $json.post_url + '.json' : $json.post_url + '/.json'}}",
        "options": {
          "responseFormat": "json"
        }
      },
      "name": "Fetch Thread JSON",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4,
      "position": [
        1240,
        320
      ]
    },
    {
      "parameters": {
        "functionCode": "const body = $json;\nconst post = body?.[0]?.data?.children?.[0]?.data || {};\nreturn [{\n  json: {\n    post_url: post.permalink ? 'https://www.reddit.com' + post.permalink : $input.first().json.post_url,\n    title: post.title || $input.first().json.title,\n    postText: post.selftext || ''\n  }\n}];"
      },
      "name": "Extract Post",
      "type": "n8n-nodes-base.function",
      "typeVersion": 2,
      "position": [
        1440,
        320
      ]
    },
    {
      "parameters": {
        "model": "gpt-4o-mini",
        "messages": [
          {
            "role": "system",
            "content": "Turn a Reddit question into practical content ideas for a local real estate business. Plain language. No hype. No politics."
          },
          {
            "role": "user",
            "content": "Thread: {{$json.post_url}}\nTitle: {{$json.title}}\nText: {{$json.postText}}\n\nReturn:\n- One blog title\n- A blog outline as 5-7 H2 bullets\n- Two short-form video hooks\n- One email subject line\n- Three email bullet points"
          }
        ]
      },
      "name": "OpenAI Repurpose",
      "type": "n8n-nodes-base.openAi",
      "typeVersion": 4,
      "position": [
        1640,
        320
      ],
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "functionCode": "const text = $json?.choices?.[0]?.message?.content || '';\nreturn [{\n  json: {\n    source_post_url: $input.first().json.post_url,\n    content_type: 'mixed',\n    title_or_hook: $input.first().json.title,\n    outline_or_talking_points: text,\n    priority: 'medium',\n    used: 'no',\n    created_at: new Date().toISOString()\n  }\n}];"
      },
      "name": "Format Row",
      "type": "n8n-nodes-base.function",
      "typeVersion": 2,
      "position": [
        1840,
        320
      ]
    },
    {
      "parameters": {
        "operation": "append",
        "documentId": "1n8TfxlswtIVqHgRg7JOkUri6BQa9NYrTTGqDZXOmGxY",
        "sheetName": "Content_Ideas",
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "source_post_url": "={{$json.source_post_url}}",
            "content_type": "={{$json.content_type}}",
            "title_or_hook": "={{$json.title_or_hook}}",
            "outline_or_talking_points": "={{$json.outline_or_talking_points}}",
            "priority": "={{$json.priority}}",
            "used": "={{$json.used}}",
            "created_at": "={{$json.created_at}}"
          }
        }
      },
      "name": "Append to Content_Ideas",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4,
      "position": [
        2040,
        320
      ],
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      }
    }
  ],
  "connections": {
    "Cron": {
      "main": [
        [
          {
            "node": "Read Inbox",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Read Inbox": {
      "main": [
        [
          {
            "node": "Filter High Score",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Filter High Score": {
      "main": [
        [
          {
            "node": "Dedup Content Ideas",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Dedup Content Ideas": {
      "main": [
        [
          {
            "node": "If Not Already Added",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If Not Already Added": {
      "main": [
        [
          {
            "node": "Fetch Thread JSON",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch Thread JSON": {
      "main": [
        [
          {
            "node": "Extract Post",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract Post": {
      "main": [
        [
          {
            "node": "OpenAI Repurpose",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Repurpose": {
      "main": [
        [
          {
            "node": "Format Row",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Format Row": {
      "main": [
        [
          {
            "node": "Append to Content_Ideas",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false
}