Animated data flow diagram

AI-Powered Telegram Chat & Image Generation Agent

Version: 1.0.0 | Last Updated: 2025-05-16

Integrates with:

OpenAI Telegram LangChain

Overview

Unlock Conversational AI & On-Demand Image Generation in Your Telegram Bot

This AI Agent transforms your Telegram bot into a dynamic assistant. It listens to user messages, uses OpenAI's GPT-4o via LangChain for smart, context-aware replies, and can generate DALL-E 3 images on request. Ideal for automating engagement, providing creative content, or streamlining team tasks directly within Telegram.

Key Features & Benefits

  • AI-Powered Conversations: Leverages OpenAI's GPT-4o model and LangChain for natural, human-like text responses within Telegram.
  • Integrated Image Generation Ability: Employs DALL-E 3 to create and send images directly in the chat. The agent intelligently decides when to use this tool based on user prompts.
  • Contextual Memory: Utilizes LangChain's Window Buffer Memory to remember recent parts of the conversation, leading to more coherent and relevant interactions.
  • Tool-Equipped Agent: A practical example of a LangChain agent using multiple tools: one for generating images via an HTTP request to OpenAI, and another specific Telegram tool for sending the generated image.
  • Customizable Persona: Easily tailor the AI's system prompt within the 'AI Agent' node to define its personality, tone, and specific operational instructions (e.g., addressing users by name).
  • Seamless Telegram Integration: Automatically triggers on new Telegram messages and sends text replies or images back to the originating chat, creating an interactive experience.

Use Cases

  • Automating B2C e-commerce customer support on Telegram with visual product aids or troubleshooting images.
  • Enhancing B2B SaaS marketing by providing an interactive Telegram bot that can answer queries and generate custom visuals for prospects.
  • Empowering solopreneurs with a unique brand engagement tool on Telegram, offering personalized AI chat and creative image generation to their audience.
  • Streamlining internal team communication by deploying a Telegram bot capable of fetching information and creating visuals on demand for projects.
  • Building interactive educational or entertainment bots that can converse and provide dynamically generated images.

Prerequisites

  • An n8n instance (Cloud or self-hosted).
  • OpenAI API Key with access to GPT-4o (or a similar powerful model) and DALL-E 3.
  • A Telegram Bot Token from BotFather.
  • Ensure your n8n instance has LangChain nodes available (usually included in Cloud; for self-hosted, you might need to install the @n8n/n8n-nodes-langchain collection).

Setup Instructions

  1. Download the n8n workflow JSON file.
  2. Import the workflow into your n8n instance.
  3. Configure the 'Listen for incoming events' (Telegram Trigger) node: Select or create new Telegram API credentials using your Bot Token.
  4. Configure the 'OpenAI Chat Model' node: Select or create new OpenAI API credentials. Ensure the model is set to gpt-4o or your preferred compatible model.
  5. Configure the 'Generate image in Dalle' (LangChain HTTP Request Tool) node: Select the same OpenAI API credentials as in step 4. Confirm the URL points to the OpenAI image generation endpoint and dall-e-3 is specified as the model.
  6. Configure the 'Send back an image' (Telegram Tool) node: Select or create your Telegram API credentials (can be the same as in step 3).
  7. Configure the 'Send final reply' (Telegram) node: Select or create your Telegram API credentials (can be the same as in step 3).
  8. In the 'AI Agent' node, customize the systemMessage under 'Options' to define your agent's behavior, persona, and how it should interact with users and tools (e.g., how to handle image requests).
  9. Verify the sessionKey in the 'Window Buffer Memory' node is dynamic (e.g., chat_with_{{ $('Listen for incoming events').first().json.message.chat.id }}) to maintain separate conversation histories for different users.
  10. Activate the workflow. Test by sending messages and image requests to your Telegram bot.

Tags:

AI AgentTelegram AutomationOpenAILangChainImage GenerationDALL-EChatbotConversational AIProductivity

Want your own unique AI agent?

Talk to us - we know how to build custom AI agents for your specific needs.

Schedule a Consultation