{
  "name": "Cross-post from Hacker News to Mastodon",
  "nodes": [
    {
      "parameters": {
        "jsCode": "return $input.first().json.hits\n  .filter(hit => hit.title || hit.story_title)\n  .map(hit => {\n    const title = hit.title || hit.story_title || 'Senza titolo';\n    const url = hit.url || hit.story_url || '';\n    const objectID = hit.objectID;\n    return {\n      json: {\n        title,\n        url,\n        objectID,\n        message: `${title} ${url}`\n      }\n    };\n  });"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        -32,
        272
      ],
      "id": "a017ed26-7e5d-4739-900c-09545154d9f0",
      "name": "Clean arrays and add objectID"
    },
    {
      "parameters": {
        "jsCode": "const data = $getWorkflowStaticData('global');\ndata.posted = data.posted ?? {};\n\nconst objectID = String($json.objectID ?? '');\nif (!objectID) return [{ json: { ...$json, pass: true, already_posted: false } }];\n\nconst already = Boolean(data.posted[objectID]);\n\nreturn [{ json: { ...$json, already_posted: already, pass: !already } }];"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        192,
        272
      ],
      "id": "12863ddf-c217-499c-938e-b0d4dd4cf901",
      "name": "Separate already present objectIDs"
    },
    {
      "parameters": {},
      "type": "n8n-nodes-base.limit",
      "typeVersion": 1,
      "position": [
        416,
        272
      ],
      "id": "154bb79c-fac2-48f6-beb5-ea44e20b982d",
      "name": "Limit to last post"
    },
    {
      "parameters": {
        "jsCode": "const data = $getWorkflowStaticData('global');\ndata.posted = data.posted ?? {};\n\nconst objectID = String(\n  $node[\"Limit to last post\"]?.json?.objectID ??\n  $node[\"Separate already present objectIDs\"]?.json?.objectID ??\n  ''\n);\n\nif (!objectID) throw new Error('Missing objectID to save (check node names / flow)');\n\ndata.posted[objectID] = Date.now();\n\nreturn [{ json: { ...$json, saved_objectID: objectID } }];"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1088,
        176
      ],
      "id": "cf338011-9649-49a1-bdb9-5f7b5ae87f12",
      "name": "Write posted objectID to file"
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://mastodon.social/api/v1/statuses",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "Bearer YOUR_TOKEN"
            }
          ]
        },
        "sendBody": true,
        "contentType": "form-urlencoded",
        "bodyParameters": {
          "parameters": [
            {
              "name": "=status",
              "value": "={{ $json.title }} {{ $json.url }}"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        864,
        176
      ],
      "id": "5a6533ad-1fcd-47d9-8056-85652a75e0fb",
      "name": "Post to Mastodon",
      "executeOnce": true
    },
    {
      "parameters": {},
      "type": "n8n-nodes-base.noOp",
      "typeVersion": 1,
      "position": [
        864,
        368
      ],
      "id": "d547f781-fe16-4b38-9dd5-0a773a71553e",
      "name": "No Operation, do nothing"
    },
    {
      "parameters": {
        "content": "## Replace the variables in \n\n**USERNAME** in node \"Query to HN API\"\n\n**MASTODON ISTANCE URL** in node \"Post to Mastodon\".\n\n**BEARER** in node \"Post to Mastodon\" .\n*Go to your profile on Mastodon -> Setting -> New Application -> enable 'write:statuses' and use the access token*\n",
        "height": 208,
        "width": 624
      },
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        0,
        0
      ],
      "typeVersion": 1,
      "id": "2d5c56c4-f670-4c98-ab14-1df5107ebc98",
      "name": "Sticky Note"
    },
    {
      "parameters": {
        "url": "https://hn.algolia.com/api/v1/search_by_date?tags=author_USERNAME,story",
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        -256,
        272
      ],
      "id": "feeae802-3185-42cc-a1ee-32c345c6b05f",
      "name": "Query HN API"
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 3
          },
          "conditions": [
            {
              "id": "74c4ffe5-be02-4fac-b444-38316386b65b",
              "leftValue": "={{ $json.pass }}",
              "rightValue": "",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.3,
      "position": [
        640,
        272
      ],
      "id": "2edc3cbe-7c1e-4887-bcf3-5629e2aedea7",
      "name": "If new objectID"
    },
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "minutes",
              "minutesInterval": 10
            }
          ]
        }
      },
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.2,
      "position": [
        -480,
        272
      ],
      "id": "890183ee-013f-492e-b903-db9091893c28",
      "name": "Schedule Trigger (every 10 min)"
    }
  ],
  "pinData": {},
  "connections": {
    "Clean arrays and add objectID": {
      "main": [
        [
          {
            "node": "Separate already present objectIDs",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Separate already present objectIDs": {
      "main": [
        [
          {
            "node": "Limit to last post",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Limit to last post": {
      "main": [
        [
          {
            "node": "If new objectID",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Post to Mastodon": {
      "main": [
        [
          {
            "node": "Write posted objectID to file",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Query HN API": {
      "main": [
        [
          {
            "node": "Clean arrays and add objectID",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If new objectID": {
      "main": [
        [
          {
            "node": "Post to Mastodon",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "No Operation, do nothing",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Schedule Trigger (every 10 min)": {
      "main": [
        [
          {
            "node": "Query HN API",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1",
    "availableInMCP": false
  },
  "versionId": "ba348e14-b4b3-4cbb-8db6-f2a2e8408599",
  "meta": {
    "instanceId": "f415c944f2c94624df7121b6ea873f198491a7a4fde37430e7d014e5cfdfd4f0"
  },
  "id": "5YTzdA8nBTev7Nb4ZLvz_",
  "tags": []
}