Platforms
How-to

Connect an Agent to Telegram

Create a bot with BotFather, configure a polling Connection, and control group, user, and direct-message access.

For
Telegram administrators, Agent creators, organization administrators, and Agent operators
On this page
  1. Overview
  2. Connection model
  3. Before you begin
  4. 1. Create the Telegram bot
  5. 2. Prepare the bot for polling
  6. 3. Create the Telegram Connection
  7. 4. Groups and privacy mode
  8. 5. Add the bot to channels
  9. 6. Find Telegram IDs
  10. 7. Configure the settings
  11. 8. Verify the integration
  12. How messages are admitted
  13. Topics, replies, and conversations
  14. Display-name enrichment
  15. Change the Connection later
  16. Manage the bot token
  17. Troubleshooting
  18. Next steps
  • Telegram
  • Hermes and OpenClaw
  • 10–15 minutes

Connect Telegram to an existing Agent by creating a Telegram Communication Connection. You create a bot with BotFather, paste its token into the Connection, and choose which groups and users may reach the Agent.

Telegram works with both Hermes and OpenClaw. Agent Barn's Communications Gateway supervises Telegram polling, so no public webhook is required.

Overview

Telegram is not selected while creating the Agent. The Agent is created headless, and Telegram is added afterward as a Connection.

  • An Agent can have zero or many Communication Connections.
  • The same Agent can have multiple Telegram Connections using different bots.
  • The Communications Gateway supervises the Telegram polling loop.
  • The Runtime never receives the Telegram bot token and does not own the polling loop.
  • A public Telegram webhook is not required.

When you finish this guide, you will have:

  • A Telegram bot created with BotFather
  • A Telegram Communication Connection on an existing Agent
  • Group and direct-message policies for that Connection
  • A verified Telegram conversation with the Agent
  • A plan for rotating the bot token through the Connection

See Communication Connections for the shared Connection lifecycle, and Compare platform compatibility for how Telegram sits beside the other Platforms.

Connection model

The Telegram Platform Plugin uses getUpdates long polling, held by the Communications Gateway:

  1. Telegram user, group, or channel
  2. Telegram Bot API
  3. Supervised getUpdates polling
  4. Communications Gateway
  5. Hermes or OpenClaw

Replies return through the same Connection, sent by the Gateway with the Connection's own bot token. The Runtime receives only normalized Communication Deliveries.

Before you begin

You need:

  • An existing Agent
  • Permission to update the Agent and manage its Connection credentials
  • A Telegram account that can interact with @BotFather
  • Permission to add the resulting bot to the intended groups or channels
  • A Telegram bot token in the <bot-id>:<secret> format

Create the Telegram bot

Open @BotFather in Telegram. BotFather is Telegram's official interface for creating and managing bot accounts.

  1. Open @BotFather.
  2. Run /newbot.
  3. Choose the bot's display name.
  4. Choose its Telegram username.
  5. Copy the bot token returned by BotFather.
  6. Confirm that the token resembles <bot-id>:<secret>.

Telegram bot usernames are between 5 and 32 characters, may contain letters, numbers, and underscores, and normally end in bot. Choose carefully, because the username becomes the public identity people use to find and mention the bot.

BotFather /newbot
You:       /newbot
BotFather: All right, a new bot. How are we going to call it?
You:       Support Agent
BotFather: Good. Now let's choose a username for your bot.
You:       agent_barn_support_bot

This is an illustration of the exchange, not a screenshot.

Bot token shape
123456789:REDACTED_BOT_TOKEN

About this credential:

  • The bot token is the only provider credential required by this Connection.
  • The bot username is not a credential, and must not be entered in place of the token.
  • Telegram does not require a separate app token or OAuth credential for this Connection.
  • The token must be kept private.

Telegram documents the creation process and token security requirements in its bot features documentation.

Prepare the bot for polling

A Telegram bot can have only one effective update consumer. Before creating the Connection:

  • Remove any webhook currently configured for the bot
  • Stop any other application or process polling the same bot token
  • Confirm the bot token is not already used by another active Communication Connection

Agent Barn enforces global credential uniqueness for the bot token, which prevents two Connections from competing for the same bot's updates.

Create the Telegram Connection

With the token in hand, create the Connection on the Agent.

  1. Open the existing Agent.
  2. Open its Communication Connections section.
  3. Choose Telegram.
  4. Enter a Connection display name.
  5. Paste the BotFather token into Bot token.
  6. Configure group and direct-message access.
  7. Create and enable the Connection.

Use a display name that identifies the bot or purpose, such as Telegram: Incident bot.

