How I built my first Telegram AI Chatbot with OpenAI API on n8n

I thought it would be very difficult to build a AI Chatbot and also must have programming and coding knowledge. After starting hands dirty with n8n workflows and few tries, I found it very easy and fun!

Now anyone can create powerful, intelligent bots that integrate with platforms like Telegram and OpenAI API in just a few steps with self-hosted or cloud based n8n platform.

In this post, I’ll share how I built my first Telegram AI chatbot using OpenAI API and n8n, from start to finish.


What You’ll Learn

  • How to connect Telegram with n8n

  • How to send and receive chat messages via webhook

  • How to integrate OpenAI API for intelligent responses

  • How to deploy your Telegram AI chatbot live


Step 1: Set Up a Telegram Bot

  1. Open Telegram and search for @BotFather.

  2. Send the command /newbot.

  3. Choose a name and a username for your bot.

  4. You’ll get an API Token — save it securely.
    Example: "1234567890:ABCdEfghIJklMNopQRstuVWxyZ"

This token allows n8n to connect to Telegram through the Telegram Trigger and Telegram Node.


Step 2: Create a New Workflow in n8n

  1. Go to your n8n dashboard.

  2. Click “New Workflow” and name it, for example:
    Telegram_AI_ChatBot

  3. Add a Telegram Trigger Node.

    • Select your Telegram credentials (use the bot token).

    • Set the event to On Message.

    • Save and activate the node.

This node will listen for any message sent to your Telegram bot.



Step 3: Connect to OpenAI API

Now, let’s make our bot intelligent using the OpenAI node.

  1. Add an HTTP Request Node after your Telegram Trigger.

  2. Configure it as follows:

    • Method: POST

    • URL: https://api.openai.com/v1/chat/completions

    • Headers:

      Authorization: Bearer YOUR_OPENAI_API_KEY
      Content-Type: application/json

This configuration sends the user’s Telegram message directly to OpenAI for processing.



Step 4: Code in JavaScript to convert the AI Response Back to Telegram

In this step we will convert the AI Response JSON to Text format, so that Telegram.

  1. Add another Telegram Node → choose Send Message.

  2. Set it up like this:

This ensures your bot replies to the same user who sent the message.


Step 5: Send AI Response Back to Telegram

Now, let’s send the AI’s reply back to the user on Telegram.

  1. Add another Telegram Node → choose Send Message.

This ensures your bot replies to the same user who sent the message.


Step 6: Test and Go Live

  1. Save your workflow.

  2. Click “Execute Workflow” or activate it for always-on mode.

  3. Go to your Telegram app, open your bot, and send a message.

You should now see your AI chatbot replying intelligently — powered by OpenAI and fully automated via n8n!


Bonus: Improving Your Bot

Once your base chatbot works, you can:

  • Add memory (store chat history in a database like PostgreSQL or Google Sheets)

  • Add filters to restrict access or add greetings

  • Integrate with webhooks for external services (like Notion, WordPress, or CRMs)

  • Deploy n8n on VPS or Docker for 24/7 uptime


Final Thoughts

Creating my first Telegram AI chatbot with n8n and OpenAI was a huge learning experience. I learned how automation workflows connect different platforms effortlessly — without writing complex code.

n8n’s visual interface makes it easy to experiment, and with OpenAI’s power, your bot can become as smart and creative as you want it to be.

If you’re thinking about building your own AI bot — start small, experiment, and let automation do the heavy lifting.


Tools Used

  • Telegram Bot API – for messaging

  • n8n – for automation workflows

  • OpenAI API (GPT-3.5/4) – for AI chat responses

  • Docker (optional) – for self-hosting n8n


Example Use Cases

  • AI-based customer support bot

  • Personal assistant for Telegram

  • Content or idea generator

  • Educational Q&A chatbot


Your Turn

Have you tried building your own Telegram or WhatsApp AI bot?
Share your experience or challenges in the comments — I’d love to hear about your setup!

Comments