Platforms
How-to

Set up Telegram

Create a Telegram bot with BotFather, connect it to Agent Barn, configure group and direct-message access, and verify the Agent.

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. Configure Telegram privacy
  6. 3. Connect Agent Barn
  7. 4. Find Telegram IDs
  8. 5. Configure access
  9. 6. Start the Agent
  10. 7. Verify the integration
  11. Manage the bot token
  12. API reference
  13. Troubleshooting
  14. Next steps
  • Telegram
  • Hermes and OpenClaw
  • 10–15 minutes

Connect an Agent to Telegram so people can communicate with it through direct messages or approved group conversations.

This guide walks you through creating a Telegram bot with BotFather, connecting its token to Agent Barn, defining who can reach it, and verifying the completed integration.

Overview

Every Telegram integration uses a Telegram bot account created through BotFather. Telegram provides a bot token, and Agent Barn supplies that token to the Agent runtime. Agent Barn does not create the bot for you.

When you finish this guide, you will have:

  • A Telegram bot created with BotFather
  • The bot connected to an Agent Barn Agent
  • Group and direct-message access policies
  • A verified Telegram conversation with the Agent
  • A plan for securely rotating the bot token
Runtime Telegram support Group access Direct messages
HermesSupportedOpen or allowlisted groupsOpen, allowlisted, or off
OpenClawSupportedOpen or allowlisted groupsOpen, allowlisted, or off

Use a separate Telegram bot for each production Agent. Although a token can technically be entered in more than one configuration, multiple runtimes consuming updates for the same bot will produce unreliable behavior.

Connection model

The integration follows this path.

  1. Telegram user or group
  2. Telegram Bot API
  3. Agent runtime
  4. Agent Barn

The runtime authenticates with Telegram using the bot token and receives updates from the Telegram Bot API.

No public Telegram webhook URL is required for this Agent Barn setup. The Agent runtime establishes the outbound connection to Telegram.

Agent Barn validates a new bot token with Telegram’s getMe method before saving it. The token is then stored as an encrypted Agent secret.

Before you begin

Make sure you have:

  • Access to the Agent Barn organization where the Agent will be created
  • Permission to create an Agent
  • Permission to manage the Agent’s secrets and channel access
  • A Telegram account that can communicate with @BotFather
  • An available Hermes or OpenClaw runtime
  • Model credentials or a model provider configured for the Agent
  • A Telegram group where you can add the bot, if you plan to support group conversations

You do not need to make the bot a Telegram group administrator for ordinary conversations. Grant administrator permissions only if your use case specifically requires them.

Create the Telegram bot

Start the Agent creation flow

In Agent Barn:

  1. Open the organization where you want to create the Agent.
  2. Select Hire Agent.
  3. Enter the Agent’s name.
  4. Select either Hermes or OpenClaw as the runtime.
  5. Select Telegram as the platform.

An Agent’s platform cannot be changed after creation. If you later need the same configuration on another platform, create another Agent.

Open BotFather

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

Send /newbot. BotFather will ask you for a display name for the bot, and then a unique Telegram username.

Telegram bot usernames are between 5 and 32 characters, may contain letters, numbers, and underscores, and normally end in bot. Choose the username carefully, because it 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.

BotFather then returns the bot token. Copy it and store it somewhere secure temporarily. Do not paste it into documentation, source control, issue trackers, or chat messages.

Bot token shape
123456789:REDACTED_BOT_TOKEN

Anyone who obtains the token can control the bot. Telegram documents the creation process and token security requirements in its bot features documentation.

You now have a Telegram bot username and its token, ready to connect to Agent Barn.

Configure Telegram privacy

Telegram enables Group Privacy for new bots by default.

With privacy enabled, Telegram sends the bot a limited set of relevant group messages, such as commands and replies. A bot that is a group administrator or has privacy disabled can receive a broader set of group messages, excluding messages sent by other bots. See Telegram’s Bots FAQ for the precise delivery rules.

Keep privacy enabled

Use when: commands and direct replies provide enough context.

Effect: Telegram limits which group messages reach the runtime, so less group conversation leaves Telegram.

Disable privacy

Use when: the Agent needs reliable group mentions and surrounding conversation context.

Effect: Telegram sends the runtime more human-authored group messages, including messages the Agent will never answer.

To change the setting:

  1. Send /mybots to BotFather.
  2. Select the new bot.
  3. Select Bot Settings.
  4. Select Group Privacy.
  5. Select Turn off if the Agent requires full group-message delivery.

Telegram also supports managing this through /setprivacy.

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.

Connect Agent Barn

Return to the Agent Barn hiring flow. In the Telegram connection section:

  1. Paste the token supplied by BotFather.
  2. Wait for Agent Barn to validate it.
  3. Confirm that the displayed bot username matches the bot you created.
  4. Finish the remaining runtime and model configuration.
  5. Create the Agent.

Agent Barn validates the token against Telegram before encrypting and storing it.

The newly created Telegram Agent initially remains Stopped while you configure channel access.

