# n8n : AI Telegram chatbot

> Source: <https://dev.to/khalid_edaoudi_f60d2bbc68/n8n-ai-telegram-chatbot-24d5>
> Published: 2026-05-26 14:57:14+00:00

n8n is a source-available, low-code workflow automation platform that allows users to automate repetitive tasks, integrate multiple apps and services, and build complex workflows with or without extensive coding knowledge.

You can use n8n in cloud (14 days in free trial), or in local by running a docker image of the official n8n's image in docker hub.

install n8nio/n8n image then run the next command:

```
docker run -it --rm --name n8n -p 5678:5678 -e GENERIC_TIMEZONE="Africa/Casablanca" -e TZ="Africa/Casablanca" -e N8N_ENFORCE_SETTINGS_FILE_PERMISSIONS=true -e N8N_RUNNERS_ENABLED=true -v n8n_data:/home/node/.n8n docker.n8n.io/n8nio/n8n
```

you can change the timezone

then create an account and you will be redirected to the n8n dashboard to create your first workflow

but in this post we will work with n8n in cloud by creating an account for free, and use the free trial, then you will have a hosted n8n instance on the web to automate tasks using various apps without problems.

In this post we will build a Telegram bot connected with n8n:

first of all create a bot in your telegram account using BotFather, follow instructions to create your personal bot.

Then create a personal workflow in n8n dashboard:

every workflow starts with a trigger as a first step, the trigger is the event listener that really executes the workflow, it can be a mouse click, message input, webhook but in this example our trigger is a telegram message, so click on the plus canvas and search for "**telegram**" and select **On message** trigger.

Then the configuration window appear :

click on **Set up credentials**, and put your access token (You can get the access token of your chatbot from **BotFather** by sending "**/token**" then the username of your bot

and click save (A success toast appear at the right bottom if the connection is successfully settled between n8n and telegram)

Now our workflow is ready to receive messages from the bot, you can test that by double clicking on the node and click on **Execute step** to pull events from telegram, then send a new message from bot, you will see an output in the right side of the window contains meta data of your message , which means the trigger is successfully receiving message from telegram.

Now you have a plus icon to add more nodes to complete your workflow, click on it

And add an AI Agent Node

Now we need to configure our Agent with a AI model to use to generate responses and a memory storage to conserve previous chats.

click on Chat Model's plus and choose **Google Gemini Chat Model**

We will use **Gemini 2.5 flash** model api key, it is completely free and you can get it from **Google AI studio** ([https://aistudio.google.com/](https://aistudio.google.com/)), create a new project an copy paste the api key into the credentials section of your node.

And that is it ! you have a real AI modal connected to your Agent, Now he can generate responses after understanding messages, that is the power of low-code tools, it does not require a lot of technical knowledge about AI Agents and coding, it's just about drag and drop and configure credentials and api tokens.

n8n offers a lot of AI models to use, all what you have to do is copy and paste the api key.

So when you have a conversation whit someone, it's always essential to keep remembering the paste chats and ideas to keep chating and interacting with him, that 'remembring' part is the memory storage in AI Agents world, the agent use the memory tool to store previous chats and interactions.

We will use a Simple Memory, you can of course use you favorite database as a memory that's will be more efficient then using the memory node offered by n8n, but that will serve us in more complex workflows.

Change the session ID to **Define Below** and copy paste this line of code into the key input :

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

Tools are representing apps to use by the AI agents like for example google calendar to retrieve appointments or google sheet to store some data etc ...

but in our chatbot workflow we will use **Think Tool**, to push the agent to think before responding.

Now we after generating the message we need to finish the workflow by the node that will send the message to the telegram bot as response, to that add **Send a text message node**.
