{
  "nodes": [
    {
      "id": "f27e8673-589c-4b31-80e7-d5ba356f6785",
      "name": "Send a text message",
      "type": "n8n-nodes-base.telegram",
      "position": [
        1520,
        3712
      ],
      "parameters": {
        "text": "={{ $json.output }}",
        "chatId": "={{ $('Telegram Trigger').item.json.message.from.id }}",
        "additionalFields": {}
      },
      "typeVersion": 1.2
    },
    {
      "id": "166bea83-85ab-42a0-9219-2df90e9c98f5",
      "name": "Telegram Trigger",
      "type": "n8n-nodes-base.telegramTrigger",
      "position": [
        -1136,
        3712
      ],
      "parameters": {
        "updates": [
          "message"
        ],
        "additionalFields": {}
      },
      "typeVersion": 1.2
    },
    {
      "id": "0b0517e2-dbe8-44c6-8a10-07ff4b8b3c56",
      "name": "Reddit Search",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -768,
        3152
      ],
      "parameters": {
        "color": 7,
        "width": 320,
        "height": 256,
        "content": "## Cast a wide net\n\nWe're running four searches at once because Reddit ranks posts differently based on sorting method. Top shows highest upvotes, Hot tracks trending discussions, Relevance matches your keywords best, and New catches fresh content. This ensures we don't miss important posts just because they're ranked differently."
      },
      "typeVersion": 1
    },
    {
      "id": "5e19940f-baf0-444d-b16b-59e269981b2b",
      "name": "Data Processing",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        112,
        3520
      ],
      "parameters": {
        "color": 2,
        "width": 880,
        "height": 156,
        "content": "## Filter out the noise\n\nFour searches means lots of duplicates and low-quality posts. We combine everything, remove posts that appear multiple times, grab only the data we need (title, upvotes, content, etc.), then filter for posts with real engagement at least 50 upvotes and posted within the last 15 days. This keeps results fresh and relevant while cutting out spam and dead threads."
      },
      "typeVersion": 1
    },
    {
      "id": "399a0307-58cc-4307-8d8e-9d6d4f0aad31",
      "name": "AI Summary",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1072,
        3536
      ],
      "parameters": {
        "color": 4,
        "width": 560,
        "height": 156,
        "content": "## Let AI do the reading\n\nGoogle Gemini reads through all the filtered posts and creates a clean summary for you. It pulls out the key points, adds upvote counts and dates, includes direct links, and formats everything so it looks good in Telegram. No need to open dozens of tabs you get the best discussions delivered in one message."
      },
      "typeVersion": 1
    },
    {
      "id": "27a4b133-432e-4166-98b4-8007f88da966",
      "name": " Search: Top Posts",
      "type": "n8n-nodes-base.reddit",
      "position": [
        -624,
        3424
      ],
      "parameters": {
        "keyword": "={{ $json.message.text }}",
        "location": "allReddit",
        "operation": "search",
        "additionalFields": {
          "sort": "top"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "00a7cd1b-4d1b-4951-9f29-5d241e8132b4",
      "name": "Search: Hot Posts",
      "type": "n8n-nodes-base.reddit",
      "position": [
        -624,
        3632
      ],
      "parameters": {
        "keyword": "={{ $json.message.text }}",
        "location": "allReddit",
        "operation": "search",
        "additionalFields": {
          "sort": "hot"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "a2f7220c-00ac-4a19-b135-27ac3276d203",
      "name": " Search: Relevance",
      "type": "n8n-nodes-base.reddit",
      "position": [
        -608,
        3824
      ],
      "parameters": {
        "keyword": "={{ $json.message.text }}",
        "location": "allReddit",
        "operation": "search",
        "additionalFields": {
          "sort": "relevance"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "0881ad10-68d6-4369-9773-575540e47a3b",
      "name": "Search: new",
      "type": "n8n-nodes-base.reddit",
      "position": [
        -608,
        4048
      ],
      "parameters": {
        "keyword": "={{ $json.message.text }}",
        "location": "allReddit",
        "operation": "search",
        "additionalFields": {
          "sort": "new"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "98e23e96-4ced-4f88-8799-9f31cae48b12",
      "name": "Merge All Searches",
      "type": "n8n-nodes-base.merge",
      "position": [
        -96,
        3680
      ],
      "parameters": {
        "numberInputs": 4
      },
      "typeVersion": 3.2
    },
    {
      "id": "f389820d-7bef-4281-8c4f-bbd1c77da5b9",
      "name": "Remove Duplicates",
      "type": "n8n-nodes-base.code",
      "position": [
        144,
        3712
      ],
      "parameters": {
        "jsCode": "// Code node: \"Remove Duplicates\"\nconst seen = new Set();\nconst uniqueItems = [];\n\nfor (const item of $input.all()) {\n  const postId = item.json.id || item.json.name;\n  if (!seen.has(postId)) {\n    seen.add(postId);\n    uniqueItems.push(item);\n  }\n}\n\nreturn uniqueItems;"
      },
      "typeVersion": 2
    },
    {
      "id": "03b21dda-e155-4743-838e-95640e455be2",
      "name": "Extract Post Data",
      "type": "n8n-nodes-base.set",
      "position": [
        384,
        3712
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "{{ASSIGNMENT_ID_1}}",
              "name": "title",
              "type": "string",
              "value": "={{ $json.title }}"
            },
            {
              "id": "{{ASSIGNMENT_ID_2}}",
              "name": "upvotes",
              "type": "string",
              "value": "={{ $json.ups }}"
            },
            {
              "id": "{{ASSIGNMENT_ID_3}}",
              "name": "subreddit_subscribers",
              "type": "string",
              "value": "={{ $json.subreddit_subscribers }}"
            },
            {
              "id": "{{ASSIGNMENT_ID_4}}",
              "name": "subreddit",
              "type": "string",
              "value": "={{ $json.subreddit }}"
            },
            {
              "id": "{{ASSIGNMENT_ID_5}}",
              "name": "date",
              "type": "string",
              "value": "={{ DateTime.fromSeconds($json.created).toLocaleString() }}"
            },
            {
              "id": "{{ASSIGNMENT_ID_6}}",
              "name": "url",
              "type": "string",
              "value": "={{ $json.url }}"
            },
            {
              "id": "{{ASSIGNMENT_ID_7}}",
              "name": "content",
              "type": "string",
              "value": "={{ $json.selftext }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "93c4c87b-b67f-4fb7-af2f-b00d464529ad",
      "name": "Filter Quality Posts",
      "type": "n8n-nodes-base.filter",
      "position": [
        624,
        3712
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "loose"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "{{CONDITION_ID_1}}",
              "operator": {
                "type": "number",
                "operation": "gte"
              },
              "leftValue": "={{ $json.upvotes }}",
              "rightValue": 50
            },
            {
              "id": "{{CONDITION_ID_2}}",
              "operator": {
                "type": "string",
                "operation": "notEmpty",
                "singleValue": true
              },
              "leftValue": "={{ $json.content }}",
              "rightValue": ""
            },
            {
              "id": "{{CONDITION_ID_3}}",
              "operator": {
                "type": "dateTime",
                "operation": "after"
              },
              "leftValue": "={{ $json.date }}",
              "rightValue": "={{ $now.minus({days: 15}).toFormat('M/d/yyyy') }}"
            }
          ]
        },
        "looseTypeValidation": true
      },
      "typeVersion": 2.2
    },
    {
      "id": "eef7619a-102f-48e0-86be-5ff5e2b659a4",
      "name": "Combine for AI",
      "type": "n8n-nodes-base.aggregate",
      "position": [
        864,
        3712
      ],
      "parameters": {
        "options": {},
        "aggregate": "aggregateAllItemData"
      },
      "typeVersion": 1
    },
    {
      "id": "90678a9c-c85c-4739-8f34-07a191adf193",
      "name": "Generate Summary",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        1168,
        3712
      ],
      "parameters": {
        "text": "=give summary to the user with links \n\nuser keyword :-  {{ $('Telegram Trigger').item.json.message.text }}\nreddit content :- \n{{ $json.data.toJsonString() }}",
        "options": {
          "systemMessage": "You are a Reddit summarizer that creates clean, readable summaries for Telegram.\n\nFormat your response like this:\n\nHere are the top Reddit discussions about [keyword]:\n\n1. Title of post\nUpvotes: [number] | Posted: [date]\nBrief summary in 1-2 sentences\nLink: [reddit url]\n\n2. Title of post\nUpvotes: [number] | Posted: [date]\nBrief summary in 1-2 sentences\nLink: [reddit url]\n\nInclude 5-7 of the most relevant posts. Keep summaries concise and focus on the key information from each post. Use minimal formatting and avoid excessive symbols or emojis.\n\nIf no relevant posts are found, respond with: No recent popular posts found for this topic."
        },
        "promptType": "define"
      },
      "typeVersion": 2.2
    },
    {
      "id": "8424cc54-df6c-415e-9edc-5aee9b96f840",
      "name": "Google Gemini Chat Model7",
      "type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
      "position": [
        1136,
        3904
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 1
    },
    {
      "id": "e9b3d73d-6354-4a3d-a084-bb2b4a517ea7",
      "name": "Simple Memory1",
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "position": [
        1264,
        3936
      ],
      "parameters": {
        "sessionKey": "={{ $('Telegram Trigger').item.json.message.from.id }}",
        "sessionIdType": "customKey",
        "contextWindowLength": 500
      },
      "typeVersion": 1.3
    },
    {
      "id": "b0463f34-8b76-49ff-a95d-680b12eb6243",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1600,
        3568
      ],
      "parameters": {
        "width": 400,
        "height": 520,
        "content": "## Reddit Search Bot via Telegram\n\nText your Telegram bot any topic and get back an AI-summarized list of the most relevant Reddit discussions complete with upvotes, dates, and links.\n\n**Why this workflow exists:** Searching Reddit manually means opening multiple tabs, dealing with different sorting options, and reading through dozens of posts. This bot does all that work for you in seconds.\n\n**Setup (5 minutes):**\n1. Add Reddit OAuth2 credentials to all Reddit nodes\n2. Connect your Google Gemini API key\n3. Create a bot via @BotFather on Telegram, add the token here\n4. Activate workflow\n5. Message your bot with any search term\n\n**What you'll get:** Top 5-7 discussions with context, sorted by relevance and engagement."
      },
      "typeVersion": 1
    }
  ],
  "connections": {
    "Search: new": {
      "main": [
        [
          {
            "node": "Merge All Searches",
            "type": "main",
            "index": 3
          }
        ]
      ]
    },
    "Combine for AI": {
      "main": [
        [
          {
            "node": "Generate Summary",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Simple Memory1": {
      "ai_memory": [
        [
          {
            "node": "Generate Summary",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "Generate Summary": {
      "main": [
        [
          {
            "node": "Send a text message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Telegram Trigger": {
      "main": [
        [
          {
            "node": " Search: Top Posts",
            "type": "main",
            "index": 0
          },
          {
            "node": "Search: Hot Posts",
            "type": "main",
            "index": 0
          },
          {
            "node": " Search: Relevance",
            "type": "main",
            "index": 0
          },
          {
            "node": "Search: new",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract Post Data": {
      "main": [
        [
          {
            "node": "Filter Quality Posts",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Remove Duplicates": {
      "main": [
        [
          {
            "node": "Extract Post Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Search: Hot Posts": {
      "main": [
        [
          {
            "node": "Merge All Searches",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    " Search: Relevance": {
      "main": [
        [
          {
            "node": "Merge All Searches",
            "type": "main",
            "index": 2
          }
        ]
      ]
    },
    " Search: Top Posts": {
      "main": [
        [
          {
            "node": "Merge All Searches",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Merge All Searches": {
      "main": [
        [
          {
            "node": "Remove Duplicates",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Filter Quality Posts": {
      "main": [
        [
          {
            "node": "Combine for AI",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Google Gemini Chat Model7": {
      "ai_languageModel": [
        [
          {
            "node": "Generate Summary",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    }
  }
}