Générer des images IA dans Telegram avec GPT-4o et Flux Pro

Avancé

Ceci est unContent Creation, Multimodal AIworkflow d'automatisation du domainecontenant 22 nœuds.Utilise principalement des nœuds comme If, Set, Telegram, Aggregate, AimlApi. Générer des images IA avec GPT-4o et Flux Pro dans Telegram

Prérequis
  • Token Bot Telegram
  • Peut nécessiter les informations d'identification d'authentification de l'API cible
  • Informations d'identification Google Sheets API
Aperçu du workflow
Visualisation des connexions entre les nœuds, avec support du zoom et du déplacement
Exporter le workflow
Copiez la configuration JSON suivante dans n8n pour importer et utiliser ce workflow
{
  "meta": {
    "instanceId": "29cf227651b207fca8739269056bd8f95a432c5e246ffae4aaf9220581f6fe53",
    "templateCredsSetupCompleted": true
  },
  "nodes": [
    {
      "id": "339179e6-1f09-435f-9b5e-c85dc3d9ed98",
      "name": "📩 Recevoir un message Telegram",
      "type": "n8n-nodes-base.telegramTrigger",
      "position": [
        -208,
        0
      ],
      "webhookId": "3ceea664-fd53-4141-8bc6-4fdaca0a661d",
      "parameters": {
        "updates": [
          "message"
        ],
        "additionalFields": {}
      },
      "credentials": {
        "telegramApi": {
          "id": "QcfQneMUvIojzFQz",
          "name": "Telegram account"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "38840cb5-dd2d-4e2c-87c0-e57b6064294c",
      "name": "📊 Récupérer les journaux d'utilisation",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        16,
        0
      ],
      "parameters": {
        "options": {
          "returnFirstMatch": false
        },
        "filtersUI": {
          "values": [
            {
              "lookupValue": "={{ $json.message.from.id }}",
              "lookupColumn": "user_id"
            },
            {
              "lookupValue": "={{ new Date().toISOString().slice(0,10) }}",
              "lookupColumn": "date"
            }
          ]
        },
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": 2060422727,
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1RHgZNdT0whop0JY3vrj83yLtmVluG73NIfLBBa8ckPg/edit#gid=2060422727",
          "cachedResultName": "Sheet1"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1RHgZNdT0whop0JY3vrj83yLtmVluG73NIfLBBa8ckPg",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1RHgZNdT0whop0JY3vrj83yLtmVluG73NIfLBBa8ckPg/edit?usp=drivesdk",
          "cachedResultName": "Image bot usage statistic"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "FAqNqtaHmPjIXEtc",
          "name": "Google Sheets account"
        }
      },
      "typeVersion": 4.6
    },
    {
      "id": "31ef4475-8a58-4dd8-850c-cfe2bbfc3ad7",
      "name": "📈 Compter les requêtes du jour",
      "type": "n8n-nodes-base.aggregate",
      "position": [
        240,
        0
      ],
      "parameters": {
        "options": {},
        "aggregate": "aggregateAllItemData"
      },
      "typeVersion": 1
    },
    {
      "id": "67f85ddc-9bcf-4c35-81a1-5a0e1f5d30a6",
      "name": "🔢 Définir la limite quotidienne",
      "type": "n8n-nodes-base.set",
      "position": [
        464,
        0
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "1514c5a1-1bd4-4ba2-8bb9-30c679ae4f8e",
              "name": "daily_limit",
              "type": "number",
              "value": 5
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "19a8f732-f6e0-4134-84fc-dfd7e14c7812",
      "name": "🚦 Limite dépassée ?",
      "type": "n8n-nodes-base.if",
      "position": [
        688,
        0
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "08e8aac4-9f6a-4fc0-b1ad-7d8493ff74bf",
              "operator": {
                "type": "number",
                "operation": "lt"
              },
              "leftValue": "={{$('📈 Count Today’s Requests').item.json.data.length }}",
              "rightValue": "={{ $json.daily_limit }}"
            }
          ]
        }
      },
      "executeOnce": false,
      "typeVersion": 2.2
    },
    {
      "id": "47ff6a8c-8a13-41f1-8847-7bb50c63014e",
      "name": "🚫 Notifier : Limite dépassée",
      "type": "n8n-nodes-base.telegram",
      "position": [
        912,
        112
      ],
      "webhookId": "bb58ce7a-45e5-42d1-a780-7cc47f7402b1",
      "parameters": {
        "text": "=Sorry! Your *daily limit of {{ $('🔢 Set Daily Limit').item.json.daily_limit }} generations* is exceeded!",
        "chatId": "={{ $('📩 Receive Telegram Message').item.json.message.chat.id }}",
        "additionalFields": {
          "appendAttribution": false
        }
      },
      "credentials": {
        "telegramApi": {
          "id": "QcfQneMUvIojzFQz",
          "name": "Telegram account"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "900536f7-d366-45a9-bafb-2fae6c1c0065",
      "name": "📝 Journaliser la génération réussie",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        1808,
        -96
      ],
      "parameters": {
        "columns": {
          "value": {
            "date": "={{ new Date().toISOString().slice(0,10) }}",
            "query": "={{ $('📩 Receive Telegram Message').item.json.message.text }}",
            "user_id": "={{ $('📩 Receive Telegram Message').item.json.message.from.id }}",
            "result_url": "={{ $('🎨 Generate Image (AI/ML API | flux-pro)').item.json.images[0].url }}"
          },
          "schema": [
            {
              "id": "user_id",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "user_id",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "date",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "date",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "query",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "query",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "result_url",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "result_url",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [
            "user_id"
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "append",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": 2060422727,
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1RHgZNdT0whop0JY3vrj83yLtmVluG73NIfLBBa8ckPg/edit#gid=2060422727",
          "cachedResultName": "Sheet1"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1RHgZNdT0whop0JY3vrj83yLtmVluG73NIfLBBa8ckPg",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1RHgZNdT0whop0JY3vrj83yLtmVluG73NIfLBBa8ckPg/edit?usp=drivesdk",
          "cachedResultName": "Image bot usage statistic"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "FAqNqtaHmPjIXEtc",
          "name": "Google Sheets account"
        }
      },
      "typeVersion": 4.6
    },
    {
      "id": "70630f26-3817-41f6-94ee-4f479ad15afe",
      "name": "🎨 Générer une image (AI/ML API | flux-pro)",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        1136,
        -96
      ],
      "parameters": {
        "url": "https://api.aimlapi.com/v1/images/generations",
        "method": "POST",
        "options": {},
        "sendBody": true,
        "authentication": "predefinedCredentialType",
        "bodyParameters": {
          "parameters": [
            {
              "name": "model",
              "value": "flux-pro"
            },
            {
              "name": "prompt",
              "value": "={{ $json.content }}"
            },
            {
              "name": "n",
              "value": "1"
            },
            {
              "name": "size",
              "value": "1024x1024"
            },
            {
              "name": "response_formats",
              "value": "=1"
            }
          ]
        },
        "nodeCredentialType": "aimlApi"
      },
      "credentials": {
        "aimlApi": {
          "id": "fzkUXwSArkMtWVYd",
          "name": "AI/ML account"
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "a47d6a9b-9ca6-4716-9083-d43b666da2e0",
      "name": "🧠 Améliorer l'invite (AI/ML API | GPT-4o)",
      "type": "n8n-nodes-aimlapi.aimlApi",
      "position": [
        912,
        -96
      ],
      "parameters": {
        "model": "openai/gpt-4o",
        "prompt": "=You are a prompt enhancer for AI image generation. Your task is to take the user's input and return only an improved version of the prompt. Do not include any explanations, introductions, or formatting. Output only the final prompt, nothing else.\n\n🧠 The user’s message is taken as the foundation for visual content generation. This input is then carefully analyzed, enriched, and transformed into a more expressive, structured, and detailed prompt. The purpose of this enhancement is to guide the AI model more effectively, resulting in an image that better matches the user's intent and imagination.\n\n✏️ Original user input:\n{{ $('📩 Receive Telegram Message').item.json.message.text }}",
        "options": {},
        "requestOptions": {}
      },
      "credentials": {
        "aimlApi": {
          "id": "fzkUXwSArkMtWVYd",
          "name": "AI/ML account"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "dcffa91d-a4c7-4851-9bdb-85552f4420e5",
      "name": "🖋 Décrire l'image (AI/ML API | GPT-4o)",
      "type": "n8n-nodes-aimlapi.aimlApi",
      "position": [
        1360,
        -96
      ],
      "parameters": {
        "model": "openai/gpt-4o",
        "prompt": "=Write a vivid and visually rich description for an AI-generated image, starting with the phrase: \"Here’s your image:\". The description should reflect the result of the prompt below, as if the image already exists.\n\nPrompt:\n\"{{ $json.prompt }}\"\n\nAvoid repeating the prompt verbatim. Use expressive language and sensory detail. Keep it to 1–2 elegant sentences.\n",
        "options": {},
        "requestOptions": {}
      },
      "credentials": {
        "aimlApi": {
          "id": "fzkUXwSArkMtWVYd",
          "name": "AI/ML account"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "560a50a5-a96a-48b2-ab1e-1f6f0bcf2a15",
      "name": "📤 Envoyer l'image à l'utilisateur",
      "type": "n8n-nodes-base.telegram",
      "position": [
        1584,
        -96
      ],
      "webhookId": "4a46da0a-9a91-4f31-802a-f0ce89516aa7",
      "parameters": {
        "file": "={{ $('🎨 Generate Image (AI/ML API | flux-pro)').item.json.images[0].url }}",
        "chatId": "={{ $('📩 Receive Telegram Message').item.json.message.chat.id }}",
        "operation": "sendPhoto",
        "additionalFields": {
          "caption": "={{ $json.content }}"
        }
      },
      "credentials": {
        "telegramApi": {
          "id": "QcfQneMUvIojzFQz",
          "name": "Telegram account"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "1fed89b3-457f-457e-ba5d-13f209a63cd4",
      "name": "Note adhésive",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -272,
        -160
      ],
      "parameters": {
        "color": 4,
        "width": 224,
        "height": 336,
        "content": "## Incoming Message\n### Handle incoming user messages from Telegram."
      },
      "typeVersion": 1
    },
    {
      "id": "3623d8a3-1933-4809-ab5b-ed54f039f116",
      "name": "Note adhésive1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -32,
        -160
      ],
      "parameters": {
        "width": 864,
        "height": 336,
        "content": "##  Usage Limit Check\n### Check how many times the user has generated today and enforce the daily limit.\n\n"
      },
      "typeVersion": 1
    },
    {
      "id": "a34ed607-47b0-4966-a11f-7298c41b4223",
      "name": "Note adhésive2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        848,
        -256
      ],
      "parameters": {
        "color": 6,
        "width": 208,
        "height": 336,
        "content": "##  Prompt Enhancement\n### Use LLM to rewrite the user's input into a rich and detailed prompt.\n\n\n"
      },
      "typeVersion": 1
    },
    {
      "id": "02a9f22d-a4d4-4deb-8ed1-4818a9ddf198",
      "name": "Note adhésive3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1072,
        -256
      ],
      "parameters": {
        "color": 6,
        "width": 208,
        "height": 336,
        "content": "##  Image Generation\n### Generate an image using the enhanced prompt via AIMLAPI.\n\n\n\n"
      },
      "typeVersion": 1
    },
    {
      "id": "31f52e39-80dc-45d5-9ef8-7c96d55b81a0",
      "name": "Note adhésive4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1296,
        -256
      ],
      "parameters": {
        "color": 6,
        "width": 208,
        "height": 336,
        "content": "##  Image Description\n### Create a vivid description of the generated image using LLM.\n\n\n\n\n\n"
      },
      "typeVersion": 1
    },
    {
      "id": "d923875c-b2d0-4804-8050-5b8daa2aaad8",
      "name": "Note adhésive5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1520,
        -256
      ],
      "parameters": {
        "color": 4,
        "width": 416,
        "height": 336,
        "content": "## Delivery & Logging\n### Send the final image and caption to the user, and log the result to Google Sheets.\n\n\n\n\n\n\n"
      },
      "typeVersion": 1
    },
    {
      "id": "46afbb51-ec45-49b2-b6b1-c3333328edf1",
      "name": "Note adhésive6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        848,
        96
      ],
      "parameters": {
        "color": 3,
        "width": 256,
        "height": 352,
        "content": "\n\n---\n\n\n---\n\n\n---\n\n\n---\n\n\n---\n\n\n##  Notify: Limit Exceeded\n### Notify the user that the daily generation limit has been reached\n\n\n \n\n"
      },
      "typeVersion": 1
    },
    {
      "id": "53ac8095-8518-465d-bc4c-965a7110bd78",
      "name": "Note adhésive8",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -336,
        -1904
      ],
      "parameters": {
        "color": 5,
        "width": 560,
        "height": 608,
        "content": "# 🧠 AI Image Generator Bot — Telegram + AIMLAPI (via n8n)\n\nThis workflow lets users generate AI images by messaging a Telegram bot. Each user has a **daily limit**, tracked using **Google Sheets**. Prompts are enhanced and images are generated using **AIMLAPI**.\n\n---\n\n## 🚀 Features\n\n* Text-to-image generation via `flux-pro` model\n* Prompt enhancement with GPT-4o\n* Descriptive captions for each image\n* Telegram delivery\n* Daily usage tracking and limiting\n* Logging all activity in Google Sheets"
      },
      "typeVersion": 1
    },
    {
      "id": "56bb2e61-b024-4e87-9471-7f379e9ee6b9",
      "name": "Note adhésive9",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -336,
        -1280
      ],
      "parameters": {
        "color": 5,
        "width": 560,
        "height": 736,
        "content": "## ⚙️ Customization\n\n* `Set Daily Limit` node controls the number of free generations\n* You can add:\n\n  * NSFW filtering\n  * Dynamic model selection\n  * `/help` or `/history` commands\n\n---\n\n## 💡 Example User Flow\n\n1. User sends:\n\n   ```\n   a dragon flying above New York at night\n   ```\n\n2. Bot replies:\n\n   > **Here’s your image:**\n   > A crimson dragon soars through moonlit clouds over Manhattan, its wings glowing against the skyline.\n\n> 3. Image is generated and sent\n"
      },
      "typeVersion": 1
    },
    {
      "id": "352ebd4e-5f9e-44b7-8802-2fcf323ca0ad",
      "name": "Note adhésive10",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        240,
        -1808
      ],
      "parameters": {
        "color": 5,
        "width": 560,
        "height": 912,
        "content": "\n# 🛠 Setup Guide\n\n### 1. 📲 Create a Telegram Bot\n\n* Go to [@BotFather](https://t.me/BotFather)\n* Use `/newbot`, set a name and username\n* Save the **API token**\n\n---\n\n### 2. 🔐 Connect Telegram API in n8n\n\n* Go to `Credentials > Telegram API`\n* Create new credentials using the token from BotFather\n\n---\n\n### 3. 📗 Create a Google Sheet\n\n* Add a sheet named `Sheet1`\n\n* Use these columns as headers:\n\n  ```\n  user_id | date | query | result_url\n  ```\n\n* Share it with your Google service account or OAuth user\n  (depends on how you authenticate Google Sheets in n8n)\n\n---\n\n### 4. 🔌 Set Up Credentials in n8n\n\n* **Google Sheets:** OAuth2 or service account\n* **AIMLAPI:** Use your API key in `AI/ML API` credentials\n\n  * Base URL: `https://api.aimlapi.com/v1`\n  * Docs: [docs.aimlapi.com](https://docs.aimlapi.com)\n"
      },
      "typeVersion": 1
    },
    {
      "id": "63074211-fe01-4947-9ffd-f45baab48fbd",
      "name": "Note adhésive11",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        240,
        -880
      ],
      "parameters": {
        "color": 5,
        "width": 560,
        "height": 336,
        "content": "## 📁 Data Logged\n\nEach generation is saved to Google Sheets:\n\n` | user_id | date | query | result_url | `\n` | ------- | ---- | ----- | ---------- | `\n\n\n## 🧪 Testing Tips\n\n* Use a test Telegram chat\n* Add `Console` or `Set` nodes to inspect payloads\n* Test the workflow using `/execute` from Telegram, **not \"Execute Node\"**, if you're using static data\n"
      },
      "typeVersion": 1
    }
  ],
  "pinData": {},
  "connections": {
    "67f85ddc-9bcf-4c35-81a1-5a0e1f5d30a6": {
      "main": [
        [
          {
            "node": "19a8f732-f6e0-4134-84fc-dfd7e14c7812",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "38840cb5-dd2d-4e2c-87c0-e57b6064294c": {
      "main": [
        [
          {
            "node": "31ef4475-8a58-4dd8-850c-cfe2bbfc3ad7",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "560a50a5-a96a-48b2-ab1e-1f6f0bcf2a15": {
      "main": [
        [
          {
            "node": "900536f7-d366-45a9-bafb-2fae6c1c0065",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "19a8f732-f6e0-4134-84fc-dfd7e14c7812": {
      "main": [
        [
          {
            "node": "a47d6a9b-9ca6-4716-9083-d43b666da2e0",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "47ff6a8c-8a13-41f1-8847-7bb50c63014e",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "31ef4475-8a58-4dd8-850c-cfe2bbfc3ad7": {
      "main": [
        [
          {
            "node": "67f85ddc-9bcf-4c35-81a1-5a0e1f5d30a6",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "339179e6-1f09-435f-9b5e-c85dc3d9ed98": {
      "main": [
        [
          {
            "node": "38840cb5-dd2d-4e2c-87c0-e57b6064294c",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "900536f7-d366-45a9-bafb-2fae6c1c0065": {
      "main": [
        []
      ]
    },
    "dcffa91d-a4c7-4851-9bdb-85552f4420e5": {
      "main": [
        [
          {
            "node": "560a50a5-a96a-48b2-ab1e-1f6f0bcf2a15",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "a47d6a9b-9ca6-4716-9083-d43b666da2e0": {
      "main": [
        [
          {
            "node": "70630f26-3817-41f6-94ee-4f479ad15afe",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "70630f26-3817-41f6-94ee-4f479ad15afe": {
      "main": [
        [
          {
            "node": "dcffa91d-a4c7-4851-9bdb-85552f4420e5",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
Foire aux questions

Comment utiliser ce workflow ?

Copiez le code de configuration JSON ci-dessus, créez un nouveau workflow dans votre instance n8n et sélectionnez "Importer depuis le JSON", collez la configuration et modifiez les paramètres d'authentification selon vos besoins.

Dans quelles scénarios ce workflow est-il adapté ?

Avancé - Création de contenu, IA Multimodale

Est-ce payant ?

Ce workflow est entièrement gratuit et peut être utilisé directement. Veuillez noter que les services tiers utilisés dans le workflow (comme l'API OpenAI) peuvent nécessiter un paiement de votre part.

Informations sur le workflow
Niveau de difficulté
Avancé
Nombre de nœuds22
Catégorie2
Types de nœuds9
Description de la difficulté

Adapté aux utilisateurs avancés, avec des workflows complexes contenant 16+ nœuds

Liens externes
Voir sur n8n.io

Partager ce workflow

Catégories

Catégories: 34