Skip to content
Docs

How to connect a Telegram agent

This guide takes you from a fresh Telegram bot to a working agent: someone messages your bot, your Agent answers, the reply lands back in Telegram, and the conversation is remembered across messages.

  • An agent flow shaped like Webhook → Agent → Channel/Telegram reply. The Telegram support agent template is wired this way, with its Webhook node named Telegram inbound, and is the easiest starting point.
  • A Telegram account (to create the bot and to chat with it).
  • An LLM provider key for the Agent (for example an OpenAI key).

In Telegram, open a chat with @BotFather, send /newbot, and follow the prompts. BotFather gives you a bot token that looks like 8012345678:AAH…. Keep it handy.

Your flow reads the bot token from a secret, so it never lives in the flow definition. In your workspace, go to Secrets and create an opaque secret:

Secret name Slug the flow expects Value
telegramBotToken telegrambottoken the BotFather token

The Telegram node reads it as {{ $secrets->telegrambottoken }}. Name the secret exactly as above so the slug matches.

The agent pays for its model with the workspace’s key for the provider, set on the AI models page, so add one there if the workspace has none. To pay with another key, pick the secret that holds it in the Agent node’s credential field.

3. Create a webhook and point the trigger at it

Section titled “3. Create a webhook and point the trigger at it”

Telegram delivers messages to an inbound webhook URL. That URL is tied to a webhook, and the Webhook node that starts your flow must reference the same one.

  1. Go to Webhooks and create a new webhook. Use Copy beside the address under its name to copy the full inbound URL, and note its ID, the address’s last part.

    The webhook's address under its name at the top of its page, with Copy beside it
    The webhook's address under its name at the top of its page, with Copy beside it
  2. Open your flow, click the Webhook node (Telegram inbound in the template), and pick that webhook in its Webhook field. Click Save changes.

Tell Telegram where to send messages by calling setWebhook once with your bot token and the URL you copied from the webhook:

Terminal window
curl "https://api.telegram.org/bot<YOUR_BOT_TOKEN>/setWebhook?url=<COPIED_WEBHOOK_URL>"

A successful response is {"ok":true,"result":true,"description":"Webhook was set"}.

Send your bot a message in Telegram, for example “Hi! What can you help with?”. Within a few seconds it replies with the agent’s response.

Voice messages. The agent hears a voice note through its attachments field, which the template sets to {!! json_encode($start->attachments) !!}. Keep it: a voice note has no text, and on Telegram a transcript is never put into the message text. The webhook needs the bot token to fetch the note (Connect a channel stores it). When the workspace transcribes Telegram voice notes on arrival (AI models → Voice messages), the agent reads that transcript instead of transcribing the note again.

  • Run: in your workspace, open Runs and confirm a run of your flow completed.

  • Reply: the agent’s answer appears in your Telegram chat.

  • The bot: when you connected the bot from an agent’s Connect a channel, its webhook (under Webhooks) holds the token, and Check the bot on the webhook’s page asks Telegram whether the token works and whether it sends the bot’s messages to this webhook.

    Check the bot for a Telegram bot: the token belongs to @AcmeDispatchBot, privacy mode limits what it hears in groups, Telegram sends its messages to this webhook, and voice notes arrive untranscribed
    Check the bot for a Telegram bot: the token belongs to @AcmeDispatchBot, privacy mode limits what it hears in groups, Telegram sends its messages to this webhook, and voice notes arrive untranscribed
  • Memory: open Conversations. A thread now exists for this conversation, keyed by the channel, chat, and user, holding both the incoming message and the agent’s reply. Send a second message that refers to the first (tell the bot a fact, then ask about it) and confirm the agent remembers, drawing on that thread.

  • Telegram reports 404 Not Found (check with getWebhookInfo): the Webhook node’s Webhook doesn’t match the webhook whose URL you registered. Point the node at the same webhook, then re-run setWebhook.
  • Telegram reports a 500: open the run under Runs for the error. A common cause is an empty or wrong secret.
  • No reply arrives: confirm the bot token secret holds the right value, that the workspace has a key for the agent’s provider on the AI models page, and that a queue worker is running to process runs.
  • Fill in the form says to start a chat with the bot first: Telegram lets a bot write only to someone who has started a chat with it, and the form’s link goes to your own chat with the bot. Open the bot, press Start, then press Fill in the form again.
  • The bot answers in a direct chat, but not in a group: Telegram’s privacy mode, on by default, lets a bot in a group hear only commands, replies to its messages and mentions of it. To have it hear every message, turn privacy off with @BotFather (/setprivacy → Disable), then remove the bot from the group and add it again.