Build a Telegram AI Chatbot with n8n and OpenAI

This workflow automates AI-powered responses on Telegram using n8n and OpenAI. It solves the challenge of providing instant, helpful, and engaging chatbot replies, saving time and enhancing user interaction.
telegramTrigger
lmChatOpenAi
agent
+1
Workflow Identifier: 1074
NODES in Use: Telegram Trigger, OpenAI Chat Model, AI Agent, Telegram

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

Learn how to Build this Workflow with AI:

Visit through Desktop for Best experience

Opening Problem Statement

Meet Sarah, a small business owner who recently launched a Telegram group to engage with her customers and provide instant support. However, the constant flood of messages overwhelms her and her team. They spend countless hours typing repetitive responses, leading to delayed replies and frustrated customers. The manual approach not only wastes time but also leaves gaps in customer satisfaction and engagement.

Sarah needs a smarter solution that can manage conversations reliably without draining resources. She wants an automated assistant that understands queries and replies naturally, providing helpful and engaging answers immediately.

What This Automation Does

This specific n8n workflow integrates Telegram with OpenAI’s language model to create a powerful AI chatbot assistant. Here’s exactly what happens when the workflow runs:

  • Listens for new messages in a specified Telegram chat using the Telegram Trigger node.
  • Processes incoming messages through an AI Agent node empowered by the OpenAI Chat Model.
  • Automatically generates friendly and emoji-enriched responses to user queries.
  • Sends the AI-generated message back to the Telegram chat, maintaining seamless conversation flow.
  • Ensures interaction happens in near real-time, reducing response delays down to seconds.
  • Offers a scalable chatbot solution without need for manual message typing or monitoring.

By automating Sarah’s messaging, this workflow can save hours each day, eliminate repetitive tasks, and enhance user engagement with personalized, fast AI replies.

Prerequisites ⚙️

  • n8n Account – for building and running the workflow.
  • Telegram Account & Bot – configured with API credentials to receive and send messages.
  • OpenAI Account – with API access to utilize the AI language model.
  • API Credentials – For both Telegram and OpenAI to authorize node operations.

Step-by-Step Guide

1. Create a Telegram Bot and Get API Credentials

Head over to Telegram and create a bot via BotFather. Obtain the bot token for API usage. You’ll need to link this token to the Telegram nodes in n8n.
Expected outcome: A bot ready to receive messages.

2. Set Up Telegram Trigger Node in n8n

In n8n, add the “Telegram Trigger” node.
Navigate: Nodes Panel → Search “Telegram Trigger” → Add to canvas
Configure it by linking your Telegram API credentials.
Select “message” as the update type.
You should see webhook information for Telegram.
Common mistake: Not setting the Telegram bot webhook properly, which prevents receiving messages.

3. Add OpenAI Chat Model Node

Add the “OpenAI Chat Model” node from the LangChain package.
Go to Nodes Panel → Search “OpenAI Chat Model” → Add.
Connect your OpenAI API credentials.
Leave default options unless customization required.
Expected outcome: Node ready to process language input.

4. Configure AI Agent Node

Add the “AI Agent” node (LangChain agent).
Use the following in the text parameter:

=Respond to this as a helpful assistant with emojis: {{ $json.message.text }}

This instructs the AI to reply helpfully, adding emoji flair.
Common mistake: Omitting the mustache syntax or incorrect JSON path causes the AI to fail generating accurate replies.

5. Wire Telegram Trigger to AI Agent

Connect the output of “Telegram Trigger” to the input of “AI Agent”.
This routes incoming messages to the AI for processing.

6. Link OpenAI Chat Model to AI Agent

Set the AI Agent’s language model to the OpenAI Chat Model node via the ai_languageModel connection.
This enables the AI Agent to use OpenAI for chat responses.

7. Connect AI Agent to Telegram Node

Add a “Telegram” node.
Set the text field to

= {{ $json.output }}

to use AI Agent’s output.
Set chatId to pass incoming chat ID:

= {{ $('Telegram Trigger').item.json.message.chat.id }}

Link AI Agent’s output to this Telegram node.
Expected outcome: The message generated by AI is sent back to the Telegram user.

8. Test the Workflow

Activate the workflow.
Send a message to your Telegram bot.
You should receive an automated, friendly reply with emojis within seconds.
Common mistake: Forgetting to activate the workflow results in no responses.

Customizations ✏️

1. Modify AI Response Style

