{
  "id": "QNYxNb9yixArNlbl",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "Reddit Brand Engagement with AI Comment Generation and Slack Notifications",
  "tags": [],
  "nodes": [
    {
      "id": "5e277ec9-9333-4e87-b33f-99d4c7c68dd2",
      "name": "Schedule Trigger",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        -384,
        336
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "triggerAtHour": 19
            }
          ]
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "b24e5eab-b578-4beb-9044-f93ef116da25",
      "name": "OpenAI Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        656,
        768
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4.1-mini"
        },
        "options": {}
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "eda03da7-34e1-4312-9adf-f07f66eda110",
      "name": "Should Reply?",
      "type": "n8n-nodes-base.filter",
      "position": [
        1088,
        336
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "af95826b-3b04-45cc-91a1-278f52675625",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              },
              "leftValue": "={{ $json.output.should_reply }}",
              "rightValue": ""
            },
            {
              "id": "5afa483f-e2d8-44d8-8ece-28704bf92435",
              "operator": {
                "type": "string",
                "operation": "notEquals"
              },
              "leftValue": "={{ $json.output.post_id }}",
              "rightValue": "1mchxl3"
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "92bf8f16-42ab-4875-b9a5-2a7d015dbe9d",
      "name": "Structured Output Parser",
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "position": [
        720,
        560
      ],
      "parameters": {
        "autoFix": true,
        "jsonSchemaExample": "{\n  \"post_id\": \"1mchxl3\",\n  \"should_reply\": true,\n  \"comment\": \"This is a seriously impressive setup \u2014 the way you've combined voice-based AI with backend workflow automation is next-level for marketing ops. I've been experimenting with similar automation for SDR workflows where AI handles lead research and cold outreach sequencing, and the trick is always keeping context and personalization tight while scaling. Sounds like your n8n agent\u2019s memory system is doing heavy lifting there. Maybe check out Astra? It helped automate outreach and follow-ups in a way that felt both personal and scalable. Curious how you handle error scenarios when the voice agent misinterprets a request?\"\n}"
      },
      "typeVersion": 1.3
    },
    {
      "id": "eefe45d8-a44e-41ad-9681-cf7a6aefc891",
      "name": "Comment AI Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        512,
        336
      ],
      "parameters": {
        "text": "=post_id: {{ $json.id }}\ntitle:  {{ $json.title }}\ntext: {{ $json.selftext }}\ncomments_count: {{ $json.num_comments }}\nupvote_ratio: {{ $json.upvote_ratio }}\nsubreddit: {{ $json.subreddit }}\npost_url: {{ $json.url }}",
        "options": {
          "systemMessage": "=You are a Reddit engagement assistant for 'Wati Astra' (AI SDR Agent). Remember - 'Wati Astra' is meant to act as an inbound SDR Agent for website owners that helps website owners capture more qualified leads for their business. It is intended to save their human SDRs time, not replace them.\n\nYour primary goal is authenticity and trust-building, not aggressive promotion.\n\nCore Engagement Filters\nReply only if all are true:\n* Subreddit is sales/startup-friendly and not hostile to tools\n* Upvote ratio > 0.7\n\nReply only if at least 2 are true:\n* OP is struggling with SDRs, lead qualification, handling website enquiries, or sales scaling\n* Post has < 20 comments\n* Discussion is about solving, not just venting\n\nSkip if:\n* \u201cWhat tools do you use?\u201d type post (oversaturated)\n* Subreddit bans tool mentions\n* OP is ranting without asking for help\n\nComment Writing Style\n* Tone: like a startup founder/SDR sharing personal experience with a peer.\n* Length: 3\u20136 sentences.\n* Language: casual, slightly messy, human. Use lowercase, slang, or light humor.\n* Authenticity markers: small imperfections (\u201cidk\u201d, \u201cngl\u201d, \u201cfwiw\u201d).\n* Structure:\n   1. Empathy \u2192 \u201cbeen there, it\u2019s rough\u2026\u201d\n   2. Share insight/experience\n   3. Offer thought or subtle suggestion\n   4. End with open question\n\nWati Astra Mention Strategy\n* Mention Wati Astra in 30\u201340% of replies\n* Never in the first sentence\n* Frame as:\n   * Personal experience: \u201cwe ended up trying Wati Astra\u2026\u201d\n   * Peer suggestion: \u201csomeone recommended Wati Astra\u2026\u201d\n* Always mix Wati Astra with other advice\n* Ensure that the replies include some newlines (\\n) as well, so it's well formatted.\n\nOutput Specification\n\n{\n  \"post_id\": \"[[post_id]]\",\n  \"should_reply\": true/false,\n  \"reason\": \"[[short explanation of why/why not]]\",\n  \"comment\": \"[[authentic, Reddit-style comment, 3\u20136 sentences]]\"\n}",
          "returnIntermediateSteps": false
        },
        "promptType": "define",
        "hasOutputParser": true
      },
      "typeVersion": 2.1
    },
    {
      "id": "19f803ed-b56d-4bab-8922-15973c487eb4",
      "name": "Send a message",
      "type": "n8n-nodes-base.slack",
      "position": [
        1312,
        336
      ],
      "parameters": {
        "text": "=Post: https://www.reddit.com/r/CRM/comments/{{ $json.output.post_id }}/\n\nComment Idea: \n{{ $json.output.comment }}",
        "select": "channel",
        "channelId": {
          "__rl": true,
          "mode": "list",
          "value": "C09DJJZ3DHQ",
          "cachedResultName": "astra-reddit-post-comment-ideas"
        },
        "otherOptions": {
          "includeLinkToWorkflow": false
        },
        "authentication": "oAuth2"
      },
      "credentials": {
        "slackOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.3
    },
    {
      "id": "8936a6b1-93e9-48c7-8e8b-90cdeb1bc03a",
      "name": "AI_Agents",
      "type": "n8n-nodes-base.reddit",
      "position": [
        -160,
        144
      ],
      "parameters": {
        "limit": 5,
        "keyword": "Sales, Sales Automation, Website Leads, Lead Qualification",
        "operation": "search",
        "subreddit": "AI_Agents",
        "additionalFields": {
          "sort": "new"
        }
      },
      "credentials": {
        "redditOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "27e78e10-6864-40ce-850a-9bb562e919dd",
      "name": "Automate",
      "type": "n8n-nodes-base.reddit",
      "position": [
        -160,
        -48
      ],
      "parameters": {
        "limit": 5,
        "keyword": "AI Agent, AI, Automation, Sales",
        "operation": "search",
        "subreddit": "Automate",
        "additionalFields": {
          "sort": "new"
        }
      },
      "credentials": {
        "redditOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "35dce505-c015-49c3-ba02-f2a55ecf68a4",
      "name": "salesdevelopment",
      "type": "n8n-nodes-base.reddit",
      "position": [
        -160,
        336
      ],
      "parameters": {
        "limit": 5,
        "keyword": "AI Agent, AI, Automation",
        "operation": "search",
        "subreddit": "salesdevelopment",
        "additionalFields": {
          "sort": "new"
        }
      },
      "credentials": {
        "redditOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "0a09670e-d75b-46f8-a942-9773ef1db9ec",
      "name": "SaaSSales",
      "type": "n8n-nodes-base.reddit",
      "position": [
        -160,
        528
      ],
      "parameters": {
        "limit": 5,
        "keyword": "AI, Automation, AI Agents",
        "operation": "search",
        "subreddit": "Automate",
        "additionalFields": {
          "sort": "new"
        }
      },
      "credentials": {
        "redditOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "98d9a563-7757-4192-8569-7b662f16d52d",
      "name": "Merge",
      "type": "n8n-nodes-base.merge",
      "position": [
        64,
        288
      ],
      "parameters": {
        "numberInputs": 5
      },
      "typeVersion": 3.2
    },
    {
      "id": "b1f40ba7-e8a2-4295-86e8-6449ba20e612",
      "name": "AskMarketing",
      "type": "n8n-nodes-base.reddit",
      "position": [
        -160,
        720
      ],
      "parameters": {
        "limit": 5,
        "keyword": "AI, Automation, AI Agents",
        "operation": "search",
        "subreddit": "AskMarketing",
        "additionalFields": {}
      },
      "credentials": {
        "redditOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "a9de7c09-d999-463c-9999-62857c91947a",
      "name": "Filter last 24 hour posts",
      "type": "n8n-nodes-base.code",
      "position": [
        288,
        336
      ],
      "parameters": {
        "jsCode": "// Debug version - let's see what we're working with\nconst inputData = $input.all();\n\n// Log the input structure for debugging\nconsole.log('Number of input items:', inputData.length);\nconsole.log('Full input structure:', JSON.stringify(inputData, null, 2));\n\n// Calculate 24 hours ago timestamp\nconst now = Math.floor(Date.now() / 1000);\nconst twentyFourHoursAgo = now - (24 * 60 * 60);\n\nconsole.log('Current timestamp:', now);\nconsole.log('24 hours ago timestamp:', twentyFourHoursAgo);\n\nlet postsToFilter = [];\n\n// Try different ways to access the data\ntry {\n  if (inputData.length === 0) {\n    console.log('ERROR: No input data received');\n    return [{ json: { error: 'No input data' } }];\n  }\n\n  // Check if first item contains an array\n  if (inputData[0] && inputData[0].json && Array.isArray(inputData[0].json)) {\n    postsToFilter = inputData[0].json;\n    console.log('Found array in first item, length:', postsToFilter.length);\n  }\n  // Check if we have multiple items\n  else if (inputData.length > 1) {\n    postsToFilter = inputData.map(item => item.json);\n    console.log('Using multiple items as posts, count:', postsToFilter.length);\n  }\n  // Check if single post object\n  else if (inputData[0] && inputData[0].json) {\n    postsToFilter = [inputData[0].json];\n    console.log('Using single post object');\n  }\n\n  console.log('Posts to filter:', postsToFilter.length);\n  \n  // Show sample of what we're filtering\n  if (postsToFilter.length > 0) {\n    console.log('Sample post structure:', JSON.stringify(postsToFilter[0], null, 2));\n  }\n\n  // Filter posts\n  const recentPosts = postsToFilter.filter(post => {\n    if (!post || !post.created_utc) {\n      console.log('Post missing created_utc field:', post);\n      return false;\n    }\n    \n    const isRecent = post.created_utc >= twentyFourHoursAgo;\n    console.log(`Post ${post.id || 'unknown'}: ${post.created_utc} >= ${twentyFourHoursAgo} = ${isRecent}`);\n    return isRecent;\n  });\n\n  console.log('Filtered posts count:', recentPosts.length);\n\n  // Return results\n  if (recentPosts.length === 0) {\n    return [{ json: { message: 'No posts from last 24 hours found', total_posts_checked: postsToFilter.length } }];\n  }\n\n  return recentPosts.map(post => ({ json: post }));\n\n} catch (error) {\n  console.log('ERROR:', error.message);\n  return [{ json: { error: error.message, input_received: inputData } }];\n}"
      },
      "typeVersion": 2
    }
  ],
  "active": true,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "f210b4da-2ac5-4ae3-a746-9766b5a18be6",
  "connections": {
    "Merge": {
      "main": [
        [
          {
            "node": "Filter last 24 hour posts",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Automate": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI_Agents": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "SaaSSales": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 3
          }
        ]
      ]
    },
    "AskMarketing": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 4
          }
        ]
      ]
    },
    "Should Reply?": {
      "main": [
        [
          {
            "node": "Send a message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Comment AI Agent": {
      "main": [
        [
          {
            "node": "Should Reply?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Schedule Trigger": {
      "main": [
        [
          {
            "node": "Automate",
            "type": "main",
            "index": 0
          },
          {
            "node": "AI_Agents",
            "type": "main",
            "index": 0
          },
          {
            "node": "salesdevelopment",
            "type": "main",
            "index": 0
          },
          {
            "node": "SaaSSales",
            "type": "main",
            "index": 0
          },
          {
            "node": "AskMarketing",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "salesdevelopment": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 2
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "Comment AI Agent",
            "type": "ai_languageModel",
            "index": 0
          },
          {
            "node": "Structured Output Parser",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Structured Output Parser": {
      "ai_outputParser": [
        [
          {
            "node": "Comment AI Agent",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    },
    "Filter last 24 hour posts": {
      "main": [
        [
          {
            "node": "Comment AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}