If validation fails:

  • Confirm that the entire token was copied.
  • Remove leading or trailing spaces.
  • Make sure the token belongs to the intended bot.
  • Check whether the token was revoked in BotFather.
  • Generate a replacement token if the original can no longer be trusted.

The Agent exists in Agent Barn with a validated Telegram credential, and is waiting for its access policy.

Find Telegram IDs

Agent Barn allowlists use numeric Telegram identifiers, not usernames.

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

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

Retrieve IDs before starting the Agent

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 explicitly 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_AGENT_TOKEN
curl --silent "https://api.telegram.org/bot${TELEGRAM_AGENT_TOKEN}/getUpdates"
unset TELEGRAM_AGENT_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 or chat 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.

Do not leave the token in scripts, saved terminal output, screenshots, or shell configuration.

If Telegram converts a group into a supergroup, its chat ID may change. Update the Agent’s allowlist with the new ID.

Configure access

In the final Telegram setup panel, open Chats & endpoint, then review both boundaries.

Group access

  • Open The Agent can respond when addressed in any group containing the bot. Suitable for controlled development environments.
  • No approved chats Group use is not exposed as a separate off switch in every configuration flow. Omit all approved chats for an Agent intended only for direct use.

Direct-message access

  • Open Any Telegram user who finds the bot can message it. Use only for public-facing bots.

For a group Allowlist, enter the numeric Telegram chat IDs as a comma-separated list:

Allowed chat IDs
-1001234567890, -1009876543210

Open access does not add the bot to groups automatically. A Telegram user must still add the bot to each group.

The runtime requires an explicit mention in group conversations. For example:

Group mention
@agent_barn_support_bot summarize the decisions in this thread

A direct reply to a message sent by the Agent may also reach it without repeating the username.

For a direct-message Allowlist, enter numeric Telegram user IDs:

Allowed user IDs
123456789, 987654321

Telegram bots cannot begin a private conversation with a user. The user must first open the bot and send a message such as /start. This is part of Telegram’s bot interaction model.

Hermes home chat

Hermes can use the first allowed Telegram chat ID as its home destination for scheduled or proactive delivery. If Hermes should send scheduled messages:

  1. Use the Allowlist group policy.
  2. Put the intended home group first in Allowed chat IDs.
  3. Make sure the bot is a member of that group.
  4. Make sure it has permission to post messages.

Without an allowed chat ID, Hermes has no default Telegram destination for proactive messages.

Start the Agent

After reviewing the Telegram policies:

  1. Select Save & Start.
  2. Wait for the Agent to move from Stopped to Initializing.
  3. Wait for it to reach Running.

Agent Barn validates the bot token again while starting the runtime. If Telegram rejects the token, the Agent may enter Error rather than Running.

If you close the setup panel without saving, the Agent remains stopped.

The Agent reports Running, and its runtime is polling Telegram for updates.

Verify the integration

Test both successful and rejected cases. A production verification should prove that the Agent responds where expected, and remains silent everywhere else.

Test Action Expected result
Allowed group mentionMention the bot in an allowed groupAgent responds
Unmentioned group messageSend an ordinary message without addressing the botAgent does not respond
Disallowed groupAdd or test the bot in a group not on the allowlistAgent does not respond
Allowed direct messageAn allowed user sends /start and a messageAgent responds
Disallowed direct messageA user outside the allowlist sends a messageAgent does not respond

A suitable group test is:

Verification message
@agent_barn_support_bot reply with "Telegram connection verified"

Then verify in Agent Barn:

  1. The Agent remains Running.
  2. The conversation appears in the Agent’s activity.
  3. The inbound message has the expected Telegram chat or user context.
  4. The Agent’s response appears in Telegram.
  5. No unexpected error appears in the Agent logs.

A Telegram delivery can succeed even if the model later fails. If the inbound message appears in Agent Barn but there is no useful response, check model credentials and runtime logs separately from the Telegram connection.

Manage the bot token

Do not:

  • Commit it to the agent-barn repository.
  • Put it in an environment example containing real values.
  • Share it in screenshots or support conversations.
  • Reuse it across production Agents.
  • Leave it in shell history.
  • Expose it in browser URLs, logs, or monitoring labels.

To rotate a compromised token:

  1. Open @BotFather.
  2. Send /mybots.
  3. Select the affected bot.
  4. Open API Token.
  5. Revoke the old token and generate a new one.
  6. Open the Agent in Agent Barn.
  7. Update the Telegram token under Keys & integrations.
  8. Select Apply & Restart if the Agent is running.
  9. Verify the integration again.

Revoking a token immediately prevents the old token from authenticating. The Agent will not reconnect until its saved credential is replaced.

Changing channel access and changing the bot token are separate operations:

  • Channel policies require permission to update the Agent.
  • Bot-token changes require permission to manage Agent secrets.

API reference

You can also create a Telegram Agent through the Agent Barn API.

Method and endpoint Purpose
POST /organizations/{organization_id}/agentsCreate the Telegram Agent in a stopped state
POST /agents/{agent_id}/startStart the Agent after checking the saved policy
PUT /agents/{agent_id}Update the access policy or the bot token

