An automated Telegram bot that generates AI images with platform-aware formatting and publishes to a channel only after human approval, built with n8n and OpenAI's image API.



Project details

Context:

Problem:


Solution

<aside> 🧠

The system receives an image request via Telegram, detects the target platform from a keyword in the message, generates the image in the correct aspect ratio, sends it back for review, and only publishes to the channel after the user explicitly approves it.

Tools used: n8n, Telegram Bot API, OpenAI (GPT-image model), Switch/Merge routing logic.

</aside>

Solution logic:

  1. A message is received via Telegram Trigger and normalized (text, user, chat ID).
  2. The message is routed by a Switch node based on keywords: "insta" → portrait format, "fb" → landscape format, no keyword → square default, "/start" → onboarding instructions.
  3. The platform keyword is stripped from the text before it's used as the image prompt — so "insta a cat drinking coffee" generates a clean prompt without the routing keyword leaking into the image.
  4. The image is generated via OpenAI's image API at the dimensions matching the detected platform (1024x1536, 1536x1024, or 1024x1024).