AutomationFlowsAI & RAG › Telegram Bot Generates Images with Google Gemini

Telegram Bot Generates Images with Google Gemini

Original n8n title: Text-to-image Generation with Google Gemini & Enhanced Prompts via Telegram Bot

ByAppStoneLab Technologies LLP @appstonelab on n8n.io

This workflow contains community nodes that are only compatible with the self-hosted version of n8n.

Event trigger★★★★☆ complexityAI-powered13 nodesHTTP RequestTelegramChain LlmOutput Parser StructuredTelegram TriggerGoogle Gemini Chat
AI & RAG Trigger: Event Nodes: 13 Complexity: ★★★★☆ AI nodes: yes Added:

This workflow corresponds to n8n.io template #5777 — we link there as the canonical source.

This workflow follows the Chainllm → HTTP Request recipe pattern — see all workflows that pair these two integrations.

The workflow JSON

Copy or download the full n8n JSON below. Paste it into a new n8n workflow, add your credentials, activate. Full import guide →

Download .json
{
  "id": "0tEmax45Rzaq4xP9",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "Telegram Image Gen",
  "tags": [
    {
      "id": "VwtLS6Wfn3QdKdqW",
      "name": "Production",
      "createdAt": "2025-07-08T10:23:28.983Z",
      "updatedAt": "2025-07-08T10:23:28.983Z"
    }
  ],
  "nodes": [
    {
      "id": "d7a28ef5-499f-44f6-b07e-baad9c655c62",
      "name": "Generate Image",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -200,
        60
      ],
      "parameters": {
        "url": "https://generativelanguage.googleapis.com/v1beta/models/gemini-2.0-flash-preview-image-generation:generateContent",
        "method": "POST",
        "options": {},
        "jsonBody": "={\n  \"contents\": [\n    {\n      \"parts\": [\n        {\n          \"text\": {{ JSON.stringify($json.output.enhanced_prompt) }}\n        }\n      ]\n    }\n  ],\n  \"generationConfig\": {\n    \"responseModalities\": [\n      \"TEXT\",\n      \"IMAGE\"\n    ]\n  }\n}",
        "sendBody": true,
        "sendQuery": true,
        "specifyBody": "json",
        "queryParameters": {
          "parameters": [
            {
              "name": "=key",
              "value": "Your API Key"
            }
          ]
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "28fe131a-f506-4609-868e-4d7edaf64772",
      "name": "Send a photo message",
      "type": "n8n-nodes-base.telegram",
      "position": [
        520,
        60
      ],
      "parameters": {
        "chatId": "={{ $('Telegram Trigger').item.json.message.chat.id }}",
        "operation": "sendPhoto",
        "binaryData": true,
        "additionalFields": {}
      },
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "7d61ed5b-a176-4404-9cb1-cbef1ead9f51",
      "name": "Generate prompt",
      "type": "@n8n/n8n-nodes-langchain.chainLlm",
      "position": [
        -680,
        60
      ],
      "parameters": {
        "text": "=You are an expert prompt engineer specialized in creating detailed, high-quality prompts for AI image generation models. Your task is to take a user's basic image request and expand it into a comprehensive, detailed prompt that will produce stunning visual results.\n\n**Users Request:**{{ $json.message.text }}\n\nINSTRUCTIONS:\n1. Analyze the user's input and identify the core subject, style, and intent\n2. Expand the basic request into a detailed description including:\n   - Visual style and artistic approach\n   - Lighting conditions and mood\n   - Composition and framing\n   - Color palette and atmosphere\n   - Technical quality specifications\n   - Specific details that enhance the image\n\n3. Structure your response as a single, well-formatted prompt ready for image generation\n\nENHANCEMENT GUIDELINES:\n- Add specific artistic styles (e.g., \"photorealistic,\" \"oil painting,\" \"digital art,\" \"cinematic\")\n- Include lighting details (e.g., \"golden hour lighting,\" \"dramatic shadows,\" \"soft diffused light\")\n- Specify camera angles and composition (e.g., \"wide shot,\" \"close-up,\" \"bird's eye view\")\n- Add mood and atmosphere descriptors\n- Include quality enhancers like \"highly detailed,\" \"8K resolution,\" \"professional photography\"\n- Mention relevant artistic influences when appropriate\n\nEXAMPLE:\nUser input: \"a cat sitting on a windowsill\"\nYour output: \"A majestic tabby cat sitting gracefully on a wooden windowsill, bathed in warm golden afternoon sunlight streaming through vintage lace curtains. The scene captures a cozy, nostalgic atmosphere with soft shadows and gentle light rays creating a dreamy ambiance. Shot in the style of fine art photography with shallow depth of field, the background shows a blurred garden view. Highly detailed fur texture, expressive amber eyes, and warm color palette dominated by golds, creams, and soft browns. Professional photography quality, 8K resolution, cinematic lighting.\"\n\nNow take the user's image request and create a detailed, enhanced prompt for optimal image generation results.",
        "batching": {},
        "promptType": "define",
        "hasOutputParser": true
      },
      "typeVersion": 1.7
    },
    {
      "id": "174c56fc-a0d0-4740-bcd6-532e63a307bd",
      "name": "Structured Prompt",
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "position": [
        -500,
        240
      ],
      "parameters": {
        "jsonSchemaExample": "{\n  \"enhanced_prompt\": \"...\"\n}"
      },
      "typeVersion": 1.3
    },
    {
      "id": "bcf4736a-73b7-474b-8af7-ed18b9acb43e",
      "name": "Telegram Trigger",
      "type": "n8n-nodes-base.telegramTrigger",
      "position": [
        -980,
        60
      ],
      "parameters": {
        "updates": [
          "message"
        ],
        "additionalFields": {}
      },
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "612e2726-0641-4362-8e84-49b5efa978fd",
      "name": "Convert to Image",
      "type": "n8n-nodes-base.convertToFile",
      "position": [
        160,
        60
      ],
      "parameters": {
        "options": {},
        "operation": "toBinary",
        "sourceProperty": "candidates[0].content.parts[1].inlineData.data"
      },
      "typeVersion": 1.1
    },
    {
      "id": "abeaddbe-2ba2-462f-b7d2-b8aae24f4a1c",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1080,
        -160
      ],
      "parameters": {
        "width": 300,
        "height": 520,
        "content": "## \ud83d\udcf1 Telegram Trigger\n\n**Listens for user messages**\n\n- Entry point for the workflow\n- Captures incoming text messages\n- Triggers the entire process\n- **Outputs:** User's image request"
      },
      "typeVersion": 1
    },
    {
      "id": "303ecc4f-3759-462e-9430-23feb81a8943",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -760,
        -160
      ],
      "parameters": {
        "color": 7,
        "width": 420,
        "height": 520,
        "content": "## \ud83e\udde0 Generate Prompt\n\n**Enhances user input with AI**\n\n- Takes basic text and makes it detailed\n- Uses prompt engineering techniques\n- Adds artistic style, lighting, composition\n- Powered by Gemini 2.5 Pro"
      },
      "typeVersion": 1
    },
    {
      "id": "0444fb7e-b578-4575-9bf4-ae6100c21432",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -320,
        -160
      ],
      "parameters": {
        "color": 2,
        "width": 340,
        "height": 520,
        "content": "## \ud83c\udfa8 Generate Image\n\n**Creates image from enhanced prompt**\n\n- Calls Google's Gemini 2.0 Flash API\n- Converts text prompt to visual image\n- Returns image in base64 format\n- HTTP POST to image generation endpoint"
      },
      "typeVersion": 1
    },
    {
      "id": "dec96747-332b-464b-82a8-604a82120603",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        40,
        -160
      ],
      "parameters": {
        "color": 6,
        "width": 340,
        "height": 520,
        "content": "## \ud83d\udcc1 Convert to Image\n\n**Prepares image for delivery**\n\n- Converts base64 data to binary file\n- Extracts image from API response\n- Makes image compatible with Telegram\n- Essential for photo message sending"
      },
      "typeVersion": 1
    },
    {
      "id": "1b1af43f-7c73-42d2-8610-34e0950248f1",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        400,
        -160
      ],
      "parameters": {
        "color": 3,
        "width": 340,
        "height": 520,
        "content": "## \ud83d\udce4 Send a Photo Message\n\n**Delivers final image to user**\n\n- Sends generated image back to Telegram\n- Uses binary data from previous node\n- Completes the user interaction\n- User receives their AI-generated image"
      },
      "typeVersion": 1
    },
    {
      "id": "2b60768c-bd3a-4815-9553-a46e3a89875e",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1440,
        -160
      ],
      "parameters": {
        "color": 4,
        "width": 340,
        "height": 520,
        "content": "## \ud83d\udd04 Workflow Summary\n\n**AI-Powered Image Generation Bot**\n\n**What it does:** User sends text \u2192 AI enhances prompt \u2192 Image generated \u2192 Sent back to user\n\n**Key Features:**\n\n- Instant text-to-image conversion\n- Professional prompt enhancement\n- Telegram bot interface\n- Google Gemini AI integration\n\n\n**Flow**: Message \u2192 Enhance \u2192 Generate \u2192 Convert \u2192 Send\n\n\n**Result:** Transform simple descriptions into stunning AI images through Telegram!"
      },
      "typeVersion": 1
    },
    {
      "id": "0d39319b-7bb4-4335-88aa-741d0ffe0f4b",
      "name": "Gemini 2.5 Pro",
      "type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
      "position": [
        -680,
        240
      ],
      "parameters": {
        "options": {},
        "modelName": "models/gemini-2.5-pro"
      },
      "credentials": {
        "googlePalmApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    }
  ],
  "active": true,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "4eb1654f-28a2-4367-9fbd-72fd8bf52b2b",
  "connections": {
    "Gemini 2.5 Pro": {
      "ai_languageModel": [
        [
          {
            "node": "Generate prompt",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Generate Image": {
      "main": [
        [
          {
            "node": "Convert to Image",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Generate prompt": {
      "main": [
        [
          {
            "node": "Generate Image",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Convert to Image": {
      "main": [
        [
          {
            "node": "Send a photo message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Telegram Trigger": {
      "main": [
        [
          {
            "node": "Generate prompt",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Structured Prompt": {
      "ai_outputParser": [
        [
          {
            "node": "Generate prompt",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    }
  }
}

Credentials you'll need

Each integration node will prompt for credentials when you import. We strip credential IDs before publishing — you'll add your own.

Pro

For the full experience including quality scoring and batch install features for each workflow upgrade to Pro

About this workflow

This workflow contains community nodes that are only compatible with the self-hosted version of n8n.

Source: https://n8n.io/workflows/5777/ — original creator credit. Request a take-down →

More AI & RAG workflows → · Browse all categories →

Related workflows

Workflows that share integrations, category, or trigger type with this one. All free to copy and import.

AI & RAG

Flexible and scalable chatbot template, designed mainly for Spanish conversations but capable of handling English and other languages. Integrates Google Gemini API for text and image generation, and T

Agent, Google Gemini Chat, Chain Llm +6
AI & RAG

This workflow is designed to save hours of manual research for digital marketers, media buyers, copywriters, and business strategists. It empowers users to quickly understand their target customers’ b

Chain Llm, Google Gemini Chat, HTTP Request +4
AI & RAG

BlogBlitz is a powerful workflow that automates the creation and publishing of SEO-optimized blog posts to WordPress, saving you hours of manual content creation. Triggered on a schedule or via Telegr

Chain Llm, Telegram Trigger, Discord +8
AI & RAG

This workflow creates a multi-talented AI assistant named Simran that interacts with users via Telegram. It can handle text and voice messages, understand the user's intent, and perform various tasks.

MongoDB, Chain Llm, Google Gemini Chat +11
AI & RAG

A Telegram bot that converts natural-language work descriptions into detailed cost estimates using AI parsing, vector search, and the open-source DDC CWICR database with 55,000+ construction work item

HTTP Request, Telegram, Telegram Trigger +6