{
  "id": "R84XmkBzgZQgQPbH",
  "meta": {
    "instanceId": "a244e08ca65e768d1cee097a486ef066f1968b077e055f21a34efe4e78c40e76",
    "templateCredsSetupCompleted": true
  },
  "name": "RSS Publish to FB & Insta",
  "tags": [
    {
      "id": "AOZlNztgqiOQKd6j",
      "name": "n8n Creators",
      "createdAt": "2025-09-28T11:02:15.227Z",
      "updatedAt": "2025-09-28T11:02:15.227Z"
    },
    {
      "id": "ay7TXKzjrY5N4ZmD",
      "name": "Bangla",
      "createdAt": "2025-07-08T20:11:28.278Z",
      "updatedAt": "2025-07-08T20:11:28.278Z"
    }
  ],
  "nodes": [
    {
      "id": "f69c226a-fb49-40eb-8e56-330381747a0d",
      "name": "RSS Feed Trigger",
      "type": "n8n-nodes-base.rssFeedReadTrigger",
      "position": [
        -3248,
        -640
      ],
      "parameters": {
        "feedUrl": "[INSERT_YOUR_RSS_CHANNEL_URL_HERE]",
        "pollTimes": {
          "item": [
            {
              "mode": "everyHour"
            }
          ]
        }
      },
      "typeVersion": 1
    },
    {
      "id": "3f91cf1a-9f1e-412f-a0c6-dbc89aff9296",
      "name": "Get row(s) in sheet",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        -3024,
        -640
      ],
      "parameters": {
        "options": {},
        "filtersUI": {
          "values": [
            {
              "lookupValue": "={{ $json.link }}",
              "lookupColumn": "URL"
            }
          ]
        },
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1VdLMMjlMb03BhUJHt1q51yG8yJOK0Cvv5pJJa8tBMLk/edit#gid=0",
          "cachedResultName": "Arkusz1"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1VdLMMjlMb03BhUJHt1q51yG8yJOK0Cvv5pJJa8tBMLk",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1VdLMMjlMb03BhUJHt1q51yG8yJOK0Cvv5pJJa8tBMLk/edit?usp=drivesdk",
          "cachedResultName": "Artykuły RSS"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "credential-id",
          "name": "googleSheetsOAuth2Api Credential"
        }
      },
      "typeVersion": 4.6,
      "alwaysOutputData": true
    },
    {
      "id": "b7154b6a-f6df-4f49-b3c8-6660f43a7a08",
      "name": "If",
      "type": "n8n-nodes-base.if",
      "position": [
        -2800,
        -640
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "5ba488f6-049b-48f0-8ec0-8e97eb3fe90d",
              "operator": {
                "type": "object",
                "operation": "empty",
                "singleValue": true
              },
              "leftValue": "={{ $item(\"0\").$node[\"Get row(s) in sheet\"].json }}",
              "rightValue": ""
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "01e742d6-6d5d-4b9f-a5d7-67af777a9059",
      "name": "HTTP Request",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -2576,
        -640
      ],
      "parameters": {
        "url": "={{ $('RSS Feed Trigger').item.json.link }}",
        "options": {}
      },
      "typeVersion": 4.2
    },
    {
      "id": "48877dcf-d9e7-431b-8d57-1cca347b40e6",
      "name": "HTML",
      "type": "n8n-nodes-base.html",
      "position": [
        -2352,
        -640
      ],
      "parameters": {
        "options": {},
        "operation": "extractHtmlContent",
        "extractionValues": {
          "values": [
            {
              "cssSelector": "*",
              "skipSelectors": "a, img"
            }
          ]
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "d989d9d1-9f63-424e-bf30-bcc6cb73598e",
      "name": "Basic LLM Chain",
      "type": "@n8n/n8n-nodes-langchain.chainLlm",
      "position": [
        -2128,
        -640
      ],
      "parameters": {
        "text": "={{ $json[''] }}",
        "batching": {},
        "messages": {
          "messageValues": [
            {
              "message": "Step into the role of a technology blog editor. You will receive an article. Your task is to summarize it in 5 sentences. Use the English language. At the end, encourage discussion or comments in a natural way. Skip unnecessary remarks. You may use a maximum of 3 emojis in the entire post. Add the source (name of the service) and 5 hashtags."
            }
          ]
        },
        "promptType": "define"
      },
      "typeVersion": 1.7
    },
    {
      "id": "66784d91-6263-44db-8723-176527cd93aa",
      "name": "Append row in sheet",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        1040,
        -640
      ],
      "parameters": {
        "columns": {
          "value": {
            "URL": "={{ $('RSS Feed Trigger').first().json.link }}",
            "Image URL": "={{ $json.public_image_url }}",
            "FB Post ID": "={{ $json.facebook_post_id }}",
            "FB Post URL": "={{ $json.facebook_post_url }}",
            "Treść posta ": "={{ $('Basic LLM Chain').first().json.text }}",
            "Instagram Post ID": "={{ $json.instagram_post_id }}",
            "Instagram Post URL": "={{ $json.instagram_post_url }}"
          },
          "schema": [
            {
              "id": "URL",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "URL",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Treść posta ",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Treść posta ",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Image URL",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Image URL",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "FB Post URL",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "FB Post URL",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "FB Post ID",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "FB Post ID",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Instagram Post URL",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Instagram Post URL",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Instagram Post ID",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Instagram Post ID",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "append",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1VdLMMjlMb03BhUJHt1q51yG8yJOK0Cvv5pJJa8tBMLk/edit#gid=0",
          "cachedResultName": "Arkusz1"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1VdLMMjlMb03BhUJHt1q51yG8yJOK0Cvv5pJJa8tBMLk",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1VdLMMjlMb03BhUJHt1q51yG8yJOK0Cvv5pJJa8tBMLk/edit?usp=drivesdk",
          "cachedResultName": "Artykuły RSS"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "credential-id",
          "name": "googleSheetsOAuth2Api Credential"
        }
      },
      "typeVersion": 4.6
    },
    {
      "id": "4119845f-0a1d-498a-88b2-2a86e357a3df",
      "name": "Post to Instagram",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -304,
        -544
      ],
      "parameters": {
        "url": "https://graph.facebook.com/v23.0/[INSERT_YOUR_SITE_ID]/media",
        "method": "POST",
        "options": {},
        "sendBody": true,
        "contentType": "form-urlencoded",
        "sendHeaders": true,
        "authentication": "predefinedCredentialType",
        "bodyParameters": {
          "parameters": [
            {
              "name": "image_url",
              "value": "={{ $json.public_url }}"
            },
            {
              "name": "caption",
              "value": "={{ $('Basic LLM Chain').item.json.text }}"
            }
          ]
        },
        "headerParameters": {
          "parameters": [
            {
              "name": "Content-Type",
              "value": "application/x-www-form-urlencoded"
            }
          ]
        },
        "nodeCredentialType": "facebookGraphApi"
      },
      "credentials": {
        "facebookGraphApi": {
          "id": "credential-id",
          "name": "facebookGraphApi Credential"
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "189295a3-794c-4171-ad92-e13efad5789d",
      "name": "Post to Instagram1",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -80,
        -544
      ],
      "parameters": {
        "url": "https://graph.facebook.com/v23.0/[INSERT_YOUR_SITE_ID]/media_publish",
        "method": "POST",
        "options": {},
        "sendBody": true,
        "contentType": "form-urlencoded",
        "sendHeaders": true,
        "authentication": "predefinedCredentialType",
        "bodyParameters": {
          "parameters": [
            {
              "name": "creation_id",
              "value": "={{ $json.id }}"
            }
          ]
        },
        "headerParameters": {
          "parameters": [
            {
              "name": "Content-Type",
              "value": "application/x-www-form-urlencoded"
            }
          ]
        },
        "nodeCredentialType": "facebookGraphApi"
      },
      "credentials": {
        "facebookGraphApi": {
          "id": "credential-id",
          "name": "facebookGraphApi Credential"
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "f7764612-2c59-4015-9841-acf33026e825",
      "name": "Get Post URL",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        144,
        -544
      ],
      "parameters": {
        "url": "={{ `https://graph.facebook.com/${$json.fbApiVersion || 'v19.0'}/${$json.id}?fields=permalink` }}",
        "options": {},
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "facebookGraphApi"
      },
      "credentials": {
        "facebookGraphApi": {
          "id": "credential-id",
          "name": "facebookGraphApi Credential"
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "a4383011-8e48-46ef-8094-cc656b6eccc0",
      "name": "Send a photo message",
      "type": "n8n-nodes-base.telegram",
      "position": [
        1264,
        -640
      ],
      "webhookId": "b91ccd44-0556-4582-bf42-f338737efbc4",
      "parameters": {
        "file": "={{ $json['Image URL'] }}",
        "chatId": "=1187348254",
        "operation": "sendPhoto",
        "additionalFields": {
          "caption": "=New post published!\n\nFacebooka Link:\n{{ $json['FB Post URL'] }}\nInstagram Link:\n{{ $json['Instagram Post URL'] }}"
        }
      },
      "credentials": {
        "telegramApi": {
          "id": "credential-id",
          "name": "telegramApi Credential"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "cbee4ab0-e47f-4543-be38-1f748d88142b",
      "name": "Basic LLM Chain1",
      "type": "@n8n/n8n-nodes-langchain.chainLlm",
      "position": [
        -1776,
        -640
      ],
      "parameters": {
        "text": "=Generate a prompt for Open AI Image Generation to create a professional image for social media (Facebook, Instagram) on this TOPIC: {{ $json.text }}. The image should be engaging, suitable for a technology blog, for example photorealistic shots of experts in the office, in the field, photos of specific devices, technologies, or concepts described in the article. The images should be aesthetic and evoke positive feelings. The subject and appearance of the image must be closely related to the given TOPIC. Remember, this is a prompt that will later be pasted into the body in the API, so avoid elements that may break the JSON (you cannot use quotation marks). Generate only the prompt, without introduction, without quotation marks. The entire message must be less than 1000 characters.",
        "batching": {},
        "promptType": "define"
      },
      "typeVersion": 1.7
    },
    {
      "id": "38b9755e-5f67-4a43-aebf-a6445f0cf488",
      "name": "Anthropic Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatAnthropic",
      "position": [
        -2064,
        -416
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "claude-sonnet-4-20250514",
          "cachedResultName": "Claude 4 Sonnet"
        },
        "options": {}
      },
      "credentials": {
        "anthropicApi": {
          "id": "credential-id",
          "name": "anthropicApi Credential"
        }
      },
      "typeVersion": 1.3
    },
    {
      "id": "b86f044c-4183-4d33-998c-587c9079e1c3",
      "name": "Google Gemini Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
      "position": [
        -1712,
        -416
      ],
      "parameters": {
        "options": {}
      },
      "credentials": {
        "googlePalmApi": {
          "id": "credential-id",
          "name": "googlePalmApi Credential"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "8b1284be-d6df-4578-9847-fcf58662870f",
      "name": "Post to Facebook",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -288,
        -768
      ],
      "parameters": {
        "url": "https://graph.facebook.com/v19.0/[INSERT_YOUR_SITE_ID]/photos",
        "method": "POST",
        "options": {},
        "sendBody": true,
        "contentType": "form-urlencoded",
        "sendHeaders": true,
        "authentication": "predefinedCredentialType",
        "bodyParameters": {
          "parameters": [
            {
              "name": "caption",
              "value": "={{ $('Basic LLM Chain').item.json.text }} \n\nŹródło: {{ $('RSS Feed Trigger').item.json.link }}"
            },
            {
              "name": "=url",
              "value": "={{ $json.public_url }}"
            },
            {}
          ]
        },
        "headerParameters": {
          "parameters": [
            {
              "name": "Content-Type",
              "value": "application/x-www-form-urlencoded"
            }
          ]
        },
        "nodeCredentialType": "facebookGraphApi"
      },
      "credentials": {
        "facebookGraphApi": {
          "id": "credential-id",
          "name": "facebookGraphApi Credential"
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "9b6166e7-caff-439e-9fb1-a28ef9296090",
      "name": "Merge",
      "type": "n8n-nodes-base.merge",
      "position": [
        592,
        -640
      ],
      "parameters": {},
      "typeVersion": 3.2
    },
    {
      "id": "c6d0cbd6-cbed-458a-a630-804b1fe34ca8",
      "name": "Send a text message",
      "type": "n8n-nodes-base.telegram",
      "position": [
        1488,
        -640
      ],
      "webhookId": "93dd7833-b953-4dd8-abdc-b1ff22ccd7b2",
      "parameters": {
        "text": "=Original article:\n{{ $('RSS Feed Trigger').first().json.title }}\n{{ $('RSS Feed Trigger').first().json.link }}\n\n\nPost Content:\n\n{{ $('Basic LLM Chain').first().json.text }}\n",
        "chatId": "123456789",
        "additionalFields": {
          "appendAttribution": false
        }
      },
      "credentials": {
        "telegramApi": {
          "id": "credential-id",
          "name": "telegramApi Credential"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "ec53d477-6b08-4bb9-9db4-13d566013d2c",
      "name": "Generate an image",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "position": [
        -1424,
        -640
      ],
      "parameters": {
        "model": "gpt-image-1",
        "prompt": "={{ $json.text }}",
        "options": {
          "size": "1024x1024",
          "quality": "high"
        },
        "resource": "image"
      },
      "credentials": {
        "openAiApi": {
          "id": "credential-id",
          "name": "openAiApi Credential"
        }
      },
      "typeVersion": 1.8
    },
    {
      "id": "f1818d78-9245-46d3-b338-c13d14b7f396",
      "name": "Edit Fields",
      "type": "n8n-nodes-base.set",
      "position": [
        -1200,
        -640
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "bb4004a1-9c8b-4603-b8ed-227e50940f87",
              "name": "filename",
              "type": "string",
              "value": "={{$now.toMillis()}}.png"
            }
          ]
        },
        "includeOtherFields": true
      },
      "typeVersion": 3.4
    },
    {
      "id": "f20e1497-7241-4c54-8b17-057050fc2e06",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -3296,
        -752
      ],
      "parameters": {
        "width": 176,
        "height": 272,
        "content": "## RSS Trigger\nPaste a RSS channel URL here"
      },
      "typeVersion": 1
    },
    {
      "id": "2039fdb6-004b-404e-b09f-5b32add81dfe",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -3056,
        -752
      ],
      "parameters": {
        "width": 384,
        "height": 272,
        "content": "## Filtering used content\nIf the URL has not been processed (row does not exist in Google Sheets), the workflow will proceed."
      },
      "typeVersion": 1
    },
    {
      "id": "299eddc0-de9d-4fea-a4de-96ed7a4f9c79",
      "name": "Upload to Supabase (uses credentials)",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -752,
        -640
      ],
      "parameters": {
        "url": "={{ ($json.supabase_base_url || '').trim().replace(/\\/+$/,'') + '/storage/v1/object/' + ($json.bucket || 'social-media-ai-generated') + '/' + $json.filename }}",
        "method": "POST",
        "options": {},
        "sendBody": true,
        "contentType": "binaryData",
        "sendHeaders": true,
        "authentication": "predefinedCredentialType",
        "headerParameters": {
          "parameters": [
            {
              "name": "content-type",
              "value": "=={{ $binary.data?.mimeType || 'application/octet-stream' }}"
            },
            {
              "name": "x-upsert",
              "value": "true"
            }
          ]
        },
        "inputDataFieldName": "data",
        "nodeCredentialType": "supabaseApi"
      },
      "credentials": {
        "supabaseApi": {
          "id": "credential-id",
          "name": "supabaseApi Credential"
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "54d2a31b-ef8b-4ea6-a900-519170db3876",
      "name": "Supabase Config",
      "type": "n8n-nodes-base.set",
      "position": [
        -976,
        -640
      ],
      "parameters": {
        "options": {
          "stripBinary": false
        },
        "assignments": {
          "assignments": [
            {
              "id": "1dbcf7c4-2e01-4df2-874e-93868b74a519",
              "name": "bucket",
              "type": "string",
              "value": "[INSERT_THE_NAME_OF_YOUR_BUCKET]"
            },
            {
              "id": "4e88d63f-01de-4265-8271-fd0ed637b5fd",
              "name": "filename",
              "type": "string",
              "value": "={{ $json.filename }}"
            },
            {
              "id": "b5579b42-bc9e-44d9-b997-2f1e505c0692",
              "name": "link_ttl_seconds",
              "type": "string",
              "value": "3600"
            },
            {
              "id": "ab260017-3161-4cbf-ad86-84d23a94e780",
              "name": "supabase_base_url",
              "type": "string",
              "value": "[INSERT_YOUR_SUPABASE_URL]"
            }
          ]
        },
        "includeOtherFields": true
      },
      "typeVersion": 3.4
    },
    {
      "id": "32b6f415-a837-4783-a76c-795276d3c4e4",
      "name": "Supabase Public URL",
      "type": "n8n-nodes-base.set",
      "position": [
        -528,
        -640
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "cdc9fb52-3d91-4af4-9ff4-8fb15e6543c4",
              "name": "public_url",
              "type": "string",
              "value": "={{ $node[\"Supabase Config\"].json.supabase_base_url.toString().trim().replace(/\\/+$/,'') + \"/storage/v1/object/public/\" + encodeURIComponent($node[\"Supabase Config\"].json.bucket) + \"/\" + encodeURIComponent($node[\"Supabase Config\"].json.filename) }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "57519156-2fe8-4f0b-8841-968eeeb443ca",
      "name": "Image pipeline",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1280,
        -752
      ],
      "parameters": {
        "width": 888,
        "height": 268,
        "content": "## Saving Image to Supabase\nUploads the image to Supabase Storage.\nSet your bucket name in the Set node or via JSON."
      },
      "typeVersion": 1
    },
    {
      "id": "a1eda551-4d5f-4504-97bb-c4186366e10f",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -2592,
        -752
      ],
      "parameters": {
        "width": 384,
        "height": 272,
        "content": "## Text extraction\nThe contents of the article gets extracted."
      },
      "typeVersion": 1
    },
    {
      "id": "b5691de0-99a5-401a-9972-603e0f38aaf9",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -2176,
        -752
      ],
      "parameters": {
        "width": 320,
        "height": 480,
        "content": "## Post generation\nA summary of the article is written by Claude."
      },
      "typeVersion": 1
    },
    {
      "id": "68990808-cec4-46fd-ae73-ea4c2045dce9",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1824,
        -752
      ],
      "parameters": {
        "width": 528,
        "height": 480,
        "content": "## Image Generation\nA prompt for image generation is created based on the Claude's summary and an image is generated in the OpenAI Image Generator."
      },
      "typeVersion": 1
    },
    {
      "id": "bc9b5229-bbe2-49a4-840f-d2fd9c38b5a6",
      "name": "Build Facebook URL",
      "type": "n8n-nodes-base.code",
      "position": [
        368,
        -736
      ],
      "parameters": {
        "jsCode": "// Pobierz post_id prosto z node 'Post to Facebook'\nconst post_id = $node[\"Post to Facebook\"].json.post_id || '';\n\n// Twój username/slug strony FB\nconst facebookUsername = 'SmartCampAI';\n\n// Wyciągnij tylko właściwy postId (po podkreślniku, jeśli występuje)\nconst parts = post_id.split('_');\nconst postId = parts.length > 1 ? parts[1] : post_id;\n\n// Buduj link\nconst facebookPostUrl = postId\n  ? `https://facebook.com/${facebookUsername}/posts/${postId}`\n  : '';\n\nreturn {\n  json: {\n    facebook_post_id: postId,\n    facebook_post_url: facebookPostUrl,\n    facebook_published: !!postId\n  }\n};"
      },
      "typeVersion": 2
    },
    {
      "id": "3cb5a6d0-dada-4485-bce7-88ef3fb7b4da",
      "name": "Build Instagram URL",
      "type": "n8n-nodes-base.code",
      "position": [
        368,
        -544
      ],
      "parameters": {
        "jsCode": "const mediaId = $json.id || '';\nreturn {\n  json: {\n    instagram_post_id: mediaId,\n    instagram_post_url: $input.first().json.permalink, // nie mamy shortcode :(\n    instagram_published: !!mediaId\n  }\n};\n"
      },
      "typeVersion": 2
    },
    {
      "id": "da68cf9b-f4ef-417b-9747-a5a98a535e72",
      "name": "Collect Important Data",
      "type": "n8n-nodes-base.code",
      "position": [
        816,
        -640
      ],
      "parameters": {
        "jsCode": "// Bezpieczny getter do $()\n// Zwraca { json: {} } gdy node nie istnieje lub nie ma danych\nfunction pickNodeFirst(name) {\n  try {\n    const arr = $(name).all();\n    if (Array.isArray(arr) && arr.length > 0) return arr[0];\n  } catch (e) {\n    // node nie istnieje – zwróć pusty obiekt, żeby nie wywalić wykonania\n  }\n  return { json: {} };\n}\n\nfunction safeGet(obj, path, def = null) {\n  try {\n    const parts = Array.isArray(path) ? path : String(path).split('.');\n    return parts.reduce((acc, key) => (acc && acc[key] !== undefined ? acc[key] : def), obj);\n  } catch {\n    return def;\n  }\n}\n\n// Skróty do node’ów (UŻYJ DOKŁADNYCH NAZW)\nconst fb   = pickNodeFirst('Build Facebook URL');\nconst insta= pickNodeFirst('Build Instagram URL');\nconst llm  = pickNodeFirst('Basic LLM Chain');\nconst rss  = pickNodeFirst('RSS Feed Trigger');\nconst pub  = pickNodeFirst('Supabase Public URL'); // <-- poprawiona nazwa\n\nreturn [\n  {\n    json: {\n      facebook_post_id:   safeGet(fb,   ['json','facebook_post_id'],   null),\n      facebook_post_url:  safeGet(fb,   ['json','facebook_post_url'],  null),\n      facebook_published: safeGet(fb,   ['json','published'],          false),\n\n      instagram_post_id:  safeGet(insta,['json','instagram_post_id'],  null),\n      instagram_post_url: safeGet(insta,['json','instagram_post_url'], null),\n      instagram_published:safeGet(insta,['json','published'],          false),\n\n      caption:            safeGet(llm,  ['json','caption'],            null),\n      title:              safeGet(rss,  ['json','title'],              null),\n\n      public_image_url:   safeGet(pub,  ['json','public_url'],   null) // URL z Supabase\n    }\n  }\n];"
      },
      "typeVersion": 2
    },
    {
      "id": "b612862f-f41c-42ef-9691-65de8f59d93f",
      "name": "Image pipeline1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -368,
        -944
      ],
      "parameters": {
        "width": 888,
        "height": 556,
        "content": "# Posting to Facebook & Instagram\nRemember to paste your unique site ID"
      },
      "typeVersion": 1
    },
    {
      "id": "d5acbcda-aa09-4b0a-98e4-45cdb6cd1f49",
      "name": "Image pipeline2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        544,
        -864
      ],
      "parameters": {
        "width": 648,
        "height": 412,
        "content": "# Collect and organize data\nInformation about generated posts gets saved to Google Sheets."
      },
      "typeVersion": 1
    },
    {
      "id": "a242af6a-6b20-4051-a5ad-736c76ff8559",
      "name": "Image pipeline3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1216,
        -864
      ],
      "parameters": {
        "width": 472,
        "height": 412,
        "content": "# Send a report via Telegram\nInformation about published posts gets sent by a Telegram bot."
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "6fbcafe1-f983-4a9a-95c6-df50b6ce31d5",
  "connections": {
    "If": {
      "main": [
        [
          {
            "node": "HTTP Request",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTML": {
      "main": [
        [
          {
            "node": "Basic LLM Chain",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Merge": {
      "main": [
        [
          {
            "node": "Collect Important Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Edit Fields": {
      "main": [
        [
          {
            "node": "Supabase Config",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Post URL": {
      "main": [
        [
          {
            "node": "Build Instagram URL",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTTP Request": {
      "main": [
        [
          {
            "node": "HTML",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Basic LLM Chain": {
      "main": [
        [
          {
            "node": "Basic LLM Chain1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Supabase Config": {
      "main": [
        [
          {
            "node": "Upload to Supabase (uses credentials)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Basic LLM Chain1": {
      "main": [
        [
          {
            "node": "Generate an image",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Post to Facebook": {
      "main": [
        [
          {
            "node": "Build Facebook URL",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "RSS Feed Trigger": {
      "main": [
        [
          {
            "node": "Get row(s) in sheet",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Generate an image": {
      "main": [
        [
          {
            "node": "Edit Fields",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Post to Instagram": {
      "main": [
        [
          {
            "node": "Post to Instagram1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Build Facebook URL": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Post to Instagram1": {
      "main": [
        [
          {
            "node": "Get Post URL",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Append row in sheet": {
      "main": [
        [
          {
            "node": "Send a photo message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Build Instagram URL": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Get row(s) in sheet": {
      "main": [
        [
          {
            "node": "If",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Supabase Public URL": {
      "main": [
        [
          {
            "node": "Post to Instagram",
            "type": "main",
            "index": 0
          },
          {
            "node": "Post to Facebook",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Anthropic Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "Basic LLM Chain",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Send a photo message": {
      "main": [
        [
          {
            "node": "Send a text message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Collect Important Data": {
      "main": [
        [
          {
            "node": "Append row in sheet",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Google Gemini Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "Basic LLM Chain1",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Upload to Supabase (uses credentials)": {
      "main": [
        [
          {
            "node": "Supabase Public URL",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}