{
  "id": "p4ZRmVhN1UVHUDR1",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "Automate Reddit Monitoring with GPT-5-Mini, Notion, and Gmail",
  "tags": [],
  "nodes": [
    {
      "id": "ac7d73be-7fdb-4451-a29e-7f41f7d60cfe",
      "name": "Send a message",
      "type": "n8n-nodes-base.gmail",
      "position": [
        5200,
        336
      ],
      "parameters": {
        "sendTo": "user@example.com",
        "message": "={{ $json.htmlEmail }}",
        "options": {},
        "subject": "New Reddit Discussions Found"
      },
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.1
    },
    {
      "id": "d5907ad8-26a5-47ca-8a67-529fef1da906",
      "name": "Define Keywords And Subreddits",
      "type": "n8n-nodes-base.set",
      "position": [
        -704,
        0
      ],
      "parameters": {
        "mode": "raw",
        "options": {},
        "jsonOutput": "{\n  \"keywords\": [\n    \"competitor\",\n    \"intelligence\"\n  ],\n  \"search_all_subs\": false,\n  \"subreddits\": \n  [\n    \"saas\", \n    \"solopreneur\", \n    \"b2bsaas\", \n    \"indiehackers\"\n  ]\n}\n"
      },
      "typeVersion": 3.4
    },
    {
      "id": "6448edd0-f5ba-438c-911b-d6bd3c1dae4f",
      "name": "Define Relevance Criteria",
      "type": "n8n-nodes-base.set",
      "position": [
        96,
        0
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "ada8880a-aacc-43b3-b309-0a2489c588df",
              "name": "RELEVANCE_CRITERIA",
              "type": "string",
              "value": "Discussions should be related to competitive intelligence."
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "de0320b0-ce93-4b53-a3f0-94599cffbfb9",
      "name": "Define Instructions For Generating Comments",
      "type": "n8n-nodes-base.set",
      "position": [
        480,
        0
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "933d9c72-1296-45bf-a453-ae4a27c398e4",
              "name": "COMMENT_INSTRUCTIONS",
              "type": "string",
              "value": "Acknowledge the challenges users face and offer clear, helpful solutions. Generate a brief comment and don't use em dash or hyphens."
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "2aa8950e-1857-4216-9817-17e523fe7d4e",
      "name": "Schedule Trigger",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        -1184,
        0
      ],
      "parameters": {
        "rule": {
          "interval": [
            {}
          ]
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "fafe3021-78a0-4599-86ad-e0b33f213ef6",
      "name": "Split Out Keywords",
      "type": "n8n-nodes-base.splitOut",
      "position": [
        -272,
        0
      ],
      "parameters": {
        "options": {},
        "fieldToSplitOut": "keywords"
      },
      "typeVersion": 1
    },
    {
      "id": "4ebf2b56-4480-4579-af2e-d72c5f0c1efa",
      "name": "Search Reddit",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        864,
        0
      ],
      "parameters": {
        "url": "={{ $(\"Define Keywords And Subreddits\").item.json.search_all_subs\n\t? \"https://www.reddit.com/search.json\"\n\t: \"https://www.reddit.com/r/\" + $(\"Define Keywords And Subreddits\").item.json.subreddits.join(\"+\") + \"/search.json\"\n}}",
        "options": {},
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "q",
              "value": "={{ $('Split Out Keywords').item.json.keywords }}"
            },
            {
              "name": "restrict_sr",
              "value": "on"
            },
            {
              "name": "sort",
              "value": "new"
            },
            {
              "name": "t",
              "value": "day"
            }
          ]
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "c07aea1c-fdec-4c3c-a44d-50081b60326e",
      "name": "Generate HTML Email",
      "type": "n8n-nodes-base.code",
      "position": [
        4736,
        336
      ],
      "parameters": {
        "jsCode": "const keywords = $('Define Keywords And Subreddits').first().json.keywords.map(k => k.toLowerCase());\nconst subreddits = $('Define Keywords And Subreddits').first().json.subreddits;\nconst searchAllSubs = $('Define Keywords And Subreddits').first().json.search_all_subs;\nconst posts = $input.first().json.posts;\n\n// Convert subreddit list or show \"All Subreddits\"\nconst subList = searchAllSubs\n  ? 'All subreddits on Reddit'\n  : subreddits.map(s => `r/${s}`).join(', ');\n\n// Helper: highlight all keywords in a text\nfunction highlightAll(text, keywords) {\n  let result = text;\n  keywords.forEach(k => {\n    const re = new RegExp(`(${k})`, 'gi');\n    result = result.replace(re, '<span style=\"background-color:#ffeb3b; color:#111; font-weight:600;\">$1</span>');\n  });\n  return result;\n}\n\n// Helper: find first keyword occurrence and extract snippet\nfunction snippetAroundKeywords(text, keywords, radius = 120) {\n  const lower = text.toLowerCase();\n  let firstIndex = -1;\n  let matchedKeyword = null;\n\n  for (const k of keywords) {\n    const i = lower.indexOf(k);\n    if (i !== -1 && (firstIndex === -1 || i < firstIndex)) {\n      firstIndex = i;\n      matchedKeyword = k;\n    }\n  }\n\n  if (firstIndex === -1) return null;\n\n  const start = Math.max(0, firstIndex - radius);\n  const end = Math.min(text.length, firstIndex + matchedKeyword.length + radius);\n\n  let snippet = text.substring(start, end);\n  return highlightAll(snippet, keywords) + (end < text.length ? '...' : '');\n}\n\n// Start modern container\nlet htmlContent = `\n<div style=\"font-family: Inter, -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Helvetica, Arial; \n            max-width: 680px; margin: 0 auto; padding: 32px; \n            background-color: #f5f7fa; color: #2b2b2b;\">\n\n  <div style=\"text-align: center; margin-bottom: 28px;\">\n    <h2 style=\"font-size: 26px; font-weight: 700; color: #111; margin-bottom: 6px;\">\n      New Reddit Discussions Identified\n    </h2>\n    <div style=\"font-size: 15px; color: #444; margin-bottom: 4px;\">\n      Keywords tracked: <span style=\"font-weight: 600; color: #0066ff;\">${keywords.join(', ')}</span>\n    </div>\n    <div style=\"font-size: 13px; color: #666;\">\n      Checked across: <span style=\"color: #222;\">${subList}</span>\n    </div>\n  </div>\n`;\n\nposts.forEach(post => {\n  const data = post.data;\n  const relevance = post.relevanceScore;\n  const aiComment = post.generatedComment;\n\n  // Highlight keywords in title\n  let title = data.title;\n  const titleLower = title.toLowerCase();\n  keywords.forEach(k => {\n    if (titleLower.includes(k)) {\n      const re = new RegExp(`(${k})`, 'gi');\n      title = title.replace(re, '<span style=\"color:#ff5722; font-weight:700;\">$1</span>');\n    }\n  });\n\n  // Extract snippet from selftext\n  let snippet = '';\n  if (data.selftext) {\n    const extracted = snippetAroundKeywords(data.selftext, keywords);\n    snippet = extracted || data.selftext.substring(0, 180) + '...';\n  }\n\n  htmlContent += `\n    <div style=\"background-color: #ffffff; padding: 22px; margin-bottom: 22px;\n                border-radius: 14px; border: 1px solid #e4e7ec;\n                box-shadow: 0 3px 10px rgba(0,0,0,0.05);\">\n\n      <div style=\"font-size: 13px; color: #666; margin-bottom: 10px;\">\n        <span style=\"color: #ff4500; font-weight: 600;\">${data.subreddit_name_prefixed}</span>\n        \u2022 u/${data.author}\n      </div>\n\n      <a href=\"https://www.reddit.com${data.permalink}\" target=\"_blank\"\n        style=\"font-size: 18px; font-weight: 700; color: #1a73e8; line-height: 1.4; text-decoration: none;\">\n        ${title}\n      </a>\n\n      ${\n        snippet\n          ? `<p style=\"font-size: 14px; margin-top: 14px; line-height: 1.6; color:#333;\">\n               ${snippet}\n             </p>`\n          : ''\n      }\n\n      <div style=\"margin-top: 12px; font-size: 13px; color: #444;\">\n        Relevance score: <strong>${relevance}/10</strong>\n      </div>\n\n      ${\n        aiComment\n          ? `<div style=\"margin-top: 10px; padding: 12px; background: #f0f4ff; border-radius: 10px; font-size: 13px; line-height: 1.5; color: #333;\">\n               <strong>AI Generated Comment:</strong><br>${aiComment}\n             </div>`\n          : ''\n      }\n\n      <div style=\"margin-top: 16px; font-size: 12px; color: #777; padding-top: 10px; border-top: 1px solid #eee;\">\n        \ud83d\udc4d ${data.ups} \u2022 \ud83d\udcac ${data.num_comments} comments\n      </div>\n    </div>\n  `;\n});\n\nhtmlContent += `</div>`;\n\nreturn [\n  {\n    json: {\n      htmlEmail: htmlContent\n    },\n    pairedItem: 0\n  }\n];\n"
      },
      "typeVersion": 2
    },
    {
      "id": "a4c3c234-1547-441e-a433-9881f1f41b0f",
      "name": "Combine Posts Into A Single Array",
      "type": "n8n-nodes-base.code",
      "position": [
        2128,
        0
      ],
      "parameters": {
        "jsCode": "\n// Get the children array from the first input item\nconst children = $input.first().json.children;\n\n// Flatten all child arrays into a single array\nconst combinedPosts = children.flat();\n\n// Return combined posts in a single array\nreturn [{\n  json: {\n    posts: combinedPosts\n  },\n  pairedItem: 0\n}];"
      },
      "typeVersion": 2
    },
    {
      "id": "0fdb3415-37db-4b57-8179-f674ddb9d90c",
      "name": "Add Relevance Score And Comment To Each Post",
      "type": "n8n-nodes-base.code",
      "position": [
        3632,
        0
      ],
      "parameters": {
        "jsCode": "const openAIMessages = $input.all();\nconst posts = $('Split Out Posts').all();\n\nreturn openAIMessages.map((msg, i) => ({\n  json: {\n    ...posts[i].json,\n    relevanceScore: msg.json.message.content.relevance_score,\n    generatedComment: msg.json.message.content.comment\n  },\n  pairedItem: i\n}));"
      },
      "typeVersion": 2
    },
    {
      "id": "b6bf431b-c178-4b84-85fb-a5b79193f3d5",
      "name": "Add Each Post to Notion Database",
      "type": "n8n-nodes-base.notion",
      "position": [
        5200,
        0
      ],
      "parameters": {
        "title": "={{ $json.data.title }}",
        "options": {},
        "resource": "databasePage",
        "databaseId": {
          "__rl": true,
          "mode": "list",
          "value": "2adc5676-4824-80cc-bce6-e96af0ea07c1",
          "cachedResultUrl": "https://www.notion.so/2adc5676482480ccbce6e96af0ea07c1",
          "cachedResultName": "Reddit Automation"
        },
        "propertiesUi": {
          "propertyValues": [
            {
              "key": "Body|rich_text",
              "textContent": "={{ ($json.data.selftext || '').slice(0, 2000) }}"
            },
            {
              "key": "Relevance Score|number",
              "numberValue": "={{ $json.relevanceScore }}"
            },
            {
              "key": "Generated Comment|rich_text",
              "textContent": "={{ $json.generatedComment }}"
            },
            {
              "key": "Subreddit|select",
              "selectValue": "={{ $json.data.subreddit }}"
            },
            {
              "key": "Upvote Ratio|number",
              "numberValue": "={{ $json.data.upvote_ratio }}"
            },
            {
              "key": "Upvotes|number",
              "numberValue": "={{ $json.data.ups }}"
            },
            {
              "key": "Down Votes|number",
              "numberValue": "={{ $json.data.downs }}"
            },
            {
              "key": "Created At|date",
              "date": "={{ new Date($json.data.created * 1000).toISOString() }}"
            },
            {
              "key": "Post ID|rich_text",
              "textContent": "={{ $json.data.id }}"
            },
            {
              "key": "Author|rich_text",
              "textContent": "={{ $json.data.author }}"
            },
            {
              "key": "Link|url",
              "urlValue": "={{ `https://www.reddit.com${$json.data.permalink}` }}"
            }
          ]
        }
      },
      "credentials": {
        "notionApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "06869200-6a5f-470d-b141-a8c8b65944ab",
      "name": "Filter Reddit Items With No Posts",
      "type": "n8n-nodes-base.filter",
      "position": [
        1280,
        0
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "0da1a4b0-47ea-429b-92fc-28562eec5ec4",
              "operator": {
                "type": "number",
                "operation": "notEquals"
              },
              "leftValue": "={{ $json.data.dist }}",
              "rightValue": 0
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "70a03e4c-39c7-41b3-bd9d-eb2ecce6ff95",
      "name": "Aggregate Reddit Items",
      "type": "n8n-nodes-base.aggregate",
      "position": [
        1696,
        0
      ],
      "parameters": {
        "options": {},
        "fieldsToAggregate": {
          "fieldToAggregate": [
            {
              "fieldToAggregate": "data.children"
            }
          ]
        }
      },
      "typeVersion": 1
    },
    {
      "id": "8b38ccbe-71eb-443a-8647-5ead7884e8d4",
      "name": "Split Out Posts",
      "type": "n8n-nodes-base.splitOut",
      "position": [
        2560,
        0
      ],
      "parameters": {
        "options": {},
        "fieldToSplitOut": "posts"
      },
      "typeVersion": 1
    },
    {
      "id": "f9ff8d99-95d1-42e3-999f-24c139997428",
      "name": "Aggregate Posts",
      "type": "n8n-nodes-base.aggregate",
      "position": [
        4192,
        0
      ],
      "parameters": {
        "options": {},
        "aggregate": "aggregateAllItemData",
        "destinationFieldName": "posts"
      },
      "typeVersion": 1
    },
    {
      "id": "ad631fbe-3668-46e5-b0e0-39f387af73a5",
      "name": "Split Out Posts Into Items",
      "type": "n8n-nodes-base.splitOut",
      "position": [
        4736,
        0
      ],
      "parameters": {
        "options": {},
        "fieldToSplitOut": "posts"
      },
      "typeVersion": 1
    },
    {
      "id": "039c6035-b7fb-4639-a6d5-49261a53f028",
      "name": "Analyze Each Post",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "position": [
        3008,
        0
      ],
      "parameters": {
        "modelId": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-5-mini",
          "cachedResultName": "GPT-5-MINI"
        },
        "options": {},
        "messages": {
          "values": [
            {
              "content": "=Analyze the following Reddit post and provide a relevance assessment and comment strictly in JSON format. Do not include any extra text outside the JSON. \n\nUse the provided Relevance Criteria to determine how relevant the post is to the topic and assign a relevance score from 1 (low) to 10 (high). \n\nThen, using the provided Comments Instructions, generate an appropriate comment for the post.\n\nOutput format:\n\n{\n  \"reasoning\": \"brief explanation of why this post is relevant or not according to the criteria\",\n  \"relevance_score\": <number from 1 to 10>,\n  \"comment\": \"comment generated based on the instructions\"\n}\n\nInputs:\n\nRelevance Criteria: {{ $('Define Relevance Criteria').first().json.RELEVANCE_CRITERIA }}\n\nComments Instructions: {{ $('Define Instructions For Generating Comments').first().json.COMMENT_INSTRUCTIONS }}\n\nPost Title: {{ $json.data.title }}\n\nPost Body: {{ $json.data.selftext }}\n"
            }
          ]
        },
        "jsonOutput": true
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.8
    },
    {
      "id": "9c856cc1-3c5b-496f-933b-848c0b817e91",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -2064,
        -272
      ],
      "parameters": {
        "width": 480,
        "height": 880,
        "content": "## How it works\nThis workflow runs daily to scan Reddit for posts matching your keywords\u2014in specific subreddits or site-wide. It pulls new posts via the Reddit API (no credentials needed), then uses GPT-4o-mini to analyze each: scoring relevance based on your criteria and generating a tailored comment suggestion. Results save to a Notion database for tracking. Optionally, it emails a summary of findings in HTML format.\n\n## Setup steps\n1. **Keywords & Subreddits**: Edit the first node to add your search terms and subreddits (or leave blank for all Reddit).\n2. **OpenAI**: Add your API key in the AI node credentials. Customize prompts for relevance scoring (e.g., \"Score 1-10 on lead potential\") and comment generation (e.g., \"Suggest a helpful reply for engagement\").\n3. **Notion**: Duplicate the template database, get your integration secret, and paste it into the Notion node's credentials. Map fields like title, score, and comment.\n4. **Email (optional)**: Set up Gmail credentials, add your recipient email, and test the summary format.\n5. **Trigger**: Activate the schedule node for daily runs\u2014adjust time if needed.\nTest end-to-end with a manual trigger before going live.\n\n\n**Need Help with This Template? Feel free to reach out. Our DMs are always open!**\n\n**Email:** [hello@scoutnow.app](mailto:hello@scoutnow.app)\n**X (Twitter):** [@ScoutNowApp](https://x.com/ScoutNowApp) \n\nNo question is too small. We\u2019re here to help!\n"
      },
      "typeVersion": 1
    },
    {
      "id": "ae309022-618a-4f08-b4cf-de201e8d99c7",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1328,
        -272
      ],
      "parameters": {
        "color": 7,
        "width": 4064,
        "height": 880,
        "content": "## 1. Fetch Latest Posts Matching Keywords from Subreddits\n\nSet your keywords, subreddits, relevance rules, and comment generation instructions in the **Define** nodes below. To search across all subreddits instead of a selected list, switch the `search_all_subs` variable to true."
      },
      "typeVersion": 1
    },
    {
      "id": "77a24a37-6642-4d7b-9489-eec3e6da2370",
      "name": "Sticky Note6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2864,
        -272
      ],
      "parameters": {
        "color": 7,
        "width": 2640,
        "height": 880,
        "content": "## 2. Analyze Each Post Using GPT-5-Mini for Relevance and Comments, Save to Notion, and Optionally Send Email\n\nUse the following Notion page as your template: [Notion Page](https://scoutnow.notion.site/2adc5676482480ccbce6e96af0ea07c1)"
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "90ff96fc-2a72-4d5e-ada3-c16c68bf603f",
  "connections": {
    "Search Reddit": {
      "main": [
        [
          {
            "node": "Filter Reddit Items With No Posts",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Aggregate Posts": {
      "main": [
        [
          {
            "node": "Generate HTML Email",
            "type": "main",
            "index": 0
          },
          {
            "node": "Split Out Posts Into Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Split Out Posts": {
      "main": [
        [
          {
            "node": "Analyze Each Post",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Schedule Trigger": {
      "main": [
        [
          {
            "node": "Define Keywords And Subreddits",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Analyze Each Post": {
      "main": [
        [
          {
            "node": "Add Relevance Score And Comment To Each Post",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Split Out Keywords": {
      "main": [
        [
          {
            "node": "Define Relevance Criteria",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Generate HTML Email": {
      "main": [
        [
          {
            "node": "Send a message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Aggregate Reddit Items": {
      "main": [
        [
          {
            "node": "Combine Posts Into A Single Array",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Define Relevance Criteria": {
      "main": [
        [
          {
            "node": "Define Instructions For Generating Comments",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Split Out Posts Into Items": {
      "main": [
        [
          {
            "node": "Add Each Post to Notion Database",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Define Keywords And Subreddits": {
      "main": [
        [
          {
            "node": "Split Out Keywords",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Combine Posts Into A Single Array": {
      "main": [
        [
          {
            "node": "Split Out Posts",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Filter Reddit Items With No Posts": {
      "main": [
        [
          {
            "node": "Aggregate Reddit Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Define Instructions For Generating Comments": {
      "main": [
        [
          {
            "node": "Search Reddit",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Add Relevance Score And Comment To Each Post": {
      "main": [
        [
          {
            "node": "Aggregate Posts",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}