Create the Agent

Create Agent request
{
  "name": "Telegram Support Agent",
  "platform": "telegram",
  "agent_type": "hermes",
  "telegram_bot_token": "REDACTED",
  "telegram_group_policy": "allowlist",
  "telegram_dm_policy": "off",
  "telegram_allowed_chat_ids": [
    "-1001234567890"
  ],
  "telegram_allowed_user_ids": [],
  "model": "REPLACE_WITH_MODEL",
  "template_key": "REPLACE_WITH_TEMPLATE",
  "skills": []
}

The API creates the Agent in a stopped state. Start it explicitly after checking the saved policy.

Update the Agent

Example access-policy update:

Update access policy
{
  "telegram_group_policy": "allowlist",
  "telegram_dm_policy": "allowlist",
  "telegram_allowed_chat_ids": [
    "-1001234567890",
    "-1009876543210"
  ],
  "telegram_allowed_user_ids": [
    "123456789"
  ]
}

Example token update:

Update bot token
{
  "telegram_bot_token": "REDACTED"
}

After updating credentials for a running Agent, restart it so the runtime receives the new secret.

Telegram fields

Field Purpose
platformMust be telegram
telegram_bot_tokenToken issued by BotFather
telegram_group_policyopen or allowlist
telegram_dm_policyoff, open, or allowlist
telegram_allowed_chat_idsNumeric group or chat IDs stored as strings
telegram_allowed_user_idsNumeric Telegram user IDs stored as strings

Never include a real token in API examples, logs, or stored request fixtures.

Troubleshooting

Agent Barn says the token is invalid

Validation runs against Telegram
  • Copy the token directly from BotFather again.
  • Check for spaces or missing characters.
  • Confirm that the token belongs to the intended bot.
  • Make sure it has not been revoked.
  • Generate a new token through BotFather if necessary.
  • Confirm that the Agent Barn host can reach api.telegram.org.

The Agent does not receive group messages

Membership, allowlist, or privacy

Check that:

  • The bot has been added to the group.
  • The Agent is Running.
  • The group is on the Agent’s allowlist.
  • The message explicitly mentions the bot, or directly replies to it.
  • Telegram Group Privacy matches your intended delivery behavior.
  • The bot was removed and added again after changing Group Privacy.
  • No other runtime is consuming updates for the same bot.

The Agent receives commands but not ordinary mentions

Group Privacy is filtering updates

Telegram Group Privacy may be limiting the updates delivered to the runtime.

Use BotFather to disable Group Privacy, remove the bot from the group, and add it again. Remember that this allows the runtime to receive more messages from the group, even though Agent Barn still applies mention gating.

Direct messages do not work

Policy or identifier mismatch
  • Confirm that direct messages are Open or Allowlist.
  • If using an allowlist, check message.from.id, not message.chat.id from a group update.
  • Ask the user to open the bot and send /start.
  • Confirm that the user has not blocked the bot.
  • Review the Agent logs for policy rejections.

The group allowlist does not work

Chat IDs are numeric and can change
  • Use the numeric message.chat.id, not the group name.
  • Keep the leading minus sign.
  • Store the ID as a string when using the API.
  • If the group became a supergroup, retrieve and save its new ID.
  • Apply the updated policy and restart the Agent if prompted.

getUpdates returns no results

Another consumer or a webhook
  • Send the bot a new targeted message or command.
  • Confirm that the token belongs to the correct bot.
  • Stop the Agent temporarily so it is not consuming the updates first.
  • Stop any other service using long polling for the same bot.
  • Check whether the bot has a webhook configured.
  • Confirm that Telegram Group Privacy permits the test message to reach the bot.

Do not leave a manual getUpdates process running after starting the Agent.

The Agent enters Error during startup

Credential or connectivity failure
  • Revalidate the token with BotFather.
  • Confirm that the token was not rotated after it was saved.
  • Check outbound network access to Telegram.
  • Review the Agent’s startup logs.
  • Replace the token and apply the configuration again.
  • Confirm that the selected runtime supports Telegram.

The Agent receives messages but does not answer

Delivery succeeded, processing failed

This normally means Telegram delivery succeeded but processing failed. Check:

  • Model credentials.
  • Model availability.
  • Runtime logs.
  • Agent configuration.
  • Tool or skill errors.
  • Provider rate limits.
  • Whether the Agent is still Running.

A scheduled Hermes message is not delivered

No usable home destination
  • Confirm that the Agent uses Hermes.
  • Add at least one allowed Telegram chat ID.
  • Put the intended destination first in the list.
  • Confirm that the bot is still a member of that chat.
  • Confirm that the bot can post messages.
  • Restart the Agent after changing the destination.

Responses appear inconsistently

Two consumers share one bot

Make sure the Telegram token is not being used by:

  • Another Agent.
  • A development runtime.
  • A local polling script.
  • A previous deployment.
  • An external automation service.

Only one Agent runtime should consume updates for a Telegram bot.

Next steps

After the Telegram integration is verified:

Documentation