{
  "name": "🔄 Async Video Polling Engine - Background Job Handler for AI Video Generation",
  "nodes": [
    {
      "id": "b174f32b-dc84-426e-9f24-9ae3ebab200b",
      "name": "Main",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -3232,
        368
      ],
      "parameters": {
        "width": 380,
        "height": 576,
        "content": "## How it works\n\n1. Receives a webhook call with video task ID from the main workflow\n2. Waits 1 minute, then checks KIE.ai API for generation status\n3. If still processing, retries (up to 15 attempts"
      }
    },
    {
      "id": "6d2ef622-0e8e-4e7f-9ef1-b81603f5087f",
      "name": "Webhook Trigger",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -2704,
        448
      ],
      "parameters": {
        "width": 520,
        "height": 80,
        "content": "**Webhook & Parse** — Receives polling request, parses input data, responds OK immediately"
      }
    },
    {
      "id": "8707a955-08d5-4494-8fac-14f1894968e5",
      "name": "Status Polling",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1968,
        464
      ],
      "parameters": {
        "width": 696,
        "height": 352,
        "content": "**Status Polling** — Waits 1 min, checks KIE.ai status, parses response for completion"
      }
    },
    {
      "id": "b45a0f9e-b1e9-4c94-aabf-9e4c384f7d30",
      "name": "Retry Logic",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1184,
        576
      ],
      "parameters": {
        "width": 508,
        "height": 384,
        "content": "**Retry Logic** — Retries up to 15x or sends timeout message"
      }
    },
    {
      "id": "3357d5d2-a485-454c-b6dc-02981f3292db",
      "name": "Video Download",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1184,
        320
      ],
      "parameters": {
        "width": 920,
        "height": 224,
        "content": "**Video Processing** — Downloads from KIE.ai, uploads to S3, checks if extend flow"
      }
    },
    {
      "id": "6aabf895-fa67-4e3b-8263-7e6ef92d22ad",
      "name": "Session Storage",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        400,
        256
      ],
      "parameters": {
        "width": 1112,
        "height": 368,
        "content": "**Session & Metadata** — Retrieves session from Redis, creates metadata, updates status"
      }
    },
    {
      "id": "c028e9e5-56aa-4b68-a80b-acbc7465b8fe",
      "name": "Telegram Delivery",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1744,
        144
      ],
      "parameters": {
        "width": 488,
        "height": 608,
        "content": "**Telegram Delivery** — Sends video preview with publish action buttons"
      }
    },
    {
      "id": "ed1d90e8-a6c5-4dd7-a2c1-32ac354fa348",
      "name": "Extend Flow",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -112,
        176
      ],
      "parameters": {
        "width": 340,
        "height": 80,
        "content": "**Extend Flow** — Add Merge Option if its an extend request, if initial request skip."
      }
    },
    {
      "id": "b3b9a267-f069-41ca-a55f-3e3092ae3e6b",
      "name": "Poll Trigger",
      "type": "n8n-nodes-base.webhook",
      "position": [
        -2672,
        576
      ]
    },
    {
      "id": "adfb0fc8-4a08-45b7-990a-8733b026cf68",
      "name": "Parse Input",
      "type": "n8n-nodes-base.code",
      "position": [
        -2448,
        576
      ]
    },
    {
      "id": "d4c934e6-4b24-4c33-b08c-9dddcc77055f",
      "name": "Respond OK",
      "type": "n8n-nodes-base.respondToWebhook",
      "position": [
        -2224,
        576
      ]
    },
    {
      "id": "7019d8f9-4cbc-4e88-ad7e-08121dce9801",
      "name": "Wait 1 Minute",
      "type": "n8n-nodes-base.wait",
      "position": [
        -2000,
        576
      ]
    },
    {
      "id": "436c017b-1e8c-4c6b-b2d3-07d932b94bf3",
      "name": "Check KIE Status",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -1776,
        576
      ]
    },
    {
      "id": "ac9fba69-a574-4382-83a6-c01cfbd6f4b4",
      "name": "Parse Status",
      "type": "n8n-nodes-base.code",
      "position": [
        -1552,
        576
      ]
    },
    {
      "id": "531e9b09-c985-488e-b8ad-1c0cac398d30",
      "name": "Completed?",
      "type": "n8n-nodes-base.if",
      "position": [
        -1328,
        576
      ]
    },
    {
      "id": "bd98177f-9a95-4f18-abef-f8c1006bac30",
      "name": "Get 1080p Video",
      "type": "n8n-nodes-base.code",
      "position": [
        -1104,
        384
      ]
    },
    {
      "id": "f7539aaa-b9a2-41f3-9dae-5774b2799903",
      "name": "Get Final URL",
      "type": "n8n-nodes-base.code",
      "position": [
        -880,
        384
      ]
    },
    {
      "id": "47b24e8c-810c-4c87-b028-d07a1e234608",
      "name": "Download Video",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -656,
        384
      ]
    },
    {
      "id": "df9664c3-8d88-4b67-a543-f906db0faf8e",
      "name": "Get Session",
      "type": "n8n-nodes-base.redis",
      "position": [
        464,
        384
      ]
    },
    {
      "id": "4ccd466e-32eb-4465-83f1-433b5664198d",
      "name": "Merge Session Data",
      "type": "n8n-nodes-base.code",
      "position": [
        688,
        384
      ]
    },
    {
      "id": "e2c2c634-d4ad-4be6-84cd-be68f136237c",
      "name": "Update Session",
      "type": "n8n-nodes-base.redis",
      "position": [
        1360,
        384
      ]
    },
    {
      "id": "2d0606a9-2ab0-4ffd-a32f-89dca688dce6",
      "name": "Download for Telegram",
      "type": "n8n-nodes-base.s3",
      "position": [
        1584,
        384
      ]
    },
    {
      "id": "bba58015-be7e-4a45-9749-b9a52e864e20",
      "name": "Is Veo Model?",
      "type": "n8n-nodes-base.if",
      "position": [
        1808,
        384
      ]
    },
    {
      "id": "d7161b85-5598-4711-b0c1-efecfb6a1bff",
      "name": "Send Video Preview (Veo)",
      "type": "n8n-nodes-base.telegram",
      "position": [
        2032,
        288
      ]
    },
    {
      "id": "a64aabf2-f9b9-472b-a7ed-af09abff099f",
      "name": "Send Video Preview (Other)",
      "type": "n8n-nodes-base.telegram",
      "position": [
        2032,
        480
      ]
    },
    {
      "id": "75afd09e-e746-449d-9c05-80f4f354bb11",
      "name": "Can Retry?",
      "type": "n8n-nodes-base.if",
      "position": [
        -1120,
        720
      ]
    },
    {
      "id": "fa1860dd-48a5-4174-b33e-eadf07e6ee23",
      "name": "Retry Poll",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -880,
        640
      ]
    },
    {
      "id": "0fa23fe4-5fe5-4c82-9e5d-06e9650225bc",
      "name": "Send Timeout",
      "type": "n8n-nodes-base.telegram",
      "position": [
        -880,
        800
      ]
    },
    {
      "id": "6379dbc9-ddcc-4a67-aba4-d4b5c5c1faf0",
      "name": "Upload a file",
      "type": "n8n-nodes-base.s3",
      "position": [
        -432,
        384
      ]
    },
    {
      "id": "3cdb8933-6193-469c-bd59-ddd6fbcc1fb1",
      "name": "Create Metadata",
      "type": "n8n-nodes-base.code",
      "position": [
        912,
        384
      ]
    },
    {
      "id": "676e3f5f-2994-49b7-a19b-1065cf1623f4",
      "name": "Upload Metadata",
      "type": "n8n-nodes-base.s3",
      "position": [
        1136,
        384
      ]
    },
    {
      "id": "6253a26f-4c47-4452-ade7-691dca7d2b9f",
      "name": "Is Extend?",
      "type": "n8n-nodes-base.if",
      "position": [
        -208,
        384
      ]
    },
    {
      "id": "9f7d4cf8-9b9e-400a-82d3-3c00bda97742",
      "name": "Skip Concat",
      "type": "n8n-nodes-base.code",
      "position": [
        16,
        480
      ]
    },
    {
      "id": "021a9e58-04b5-47d9-b4aa-d6d3e402df02",
      "name": "Merge After Concat",
      "type": "n8n-nodes-base.merge",
      "position": [
        240,
        384
      ]
    },
    {
      "id": "3f7921d2-1352-4bd4-a8b1-8740d39f6b21",
      "name": "Send Merge Options",
      "type": "n8n-nodes-base.telegram",
      "position": [
        16,
        288
      ]
    }
  ],
  "connections": {
    "Can Retry?": {
      "main": [
        [
          {
            "node": "Retry Poll",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Send Timeout",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Completed?": {
      "main": [
        [
          {
            "node": "Get 1080p Video",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Can Retry?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Is Extend?": {
      "main": [
        [
          {
            "node": "Send Merge Options",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Skip Concat",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Respond OK": {
      "main": [
        [
          {
            "node": "Wait 1 Minute",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Session": {
      "main": [
        [
          {
            "node": "Merge Session Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Parse Input": {
      "main": [
        [
          {
            "node": "Respond OK",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Skip Concat": {
      "main": [
        [
          {
            "node": "Merge After Concat",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Parse Status": {
      "main": [
        [
          {
            "node": "Completed?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Poll Trigger": {
      "main": [
        [
          {
            "node": "Parse Input",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Final URL": {
      "main": [
        [
          {
            "node": "Download Video",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Is Veo Model?": {
      "main": [
        [
          {
            "node": "Send Video Preview (Veo)",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Send Video Preview (Other)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Upload a file": {
      "main": [
        [
          {
            "node": "Is Extend?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wait 1 Minute": {
      "main": [
        [
          {
            "node": "Check KIE Status",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Download Video": {
      "main": [
        [
          {
            "node": "Upload a file",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Update Session": {
      "main": [
        [
          {
            "node": "Download for Telegram",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create Metadata": {
      "main": [
        [
          {
            "node": "Upload Metadata",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get 1080p Video": {
      "main": [
        [
          {
            "node": "Get Final URL",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Upload Metadata": {
      "main": [
        [
          {
            "node": "Update Session",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check KIE Status": {
      "main": [
        [
          {
            "node": "Parse Status",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Merge After Concat": {
      "main": [
        [
          {
            "node": "Get Session",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Merge Session Data": {
      "main": [
        [
          {
            "node": "Create Metadata",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send Merge Options": {
      "main": [
        [
          {
            "node": "Merge After Concat",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Download for Telegram": {
      "main": [
        [
          {
            "node": "Is Veo Model?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}