{
  "nodes": [
    {
      "id": "688ca90b-8d7c-4baf-9a85-3647c8be1cd5",
      "name": "Every Monday 8AM",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        960,
        480
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "weeks",
              "triggerAtDay": [
                1
              ],
              "triggerAtHour": 8
            }
          ]
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "85d0dee7-7180-4ef4-a6ae-7b9f9c33e866",
      "name": "When clicking \u2018Execute workflow\u2019",
      "type": "n8n-nodes-base.manualTrigger",
      "position": [
        960,
        640
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "aeea1ae9-28f7-4e07-b4a3-eeab52888e96",
      "name": "1. Define Subreddits",
      "type": "n8n-nodes-base.code",
      "position": [
        1200,
        480
      ],
      "parameters": {
        "jsCode": "return [\n  \"entrepreneur\",\n  \"smallbusiness\",\n  \"freelance\",\n  \"SaaS\",\n  \"startups\",\n  \"productivity\",\n  \"webdev\",\n  \"marketing\",\n  \"consulting\",\n  \"Accounting\"\n].map(s => ({ json: { subreddit: s } }));"
      },
      "typeVersion": 2
    },
    {
      "id": "59158f78-222c-4c3c-9d32-90ad90be2ac7",
      "name": "2. Fetch Reddit Posts",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        1424,
        480
      ],
      "parameters": {
        "url": "=https://www.reddit.com/r/{{ $json.subreddit }}/new.json",
        "options": {},
        "sendQuery": true,
        "sendHeaders": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "limit",
              "value": "100"
            }
          ]
        },
        "headerParameters": {
          "parameters": [
            {
              "name": "User-Agent",
              "value": "n8n-pain-miner/1.0 (automated research tool)"
            }
          ]
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "8a3f8345-f5a3-44bd-b5f7-400c8bf046f3",
      "name": "3. Filter Pain Points",
      "type": "n8n-nodes-base.code",
      "position": [
        1648,
        480
      ],
      "parameters": {
        "jsCode": "const posts = ($json.data?.children || []).map(p => p.data);\n\nconst keywords = [\n  \"i hate\",\n  \"why doesn't\",\n  \"why isn't\",\n  \"there's no tool\",\n  \"there is no tool\",\n  \"wish there was\",\n  \"no app for\",\n  \"why is there no\",\n  \"someone should build\",\n  \"why can't\",\n  \"so frustrated\",\n  \"sick of manually\",\n  \"tired of doing\",\n  \"doesn't exist\",\n  \"pain point\",\n  \"annoying that\",\n  \"is it just me\",\n  \"can't find anything\",\n  \"i need a way to\",\n  \"such a waste of time\",\n  \"why do i have to\",\n  \"manual process\",\n  \"no solution\",\n  \"nobody has built\",\n  \"looking for a tool\",\n  \"does anyone know of a\",\n  \"is there a way to automate\",\n  \"still no way to\"\n];\n\nconst filtered = posts.filter(p => {\n  const text = `${p.title} ${p.selftext || ''}`.toLowerCase();\n  return keywords.some(kw => text.includes(kw));\n});\n\nif (filtered.length === 0) return [];\n\nreturn filtered.map(p => ({\n  json: {\n    subreddit: `r/${p.subreddit}`,\n    title: p.title,\n    text: (p.selftext || '').slice(0, 400),\n    url: `https://reddit.com${p.permalink}`,\n    score: p.score,\n    comments: p.num_comments\n  }\n}));"
      },
      "typeVersion": 2
    },
    {
      "id": "2d4e662b-f03e-406d-b337-8a33ab80aa1a",
      "name": "4. Aggregate All Posts",
      "type": "n8n-nodes-base.aggregate",
      "position": [
        1856,
        480
      ],
      "parameters": {
        "options": {},
        "aggregate": "aggregateAllItemData",
        "destinationFieldName": "posts"
      },
      "typeVersion": 1
    },
    {
      "id": "b8ee7fdb-5084-4014-906a-d1f5e24cb3e0",
      "name": "5. Build AI Prompt",
      "type": "n8n-nodes-base.code",
      "position": [
        2080,
        480
      ],
      "parameters": {
        "jsCode": "const posts = $json.posts || [];\n\nif (posts.length === 0) {\n  return [{ json: { requestBody: { model: 'gpt-4o', max_tokens: 500, messages: [{ role: 'user', content: 'Say: No pain points were found this week across the monitored subreddits.' }] }, postCount: 0 } }];\n}\n\nconst postsText = posts\n  .map((p, i) => `${i + 1}. [${p.subreddit}] \"${p.title}\"\\n${p.text}\\nScore: ${p.score} | Comments: ${p.comments} | ${p.url}`)\n  .join('\\n\\n---\\n\\n');\n\nconst systemPrompt = `You are a sharp, no-fluff startup opportunity analyst. \nYou analyze Reddit posts to find genuine unmet needs and viable business opportunities. \nBe specific. Avoid generic advice. Think like a product builder, not a consultant.`;\n\nconst userPrompt = `Analyze these ${posts.length} Reddit posts collected this week. People are expressing real frustration, wishing tools existed, or describing manual processes they hate.\n\nProduce a clean, structured report with exactly these sections:\n\n\ud83d\udd25 TOP PAIN POINT CLUSTERS\nGroup similar complaints together. For each cluster:\n- Cluster name\n- The core unmet need in one sentence\n- Number of posts mentioning it\n- Which subreddits it appears in\n\n\ud83d\udca1 BEST OPPORTUNITIES\nFor each top cluster, describe:\n- What product/tool/service solves it\n- Who exactly would pay for this\n- How to validate it in 1 week (be specific)\n\n\ud83c\udfaf UNDERSERVED NICHES\nCall out 2-3 very specific pain points that seem overlooked \u2014 small but real markets with little competition\n\n\u26a1 QUICK WINS\n2-3 ideas that could be built as an MVP or validated in under 2 weeks. Be concrete.\n\nHere are the posts (${posts.length} total):\n\n${postsText}`;\n\nreturn [{\n  json: {\n    requestBody: {\n      model: \"gpt-4o\",\n      max_tokens: 2500,\n      messages: [\n        { role: \"system\", content: systemPrompt },\n        { role: \"user\", content: userPrompt }\n      ]\n    },\n    postCount: posts.length\n  }\n}];"
      },
      "typeVersion": 2
    },
    {
      "id": "60d086ed-d2d1-4789-9727-8ccc3984550c",
      "name": "6. HTTP Request @Groq",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        2272,
        480
      ],
      "parameters": {
        "url": "https://api.groq.com/openai/v1/chat/completions",
        "method": "POST",
        "options": {},
        "jsonBody": "={\n  \"model\": \"llama-3.3-70b-versatile\",\n  \"max_tokens\": 2500,\n  \"messages\": {{ JSON.stringify($('5. Build AI Prompt').first().json.requestBody.messages) }}\n}",
        "sendBody": true,
        "specifyBody": "json",
        "authentication": "predefinedCredentialType"
      },
      "credentials": {
        "groqApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.3
    },
    {
      "id": "854eb94c-dfb8-4619-9751-c7f107157606",
      "name": "7. Format Email",
      "type": "n8n-nodes-base.code",
      "position": [
        2464,
        480
      ],
      "parameters": {
        "jsCode": "//const aiContent = $json.text || $json.output || $input.first().json.text || 'AI analysis failed.';\nconst aiContent = $json.choices?.[0]?.message?.content || 'AI analysis failed.';\nconst postCount = $('5. Build AI Prompt').first().json.postCount;\nconst today = new Date().toLocaleDateString('en-US', {\n  weekday: 'long', year: 'numeric', month: 'long', day: 'numeric'\n});\n\nconst htmlBody = `\n<div style=\"font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; max-width: 700px; margin: 0 auto; color: #1a1a1a;\">\n  <div style=\"background: #0f0f0f; color: white; padding: 24px 32px; border-radius: 12px 12px 0 0;\">\n    <h1 style=\"margin:0; font-size: 22px;\">\ud83d\udd0d Reddit Pain Mining Report</h1>\n    <p style=\"margin: 8px 0 0; color: #aaa; font-size: 14px;\">${today}</p>\n  </div>\n  <div style=\"background: #f9f9f9; padding: 16px 32px; border-left: 4px solid #ff4500; margin: 0;\">\n    <p style=\"margin:0; font-size: 14px; color: #555;\"><strong>${postCount}</strong> pain-point posts analyzed across 10 subreddits this week.</p>\n  </div>\n  <div style=\"padding: 32px; background: white; border: 1px solid #eee; border-radius: 0 0 12px 12px;\">\n    <pre style=\"font-family: inherit; white-space: pre-wrap; font-size: 15px; line-height: 1.7; margin: 0;\">${aiContent}</pre>\n  </div>\n  <p style=\"text-align:center; color: #bbb; font-size: 12px; margin-top: 16px;\">\n    Generated by n8n Pain Mining Workflow &nbsp;\u00b7&nbsp; Subreddits: entrepreneur, smallbusiness, freelance, SaaS, startups, productivity, webdev, marketing, consulting, Accounting\n  </p>\n</div>\n`;\n\nreturn [{\n  json: {\n    subject: `\ud83d\udd0d Reddit Pain Mining \u2014 ${postCount} Opportunities Found (${today})`,\n    htmlBody\n  }\n}];"
      },
      "typeVersion": 2
    },
    {
      "id": "289a652b-ba27-4d5e-963d-a1bca7fb4380",
      "name": "8. Gmail. Send Email Report",
      "type": "n8n-nodes-base.gmail",
      "position": [
        2672,
        480
      ],
      "parameters": {
        "sendTo": "your@email.com",
        "message": "={{ $json.htmlBody }}",
        "options": {},
        "subject": "={{ $json.subject }}"
      },
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.1
    },
    {
      "id": "222f6927-4b9f-4000-8cc0-9bba94a62994",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        0,
        0
      ],
      "parameters": {
        "width": 880,
        "height": 1040,
        "content": "# Reddit Pain Mining \u2014 Weekly Opportunity Report\n\n### Automatically scans 10 subreddits every Monday, filters ~1000 posts for genuine frustration signals, runs AI analysis, and delivers a structured startup opportunity report to your inbox \u2014 all in under 60 seconds.\n\n---\n\n## What this workflow does\n\n1. Runs automatically every Monday at 8AM via Schedule Trigger\n2. Loops through 10 target subreddits (entrepreneur, smallbusiness, freelance, SaaS, startups, productivity, webdev, marketing, consulting, Accounting)\n3. Fetches the 100 newest posts from each subreddit using Reddit's public JSON API (no auth required)\n4. Filters posts using 27 frustration-signal keywords (\"I hate\", \"why doesn't X exist\", \"wish there was a tool\", \"sick of manually\", etc.)\n5. Aggregates all matched posts across all subreddits into a single dataset\n6. Builds a structured AI prompt embedding all posts with instructions to cluster pain points, identify opportunities, and surface underserved niches\n7. Sends the full dataset to Groq (llama-3.3-70b-versatile) for analysis\n8. Formats the AI response into a clean HTML email report\n9. Delivers the weekly report to your inbox via Gmail\n10. Each run analyzes ~1000 posts and produces actionable startup/product opportunities in under 60 seconds\n\n---\n\n\n## Setup requirements\n\n- **Groq account** \u2014 free at [console.groq.com](https://console.groq.com), create an API key, add as HTTP Header Auth credential (`Authorization: Bearer your-key-here`)\n- **Gmail OAuth2** \u2014 connect your Google account via n8n's built-in Gmail credential\n- **No Reddit auth needed** \u2014 uses public JSON API with a User-Agent header\n- Open the **Gmail node** and change the `To` field to your own email address\n\n---\n\n## Customization tips\n\n- Edit the subreddit list in the **Define Subreddits** node to target your specific niche\n- Add or remove keywords in the **Filter Pain Points** node to tune sensitivity\n- Swap the **Gmail** node for **Slack**, **Telegram**, or **Outlook** if preferred\n- Change the schedule in **Every Monday 8AM** to run daily for higher frequency\n- Replace Groq with **OpenAI GPT-4o** by swapping the HTTP Request URL and auth header\n"
      },
      "typeVersion": 1
    },
    {
      "id": "f15b1db6-0d5a-43b6-aa12-dbc3083cb255",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        928,
        0
      ],
      "parameters": {
        "color": 6,
        "width": 720,
        "height": 432,
        "content": "\n## Workflow diagram (high level)\n\n- **Schedule Trigger** \u2192 fires every Monday 8AM\n- **Define Subreddits** \u2192 outputs 10 items, one per subreddit\n- **Fetch Reddit Posts** \u2192 HTTP GET to `reddit.com/r/{subreddit}/new.json` \u2014 runs 10 times\n- **Filter Pain Points** \u2192 Code node scanning title + body for 27 keywords\n  - Match \u2192 passes forward with title, text, score, comments, URL\n  - No match \u2192 item dropped silently\n- **Aggregate All Posts** \u2192 merges all 10 subreddit results into one array\n- **Build AI Prompt** \u2192 Code node constructing full system + user prompt with all posts embedded\n- **HTTP Request \u2192 Groq** \u2192 POST to `api.groq.com/openai/v1/chat/completions`\n  - Model: `llama-3.3-70b-versatile`\n  - Returns: clustered pain points, best opportunities, underserved niches, quick wins\n- **Format Email** \u2192 Code node wrapping AI output in styled HTML template\n- **Gmail** \u2192 sends final report to your inbox\n  - Success \u2192 report delivered\n  - Gmail auth failure \u2192 reconnect OAuth credential\n\n---"
      },
      "typeVersion": 1
    },
    {
      "id": "93a4356c-3e36-459d-8800-a6174767d3d1",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2912,
        208
      ],
      "parameters": {
        "width": 656,
        "height": 576,
        "content": "\n## Example output sections\n\n### The weekly email report is structured into four sections:\n\n### \ud83d\udd25 **Top Pain Point Clusters**\n### Grouped complaints with subreddit sources and post frequency. Tells you what people keep complaining about across multiple communities.\n\n### \ud83d\udca1 **Best Opportunities**\n### For each top cluster: what to build, who would pay for it, and how to validate it in 1 week \u2014 specific and actionable.\n\n### \ud83c\udfaf **Underserved Niches**\n### 2\u20133 very specific pain points that appear overlooked \u2014 small but real markets with little competition.\n\n### \u26a1 **Quick Wins**\n### Ideas that could be built as an MVP or validated in under 2 weeks. Concrete, not generic.\n\n---\n"
      },
      "typeVersion": 1
    }
  ],
  "connections": {
    "7. Format Email": {
      "main": [
        [
          {
            "node": "8. Gmail. Send Email Report",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Every Monday 8AM": {
      "main": [
        [
          {
            "node": "1. Define Subreddits",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "5. Build AI Prompt": {
      "main": [
        [
          {
            "node": "6. HTTP Request @Groq",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "1. Define Subreddits": {
      "main": [
        [
          {
            "node": "2. Fetch Reddit Posts",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "2. Fetch Reddit Posts": {
      "main": [
        [
          {
            "node": "3. Filter Pain Points",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "3. Filter Pain Points": {
      "main": [
        [
          {
            "node": "4. Aggregate All Posts",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "6. HTTP Request @Groq": {
      "main": [
        [
          {
            "node": "7. Format Email",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "4. Aggregate All Posts": {
      "main": [
        [
          {
            "node": "5. Build AI Prompt",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "When clicking \u2018Execute workflow\u2019": {
      "main": [
        [
          {
            "node": "1. Define Subreddits",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}