{
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "nodes": [
    {
      "id": "9844b3ab-8ce5-49b8-b6bb-c076b62e3de1",
      "name": "Image to Base64",
      "type": "n8n-nodes-base.extractFromFile",
      "position": [
        -2528,
        192
      ],
      "parameters": {
        "options": {},
        "operation": "binaryToPropery"
      },
      "typeVersion": 1
    },
    {
      "id": "d91f3b12-0fea-4a24-90fc-165d2e8dc908",
      "name": "AI Design Analysis",
      "type": "@n8n/n8n-nodes-langchain.googleGemini",
      "position": [
        -2528,
        384
      ],
      "parameters": {
        "text": "=You are an expert product photographer and advertising creative director. Analyze the uploaded product image and its caption: {{ $('Telegram Trigger Received').item.json.message.caption }}\n\nYour task is to create a detailed image generation prompt that will transform this product photo into a premium, commercial-grade advertisement visual.\n\nANALYSIS REQUIREMENTS:\n1. **Product Identification**: Identify the product type, size, category, material, color scheme, and key features\n2. **Current State Assessment**: Note the current lighting, background, composition, and quality issues\n3. **Target Aesthetic**: Determine the ideal advertising style based on product category (luxury, tech, food, fashion, etc.)\n\nOUTPUT (Strict JSON format):\n{\n  \"product_analysis\": {\n    \"type\": \"Detailed product category and specific item\",\n    \"size\": \"Estimated dimensions or scale\",\n    \"material\": \"Primary materials and textures\",\n    \"color_palette\": \"Dominant colors in the product\",\n    \"current_issues\": \"List any quality problems in original image\"\n  },\n  \n  \"image_generation_prompt\": \"Create a hyper-detailed prompt (500+ words) for generating the perfect product advertisement:\n\nPRODUCT PLACEMENT: [Describe exact positioning - centered, rule of thirds, etc. Keep product 100% identical to original]\n\nLIGHTING SETUP: \n- Key light: [direction, intensity, color temperature]\n- Fill light: [softness, position, ratio]\n- Rim/edge lighting: [accent placement]\n- Background light: [separation and depth]\n- Overall mood: [bright/moody/dramatic with specific color temperatures]\n\nBACKGROUND & ENVIRONMENT:\n- Style: [minimalist studio/lifestyle scene/luxury setting]\n- Surface: [marble/concrete/wood/fabric texture]\n- Color scheme: [complementary or analogous to product]\n- Props: [if any, subtle and relevant]\n- Depth: [bokeh, gradient, shadows for dimension]\n\nCOMPOSITION DETAILS:\n- Framing: [16:9 landscape, tight/medium/wide shot]\n- Focal point: [product positioning for visual hierarchy]\n- Negative space: [strategic empty areas]\n- Visual flow: [leading lines, eye movement path]\n\nCOLOR GRADING & POST-PROCESSING:\n- Product color: [enhance vibrancy by X%, specific adjustments]\n- Background treatment: [saturation, tone, contrast]\n- Shadow tint: [cool/warm, specific color]\n- Highlight treatment: [golden hour glow, crisp whites]\n- Overall contrast: [percentage increase]\n- Film style: [if applicable - cinematic, clean, vintage]\n\nVISUAL EFFECTS:\n- Depth of field: [f-stop equivalent blur]\n- Reflections: [surface reflections if relevant]\n- Particles/atmosphere: [dust motes, mist, light rays]\n- Glow/halo: [subtle rim light effect]\n- Shadows: [soft/hard, direction, opacity]\n\nSTYLE REFERENCES:\n- Match the aesthetic of: [Apple, Nike, luxury cosmetics, food photography, etc.]\n- Platform optimization: [Instagram, Pinterest, e-commerce]\n- Commercial quality: [editorial, catalog, hero shot]\n\nTECHNICAL SPECIFICATIONS:\n- Aspect ratio: 16:9 horizontal\n- Resolution: High-res, sharp focus on product\n- Camera angle: [eye-level/slightly above/dramatic low angle]\n- Lens effect: [50mm equivalent, 85mm portrait, macro detail]\n\nCRITICAL RULES:\n- Keep original product EXACTLY as is - no modifications\n- Professional studio photography quality\n- Ensure product is clearly visible and hero element\n- Create scroll-stopping visual appeal\n- Balance artistry with commercial clarity\"\n}",
        "modelId": {
          "__rl": true,
          "mode": "list",
          "value": "models/gemini-2.5-flash-lite",
          "cachedResultName": "models/gemini-2.5-flash-lite"
        },
        "options": {},
        "resource": "image",
        "inputType": "binary",
        "operation": "analyze"
      },
      "credentials": {
        "googlePalmApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "1db14467-6fc9-43ec-a347-98bfce50a3d3",
      "name": "Combine Image & Analysis",
      "type": "n8n-nodes-base.merge",
      "position": [
        -2208,
        288
      ],
      "parameters": {},
      "typeVersion": 3.2
    },
    {
      "id": "3ba57f26-ceb1-4a01-bf85-b302e985c26e",
      "name": "Prepare API Payload",
      "type": "n8n-nodes-base.code",
      "position": [
        -2000,
        288
      ],
      "parameters": {
        "jsCode": "// Collect all items from both inputs\nconst input1 = $items(\"Combine Image & Analysis\").map(i => i.json);\nconst input2 = $items(\"Combine Image & Analysis\").map(i => i.json);\n\n// Return as a single item\nreturn [\n  {\n    json: {\n      input1: input1,\n      input2: input2\n    }\n  }\n];\n"
      },
      "typeVersion": 2
    },
    {
      "id": "c3c77f2c-9e66-4b7b-8c42-5f00b730f852",
      "name": "Generate Enhanced Image",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -1760,
        288
      ],
      "parameters": {
        "url": "https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash-image-preview:generateContent",
        "method": "POST",
        "options": {},
        "jsonBody": "={\n  \"contents\": [\n    {\n      \"parts\": [\n        {\n          \"text\": {{ JSON.stringify($json.input1[1].content.parts[0].text) }}\n        },\n        {\n          \"inlineData\": {\n            \"mimeType\": \"image/png\",\n            \"data\": \"{{ $json.input1[0].data }}\"\n          }\n        }\n      ]\n    }\n  ],\n  \"generationConfig\": {\n    \"responseModalities\": [\"TEXT\", \"IMAGE\"],\n    \"imageConfig\": {\n      \"aspectRatio\": \"9:16\"\n    }\n  }\n}",
        "sendBody": true,
        "specifyBody": "json",
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "googlePalmApi"
      },
      "credentials": {
        "googlePalmApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "06980560-5f85-4af8-af45-0b1a74e0f791",
      "name": "Convert Base64 to Image (only image)",
      "type": "n8n-nodes-base.convertToFile",
      "onError": "continueErrorOutput",
      "position": [
        -1536,
        288
      ],
      "parameters": {
        "options": {},
        "operation": "toBinary",
        "sourceProperty": "candidates[0].content.parts[0].inlineData.data"
      },
      "typeVersion": 1.1
    },
    {
      "id": "2f21e558-c4bf-4c89-ac40-f8194fdf239b",
      "name": "Convert Base64 to Image (image and text)",
      "type": "n8n-nodes-base.convertToFile",
      "position": [
        -1344,
        416
      ],
      "parameters": {
        "options": {},
        "operation": "toBinary",
        "sourceProperty": "candidates[0].content.parts[1].inlineData.data"
      },
      "typeVersion": 1.1
    },
    {
      "id": "f926cf4c-744a-48e2-88ba-3216993d23fc",
      "name": "Initiate veo 3.1 Video Generation",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -1136,
        272
      ],
      "parameters": {
        "url": "https://us-central1-aiplatform.googleapis.com/v1/projects/YOUR_GCP_PROJECT_ID/locations/us-central1/publishers/google/models/veo-3.1-generate-preview:predictLongRunning",
        "method": "POST",
        "options": {},
        "jsonBody": "={\n  \"instances\": [\n    {\n      \"prompt\": \"Create a visually appealing 8-second marketing video showcasing this product. Add dynamic motion and suitable background audio.\",\n      \"image\": {\n        \"bytesBase64Encoded\": \"{{ $('Generate Enhanced Image').item.json.candidates[0].content.parts[1].inlineData.data }}\",\n        \"mimeType\": \"{{ $json.candidates[0].content.parts[1].inlineData.mimeType }}\"\n      }\n    }\n  ],\n  \"parameters\": {\n    \"aspectRatio\": \"9:16\",\n    \"sampleCount\": 1,\n    \"durationSeconds\": \"8\",\n    \"personGeneration\": \"allow_all\",\n    \"addWatermark\": true,\n    \"includeRaiReason\": true,\n    \"generateAudio\": true,\n    \"resolution\": \"1080p\"\n  }\n}\n",
        "sendBody": true,
        "specifyBody": "json",
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "googleOAuth2Api"
      },
      "credentials": {
        "googlePalmApi": {
          "name": "<your credential>"
        },
        "googleOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "f261dd46-ca76-4d40-bd62-0c94eaa355c9",
      "name": "Check Video Status",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -912,
        272
      ],
      "parameters": {
        "url": "https://us-central1-aiplatform.googleapis.com/v1/projects/YOUR_GCP_PROJECT_ID/locations/us-central1/publishers/google/models/veo-3.1-generate-preview:fetchPredictOperation",
        "method": "POST",
        "options": {},
        "jsonBody": "={\n  \"operationName\": \"{{ $json.name }}\"\n}",
        "sendBody": true,
        "specifyBody": "json",
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "googleOAuth2Api"
      },
      "credentials": {
        "googlePalmApi": {
          "name": "<your credential>"
        },
        "googleOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "d2dd1aa3-71f0-4bd3-8379-6b61325482e9",
      "name": "Video Ready Validator",
      "type": "n8n-nodes-base.if",
      "position": [
        -704,
        272
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "loose"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "547fbae3-5ef7-4d29-94c4-ad0dfbfc5547",
              "operator": {
                "type": "string",
                "operation": "exists",
                "singleValue": true
              },
              "leftValue": "={{ $json.response.videos[0].bytesBase64Encoded }}",
              "rightValue": ""
            }
          ]
        },
        "looseTypeValidation": true
      },
      "typeVersion": 2.2
    },
    {
      "id": "9929ab38-3857-4e5d-b549-b144bc82f443",
      "name": "Processing Delay (30s)",
      "type": "n8n-nodes-base.wait",
      "position": [
        -512,
        432
      ],
      "parameters": {
        "amount": 30
      },
      "typeVersion": 1.1
    },
    {
      "id": "e053e479-be53-46af-90fc-f7c359937ba4",
      "name": "Convert Base64 to video",
      "type": "n8n-nodes-base.convertToFile",
      "position": [
        -432,
        256
      ],
      "parameters": {
        "options": {},
        "operation": "toBinary",
        "sourceProperty": "response.videos[0].bytesBase64Encoded"
      },
      "typeVersion": 1.1
    },
    {
      "id": "c56f49fb-3940-46c5-8133-1390636eef4b",
      "name": "Download Image File",
      "type": "n8n-nodes-base.telegram",
      "position": [
        -2960,
        288
      ],
      "parameters": {
        "fileId": "={{ $json.message.photo[0].file_id }}",
        "resource": "file",
        "additionalFields": {}
      },
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "2486c478-ae50-4c42-a253-e519ee27a343",
      "name": "Telegram Trigger Received",
      "type": "n8n-nodes-base.telegramTrigger",
      "position": [
        -3168,
        288
      ],
      "parameters": {
        "updates": [
          "message"
        ],
        "additionalFields": {}
      },
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "e5d85127-8a10-4c2c-8b5c-03c2cc9f1024",
      "name": "Send veo 3.1 video",
      "type": "n8n-nodes-base.telegram",
      "position": [
        -224,
        256
      ],
      "parameters": {
        "chatId": "={{ $('Telegram Trigger Received').first().json.message.from.id }}",
        "operation": "sendVideo",
        "binaryData": true,
        "additionalFields": {}
      },
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "e1c4a302-8ece-44db-96c6-2791835e6089",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -3664,
        -464
      ],
      "parameters": {
        "width": 3648,
        "height": 1776,
        "content": "# Product Video Creator with Nano Banana & Veo 3.1 via Telegram \n\n## \ud83c\udfaf What This Does\nTransforms ordinary product photos into professional marketing videos with AI enhancement and video generation.\n\n---\n\n## \ud83d\udd04 Workflow Stages\n\n### **Stage 1: Input & Download** \ud83d\udce5\n- User sends product photo via Telegram bot\n- Bot downloads the image file\n- Caption is captured for context\n\n### **Stage 2: AI Analysis** \ud83e\udde0\n- **Image \u2192 Base64**: Converts image to data format\n- **AI Design Analysis**: Nano Banana analyzes the product and creates detailed enhancement prompt\n  - Identifies product type, materials, colors\n  - Suggests professional lighting setup\n  - Recommends composition improvements\n  - Generates 500+ word creative prompt\n\n### **Stage 3: Image Enhancement** \u2728\n- **Merge Data**: Combines original image + AI analysis\n- **Generate Enhanced Image**: Nano Banana creates professional product photo\n  - Aspect ratio: 9:16 (vertical/mobile-optimized)\n  - Studio-quality lighting\n  - Commercial-grade composition\n\n### **Stage 4: Video Generation** \ud83c\udfac\n- **Initiate Veo 3.1**: Sends enhanced image to Veo 3.1 video AI\n  - Duration: 8 seconds\n  - Resolution: 1080p\n  - With audio\n  - 9:16 vertical format\n\n### **Stage 5: Processing Loop** \u23f3\n- **Check Status**: Polls video generation progress\n- **Validator**: Checks if video is ready\n  - \u2705 **Ready** \u2192 Convert & send\n  - \u274c **Not Ready** \u2192 Wait 30s \u2192 Check again\n\n### **Stage 6: Delivery** \ud83d\udce4\n- Converts Base64 video to binary file\n- Sends final video back to user on Telegram\n\n---\n\n## \u23f1\ufe0f Expected Timeline\n- Image enhancement: ~5-10 seconds\n- Video generation: ~30-90 seconds\n- Total: 1-2 minutes per video\n\n---\n\n## \ud83d\udca1 Best Practices\n1. **Caption matters**: Include product details in photo caption\n2. **Clear photos**: Better input = better output\n3. **Patience**: Video generation takes time, bot will auto-retry\n4. **Vertical photos**: Work best for 9:16 format\n\n---\n\n## \ud83c\udfa8 Fully Customizable\n**Change based on your requirements:**\n- **Prompt**: Modify AI analysis instructions\n- **Aspect Ratio**: 16:9, 9:16 etc.\n- **Duration**: 4s to 8s videos\n- **Quality**: 720p, 1080p resolution\n- **Audio**: Enable/disable background music\n- **Watermark**: Add/remove branding\n"
      },
      "typeVersion": 1
    }
  ],
  "connections": {
    "Image to Base64": {
      "main": [
        [
          {
            "node": "Combine Image & Analysis",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI Design Analysis": {
      "main": [
        [
          {
            "node": "Combine Image & Analysis",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Check Video Status": {
      "main": [
        [
          {
            "node": "Video Ready Validator",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Download Image File": {
      "main": [
        [
          {
            "node": "Image to Base64",
            "type": "main",
            "index": 0
          },
          {
            "node": "AI Design Analysis",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Prepare API Payload": {
      "main": [
        [
          {
            "node": "Generate Enhanced Image",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Video Ready Validator": {
      "main": [
        [
          {
            "node": "Convert Base64 to video",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Processing Delay (30s)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Processing Delay (30s)": {
      "main": [
        [
          {
            "node": "Check Video Status",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Convert Base64 to video": {
      "main": [
        [
          {
            "node": "Send veo 3.1 video",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Generate Enhanced Image": {
      "main": [
        [
          {
            "node": "Convert Base64 to Image (only image)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Combine Image & Analysis": {
      "main": [
        [
          {
            "node": "Prepare API Payload",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Telegram Trigger Received": {
      "main": [
        [
          {
            "node": "Download Image File",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Initiate veo 3.1 Video Generation": {
      "main": [
        [
          {
            "node": "Check Video Status",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Convert Base64 to Image (only image)": {
      "main": [
        [
          {
            "node": "Initiate veo 3.1 Video Generation",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Convert Base64 to Image (image and text)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Convert Base64 to Image (image and text)": {
      "main": [
        [
          {
            "node": "Initiate veo 3.1 Video Generation",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}