AutomationFlowsAI & RAG › Generate AI Images via Telegram Using Gemini & Pollinations

Generate AI Images via Telegram Using Gemini & Pollinations

ByNAZIA AI ACADEMY @merzag on n8n.io

How it works This workflow lets users generate AI images directly from Telegram messages using:

Chat trigger trigger★★★★☆ complexityAI-powered15 nodesChat TriggerHTTP RequestTelegram TriggerGoogle Gemini ChatAgentTelegramRead Write File
AI & RAG Trigger: Chat trigger Nodes: 15 Complexity: ★★★★☆ AI nodes: yes Added:

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

This workflow follows the Agent → Chat Trigger 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": "29TYbvP5Qc5CKZW2",
  "meta": {
    "templateId": "5626"
  },
  "name": "Free AI Image Generator via Telegram using Gemini API & Pollinations",
  "tags": [],
  "nodes": [
    {
      "id": "d5d1fe1b-f053-4162-adf4-5b52b409942d",
      "name": "Fields - Set Values",
      "type": "n8n-nodes-base.set",
      "position": [
        1296,
        1104
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "4e04fec4-441e-45f7-acea-0017a4b5c104",
              "name": "model",
              "type": "string",
              "value": "flux"
            },
            {
              "id": "aa80cd68-1c82-4032-b1d7-e098856eec38",
              "name": "width",
              "type": "string",
              "value": "1080"
            },
            {
              "id": "da6d305f-aece-49bd-ae02-52df59915c60",
              "name": "height",
              "type": "string",
              "value": "1920"
            },
            {
              "id": "0833b9c8-41c3-45f5-a083-26cea1ac5a3e",
              "name": "chat",
              "type": "string",
              "value": "={{ $json.message.text }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "e108c56f-b7fb-4818-aed5-c55c59b81516",
      "name": "When chat message received",
      "type": "@n8n/n8n-nodes-langchain.chatTrigger",
      "disabled": true,
      "position": [
        1072,
        1200
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 1.1
    },
    {
      "id": "7565ff7c-cfe7-4157-953b-74c1e66d659e",
      "name": "Code - Clean Json",
      "type": "n8n-nodes-base.code",
      "position": [
        2032,
        1104
      ],
      "parameters": {
        "jsCode": "function cleanAndExtractJSON(response) {\n    try {\n        const result = {\n            image_prompt: []\n        };\n\n        const lines = response.split('\\n');\n        let currentPrompt = '';\n\n        for (const line of lines) {\n            if (line.includes('\"prompt\":')) {\n                if (currentPrompt) {\n                    result.image_prompt.push(currentPrompt.trim());\n                }\n                currentPrompt = line.split('\"prompt\":')[1].trim();\n            }\n        }\n\n        if (currentPrompt) {\n            result.image_prompt.push(currentPrompt.trim());\n        }\n\n        return { json: result };\n        \n    } catch (error) {\n        return { \n            json: {\n                image_prompt: []\n            }\n        };\n    }\n}\n\nconst response = $input.first().json.output;\nreturn cleanAndExtractJSON(response);"
      },
      "executeOnce": false,
      "typeVersion": 2,
      "alwaysOutputData": true
    },
    {
      "id": "8e33813d-bd34-46b9-91c8-89dac7f28add",
      "name": "Code - Get Prompt",
      "type": "n8n-nodes-base.code",
      "position": [
        2208,
        1104
      ],
      "parameters": {
        "jsCode": "return $input.first().json.image_prompt.map(prompt => ({\n  json: {\n    body: {\n      prompt: prompt,\n  \"image_size\": {\n    \"width\": $('Fields - Set Values').first().json.width,\n    \"height\": $('Fields - Set Values').first().json.height\n  },\n  \"num_inference_steps\": 12,\n  \"guidance_scale\": 3.5,\n  \"num_images\": 1,\n  \"enable_safety_checker\": true,\n}\n    }\n  }\n));"
      },
      "typeVersion": 2,
      "alwaysOutputData": true
    },
    {
      "id": "fba88baa-70e8-452c-b44e-d1685df0eb7d",
      "name": "HTTP Request - Create Image",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        2656,
        1104
      ],
      "parameters": {
        "url": "=https://image.pollinations.ai/prompt/{{ $json.body.prompt }}",
        "options": {},
        "jsonQuery": "={\n  \"width\": {{ $('Fields - Set Values').item.json.width }},\n  \"height\": {{ $('Fields - Set Values').item.json.height }},\n  \"model\": \"{{ $('Fields - Set Values').item.json.model }}\",\n  \"seed\": 42,\n  \"nologo\": true\n}",
        "sendQuery": true,
        "sendHeaders": true,
        "specifyQuery": "json",
        "headerParameters": {
          "parameters": [
            {
              "name": "Content-Type",
              "value": "application/json"
            },
            {
              "name": "Accept",
              "value": "application/json"
            }
          ]
        }
      },
      "retryOnFail": true,
      "typeVersion": 4.2,
      "alwaysOutputData": true,
      "waitBetweenTries": 5000
    },
    {
      "id": "25617f21-8d05-4ca2-9c16-5cd97e369bdb",
      "name": "Telegram Trigger",
      "type": "n8n-nodes-base.telegramTrigger",
      "position": [
        1072,
        1008
      ],
      "parameters": {
        "updates": [
          "message"
        ],
        "additionalFields": {}
      },
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "de666684-e743-40ef-b604-1cff33b107de",
      "name": "Code - Set Filename",
      "type": "n8n-nodes-base.code",
      "position": [
        2368,
        1104
      ],
      "parameters": {
        "jsCode": "for (let i = 0; i < items.length; i++) {\n  items[i].json.fileName = `images_${(i + 1).toString().padStart(3, '0')}.png`;\n}\nreturn items;"
      },
      "typeVersion": 2
    },
    {
      "id": "e04c2a46-a670-4042-88d1-79207731c864",
      "name": "Google Gemini Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
      "position": [
        1600,
        1312
      ],
      "parameters": {
        "options": {
          "topK": 40,
          "topP": 1,
          "temperature": 0.5,
          "safetySettings": {
            "values": [
              {
                "category": "HARM_CATEGORY_HARASSMENT",
                "threshold": "BLOCK_NONE"
              },
              {
                "category": "HARM_CATEGORY_HATE_SPEECH",
                "threshold": "BLOCK_NONE"
              },
              {
                "category": "HARM_CATEGORY_SEXUALLY_EXPLICIT",
                "threshold": "BLOCK_NONE"
              },
              {
                "category": "HARM_CATEGORY_DANGEROUS_CONTENT",
                "threshold": "BLOCK_NONE"
              }
            ]
          },
          "maxOutputTokens": 65536
        },
        "modelName": "models/gemini-2.0-flash"
      },
      "credentials": {
        "googlePalmApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "cb6fb57a-e3c1-45ff-9b81-4a2152f397fc",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        992,
        800
      ],
      "parameters": {
        "color": 7,
        "width": 440,
        "height": 620,
        "content": "## **1. Get The Inputs**\nWe\u2019ll take your image idea from the text you send in the chat, along with any settings like image size or style. This information is parsed and prepared for the image generation step.\n\n"
      },
      "typeVersion": 1
    },
    {
      "id": "876439a4-dbfe-4394-96d7-8f6c8a63778d",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1520,
        800
      ],
      "parameters": {
        "color": 7,
        "width": 420,
        "height": 620,
        "content": "## **2. Use Google Gemini's Image Model To Generate The Image**\nYour prompt and settings are sent to Google Gemini\u2019s Image Generation Model.\nPrefer a different model? You can easily swap in alternatives like OpenAI ChatGPT or Microsoft Copilot.\n\n"
      },
      "typeVersion": 1
    },
    {
      "id": "ac07f44c-c881-4d80-bd65-a8aa0ce39375",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2592,
        800
      ],
      "parameters": {
        "color": 7,
        "width": 540,
        "height": 620,
        "content": "## **4. Preview And Save The Image**\nOnce your image is ready in a downloadable format, you\u2019ll be able to preview it. If you're happy with the result, you can save it in one of two ways by activating either of them before running the workflow:\n- As a reply in Telegram chat\n- To your local storage (disk)\n\n\n\n"
      },
      "typeVersion": 1
    },
    {
      "id": "fdd981c2-2659-4a31-b37f-b5c4cd51ee3c",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2000,
        800
      ],
      "parameters": {
        "color": 7,
        "width": 520,
        "height": 620,
        "content": "## **3. Prepare The Final Image Feasible For Preview And Saving**\nThis stage helps to clean up the raw output from the AI Agent for your image request and format it into a complete, ready-to-view and downloadable format. \n"
      },
      "typeVersion": 1
    },
    {
      "id": "3a150703-2a7f-4255-9da0-6a15c005290c",
      "name": "AI Agent - Create Image From Prompt",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        1600,
        1104
      ],
      "parameters": {
        "text": "={{ $json.chat }}",
        "options": {
          "systemMessage": "=You are an AI image\u2011prompt creation expert. Please create a post using the following JSON format:\nAI Image Generation Prompt Guidelines:\nObjective\nCreate highly realistic, high\u2010quality images\nEnsure the image content faithfully conveys the spirit of the original text\nIntegrate short text (10\u201320 characters) naturally into the image\nMaintain consistency and professionalism\n\nStandard Prompt Structure\n[Main Scene] | [Key Elements] | [Text Integration] | [Lighting & Atmosphere] | [Technical Parameters] | [Style Parameters]\n\nComponent Breakdown\n1. Main Scene (Weight ::8)\nDescribe the primary setting in line with the content.\nExamples:\nTech news: \u201cmodern tech office setting, minimalist workspace\u201d\nEconomy news: \u201cprofessional financial district, corporate environment\u201d\nEducation news: \u201cmodern classroom, advanced learning environment\u201d\n\n2. Key Elements (Weight ::8)\nList the main visual elements required.\nExamples:\n\u201clarge HD display showing text \u2018AI Ethics\u2019 in modern typography\u201d\n\u201cprofessional people in business attire discussing around interactive screen\u201d\n\u201cdetailed infographic elements floating in augmented reality style\u201d\n\n3. Text Integration (Weight ::7)\nHow to display text within the image:\ntext elements | elegant typography, clear readable text, integrated naturally into scene ::7\n\n4. Lighting & Atmosphere (Weight ::7)\nlighting | cinematic dramatic lighting, natural ambient light, professional studio setup ::7\nbackground | depth of field blur, clean professional environment ::6\n\n5. Technical Parameters\nparameters | 8k resolution, hyperrealistic, photorealistic quality, octane render, cinematic composition --ar 16:9\nsettings | sharp focus, high detail, professional photography --s 1000 --q 2\nComplete Examples\nExample\u00a01: AI Ethics News\nprofessional tech conference room | large display showing \"AI Ethics Now\" in modern typography, group of diverse executives in discussion ::8 | clean modern workspace, glass walls, tech atmosphere ::7 | cinematic lighting, natural window light ::7 | 8k resolution, hyperrealistic quality, octane render --ar 16:9 --s 1000 --q 2\nExample\u00a02: Financial Market News\nmodern stock exchange environment | giant LED wall showing \"Market Alert\" in bold typography, professional traders in action ::8 | dynamic financial data visualization, sleek modern interior ::7 | dramatic lighting, blue-tinted atmosphere ::7 | 8k resolution, photorealistic quality --ar 16:9 --s 1000 --q 2\n\nAdditional Parameters\n--chaos [0\u2013100]: Adjust randomness\n--stylize [0\u20131000]: Degree of stylization\n--seed [number]: Ensure consistency across generations\n--niji: Optimized for Asian\u2010style aesthetics\n--v 5.2: Use the latest model version\n\nImportant Notes\nText in Image\nKeep it short and legible\nUse professional fonts\nIntegrate naturally into the scene\n\nComposition\nFollow the rule of thirds\nEnsure a clear focal point\nBalance text and imagery\n\nColor\nMatch a professional tone\nProvide sufficient contrast for readability\nMaintain visual consistency\n\nTechnical Details\nAlways use high resolution (8k)\nEnsure professional lighting\nOptimize for sharpness and detail\n\nCommon Pitfalls to Avoid\nOverly generic prompts\nMissing text\u2010integration guidance\nFailing to specify composition rules\nOmitting key technical parameters\n\nThe structure is:\n{\n  prompt_image {prompt : \"\" , ...}\n}"
        },
        "promptType": "define",
        "hasOutputParser": true
      },
      "typeVersion": 1.7
    },
    {
      "id": "a3e5fa40-51c1-41fa-83cb-d6d598f1ff49",
      "name": "Telegram Response",
      "type": "n8n-nodes-base.telegram",
      "position": [
        2880,
        1008
      ],
      "parameters": {
        "chatId": "123456789",
        "operation": "sendPhoto",
        "binaryData": true,
        "additionalFields": {}
      },
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "f7059ea5-106b-4b73-8cb3-b0e10e1c0c13",
      "name": "Save Image To Disk",
      "type": "n8n-nodes-base.readWriteFile",
      "disabled": true,
      "position": [
        2880,
        1200
      ],
      "parameters": {
        "options": {},
        "fileName": "=/files/{{ $('Code').item.json.fileName }}",
        "operation": "write"
      },
      "typeVersion": 1
    }
  ],
  "active": true,
  "settings": {},
  "versionId": "fefde9c2-1454-436a-b555-3910ca29bc88",
  "connections": {
    "Telegram Trigger": {
      "main": [
        [
          {
            "node": "Fields - Set Values",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Code - Clean Json": {
      "main": [
        [
          {
            "node": "Code - Get Prompt",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Code - Get Prompt": {
      "main": [
        [
          {
            "node": "Code - Set Filename",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Code - Set Filename": {
      "main": [
        [
          {
            "node": "HTTP Request - Create Image",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fields - Set Values": {
      "main": [
        [
          {
            "node": "AI Agent - Create Image From Prompt",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Google Gemini Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent - Create Image From Prompt",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "When chat message received": {
      "main": [
        [
          {
            "node": "Fields - Set Values",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTTP Request - Create Image": {
      "main": [
        [
          {
            "node": "Save Image To Disk",
            "type": "main",
            "index": 0
          },
          {
            "node": "Telegram Response",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI Agent - Create Image From Prompt": {
      "main": [
        [
          {
            "node": "Code - Clean Json",
            "type": "main",
            "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

How it works This workflow lets users generate AI images directly from Telegram messages using:

Source: https://n8n.io/workflows/6197/ — 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

Use cases are many: You can use it for marketing visuals, character art, digital posters, storyboards, or even daily image generation for your personal purposes. The flow is triggered by a chat messag

Chat Trigger, HTTP Request, Telegram Trigger +4
AI & RAG

Proxmox Ai Agent With N8N And Generative Ai Integration. Uses httpRequest, toolHttpRequest, outputParserAutofixing, lmChatGoogleGemini. Chat trigger; 35 nodes.

HTTP Request, Tool Http Request, Output Parser Autofixing +6
AI & RAG

Telegram. Uses httpRequest, toolHttpRequest, outputParserAutofixing, lmChatGoogleGemini. Chat trigger; 35 nodes.

HTTP Request, Tool Http Request, Output Parser Autofixing +6
AI & RAG

This template automates IT operations on a Proxmox Virtual Environment (VE) using an AI-powered conversational agent built with n8n. By integrating Proxmox APIs and generative AI models (e.g., Google

HTTP Request, Tool Http Request, Output Parser Autofixing +6
AI & RAG

This project is an automation workflow that generates a personalized resume and cover letter for each job listing. Generates an HTML resume from your data. Hosts it live on GitHub Pages. Converts it t

HTTP Request, Agent, OpenAI Chat +10