The Communications Gateway validates the bot token with Telegram and supervises its polling lifecycle. If validation fails, confirm that the entire token was copied, remove leading or trailing spaces, check that the token belongs to the intended bot, and generate a replacement in BotFather if the original can no longer be trusted.

Add the bot to groups and set privacy

Telegram decides which group messages reach a bot at all, before Agent Barn sees them.

  1. Add the bot to every Telegram group or supergroup it should serve.
  2. Open @BotFather.
  3. Run /setprivacy.
  4. Select the bot.
  5. Disable privacy mode when the Agent must receive ordinary group messages.

Telegram enables Group Privacy for new bots by default. With privacy enabled, Telegram delivers only a limited set of group messages, generally favoring commands, replies, and mentions. Disabling it delivers a broader set of human-authored group messages. See Telegram's Bots FAQ for the precise delivery rules.

Keep privacy enabled

Use when: commands, replies, and mentions provide enough context.

Effect: Telegram limits which group messages leave Telegram at all.

Disable privacy

Use when: the Agent needs reliable delivery of ordinary group conversation.

Effect: Telegram delivers more group messages, including messages the Agent will never answer.

If you change Group Privacy after adding the bot to a group, remove the bot and add it again so Telegram applies the new setting. This requirement is documented in Telegram's bot feature guide.

Add the bot to channels

For Telegram channels:

  • The bot must be added to the channel.
  • The bot should be made a channel administrator when it needs to receive channel posts and send replies.
  • Channel access still remains subject to the Communication Connection's group policy.

Adding the bot does not authorize every channel. Presence in Telegram and admission in Agent Barn are two separate gates, and an allowlist policy still needs the channel's ID.

Find Telegram IDs

Connection allowlists use numeric Telegram identifiers, not usernames.

Identifier Used for Typical format
Group, supergroup, or channel IDGroup allowlistNegative number, often beginning with -100 for a supergroup
User IDDirect-message allowlistPositive number
Bot usernameMentions and discovery, never access control@agent_barn_support_bot

Telegram chat IDs are stable numeric identifiers. Group names and user display names are not access-control identifiers and cannot be entered in an allowlist.

Retrieve IDs before enabling the Connection

You can inspect updates received by the bot using Telegram's getUpdates method. First:

  1. Add the bot to the intended Telegram group.
  2. Send a command, direct reply, or message addressed to the bot.
  3. If you need a user ID, send the bot a direct message as that user.

Then run:

Read updates
read -s TELEGRAM_BOT_TOKEN
curl --silent "https://api.telegram.org/bot${TELEGRAM_BOT_TOKEN}/getUpdates"
unset TELEGRAM_BOT_TOKEN

When prompted by read, paste the bot token and press Enter. The token is not displayed, and its value is not included in the command history.

Inspect the response for fields similar to:

getUpdates response
{
  "message": {
    "from": {
      "id": 123456789
    },
    "chat": {
      "id": -1001234567890,
      "title": "Engineering"
    }
  }
}
Response field mapping
message.chat.id
allowed_chat_ids: the group allowlist
message.from.id
allowed_user_ids: the direct-message allowlist

The Bot API defines getUpdates and chat identifiers in the Telegram Bot API reference.

Configure the Connection settings

The Telegram Platform Plugin supplies these settings on the Connection form.

Setting Behavior Underlying setting
Group access open: accept eligible messages from any group, supergroup, or channel where the bot is present; allowlist: accept messages only from configured Telegram chat IDs group_policy
Allowed groups Telegram group, supergroup, or channel IDs, used when Group access is allowlist allowed_chat_ids
Direct messages off: ignore private chats; open: accept private messages from any Telegram user; allowlist: accept private messages only from configured users dm_policy
Allowed DM senders Numeric Telegram user IDs, used when Direct messages is allowlist allowed_user_ids

When entering identifiers:

  • Use numeric Telegram IDs, not usernames.
  • Group and supergroup IDs are often negative.
  • Preserve IDs exactly as Telegram supplies them, including the leading minus sign.
  • A username such as @example is not a substitute for a numeric user ID.

Start with one allowed group and direct messages off, then widen after the first successful exchange. See Configure channel access for policy guidance.

Verify the integration

Confirm the Connection is enabled and its poller is healthy, then test from a controlled chat.

Test Expected result
Address the Agent in an allowed groupThe Agent responds
Send a message from a group outside the allowlistThe Agent does not respond
Send a private message while Direct messages is offThe Agent does not respond
Send a private message as an allowed user while Direct messages is allowlistThe Agent responds

