{
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "nodes": [
    {
      "id": "11611fbd-a8ff-45bf-aca8-15fea2cead1b",
      "name": "video scraping",
      "type": "n8n-nodes-base.set",
      "position": [
        -2352,
        -80
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "bf1ec381-c09a-4e4d-b299-414d197e0c1e",
              "name": "data",
              "type": "string",
              "value": "={{ $json.data }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "8fcc67ba-589a-4fd0-8a81-bc4b8f28632e",
      "name": "Genrate download link",
      "type": "n8n-nodes-base.code",
      "position": [
        -2128,
        -80
      ],
      "parameters": {
        "jsCode": "const html = $json[\"data\"]; // replace 'data' with your actual field name\nconst match = html.match(/https:\\/\\/dl\\.snapcdn\\.app\\/download\\?token=[^\"]+/);\n\nreturn {\n  json: {\n    downloadUrl: match ? match[0] : null\n  }\n};\n"
      },
      "typeVersion": 2
    },
    {
      "id": "c8eada7d-335b-4861-aae7-5d39f2cf1301",
      "name": "Telegram Trigger",
      "type": "n8n-nodes-base.telegramTrigger",
      "position": [
        -3552,
        0
      ],
      "parameters": {
        "updates": [
          "message"
        ],
        "additionalFields": {}
      },
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "230b0026-fbf1-405c-a96c-a6c5fce519d8",
      "name": "Link checking",
      "type": "n8n-nodes-base.if",
      "position": [
        -2864,
        16
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "62b26b58-bd15-4eb8-90e7-235eabe34cc7",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              },
              "leftValue": "={{ $json.isFacebookLink }}",
              "rightValue": "true"
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "cddc9f65-7935-4126-99ca-a3a6967907a2",
      "name": "If",
      "type": "n8n-nodes-base.if",
      "position": [
        -3104,
        0
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "9f62fc1b-5b1a-41ae-9b44-429bde6795ae",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              },
              "leftValue": "={{ $json.isInstagramLink }}",
              "rightValue": ""
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "3ef62436-4c2f-49a5-a19c-4113666cbb82",
      "name": "FB API FETCHING",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -2576,
        -80
      ],
      "parameters": {
        "url": "https://fbdownloader.to/api/ajaxSearch",
        "method": "POST",
        "options": {},
        "sendBody": true,
        "contentType": "multipart-form-data",
        "bodyParameters": {
          "parameters": [
            {
              "name": "q",
              "value": "={{ $('Telegram Trigger').item.json.message.text }}"
            }
          ]
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "c4b39d39-8923-4205-9ae1-3fb58b41a5f8",
      "name": "INSTA API FETCHING",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -2512,
        -368
      ],
      "parameters": {
        "url": "=https://snapdownloader.com/tools/instagram-downloader/download?url={{ $json.instagramUrl }}",
        "options": {}
      },
      "typeVersion": 4.2
    },
    {
      "id": "c4fc0f16-fa4b-4594-bab7-8dcc09e46baf",
      "name": "URL FINDER",
      "type": "n8n-nodes-base.code",
      "position": [
        -2272,
        -368
      ],
      "parameters": {
        "jsCode": "// n8n Function node\n// Input: HTTP Request node output (with HTML inside `data` field)\n// Output: Only the video file URL\n\nconst results = [];\n\nfor (const item of items) {\n  const html = item.json.data || \"\";\n  \n  // Regex to capture video .mp4 links\n  const regex = /(https?:\\/\\/[^\\s\"']+\\.mp4[^\\s\"']*)/gi;\n  const matches = html.match(regex);\n\n  if (matches && matches.length > 0) {\n    results.push({ json: { videoUrl: matches[0] } }); // take first video link\n  } else {\n    results.push({ json: { videoUrl: null } });\n  }\n}\n\nreturn results;\n"
      },
      "typeVersion": 2
    },
    {
      "id": "bad84de5-9038-41d2-baeb-c54450b422df",
      "name": "URL DECODER",
      "type": "n8n-nodes-base.code",
      "position": [
        -2064,
        -368
      ],
      "parameters": {
        "jsCode": "// Function node\n// Input: items[i].json.videoUrl\n// Output: items[i].json.videoUrlClean\nreturn items.map(item => {\n  const url = (item.json.videoUrl || '').split('&amp;').join('&');\n  return { json: { ...item.json, videoUrlClean: url } };\n});\n"
      },
      "typeVersion": 2
    },
    {
      "id": "63b7d8c9-2161-4208-a338-10851ff231cf",
      "name": "DOWNLOAD INSTA VID",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -1824,
        -368
      ],
      "parameters": {
        "url": "={{ $json.videoUrlClean }}",
        "options": {}
      },
      "typeVersion": 4.2
    },
    {
      "id": "d3ef124d-61c4-46d1-98aa-c411e9d88117",
      "name": "DOWNLOAD FB VID",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -1904,
        -80
      ],
      "parameters": {
        "url": "={{ $json.downloadUrl }}",
        "options": {}
      },
      "typeVersion": 4.2
    },
    {
      "id": "16dfda54-ea22-4c09-904d-8ca4ea937b09",
      "name": "SEND INSTA VIDEO",
      "type": "n8n-nodes-base.telegram",
      "position": [
        -1520,
        -368
      ],
      "parameters": {
        "chatId": "={{ $('Telegram Trigger').item.json.message.chat.id }}",
        "operation": "sendVideo",
        "binaryData": true,
        "forceReply": {},
        "replyMarkup": "forceReply",
        "additionalFields": {}
      },
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "f30aea16-7135-485b-8054-fb760d6ff58e",
      "name": "SEND FB VIDEO",
      "type": "n8n-nodes-base.telegram",
      "position": [
        -1520,
        128
      ],
      "parameters": {
        "chatId": "={{ $('Telegram Trigger').item.json.message.chat.id }}",
        "operation": "sendVideo",
        "binaryData": true,
        "forceReply": {},
        "replyMarkup": "forceReply",
        "additionalFields": {}
      },
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "2b13d770-8da9-4435-a251-a50a5e0993cd",
      "name": "INVALID URL",
      "type": "n8n-nodes-base.telegram",
      "position": [
        -2528,
        368
      ],
      "parameters": {
        "text": "Please paste only facebook/Instagram link \u26a0\ufe0f",
        "chatId": "={{ $('Telegram Trigger').item.json.message.chat.id }}",
        "additionalFields": {
          "appendAttribution": false
        }
      },
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "d9487499-bf52-4954-91cc-546ad723a15f",
      "name": "Send a text message",
      "type": "n8n-nodes-base.telegram",
      "position": [
        -1520,
        -576
      ],
      "parameters": {
        "text": "\u23ecDownloading.... Please wait \u231b",
        "chatId": "={{ $('Telegram Trigger').item.json.message.chat.id }}",
        "additionalFields": {
          "appendAttribution": false
        }
      },
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "d781ba41-6168-414a-a5e4-7444de71f9e4",
      "name": "Send a text message1",
      "type": "n8n-nodes-base.telegram",
      "position": [
        -1520,
        -80
      ],
      "parameters": {
        "text": "\u23ecDownloading.... Please wait \u231b",
        "chatId": "={{ $('Telegram Trigger').item.json.message.chat.id }}",
        "additionalFields": {
          "appendAttribution": false
        }
      },
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "438f2deb-64d9-4e63-8fac-43c31088f603",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -3584,
        -64
      ],
      "parameters": {
        "color": 3,
        "width": 400,
        "height": 240,
        "content": "## Getting link from usr"
      },
      "typeVersion": 1
    },
    {
      "id": "c603ccb2-7812-4d8f-b4dd-ec0db9fdbd72",
      "name": "FB IG LINK REGEX",
      "type": "n8n-nodes-base.code",
      "position": [
        -3312,
        0
      ],
      "parameters": {
        "jsCode": "const url = $input.first().json.message.text; // your input text\n\n// Regex patterns\nconst fbRegex = /https?:\\/\\/([a-zA-Z0-9-]+\\.)?facebook\\.com\\/[^\\s]+/i;\nconst igRegex = /https?:\\/\\/([a-zA-Z0-9-]+\\.)?instagram\\.com\\/[^\\s]+/i;\n\n// Match\nconst fbMatch = url.match(fbRegex);\nconst igMatch = url.match(igRegex);\n\nreturn {\n  json: {\n    isFacebookLink: !!fbMatch,\n    facebookUrl: fbMatch ? fbMatch[0] : null,\n    isInstagramLink: !!igMatch,\n    instagramUrl: igMatch ? igMatch[0] : null\n  }\n};\n"
      },
      "typeVersion": 2
    },
    {
      "id": "a3c4d451-ec17-473f-8c27-14f3129ef114",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -3168,
        -48
      ],
      "parameters": {
        "color": 5,
        "height": 176,
        "content": "## Checking FB or IG"
      },
      "typeVersion": 1
    },
    {
      "id": "d9f31402-cd1f-49b6-9a60-e3dcf67531f4",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -2608,
        -128
      ],
      "parameters": {
        "color": 4,
        "width": 1360,
        "height": 400,
        "content": "## FACEBOOK NODE"
      },
      "typeVersion": 1
    },
    {
      "id": "1501a1c7-537a-4dbf-b998-98d1e756e5f3",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -2608,
        -592
      ],
      "parameters": {
        "color": 6,
        "width": 1360,
        "height": 400,
        "content": "## INSTAGRAM NODE"
      },
      "typeVersion": 1
    },
    {
      "id": "db4effe7-e559-444f-aa6e-c83029165eda",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -2912,
        -112
      ],
      "parameters": {
        "color": 7,
        "width": 192,
        "height": 304,
        "content": "## CHECKING VALID LINK"
      },
      "typeVersion": 1
    },
    {
      "id": "5a522951-eb06-4cb0-900a-0931cf36ab11",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -2592,
        304
      ],
      "parameters": {
        "color": 2,
        "width": 416,
        "height": 208,
        "content": "## SENDING ERROR MSG IF INVALID LINK"
      },
      "typeVersion": 1
    },
    {
      "id": "57177adf-1f58-4bcf-8063-3a554d4e8121",
      "name": "Sticky Note6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -3632,
        -656
      ],
      "parameters": {
        "color": 5,
        "width": 2704,
        "height": 1216,
        "content": "\n"
      },
      "typeVersion": 1
    }
  ],
  "connections": {
    "If": {
      "main": [
        [
          {
            "node": "INSTA API FETCHING",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Link checking",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "URL FINDER": {
      "main": [
        [
          {
            "node": "URL DECODER",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "URL DECODER": {
      "main": [
        [
          {
            "node": "DOWNLOAD INSTA VID",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Link checking": {
      "main": [
        [
          {
            "node": "FB API FETCHING",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "INVALID URL",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "SEND FB VIDEO": {
      "main": [
        []
      ]
    },
    "video scraping": {
      "main": [
        [
          {
            "node": "Genrate download link",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "DOWNLOAD FB VID": {
      "main": [
        [
          {
            "node": "SEND FB VIDEO",
            "type": "main",
            "index": 0
          },
          {
            "node": "Send a text message1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "FB API FETCHING": {
      "main": [
        [
          {
            "node": "video scraping",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "FB IG LINK REGEX": {
      "main": [
        [
          {
            "node": "If",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Telegram Trigger": {
      "main": [
        [
          {
            "node": "FB IG LINK REGEX",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "DOWNLOAD INSTA VID": {
      "main": [
        [
          {
            "node": "SEND INSTA VIDEO",
            "type": "main",
            "index": 0
          },
          {
            "node": "Send a text message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "INSTA API FETCHING": {
      "main": [
        [
          {
            "node": "URL FINDER",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Genrate download link": {
      "main": [
        [
          {
            "node": "DOWNLOAD FB VID",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}