Build an Agentic Telegram AI Bot with LangChain in n8n

Discover how to create a powerful Telegram AI bot integrating LangChain nodes and OpenAI’s GPT-4o. This automation listens for Telegram messages, manages conversation memory, and can generate and send Dall-E-3 images, saving hours in user interaction handling.
telegramTrigger
lmChatOpenAi
memoryBufferWindow
+4
Workflow Identifier: 1899
NODES in Use: telegramTrigger, lmChatOpenAi, memoryBufferWindow, telegram, toolHttpRequest, agent, telegramTool
Automate Telegram AI with n8n and LangChain

Press CTRL+F5 if the workflow didn't load.

Learn how to Build this Workflow with AI:

What This Workflow Does

This workflow listens to Telegram messages and replies using AI. It answers chat messages and can make images when asked. It remembers the last 10 messages to keep the chat natural. The AI chooses if it answers by text or by creating an image. The result is faster replies and useful images sent back in Telegram.


Who Should Use This Workflow

This workflow is for anyone who talks to many people on Telegram and wants help answering messages. It works well for freelancers, support teams, or small businesses that want faster replies without typing all the time. Users who want images made by AI inside Telegram will also find it useful.


Tools and Services Used

  • Telegram Bot API: Receives user messages and sends replies or images.
  • n8n automation platform: Runs the workflow connecting all steps and tools.
  • OpenAI GPT-4o model: Generates chat replies with creative but limited repetition.
  • OpenAI Dall-E-3 API: Creates images from user prompts.
  • LangChain nodes in n8n: Handle AI models and manage conversation memory.

Beginner Step-by-Step: How to Use This Workflow in n8n

Step 1: Import the Workflow

  1. Download the ready workflow file using the “Download” button on this page.
  2. Open n8n and go to the editor screen.
  3. Click on “Import from File” and choose the downloaded workflow file.

Step 2: Configure Credentials

  1. Enter your Telegram Bot API Token in the Telegram credentials section.
  2. Add your OpenAI API Key for GPT-4o and Dall-E-3 access.

Step 3: Adjust Settings if Needed

  1. Check nodes that use chat IDs or file paths and update values if required.
  2. Review prompt messages in the AI Agent node to add your style or name.

Step 4: Test the Workflow

  1. Send test messages to your Telegram bot and watch the responses in n8n executions.
  2. Make sure images generate correctly when prompted.

Step 5: Activate for Production

  1. Turn on the workflow by clicking the “Active” toggle in n8n.
  2. Keep your n8n server running so messages process without delay. Consider self-host n8n if needed.

Input → Process → Output

Input

Processing Steps

  • Telegram Trigger detects new messages.
  • Window Buffer Memory stores last 10 messages per user for context.
  • AI Agent decides if reply is text or image based on input.
  • OpenAI Chat Model creates text replies using GPT-4o with controlled creativity.
  • Generate image in Dalle makes an image using Dall-E-3 when requested.
  • Send back an image sends generated image file to user in Telegram.
  • Send final reply posts text answer back to user.

Output


Customization Ideas

  • Change Window Buffer Memory to keep more messages for longer chat history.
  • Switch AI models for cheaper or faster responses in OpenAI Chat Model node.
  • Edit system messages in AI Agent node to add custom greetings or instructions.
  • Add command recognition to handle Telegram commands like “/help” and reply with templates.
  • Customize image style in prompts to produce pictures in specific artistic looks.

Common Problems and Fixes

Problem: Workflow Does Not Start on Telegram Message

Cause might be wrong Telegram API Key or webhook not accessible.

Fix by rechecking credentials in the Telegram Trigger. Make sure n8n server is public and Telegram can send updates. Use “Test Trigger” button to confirm.

Problem: Images Are Not Sent Back

User may not get image if the Send back an image node does not get a valid URL or Telegram bot lacks permission.

Check the AI Agent output for image URLs. Confirm bot permissions allow sending documents. Test image URL manually to verify it opens correctly.

Summary and Results

✓ The workflow listens and replies fast to user chats.

✓ It remembers recent talks for better replies.

✓ It makes images when users want pictures.

→ The user gets good, friendly answers and images inside Telegram.

→ This saves time and helps users stay engaged.


Pre-Production Checklist

  • Check Telegram API credentials and bot permissions.
  • Confirm OpenAI API keys work for GPT-4o and Dall-E-3.
  • Test webhook triggers with example Telegram messages.
  • Make sure conversation memory works by checking stored messages.
  • Verify image generation results in pictures arriving in Telegram.
  • Save a backup copy of the workflow JSON before deploying.

Deployment Guide

After tests pass and workflow nodes show running, toggle the “Active” switch in n8n.

Keep the n8n service running all the time. Consider self-host n8n for stable access.

Watch the Telegram trigger node to see incoming messages and use logs for error checking.

Track OpenAI API usage to avoid exceeding limits or unexpected billing.


Automate Telegram AI with n8n and LangChain

Visit through Desktop to Interact with the Workflow.

Frequently Asked Questions

In n8n, go to Settings then API Credentials. Add the Telegram Bot API Token under Telegram credentials. Test the connection in the Telegram Trigger node.
Images may not send if the image URL is missing or invalid in the AI Agent output. Also check that the bot has permission to send documents.
Yes. The Window Buffer Memory node uses chat IDs to keep conversation history separate for each user.
Test messages in your Telegram bot until the workflow works. Then switch on the workflow’s Active button in n8n. Make sure n8n runs continuously.

Promoted by BULDRR AI

Related Workflows

Automate Twist Channel Creation and Messaging with n8n

This workflow automates creating and updating a channel in Twist and sending a personalized message to specific users. It eliminates manual setup errors and saves time managing Twist communications.

Automate Ideogram Image Generation with Google Sheets & Gmail

This workflow automates graphic design image generation via Ideogram AI, storing image data in Google Sheets and Google Drive, with email alerts via Gmail. It saves designers hours by automating image creation, remixing, review, and record-keeping.

Automate IT Support with Slack and OpenAI in n8n

Streamline IT support by automating Slack message handling using n8n and OpenAI. This workflow handles Slack DMs, filters bots, queries a Confluence knowledge base, and delivers AI-generated responses, improving support efficiency and response time.

Automate Crypto Analysis with CoinMarketCap & n8n AI Agent

Discover how this unique n8n workflow leverages CoinMarketCap’s multi-agent AI to deliver precise, real-time cryptocurrency insights directly via Telegram. Manage crypto data analysis efficiently with automated multi-source API integration.

Automate Gumroad to Beehiiv Subscriber Sync with n8n

Learn how to automatically add new Gumroad sales customers as Beehiiv newsletter subscribers using n8n automation. This workflow saves time by syncing sales data to Google Sheets CRM and notifying your Telegram channel instantly.

Generate On-Brand Blog Articles Using n8n and OpenAI

This workflow automates the creation of on-brand blog articles by analyzing existing company content using n8n and OpenAI. It extracts article structures and brand voice to produce consistent draft articles, saving significant content creation time.
1:1 Free Strategy Session
Your competitors are already automating. Are you still paying for it manually?

Do you want to adopt AI Automation?

Every hour your team does repetitive work, you're burning real money.
While you wait, faster businesses are cutting costs and moving quicker.
AI and automations aren't the future anymore — they're the present.

Book a live 1-on-1 session where we show you exactly which of your daily tasks can be automated — and what it’s costing you not to.