{
  "nodes": [
    {
      "id": "{{NODE_ID_1}}",
      "name": "Daily 8 AM Trigger",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        -640,
        -1088
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "triggerAtHour": 8
            }
          ]
        }
      },
      "typeVersion": 1.3
    },
    {
      "id": "{{NODE_ID_2}}",
      "name": "Workflow Configuration",
      "type": "n8n-nodes-base.set",
      "position": [
        -416,
        -1088
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "{{ASSIGNMENT_ID_1}}",
              "name": "niches",
              "type": "array",
              "value": "[\"technology\", \"programming\", \"science\", \"gaming\"]"
            },
            {
              "id": "{{ASSIGNMENT_ID_2}}",
              "name": "telegramChatId",
              "type": "string",
              "value": "{{TELEGRAM_CHAT_ID_PLACEHOLDER}}"
            }
          ]
        },
        "includeOtherFields": true
      },
      "typeVersion": 3.4
    },
    {
      "id": "{{NODE_ID_3}}",
      "name": "Loop Over Niches",
      "type": "n8n-nodes-base.splitInBatches",
      "position": [
        32,
        -1088
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 3
    },
    {
      "id": "{{NODE_ID_4}}",
      "name": "Get Reddit Viral Posts",
      "type": "n8n-nodes-base.reddit",
      "position": [
        256,
        -1040
      ],
      "parameters": {
        "limit": 50,
        "filters": {
          "category": "new"
        },
        "operation": "getAll",
        "subreddit": "={{ $json.niches }}"
      },
      "credentials": {
        "redditOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "{{NODE_ID_5}}",
      "name": "Extract Post Data",
      "type": "n8n-nodes-base.set",
      "position": [
        256,
        -1232
      ],
      "parameters": {
        "options": {
          "ignoreConversionErrors": true
        },
        "assignments": {
          "assignments": [
            {
              "id": "{{ASSIGNMENT_ID_3}}",
              "name": "title",
              "type": "string",
              "value": "={{ $json.title }}"
            },
            {
              "id": "{{ASSIGNMENT_ID_4}}",
              "name": "postLink",
              "type": "string",
              "value": "={{ $json.url }}"
            },
            {
              "id": "{{ASSIGNMENT_ID_5}}",
              "name": "upvotes",
              "type": "number",
              "value": "={{ $json.ups }}"
            },
            {
              "id": "{{ASSIGNMENT_ID_6}}",
              "name": "createdAt",
              "type": "number",
              "value": "={{ new Date($json.created_utc * 1000).toLocaleDateString('en-GB').replace(/\\//g, '-') }}"
            },
            {
              "id": "{{ASSIGNMENT_ID_7}}",
              "name": "subreddit",
              "type": "string",
              "value": "={{ $json.subreddit }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "{{NODE_ID_6}}",
      "name": "AI Summarizer",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        960,
        -1232
      ],
      "parameters": {
        "text": "=Reddit Post Data:\n\n{{ $json.data.toJsonString() }}\n",
        "options": {
          "systemMessage": "=You are an AI assistant that creates concise summaries of Reddit posts.\n\nYour task is to:\n1. Analyze the provided Reddit post data including title, content, upvotes, and metadata\n2. Create a clear and engaging summary that captures the key points\n3. Highlight why the post is viral (high upvotes, interesting content)\n4. Keep the summary between 100-200 words\n5. Return the summary in the structured format provided\n\noutput in telegram formatted text"
        },
        "promptType": "define"
      },
      "typeVersion": 3.1
    },
    {
      "id": "{{NODE_ID_7}}",
      "name": "OpenAI Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        928,
        -1008
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "id",
          "value": "gpt-4o-mini"
        },
        "options": {},
        "builtInTools": {}
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.3
    },
    {
      "id": "{{NODE_ID_8}}",
      "name": "Send to Telegram",
      "type": "n8n-nodes-base.telegram",
      "position": [
        1376,
        -1232
      ],
      "parameters": {
        "text": "={{ $json.output }}",
        "chatId": "={{ $('Workflow Configuration').item.json.telegramChatId }}",
        "additionalFields": {
          "parse_mode": "Markdown"
        }
      },
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "{{NODE_ID_9}}",
      "name": "Split Out",
      "type": "n8n-nodes-base.splitOut",
      "position": [
        -192,
        -1088
      ],
      "parameters": {
        "options": {},
        "fieldToSplitOut": "niches"
      },
      "typeVersion": 1
    },
    {
      "id": "{{NODE_ID_10}}",
      "name": "Filter",
      "type": "n8n-nodes-base.filter",
      "position": [
        480,
        -1232
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 3,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "loose"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "{{CONDITION_ID_1}}",
              "operator": {
                "type": "number",
                "operation": "gt"
              },
              "leftValue": "={{ $json.upvotes }}",
              "rightValue": 500
            },
            {
              "id": "{{CONDITION_ID_2}}",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              },
              "leftValue": "={{\n  $json.upvotes > 70 &&\n  (\n    Date.now() -\n    new Date(\n      $json.createdAt.split('-').reverse().join('-')\n    ).getTime()\n  ) <= (1 * 24 * 60 * 60 * 1000)\n}}",
              "rightValue": ""
            }
          ]
        },
        "looseTypeValidation": true
      },
      "typeVersion": 2.3
    },
    {
      "id": "{{NODE_ID_11}}",
      "name": "Aggregate",
      "type": "n8n-nodes-base.aggregate",
      "position": [
        704,
        -1232
      ],
      "parameters": {
        "options": {},
        "aggregate": "aggregateAllItemData"
      },
      "typeVersion": 1
    },
    {
      "id": "{{NODE_ID_12}}",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1072,
        -1248
      ],
      "parameters": {
        "width": 400,
        "height": 464,
        "content": "## How it works\n\nThis workflow monitors Reddit for viral posts in your chosen niches and sends AI-generated summaries to Telegram. It runs daily at 8 AM, fetching the latest posts from specified subreddits, filtering for high engagement (500+ upvotes OR 70+ upvotes within 24 hours), and creating concise summaries using GPT-4o-mini.\n\n## Setup steps\n\n1. Configure your niches in the \"Workflow Configuration\" node (currently: technology, programming, science, gaming)\n2. Add your Telegram chat ID in the same node\n3. Connect your Reddit OAuth2 credentials\n4. Connect your Telegram bot credentials\n5. Adjust the schedule trigger if needed (default: daily at 8 AM)\n6. Test the workflow manually before activating"
      },
      "typeVersion": 1
    },
    {
      "id": "{{NODE_ID_13}}",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -416,
        -1280
      ],
      "parameters": {
        "color": 7,
        "width": 320,
        "content": "## Configuration\nSets up niches to monitor and Telegram destination, then splits into individual subreddit checks"
      },
      "typeVersion": 1
    },
    {
      "id": "{{NODE_ID_14}}",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        256,
        -1424
      ],
      "parameters": {
        "color": 7,
        "width": 320,
        "content": "## Quality Filter\nKeeps only viral posts meeting engagement thresholds, then aggregates for batch processing"
      },
      "typeVersion": 1
    },
    {
      "id": "{{NODE_ID_15}}",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        48,
        -816
      ],
      "parameters": {
        "color": 7,
        "width": 320,
        "content": "## Reddit Data Fetching\nLoops through each niche, fetches the 50 newest posts, and extracts relevant metadata"
      },
      "typeVersion": 1
    },
    {
      "id": "{{NODE_ID_16}}",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        704,
        -1424
      ],
      "parameters": {
        "color": 7,
        "width": 480,
        "height": 144,
        "content": "## Summary Generation\nUses AI to create concise post summaries in Telegram-formatted text and delivers to your chat"
      },
      "typeVersion": 1
    }
  ],
  "connections": {
    "Filter": {
      "main": [
        [
          {
            "node": "Aggregate",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Aggregate": {
      "main": [
        [
          {
            "node": "AI Summarizer",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Split Out": {
      "main": [
        [
          {
            "node": "Loop Over Niches",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI Summarizer": {
      "main": [
        [
          {
            "node": "Send to Telegram",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Loop Over Niches": {
      "main": [
        [
          {
            "node": "Extract Post Data",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Get Reddit Viral Posts",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract Post Data": {
      "main": [
        [
          {
            "node": "Filter",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "AI Summarizer",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Daily 8 AM Trigger": {
      "main": [
        [
          {
            "node": "Workflow Configuration",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Reddit Viral Posts": {
      "main": [
        [
          {
            "node": "Loop Over Niches",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Workflow Configuration": {
      "main": [
        [
          {
            "node": "Split Out",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}