n8nflow.net logo

Generate AI Images in Telegram with GPT-4o Enhancement and Flux Pro

by AI/ML API | D1m7asisβ€’Updated: Last update 2 months agoβ€’Source: n8n.io
Loading workflow viewer...

Getting Started

🧠 AI Image Generator Bot β€” Telegram + AI/ML API

This n8n workflow allows users to generate AI-generated images by sending messages to a Telegram bot. Each request is logged in Google Sheets and limited by a daily quota per user. Image prompts are enhanced by LLM before generation.


πŸš€ Features

  • πŸ“© Telegram-based input
  • 🧠 Prompt enhancement with GPT-4o
  • 🎨 AI image generation via flux-pro model (AIMLAPI)
  • πŸ–‹ Auto-caption generation
  • πŸ“Š Usage tracked per user daily in Google Sheets
  • πŸ”’ Daily request limits
  • βœ… Graceful UX for over-limit cases

πŸ›  Setup Guide

1. πŸ“² Create Telegram Bot

  • Talk to @BotFather
  • Use /newbot β†’ Choose a name and username
  • Save the bot token

2. πŸ” Set Up Credentials in n8n

  • Telegram API: Use your bot token
  • Google Sheets: Set up via OAuth2 or Service Account
  • AI/ML API: Set up with your API key from aimlapi.com

3. πŸ“— Prepare Google Sheet

  • Name: Any (e.g., Image bot usage statistic)

  • Sheet: Sheet1

  • Columns:

    user_id | date | query | result_url

  • Share the sheet with the email of your service/OAuth2 account

4. πŸ”§ Configure the Workflow

  • Open the n8n editor and import the JSON

  • Update:

    • Telegram credential
    • Google Sheets credential and Sheet ID
    • AI/ML API credentials

βš™οΈ Flow Summary

NodeFunction
πŸ“© Receive Telegram MessageTriggered by user message
πŸ“Š Fetch Usage LogsReads today's entries from Sheet
πŸ“ˆ Count Today’s RequestsCounts how many generations today
πŸ”’ Set Daily LimitSets default limit (5)
🚦 Check Limit Exceeded?If over limit β†’ notify
🧠 Enhance PromptUses GPT-4o to improve user's prompt
🎨 Generate ImageSends to AIMLAPI to generate
πŸ–‹ Describe ImageGenerates caption for the image
πŸ“€ Send Image to UserSends back to Telegram
πŸ“ Log Successful GenerationWrites to Google Sheets

πŸ“ Data Logging

Each successful generation is stored in Google Sheets:

user_iddatequeryresult_url

πŸ’‘ Example Prompt Flow

  1. User sends:

    astronaut cat floating in space

  2. Bot replies:

Here’s your image:
A majestic feline astronaut drifts through a glittering cosmic void, its helmet reflecting starlight.

  1. The image is sent with the caption

πŸ”„ Daily Limit

  • Default: 5 generations/day per Telegram user
  • You can change this in the πŸ”’ Set Daily Limit node

πŸ§ͺ Testing

  • Use /execute workflow in Telegram β€” not "Execute Node" in editor
  • Log test results to sheet
  • Add extra Set nodes for debugging as needed

πŸ“Ž Resources