{
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "nodes": [
    {
      "id": "61a48c7f-29f0-4cfe-9faf-6b8f78a79734",
      "name": "Photo Message Receiver",
      "type": "n8n-nodes-base.telegramTrigger",
      "position": [
        -96,
        2048
      ],
      "parameters": {
        "updates": [
          "message"
        ],
        "additionalFields": {}
      },
      "typeVersion": 1.2
    },
    {
      "id": "675d0f05-d9f6-446d-9fd1-8ad5965d1b28",
      "name": "Download Telegram Photo",
      "type": "n8n-nodes-base.telegram",
      "position": [
        112,
        2048
      ],
      "parameters": {
        "fileId": "={{ $('Photo Message Receiver').item.json.message.photo[0].file_id }}",
        "resource": "file",
        "additionalFields": {}
      },
      "typeVersion": 1.2
    },
    {
      "id": "c08670f8-81f0-41b9-ac7c-bc30847e5fba",
      "name": "Convert Photo to Base64",
      "type": "n8n-nodes-base.extractFromFile",
      "position": [
        304,
        2048
      ],
      "parameters": {
        "options": {},
        "operation": "binaryToPropery"
      },
      "typeVersion": 1
    },
    {
      "id": "0880f91f-0499-4ee5-a813-398156eeb3b4",
      "name": "Format Image Data URL",
      "type": "n8n-nodes-base.code",
      "position": [
        512,
        2048
      ],
      "parameters": {
        "jsCode": "const items = $input.all();\nconst updatedItems = items.map((item) => {\n  const base64Url = item?.json?.data;\n  const url = `data:image/png;base64,${base64Url}`;\n  return { url };\n});\nreturn updatedItems;\n"
      },
      "typeVersion": 2
    },
    {
      "id": "cb1a2a0c-38d4-47e3-9463-46a1be61f28a",
      "name": "Parse AI Response Data",
      "type": "n8n-nodes-base.set",
      "position": [
        912,
        2048
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "3782b286-b6fd-4943-8530-ff922944b803",
              "name": "base",
              "type": "string",
              "value": "={{ $json.choices[0].message.images[0].image_url.url.split(',')[1] }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "398dc9e7-4ff4-4fe8-bcad-aec622a9b63b",
      "name": "Base64 to Binary File",
      "type": "n8n-nodes-base.convertToFile",
      "position": [
        1136,
        2048
      ],
      "parameters": {
        "options": {},
        "operation": "toBinary",
        "sourceProperty": "base"
      },
      "typeVersion": 1.1
    },
    {
      "id": "c9cbd76a-0f2b-4d9f-aed7-0b5a0454f1fc",
      "name": "Send Processed Photo",
      "type": "n8n-nodes-base.telegram",
      "position": [
        1360,
        2048
      ],
      "parameters": {
        "chatId": "YOUR_CHAT_ID_HERE",
        "operation": "sendPhoto",
        "binaryData": true,
        "additionalFields": {}
      },
      "typeVersion": 1.2
    },
    {
      "id": "408c2c7c-3e0a-4a56-baae-d1334fffbb49",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -608,
        1648
      ],
      "parameters": {
        "width": 2240,
        "height": 928,
        "content": "# \ud83e\udd16 Nano Banana AI Image Editor \n\n## \ud83d\udccb Workflow Overview\n**Purpose:** Receives photos via Telegram, processes them with AI vision, and sends back analyzed images\n\n## \ud83d\udd04 Process Flow\n\n1. **\ud83d\udcf1 Photo Message Receiver**\n   - Listens for incoming Telegram messages with photos\n\n2. **\u2b07\ufe0f Download Telegram Photo**\n   - Fetches the photo file from Telegram servers\n\n3. **\ud83d\udd04 Convert Photo to Base64**\n   - Extracts binary data and converts to Base64 format\n\n4. **\ud83d\udd17 Format Image Data URL**\n   - Creates proper data URL format for AI processing\n\n5. **\ud83e\udde0 Nano Banana Image Processor**\n   - Sends image + caption to Gemini 2.5 Flash via OpenRouter\n   - AI analyzes the image and generates response\n\n6. **\ud83d\udcca Parse AI Response Data**\n   - Extracts image URL and metadata from AI response\n\n7. **\ud83d\udcbe Base64 to Binary File**\n   - Converts processed image back to binary format\n\n8. **\ud83d\udce4 Send Processed Photo**\n   - Returns the AI-processed image to Telegram chat\n\n## \u2699\ufe0f Technical Details\n- **AI Model:** Nano Banana(Gemini 2.5 Flash Image Preview)\n- **API Provider:** OpenRouter (Free tier)\n- **Target Chat ID:** Your chat id\n- **Image Format:** PNG\n\n"
      },
      "typeVersion": 1
    },
    {
      "id": "a04f072e-da6b-4d02-8369-556cfa728aab",
      "name": "Nano Banana Image Processor",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        704,
        2048
      ],
      "parameters": {
        "url": "https://openrouter.ai/api/v1/chat/completions",
        "method": "POST",
        "options": {},
        "jsonBody": "={\n  \"model\": \"google/gemini-2.5-flash-image-preview:free\",\n  \"messages\": [\n    {\n      \"role\": \"user\",\n      \"content\": [\n        {\n          \"type\": \"text\",\n          \"text\": \"{{ $('Photo Message Receiver').item.json.message.caption }}\"\n        },\n        {\n          \"type\": \"image_url\",\n          \"image_url\": {\n            \"url\": \"{{ $json.url }}\"\n          }\n        }\n      ]\n    }\n  ]\n}",
        "sendBody": true,
        "sendHeaders": true,
        "specifyBody": "json",
        "authentication": "predefinedCredentialType",
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "Bearer $OPENROUTER_API_KEY"
            }
          ]
        },
        "nodeCredentialType": "openRouterApi"
      },
      "typeVersion": 4.2
    }
  ],
  "connections": {
    "Base64 to Binary File": {
      "main": [
        [
          {
            "node": "Send Processed Photo",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Format Image Data URL": {
      "main": [
        [
          {
            "node": "Nano Banana Image Processor",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Parse AI Response Data": {
      "main": [
        [
          {
            "node": "Base64 to Binary File",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Photo Message Receiver": {
      "main": [
        [
          {
            "node": "Download Telegram Photo",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Convert Photo to Base64": {
      "main": [
        [
          {
            "node": "Format Image Data URL",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Download Telegram Photo": {
      "main": [
        [
          {
            "node": "Convert Photo to Base64",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Nano Banana Image Processor": {
      "main": [
        [
          {
            "node": "Parse AI Response Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}