{
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "nodes": [
    {
      "id": "4754628a-fc33-4525-b57e-00cdf15e722b",
      "name": "Daily 9AM Trigger",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        -380,
        260
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "hours",
              "hoursInterval": 24
            }
          ]
        }
      },
      "typeVersion": 1.1
    },
    {
      "id": "dd4dea2c-609f-4b0a-9949-efd9beae6474",
      "name": "Extract Recent Posts",
      "type": "n8n-nodes-base.code",
      "position": [
        80,
        260
      ],
      "parameters": {
        "jsCode": "const posts = [];\nconst redditData = $input.first().json;\n\nif (redditData && redditData.data && redditData.data.children) {\n  for (const post of redditData.data.children) {\n    const postData = post.data;\n    \n    // Only get posts from last 24 hours\n    const postTime = new Date(postData.created_utc * 1000);\n    const yesterday = new Date(Date.now() - 24 * 60 * 60 * 1000);\n    \n    if (postTime > yesterday) {\n      posts.push({\n        title: postData.title,\n        author: postData.author,\n        url: 'https://reddit.com' + postData.permalink,\n        score: postData.score,\n        num_comments: postData.num_comments,\n        created_utc: postData.created_utc,\n        created_date: postTime.toISOString(),\n        selftext: postData.selftext || '',\n        flair: postData.link_flair_text || 'No Flair',\n        id: postData.id,\n        domain: postData.domain || 'self.n8n'\n      });\n    }\n  }\n}\n\nif (posts.length === 0) {\n  return [{ json: { noPosts: true, message: 'No new posts found in the last 24 hours' } }];\n}\n\nreturn [{ json: { posts: posts, count: posts.length } }];"
      },
      "typeVersion": 2
    },
    {
      "id": "581c97a3-03af-44da-8d1e-55d1bafdf40b",
      "name": "Prepare Email Content",
      "type": "n8n-nodes-base.code",
      "position": [
        300,
        260
      ],
      "parameters": {
        "jsCode": "const data = $input.first().json;\nconst today = new Date().toLocaleDateString('en-US', { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' });\n\nlet emailSubject;\nlet emailContent;\n\nif (data.noPosts) {\n  emailSubject = `r/n8n Daily Update - No new posts (${new Date().toLocaleDateString()})`;\n  emailContent = `\n    <div style=\"font-family: Arial, sans-serif; max-width: 600px; margin: 0 auto;\">\n      <h2 style=\"color: #ff4500; border-bottom: 2px solid #ff4500; padding-bottom: 10px;\">r/n8n Daily Update - ${today}</h2>\n      <div style=\"background-color: #f8f9fa; padding: 20px; border-radius: 5px; margin: 20px 0;\">\n        <p style=\"color: #666; font-size: 16px; margin: 0;\">No new posts were found in r/n8n in the last 24 hours.</p>\n      </div>\n      <p style=\"color: #888; font-size: 12px; margin-top: 30px; border-top: 1px solid #ddd; padding-top: 10px;\">\n        This email was automatically generated by your n8n workflow at ${new Date().toLocaleString()}.\n      </p>\n    </div>\n  `;\n} else {\n  const posts = data.posts;\n  emailSubject = `r/n8n Daily Update - ${posts.length} new post${posts.length === 1 ? '' : 's'} (${new Date().toLocaleDateString()})`;\n  \n  emailContent = `\n    <div style=\"font-family: Arial, sans-serif; max-width: 600px; margin: 0 auto;\">\n      <h2 style=\"color: #ff4500; border-bottom: 2px solid #ff4500; padding-bottom: 10px;\">r/n8n Daily Update - ${today}</h2>\n      <p style=\"color: #333; font-size: 16px;\">Found <strong>${posts.length}</strong> new post${posts.length === 1 ? '' : 's'} in r/n8n:</p>\n  `;\n  \n  for (const post of posts) {\n    const postDate = new Date(post.created_utc * 1000).toLocaleString();\n    const truncatedText = post.selftext.length > 150 ? post.selftext.substring(0, 150) + '...' : post.selftext;\n    \n    emailContent += `\n      <div style=\"border: 1px solid #e1e4e8; padding: 20px; margin: 15px 0; border-radius: 8px; background-color: #fafbfc;\">\n        <h3 style=\"margin: 0 0 10px 0;\">\n          <a href=\"${post.url}\" style=\"color: #ff4500; text-decoration: none; font-size: 18px;\">${post.title}</a>\n        </h3>\n        <div style=\"color: #666; font-size: 14px; margin-bottom: 10px;\">\n          <span style=\"margin-right: 15px;\">\ud83d\udc64 <strong>u/${post.author}</strong></span>\n          <span style=\"margin-right: 15px;\">\u2b06\ufe0f ${post.score} points</span>\n          <span style=\"margin-right: 15px;\">\ud83d\udcac ${post.num_comments} comments</span>\n          <span style=\"background-color: #0366d6; color: white; padding: 2px 6px; border-radius: 3px; font-size: 12px;\">${post.flair}</span>\n        </div>\n        ${truncatedText ? `<p style=\"color: #333; margin: 10px 0; font-size: 14px; line-height: 1.4;\">${truncatedText}</p>` : ''}\n        <div style=\"color: #888; font-size: 12px; margin-top: 10px;\">\n          <span>\ud83d\udcc5 ${postDate}</span>\n          <span style=\"margin-left: 15px;\">\ud83c\udf10 ${post.domain}</span>\n        </div>\n      </div>\n    `;\n  }\n  \n  emailContent += `\n      <div style=\"background-color: #f1f3f4; padding: 15px; border-radius: 5px; margin: 20px 0;\">\n        <p style=\"color: #555; font-size: 14px; margin: 0;\">\n          \ud83d\udca1 <strong>Tip:</strong> Click on any post title to view it on Reddit. Stay updated with the latest n8n discussions, tutorials, and community updates!\n        </p>\n      </div>\n      <p style=\"color: #888; font-size: 12px; margin-top: 30px; border-top: 1px solid #ddd; padding-top: 10px;\">\n        This email was automatically generated by your n8n workflow at ${new Date().toLocaleString()}.\n      </p>\n    </div>\n  `;\n}\n\nreturn [{\n  json: {\n    subject: emailSubject,\n    html: emailContent,\n    postCount: data.noPosts ? 0 : data.count\n  }\n}];"
      },
      "typeVersion": 2
    },
    {
      "id": "42dfce0f-6c79-4aed-a72f-c440ac92b14b",
      "name": "Send Gmail",
      "type": "n8n-nodes-base.gmail",
      "position": [
        520,
        260
      ],
      "parameters": {
        "sendTo": "<Enter email ID to receive email>",
        "message": "={{ $json.html }}",
        "options": {},
        "subject": "={{ $json.subject }}"
      },
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.1
    },
    {
      "id": "6151e67a-c067-449c-a886-0615efdbdc9a",
      "name": "Setup Instructions",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -400,
        40
      ],
      "parameters": {
        "color": 5,
        "width": 420,
        "height": 400,
        "content": "# Setup Required:\n1. Configure Gmail OAuth2 credentials\n2. Update email address in 'Send Gmail' node\n3. Adjust timezone in trigger if needed\n4. Test the workflow manually first\n\n\u2705 This workflow runs daily at 9 AM and sends recent <Topics> posts via Gmail"
      },
      "typeVersion": 1
    },
    {
      "id": "b2681cee-fce8-4a3f-ac80-232a9540c239",
      "name": "Workflow Features",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        40,
        40
      ],
      "parameters": {
        "color": 6,
        "width": 660,
        "height": 400,
        "content": "# Features:\n\ud83d\udce7 Daily email at 9 AM\n\ud83d\udd50 Only posts from last 24 hours\n\ud83d\udcdd Rich HTML email with post details\n\u2b06\ufe0f Shows upvotes, comments, and flair\n\ud83c\udfaf Handles days with no new posts\n\ud83d\udcf1 Mobile-friendly email format"
      },
      "typeVersion": 1
    },
    {
      "id": "8a6b054b-1812-4bdc-8ef7-cfcdbd5604c1",
      "name": "Scrape Reddit Page",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -160,
        260
      ],
      "parameters": {
        "url": "<Enter reddit page link>",
        "options": {
          "timeout": 10000
        },
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "User-Agent",
              "value": "<Topic of your Interest>"
            }
          ]
        }
      },
      "typeVersion": 4.2
    }
  ],
  "connections": {
    "Daily 9AM Trigger": {
      "main": [
        [
          {
            "node": "Scrape Reddit Page",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Scrape Reddit Page": {
      "main": [
        [
          {
            "node": "Extract Recent Posts",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract Recent Posts": {
      "main": [
        [
          {
            "node": "Prepare Email Content",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Prepare Email Content": {
      "main": [
        [
          {
            "node": "Send Gmail",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}