Then confirm the exchange in Agent Barn:

  1. Open the Agent.
  2. Open Conversations.
  3. Select this Telegram Connection.
  4. Confirm the inbound message and outbound response appear under it.

See Verify your Agent for the full layered verification.

How messages are admitted

Telegram visibility and Agent Barn authorization are two separate gates:

  • Telegram determines which group messages reach the bot at all, through its privacy mode.
  • Messages that reach Agent Barn are then evaluated against the Connection's group or direct-message policy.
  • Bot-authored messages are ignored.
  • Direct messages do not require mentions, but must pass the direct-message policy.
  • Telegram does not expose Slack's every_message or start_only thread mention setting.

So a message can be withheld by Telegram, or delivered by Telegram and then rejected by Connection policy. The Connection journal distinguishes the two.

Topics, replies, and conversations

  • Telegram message replies are preserved as reply relationships where provider data is available.
  • Telegram forum topics are represented using the provider's message thread ID.
  • Conversations and message history remain scoped to the Telegram Connection.

The same Agent can use other Telegram bots or other Platforms without sharing provider credentials or conversation histories between Connections.

Display-name enrichment

Agent Barn may use credential-scoped Telegram lookups to fill missing chat or sender display names.

  • Provider-supplied names are preferred.
  • Name enrichment is best-effort.
  • A lookup failure does not reject an otherwise valid message.
  • Telegram IDs remain the stable policy and conversation identifiers.
  • Cached lookups remain isolated by bot credential.

This is not a browsable directory. Telegram does not offer the Connection directory-selection experience that Slack and Discord provide, so allowlists are built from IDs you collect yourself.

Change the Connection later

Telegram settings and credentials can be changed at any time without touching the Agent.

  • Connection updates increment the Connection revision.
  • The Communications Gateway reconciles the supervised Telegram poller independently.
  • Updating the Connection does not rebuild or restart the Agent Runtime.
  • Retiring or disabling the Connection stops its provider activity without deleting the Agent.

Rotate the credential by updating the Connection with the new BotFather token. There is no need to recreate the Agent.

Manage the bot token

The token lives in two places: BotFather, and the Connection's credential field.

  1. Generate the replacement token in BotFather.
  2. Open the Agent's Telegram Connection.
  3. Enter the new token.
  4. Save the Connection.

The Gateway validates the new token and reconciles the poller on the next revision. Replacing a token requires Agent secret-management permission.

Troubleshooting

Start at the saved Connection's health and diagnostics, then work through these checks:

  • The bot token came from BotFather and is still valid
  • No Telegram webhook is configured for the bot
  • No other process is polling the same token
  • The bot has been added to the intended group or channel
  • Privacy mode is disabled when ordinary group messages are required
  • The bot has the necessary channel administrator access
  • The group chat ID passes the configured group policy
  • The sender ID passes the configured direct-message policy
  • The Connection is enabled and its poller is healthy

The Connection journal shows whether an update was observed, rejected by policy, delivered, retried, or dead-lettered. Use it to decide which layer to investigate.

The bot token is rejected

Confirm the full <bot-id>:<secret> value was copied with no surrounding whitespace, that it belongs to the intended bot, and that it was not revoked in BotFather. Generate a replacement token if needed, then update the Connection.

Also confirm the token is not already held by another active Connection.

No updates arrive at all

Check whether a webhook is configured for the bot, or whether another process is polling the same token. Telegram allows only one effective update consumer, and a configured webhook prevents polling entirely.

If the journal shows nothing observed, the problem is on the Telegram side or in the poller, not in the Agent.

The Agent does not receive ordinary group messages

This is usually Telegram privacy mode. Disable Group Privacy in BotFather, then remove the bot from the group and add it again so Telegram applies the new setting.

If privacy is already disabled, check the group policy and the allowed chat IDs, including the leading minus sign.

Direct messages do not work

Check the direct-message policy. When it is allowlist, confirm the sender's numeric user ID is listed; a username is not a substitute. When it is off, private chats are ignored by design.

The group allowlist does not match

Re-read the chat ID from a getUpdates response and compare it exactly. Supergroup IDs are negative and often begin with -100, and a group that is upgraded to a supergroup receives a new ID.

Responses appear inconsistently

Two consumers are usually competing for the same bot's updates. Stop any other poller, including a local getUpdates loop or a second Connection using the same token.

Messages are delivered but the Agent does not answer

Admission succeeded, so the problem is downstream. Review Agent health and logs for the Runtime, then review the Connection's delivery diagnostics for the outbound reply.

Do not restart the Agent for a provider or policy problem.

Next steps

After the Telegram Connection is working:

Documentation