{
  "id": "pQsIsuD3FqbyPYgJ",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "Reddit Poster to Discord",
  "tags": [],
  "nodes": [
    {
      "id": "93d15b82-9ce5-4189-8913-1f29bea05a23",
      "name": "Schedule Trigger",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        -140,
        -40
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "minutes",
              "minutesInterval": 15
            }
          ]
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "4bd7becf-e6cc-4975-a098-441accc2d24b",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        120,
        -200
      ],
      "parameters": {
        "width": 600,
        "height": 440,
        "content": "## Fetch and filter reddit posts\n- Fetches latest post from a subreddit, filters out aome postIDs from mod posts.\n- Add another one if nessecary"
      },
      "typeVersion": 1
    },
    {
      "id": "2602f8be-c1c3-4403-9b61-714bbfe517e7",
      "name": "Fetch latest reddit posts",
      "type": "n8n-nodes-base.reddit",
      "position": [
        220,
        -40
      ],
      "parameters": {
        "limit": 3,
        "filters": {},
        "operation": "getAll",
        "subreddit": "news"
      },
      "credentials": {
        "redditOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "1c24ec32-b231-4139-967d-677dad046ac6",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        740,
        -200
      ],
      "parameters": {
        "color": 7,
        "width": 560,
        "height": 440,
        "content": "## Post fetching and URL extraction\n- Fetches per post data, extracts direct URL for image."
      },
      "typeVersion": 1
    },
    {
      "id": "fc5bca77-baaa-4e68-ae8c-4c246aea43bc",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1320,
        -200
      ],
      "parameters": {
        "color": 3,
        "width": 280,
        "height": 440,
        "content": "## Post To platforms\n- Send Direct image + context to social media platforms"
      },
      "typeVersion": 1
    },
    {
      "id": "38f3aa18-95db-4814-9383-801d22b66cee",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -220,
        -200
      ],
      "parameters": {
        "color": 5,
        "width": 320,
        "height": 440,
        "content": "## Scheduling\n- Set up the frequency of time to check for new posts\n"
      },
      "typeVersion": 1
    },
    {
      "id": "2331d25e-9468-4787-871f-8692ff0b8546",
      "name": "Filter out announcement posts",
      "type": "n8n-nodes-base.if",
      "position": [
        440,
        -40
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "7e7d515c-16f4-4fe7-9636-8282f53ac104",
              "operator": {
                "name": "filter.operator.equals",
                "type": "string",
                "operation": "equals"
              },
              "leftValue": "={{ $json.author_fullname }}",
              "rightValue": "t2_6l4z3"
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "a8126cca-1674-478a-878a-a69d1d002959",
      "name": "Fetch Reddit Post",
      "type": "n8n-nodes-base.reddit",
      "position": [
        800,
        -40
      ],
      "parameters": {
        "postId": "={{ $('Filter out announcement posts').item.json.id }}",
        "operation": "get",
        "subreddit": "news"
      },
      "credentials": {
        "redditOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "85e63030-ed64-4f82-a2a5-c4aeecbb4679",
      "name": "Extract Image URL",
      "type": "n8n-nodes-base.code",
      "position": [
        1100,
        -40
      ],
      "parameters": {
        "jsCode": "return items.map(item => {\n  const mediaMetadata = item.json.media_metadata;\n  if (!mediaMetadata) return { directUrl: null };\n  \n  const mediaKey = Object.keys(mediaMetadata)[0];\n  const media = mediaMetadata[mediaKey];\n  if (!media || !media.s || !media.s.u) return { directUrl: null };\n\n  let url = media.s.u.replace(/&amp;/g, '&');\n  \n  const match = url.match(/([a-z0-9]+)\\.(jpg|png|gif)/i);\n  if (!match) return { directUrl: null };\n  \n  const imageName = match[1];\n  const extension = match[2];\n  \n  const directUrl = `https://i.redd.it/${imageName}.${extension}`;\n  \n  return { directUrl };\n});\n"
      },
      "typeVersion": 2
    },
    {
      "id": "c11ecaf3-9f82-47cd-bc86-0a17b1c869db",
      "name": "Send to discord",
      "type": "n8n-nodes-base.discord",
      "position": [
        1420,
        -40
      ],
      "parameters": {
        "content": "=New post on reddit:\n{{ $('Fetch Reddit Post').item.json.title }}\n{{ $json.directUrl }}\n{{ $('Filter out announcement posts').item.json.url_overridden_by_dest }}",
        "options": {},
        "authentication": "webhook"
      },
      "credentials": {
        "discordWebhookApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2
    },
    {
      "id": "63672e8c-1ebc-44ca-845c-2a17ad0acc40",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -220,
        -380
      ],
      "parameters": {
        "color": 6,
        "width": 940,
        "content": "## SETUP\n- Set up a reddit account including reddit app, copy client/id secret.\n- Configure redirect URL as n8n base url.\n- Configure subreddit in both reddit nodes.\n- Add a webhook to discord."
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "1909d356-13e9-4045-8aed-8c640c93fe39",
  "connections": {
    "Schedule Trigger": {
      "main": [
        [
          {
            "node": "Fetch latest reddit posts",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract Image URL": {
      "main": [
        [
          {
            "node": "Send to discord",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch Reddit Post": {
      "main": [
        [
          {
            "node": "Extract Image URL",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch latest reddit posts": {
      "main": [
        [
          {
            "node": "Filter out announcement posts",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Filter out announcement posts": {
      "main": [
        [],
        [
          {
            "node": "Fetch Reddit Post",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}