Minggu, 17 Agustus 2025

Creating a Telegram Bot with N8N

| Minggu, 17 Agustus 2025

N8N has been gaining popularity lately due to its high flexibility. This platform can be installed on your own server (self-hosted) and is free to use, although there is a paid version with additional features.

So what is N8N? N8N is an open-source workflow automation platform that allows you to connect various applications and services without the need for heavy coding. Simply drag and drop the available nodes, then connect them like a puzzle.

What makes N8N even more popular is its ability to easily connect to various AI models such as OpenAI, Gemini, Claude, and even open-source models like Llama 2 and Mistral.

Previously, we discussed how to create a Telegram Bot using coding (Node.js and Go). This time, we will try an easier approach — creating a Bot without any coding at all!

Yep, with N8N, we can create a functional and interactive Bot simply by dragging and dropping. It's perfect for those who want to create a Bot but don't want to deal with programming syntax.

Fun Fact Bot
The bot we are going to create this time is the Fun Fact Bot. The concept is simple but fun — just give the bot any topic, and it will immediately provide interesting and unique facts!

For example, if we chat N8N to the bot, it will respond with interesting facts about N8N, as shown in the image below:

Fun Fact Bot

This is a Fun Fact Bot in Telegram App that you can try out.

Preparation
Before starting to create a Telegram Bot with N8N, there are several things we need to prepare.

  • Bot Token
    We need a Bot Token, which can be obtained from @BotFather on Telegram. This token functions as an access key so that the Bot can operate properly.

  • N8N
    Ensure that N8N is installed, either in a local or production environment. If using a local environment, ensure that you also use Ngrok or similar tools so that the N8N URL can be accessed using the HTTPS protocol (this is mandatory for Telegram webhooks).

  • Gemini API Key
    We will use Google Gemini to generate fun facts based on the given topic. The API key can be created for free on Google AI Studio — this will be the ‘brain’ of the Bot in generating interesting content.

Step 1: Telegram Trigger Node

First, we will create a Telegram Trigger Node that will receive a response when users send messages through the Bot we created.

Telegram Trigger Node

Ensure that Credential is set using the token obtained from BotFather.

Credential

Once you have configured your credentials, we will then set up the Bot webhook in Telegram by accessing this page.

https://api.telegram.org/bot<TOKEN_BOT_ANDA>/setWebhook?url=<URL_WEBHOOK_N8N>

Ensure that is replaced with the token obtained from BotFather and from Webhook Urls in N8N, and also ensure that you are using the HTTPS protocol.

If we access the URL, it should return a success message indicating that the webhook has been successfully set.

{
  "ok": true,
  "result": true,
  "description": "Webhook was set"
}

Next, we can press the Execute Step button to run the Node, and when the message Listening for test event appears, we can send a message to the Bot via the Telegram application.

Telegram Trigger Node

After sending a message to the Bot via the Telegram app, the message information will appear in the Output panel as follows:

Fun Fact Bot

After successfully receiving the message, Step 1 has been completed, and the following is the N8N workflow display after Step 1.

Fun Fact Bot

Step 2: LLM Basic Chain Node
The next step is to process the message received from the user into a fun fact with the help of the LLM Basic Chain Node.

LLM Basic Chain Node

In the Source for Prompt section, we will use the Define Below option and fill in the prompt with the following text:

I want a Fun Fact with the topic ``

Then connect the previous Telegram Trigger Node to the Basic LLM Chain Node

LLM Basic Chain Node

Once connected, an Input Panel containing data from the Telegram Trigger Node will appear on the Basic LLM Chain Node.

LLM Basic Chain Node

Then we will create a Chat Message with the System type and contain the following Message

You are a Fun Fact generator. Create a Fun Fact with the given topic in a format that is to the point, clear, concise, and written in an interesting style. Always start your answer with ‘Did you know?’.

Next, create a Google Gemini Chat Model Node and fill in the credentials with the Gemini API Key obtained from AI Studio. You can use the model as needed.

Google Gemini Chat Model Node

Connect the Basic LLM Chain Node with the Google Gemini Chat Model Node as shown in the following image:

Google Gemini Chat Model Node

Once all nodes are connected, it is time to run the Basic LLM Chain Node by pressing the Execute Step button. If successful, the fun fact results from Gemini AI will appear on the Output panel as follows.

Google Gemini Chat Model Node

Step 3: Telegram Node
The final step is to send the fun fact results from Gemini AI to users via Telegram. Create a new Telegram Node to send the message Send a text message.

Telegram Node

Then connect it to the Basic LLM Chain Node. In the Chat ID section, use the data from the Telegram Trigger Node and for Text use the data from the Basic LLM Chain Node.

Telegram Node

Then run Node by pressing the Execute Step button. If successful, information will appear in the Output Panel and a message will be sent to the user via Bot as follows:

Telegram Node

The final result of the N8N workflow will be as follows

N8N workflow

Conclusion
Creating a Telegram Bot with N8N is surprisingly easy! With just three nodes (Telegram Trigger, LLM Basic Chain, and Telegram), you can create an interactive and useful Bot without the hassle of coding.

Why is N8N a great choice?

  • Drag and drop — simply connect the nodes like a puzzle
  • Flexible — easily connect to various AI platforms (Gemini, OpenAI, Claude)
  • Fast — workflows are ready to go, no need for complicated coding environment setup

Fun Fact This bot is just the beginning. You can further develop it by adding features like a database to store chat history, an inline keyboard for cooler interactions, or even scheduling the bot to automatically send fun facts every day.


Related Posts

Tidak ada komentar:

Posting Komentar