Animated data flow diagram

Telegram AI Agent: GPT-4 Chat & DALL-E 3 Image Generation with Langchain

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

Integrates with:

OpenAI Telegram Langchain

Overview

Unlock Interactive AI Engagement & On-Demand Image Creation with this AI Agent

This n8n workflow deploys a sophisticated AI Agent for your Telegram channel. It's not just a chatbot; it's an AI assistant with dual abilities: engaging in intelligent, context-aware conversations using OpenAI's GPT-4, and generating stunning images on demand with DALL-E 3 directly within the chat.

Imagine your users or team members interacting naturally, asking complex questions, and even requesting custom visuals—all automated. This agent is perfect for enhancing customer engagement, providing automated support, or offering creative assistance with visual content.

Key Features & Abilities

  • Advanced Conversational AI: Leverages OpenAI's GPT-4 for natural, human-like text interactions and understanding user intent.
  • AI Image Generation: Equipped with a DALL-E 3 tool, allowing users to request and receive AI-generated images through simple chat commands.
  • Contextual Memory: Utilizes Langchain's window buffer memory to maintain conversation history, leading to more coherent and relevant dialogues over multiple turns.
  • Seamless Telegram Integration: Listens for incoming Telegram messages via a trigger and responds directly to users, including handling HTML formatting for rich messages.
  • Intelligent Tool Usage: The AI Agent can decide when to use its tools (like the DALL-E 3 image generator) based on the conversation.
  • Extensible & Customizable: The core agent logic, including the system prompt defining its personality and operational guidelines, can be easily modified to suit specific needs.
  • Handles Telegram Commands: Designed to interpret and respond to standard Telegram commands (e.g., /start) and custom commands you might define.

Use Cases

  • B2C E-commerce: Offer 24/7 AI customer support on Telegram, answer product queries, and generate product mockups or creative visuals for marketing campaigns.
  • B2B SaaS: Provide instant AI-driven technical assistance or feature explanations via Telegram, and generate diagrams or concept art for presentations.
  • Solopreneurs/Creators: Automate responses to common questions on a Telegram community channel and offer unique AI-generated art or content based on user requests.
  • Internal Team Tool: Create an internal Telegram bot for team members to quickly get information or generate creative assets for projects.

Prerequisites

  • An n8n instance (Cloud or self-hosted).
  • OpenAI API Key with access to a GPT-4 model (e.g., gpt-4-1106-preview) and DALL-E 3.
  • Telegram Bot API Token.
  • n8n Langchain nodes installed (e.g., @n8n/n8n-nodes-langchain).

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: Set up your Telegram Bot API credentials.
  4. Configure the 'OpenAI Chat Model' node: Add your OpenAI API credentials.
  5. Configure the 'Generate image in Dall-E 3' (HTTP Request) node: Add your OpenAI API credentials.
  6. Configure all 'Telegram' (send message) nodes: Ensure they use the same Telegram Bot API credentials as the trigger.
  7. Review the 'Window Buffer Memory' node: The sessionKey (e.g., chat_with_{{ $('Listen for incoming events').first().json.message.chat.id }}) is crucial for per-user conversation memory.
  8. Customize the 'AI Agent' node: Modify the systemMessage to define your AI's personality, HTML formatting rules, and how it handles commands.
  9. The 'Dall-E 3 Tool' node is set up to call this same workflow to generate images. The Execute Workflow Trigger and subsequent nodes handle this image generation flow. Ensure the tool's workflowId parameter is correctly set to {{ $workflow.id }}.
  10. Activate the workflow and test by sending messages to your Telegram bot, including requests to draw images.

Tags:

AI AgentTelegramOpenAIDALL-E 3Image GenerationChatbotLangchainAutomationConversational AI

Want your own unique AI agent?

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

Schedule a Consultation