In the AI Agent node, change the text parameter prompt. For example, switch “helpful assistant with emojis” to “professional and concise answers”.
This alters the personality of the chatbot.

2. Support More Telegram Updates

In Telegram Trigger node, add update types such as “edited_message” or “callback_query”.
This broadens the kinds of interactions your bot can handle.

3. Log Conversations for Analysis

Add additional nodes (e.g., Google Sheets, Airtable) to store incoming questions and AI replies.
This requires integrating those nodes and mapping relevant fields.
Use this data to improve bot training later.

Troubleshooting 🔧

Problem: “No messages received in Telegram Trigger”

Cause: Telegram webhook not configured or invalid bot token.
Solution: Recheck Telegram bot webhook URL in Telegram Trigger settings, confirm API token validity.

Problem: “AI Agent returns no output”

Cause: Incorrect prompt syntax or unlinked OpenAI Chat Model node.
Solution: Verify the prompt field uses {{ $json.message.text }} correctly and the ‘ai_languageModel’ connection is properly set.

Pre-Production Checklist ✅

  • Confirm Telegram bot token and API credentials are correct.
  • Test webhook connectivity by sending a test message to the bot.
  • Ensure OpenAI API key has sufficient usage quota.
  • Validate that the AI agent responds correctly to test inputs.
  • Activate workflow only after complete setup.

Deployment Guide

Once tested, activate the workflow in n8n.
Monitor runtime logs via the n8n dashboard.
This chatbot can handle multiple user queries concurrently due to n8n’s event-driven architecture.
For self-hosting enthusiasts, consider hosting your own n8n instance for full control—visit Hostinger n8n Hosting.

FAQs

Can I use a different messaging platform instead of Telegram?

Yes, but you will need to replace the Telegram Trigger and Telegram nodes with equivalents for other platforms like Slack or WhatsApp if available in n8n.

Does this workflow consume OpenAI API credits?

Yes, each message processed via the OpenAI Chat Model counts toward your API usage quota. Monitor usage in your OpenAI dashboard.

Is my data safe in this automation?

Your messages and AI responses pass through n8n and OpenAI servers. Secure your API keys and consider self-hosting n8n for added privacy.

Conclusion

By following this tutorial, you created a smart Telegram AI chatbot using n8n and OpenAI. It transforms manual message handling into automated, friendly conversations enriched with emojis. Sarah’s team now saves hours daily and engages customers instantly with minimal effort.

Next up, you can explore adding conversation logging for analytics or expand to multi-channel support with other messaging apps. Keep experimenting and enhancing your automation skills!

Promoted by BULDRR AI

Related Workflows

Automate Viral UGC Video Creation Using n8n + Degaus (Beginner-Friendly Guide)

Learn how to automate viral UGC video creation using n8n, AI prompts, and Degaus. This beginner-friendly guide shows how to import, configure, and run the workflow without technical complexity.
Form Trigger
Google Sheets
Gmail
+37
Free

AI SEO Blog Writer Automation in n8n (Beginner Guide)

A complete beginner guide to building an AI-powered SEO blog writer automation using n8n.
AI Agent
Google Sheets
httpRequest
+5
Free

Automate CrowdStrike Alerts with VirusTotal, Jira & Slack

This workflow automates processing of CrowdStrike detections by enriching threat data via VirusTotal, creating Jira tickets for incident tracking, and notifying teams on Slack for quick response. Save hours daily by transforming complex threat data into actionable alerts effortlessly.
scheduleTrigger
httpRequest
jira
+5
Free

Automate Telegram Invoices to Notion with AI Summaries & Reports

Save hours on financial tracking by automating invoice extraction from Telegram photos to Notion using Google Gemini AI. This workflow extracts data, records transactions, and generates detailed spending reports with charts sent on schedule via Telegram.
lmChatGoogleGemini
telegramTrigger
notion
+9
Free

Automate Email Replies with n8n and AI-Powered Summarization

Save hours managing your inbox with this n8n workflow that uses IMAP email triggers, AI summarization, and vector search to draft concise replies requiring minimal review. Automate business email processing efficiently with AI guidance and Gmail integration.
emailReadImap
vectorStoreQdrant
emailSend
+12
Free

Automate Email Campaigns Using n8n with Gmail & Google Sheets

This n8n workflow automates personalized email outreach campaigns by integrating Gmail and Google Sheets, saving hours of manual follow-up work and reducing errors in email sequences. It ensures timely follow-ups based on previous email interactions, optimizing communication efficiency.
googleSheets
gmail
code
+5
Free