{
  "name": "Telegram AI image bot with Nano Banana Pro (MegaBrain)",
  "nodes": [
    {
      "parameters": {
        "content": "# Telegram image bot — Nano Banana Pro\nSend the bot a description, get back a 2K image made by Google **Nano Banana Pro** through the MegaBrain API ($0.17 an image, pay as you go).\n\n## Setup (2 minutes)\n1. Get a key at [getmegabrain.com/keys](https://getmegabrain.com/keys).\n2. In n8n create a **Header Auth** credential named `MegaBrain API key`:\n   - Name: `Authorization`\n   - Value: `Bearer YOUR_KEY`\n3. Pick it in every HTTP Request node with the 🔑 mark.\n\nFailed jobs are refunded automatically. Prices: [getmegabrain.com/docs/media](https://getmegabrain.com/docs/media).\n\nAlso create a **Telegram** credential with your bot token from @BotFather.",
        "height": 560,
        "width": 440
      },
      "id": "2224071b-d49f-513e-9789-1ef963c8e7b2",
      "name": "About",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -520,
        -260
      ]
    },
    {
      "parameters": {
        "updates": [
          "message"
        ],
        "additionalFields": {}
      },
      "id": "bf1115d4-eeb5-5a8f-814a-f1a13b9bf762",
      "name": "Telegram Trigger",
      "type": "n8n-nodes-base.telegramTrigger",
      "typeVersion": 1.2,
      "position": [
        0,
        0
      ],
      "webhookId": "c7dfc853-49dc-5c16-b19a-742b03ccd9f0"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "979f49a5-1591-57e3-af48-13f994efdc24",
              "name": "model",
              "value": "nano-banana-pro",
              "type": "string"
            },
            {
              "id": "64b8170a-987d-5e7b-9696-c0d42b837cdc",
              "name": "aspect_ratio",
              "value": "1:1",
              "type": "string"
            },
            {
              "id": "ef3c3395-1ab8-533f-ae32-177a59bbc73d",
              "name": "resolution",
              "value": "2K",
              "type": "string"
            },
            {
              "id": "03e23462-2a63-5e48-a833-4ccd6d82640e",
              "name": "caption",
              "value": "Made with Nano Banana Pro on getmegabrain.com",
              "type": "string"
            }
          ]
        },
        "includeOtherFields": true,
        "options": {}
      },
      "id": "595b8b3b-0cae-541f-becd-99047917a50a",
      "name": "Settings",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        200,
        0
      ]
    },
    {
      "parameters": {
        "operation": "sendChatAction",
        "chatId": "={{ $json.message.chat.id }}",
        "action": "upload_photo"
      },
      "id": "6d20a979-ba7c-5cfb-905d-fb8501b5b726",
      "name": "Show 'sending photo'",
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [
        420,
        0
      ],
      "webhookId": "7193e9b7-08ef-5ee4-a6a3-bb8b1b578ed9"
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://getmegabrain.com/api/gateway/v1/images/generations",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ model: $('Settings').item.json.model, prompt: $('Telegram Trigger').item.json.message.text, aspect_ratio: $('Settings').item.json.aspect_ratio, resolution: $('Settings').item.json.resolution, output_format: 'jpeg' }) }}",
        "options": {
          "timeout": 120000
        },
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth"
      },
      "id": "18d38837-2f85-56d7-bace-b5f9d1ecdb46",
      "name": "Generate image (Nano Banana Pro)",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        640,
        0
      ],
      "onError": "continueErrorOutput"
    },
    {
      "parameters": {
        "operation": "sendPhoto",
        "chatId": "={{ $('Telegram Trigger').item.json.message.chat.id }}",
        "file": "={{ $json.image_url }}",
        "additionalFields": {
          "caption": "={{ $('Settings').item.json.caption }}"
        }
      },
      "id": "d19729a2-c95c-5183-80a0-4c0e25c996d8",
      "name": "Send photo",
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [
        1340,
        -100
      ],
      "webhookId": "a337eea7-16f6-5178-91a2-4c8b464d2f37"
    },
    {
      "parameters": {
        "chatId": "={{ $('Telegram Trigger').item.json.message.chat.id }}",
        "text": "=Could not make the image: {{ $json.error?.message || 'unknown error' }}",
        "additionalFields": {
          "appendAttribution": false
        }
      },
      "id": "4842e927-fbc7-51f1-825a-c33e15568e33",
      "name": "Tell the user it failed",
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [
        1340,
        260
      ],
      "webhookId": "f064e378-94fb-53c3-a3cc-ee0ca900d3f5"
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "loose",
            "version": 2
          },
          "conditions": [
            {
              "id": "271316d1-2b33-5578-89be-35ccaa6f1bf8",
              "leftValue": "={{ $json.data?.[0]?.url ?? $json.images?.[0]?.url ?? '' }}",
              "rightValue": "",
              "operator": {
                "type": "string",
                "operation": "notEmpty",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "5fc9dee3-4485-59cb-988a-0928312bd58e",
      "name": "Image ready?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        860,
        0
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "9d5543bb-93ed-5a03-8d04-6e884861ff08",
              "name": "image_url",
              "value": "={{ $json.data?.[0]?.url ?? $json.images?.[0]?.url ?? '' }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "id": "800c87a0-1ca7-5a17-8e97-74e2b0f0bab2",
      "name": "Image URL",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        1080,
        -100
      ]
    },
    {
      "parameters": {
        "amount": 10
      },
      "id": "9e314536-317d-538b-88f0-a881e1544752",
      "name": "Queued: wait 10s (Image)",
      "type": "n8n-nodes-base.wait",
      "typeVersion": 1.1,
      "position": [
        1080,
        120
      ],
      "webhookId": "9c030a1e-766c-5a85-a23f-0cc442644072"
    },
    {
      "parameters": {
        "url": "={{ $json.response_url }}",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "options": {
          "timeout": 60000
        }
      },
      "id": "eee7ecfc-ff10-53e4-a709-2edb4c0ecf57",
      "name": "Fetch queued image",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1300,
        120
      ],
      "onError": "continueErrorOutput"
    },
    {
      "parameters": {
        "content": "## 1. Settings\nChange the model, frame and caption here. `resolution` 4K costs twice as much; for cheaper drafts use `nano-banana-2` or `flux-2` (FLUX takes no `resolution`: remove it from the request).",
        "height": 220,
        "width": 420,
        "color": 5
      },
      "id": "97b7c95c-ff7c-5314-b89b-961165d09dc1",
      "name": "Note: settings",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        140,
        -260
      ]
    },
    {
      "parameters": {
        "content": "## 2. Wait for a queued image\nThe API waits up to ~110 s. A slower image comes back as `202` with a `response_url`: the loop waits 10 s and asks again until the image is ready. A failed job is refunded and the user gets the reason.",
        "height": 220,
        "width": 460,
        "color": 5
      },
      "id": "8c3d5ffb-3957-5f37-886d-c799e0a3245b",
      "name": "Note: queue",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        820,
        -260
      ]
    }
  ],
  "connections": {
    "Show 'sending photo'": {
      "main": [
        [
          {
            "node": "Generate image (Nano Banana Pro)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Generate image (Nano Banana Pro)": {
      "main": [
        [
          {
            "node": "Image ready?",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Tell the user it failed",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Image ready?": {
      "main": [
        [
          {
            "node": "Image URL",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Queued: wait 10s (Image)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Queued: wait 10s (Image)": {
      "main": [
        [
          {
            "node": "Fetch queued image",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch queued image": {
      "main": [
        [
          {
            "node": "Image ready?",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Tell the user it failed",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Telegram Trigger": {
      "main": [
        [
          {
            "node": "Settings",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Settings": {
      "main": [
        [
          {
            "node": "Show 'sending photo'",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Image URL": {
      "main": [
        [
          {
            "node": "Send photo",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "meta": {
    "templateCredsSetupCompleted": false
  },
  "tags": []
}
