Automation with AI and Telegram: Creating an Intelligent Chatbot
IN THIS ARTICLE
Artificial intelligence is becoming part of everyday work. More and more users are adding AI-powered apps to their automations to unlock practical new use cases.
Goal of this automation
To create a custom chatbot by integrating Telegram and an AI app. This bot answers questions and remembers the dialogue, providing a deeper and more personalized experience.
How the automation works
-
Clear dialog — Send the /clear command to erase your conversation history with the AI. This is handy when you want to start a new dialog from scratch.
-
Ask questions — Enter your messages, gradually making your queries more complex. The AI will take into account all previous context and provide more accurate answers.
-
Change topic — To start a new topic, use /clear again. This ensures that the old context does not affect the current dialog.
Telegram is used here as an example because it is popular, quick to set up, and well suited for integration. You can adapt the same logic to another messenger if needed. You can also run the bot inside a Telegram group so each participant can ask the AI a question and everyone can see the answer. In a group, questions for the AI should begin with, for example: /what model are you?.
Before proceeding to automation setup, create connections to the services you will need.
-
Create and configure the Albato Telegram Bot connection following the instructions in Connecting Telegram to Albato.
-
To store the chat history, create and configure temporary storage — Albato Data Storage.
-
Register in OpenRouter and create a connection in Albato following the instructions at OpenRouter.
Create the automation
Go to the Automations tab and click Create a new automation.

Step 1
Set up the Telegram: Incoming message trigger.

Select the application, trigger, and the connection you created earlier, then click Continue.

Step 2
Add the Router tool, but do not configure it yet. We will return to it later.
To add the tool, perform the following actions.


For now, skip the configuration and close the window.

Step 3
Clear the message history storage, since the chat is new. Add a Data Storage action step and configure it.



After clearing the previous dialog, send a confirmation message so the user knows the command was accepted and the history was cleared.
Step 4
Add the Telegram: Send message action step. Click Add, choose an action, and configure it.

Choose the application, action, and connection, then click Continue.

Enter the message text. You can write what you like. Click Save when done.

Because the Router tool branches the automation, you need a Break step after clearing the history and sending the confirmation message.
Step 5
Click Add, select Tool, and find Break. This tool requires no settings — just insert it into the automation.


Next, find the record of the chat and all previous messages in storage.
Step 6
Add an action step and configure it. The action here is Find Value.


Now go back to Step 2 — Router — and configure it.
Set the conditions: if the incoming Telegram message text equals /clear, go to Step 3; otherwise go to Step 6. Click Save. The result should look like the screenshot below.


Next, add a JavaScript step so the conversation is stored in sequence inside Data Storage.
Step 7
Click Add, choose Action, find JavaScript, and open its settings.


Configure the incoming and outgoing data fields, and specify which data to take from previous steps.
Paste the following script:
const chat = history ? ${history}\nUser: ${message} : User: ${message};


Save the changes before moving on.
Now configure the request that will be sent to the AI.
Step 8
Add an action step, find the OpenRouter application, and configure it.

In this example, a free AI model is used with replies limited to 100 words. You can adapt this step later by choosing a different model or changing the prompt.

Next, save the AI response back to the chat history.
Step 9
Add the Data Storage action step again and configure it.


The final step is to send the AI response back to Telegram.
Step 10
Add the Telegram: Send message action and configure it.


Your automation is now ready. The final flow should look like this:

Don't forget to start the automation.

Now you can use your AI-powered Telegram chatbot with persistent conversation history. If you have any questions, contact our support via chat.
Did this answer your question?