n8n

How to Generate Telegram OpenAI Image Replies?

Turn your Telegram bot into a smart chat assistant that can answer questions and create images on request. Great for marketing and social media teams that need fast mockups, product images, or quick visual ideas right in chat. Everyone can ask for text or images without leaving Telegram.

Incoming Telegram messages start the flow. A GPT 4o chat model reads the message and keeps short memory of the last 10 messages per chat, so replies stay on topic and use the user’s first name. If a user asks for an image, the agent calls the Dall E 3 image API through a secure HTTP request and returns a direct image link. The bot then sends the image file back in Telegram. If no image is needed, a text reply is sent. All keys are stored as n8n credentials for safety.

You need a Telegram bot token and an OpenAI API key. Connect both in n8n and link them to the trigger, chat model, tools, and send steps. Expect faster content turnarounds and fewer back and forth messages. Use it for ad mockups, social posts, sales visuals, or quick concept art in a team chat. Setup is simple and can be live in minutes.

What are the key features?

  • Telegram trigger listens to all incoming events and starts the chat flow
  • GPT 4o chat model generates friendly replies and addresses users by first name
  • Window memory stores the last 10 messages per chat for context
  • Dall E 3 image generation via a secure HTTP POST to the OpenAI images endpoint
  • Agent tool routing sends image results back to Telegram as a file
  • Text replies are sent when no image is requested using mapped output
  • Credential management for Telegram and OpenAI keeps API keys safe

What are the benefits?

  • Reduce content requests from hours to minutes by replying and generating images inside Telegram
  • Automate up to 80 percent of simple image requests without designer involvement
  • Handle 5 times more chat requests with the same team using AI replies
  • Keep context for the last 10 messages to improve response quality
  • Connect Telegram and OpenAI in one flow with secure credentials

How do you set it up?

  1. Import the template into n8n: Create a new workflow in n8n > Click the three dots menu > Select 'Import from File' > Choose the downloaded JSON file.
  2. You'll need accounts with Telegram and OpenAI. See the Tools Required section above for links to create accounts with these services.
  3. In Telegram, use BotFather to create a bot and copy the bot token. Send a /start message to your bot so it can receive messages.
  4. In the n8n credentials manager, create a new Telegram credential. Paste the bot token and save. Name the credential clearly, for example Telegram Bot Main.
  5. Open the Telegram Trigger node and choose your Telegram credential. Keep updates set to all or messages. Save the node.
  6. In the n8n credentials manager, create a new OpenAI API Key credential. Get the key from your OpenAI account API page and paste it. Save and give it a clear name.
  7. Open the OpenAI Chat Model node and select your OpenAI credential. Confirm the model is gpt-4o and leave temperature and frequency settings as needed.
  8. Open the Generate image in Dalle tool node and select the same OpenAI credential. Confirm the model is set to dall-e-3 and that the method is POST to the images generations endpoint.
  9. Open the AI Agent node and confirm it uses the chat model, the memory buffer, and both tools. Keep the system message that instructs the agent to call the image tool when a user asks for an image.
  10. Check the Send final reply and Send back an image nodes. Make sure chatId fields reference the incoming Telegram message and that the image tool maps the url field correctly.
  11. Activate the workflow. In Telegram, send a normal question to confirm a text reply works. Then ask for an image, like Create a sunset beach logo, to confirm the image is returned.
  12. If no image is received, check n8n execution logs, confirm your OpenAI billing is active, verify the OpenAI credential key, and make sure the bot has been started in Telegram.

Tools Required

$24 / mo or $20 / mo billed annually to use n8n in the cloud. However, the local or self-hosted n8n Community Edition is free.

OpenAI

Sign up

Pay-as-you-go: GPT-5 at $1.25 per 1M input tokens and $10 per 1M output tokens

Telegram

Sign up

Free: $0, Telegram Bot API usage is free for developers

Similar Templates

Join Futurise to access 1,200+ automation templates

Get instant access to ready-made automation workflows for n8n, Make.com, AI agents, and more. Download, customise, and deploy in minutes.