Albato
  • Language
    En
    English
    Portuguese
    Spanish
  • Welcome to Albato Help

    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

    1. 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.

    2. 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.

    3. 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.

    1. Create and configure the Albato Telegram Bot connection following the instructions in Connecting Telegram to Albato.

    2. To store the chat history, create and configure temporary storage — Albato Data Storage.

    3. 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.

    Automations tab with Create a new automation button

    Step 1

    Set up the Telegram: Incoming message trigger.

    Telegram Incoming message trigger setup

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

    Selecting Telegram trigger connection and clicking 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.

    Adding Router tool step

    Router tool added to automation

    For now, skip the configuration and close the window.

    Closing Router configuration window

    Step 3

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

    Adding Data Storage action step

    Data Storage step configuration — part 1

    Data Storage step configuration — part 2

    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.

    Adding Telegram Send message action step

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

    Selecting Telegram Send message connection and clicking Continue

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

    Entering message text in Telegram Send message step

    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.

    Adding Break tool to automation

    Break tool inserted into 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.

    Adding Find Value action step from Data Storage

    Find Value step configuration

    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.

    Router configuration — condition for /clear command

    Router configuration — complete branch setup

    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.

    Adding JavaScript action step

    JavaScript step 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};

    JavaScript step — incoming data configuration

    JavaScript step — outgoing data configuration

    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.

    Adding OpenRouter action step

    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.

    OpenRouter step configuration

    Next, save the AI response back to the chat history.

    Step 9

    Add the Data Storage action step again and configure it.

    Adding Data Storage step to save AI response

    Data Storage step for saving AI response — configuration

    The final step is to send the AI response back to Telegram.

    Step 10

    Add the Telegram: Send message action and configure it.

    Adding Telegram Send message step for AI response

    Telegram Send message step configuration for AI response

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

    Complete automation flow overview

    Don't forget to start the automation.

    Starting 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?