Back to Lobehub

Connect LobeHub to Telegram

docs/usage/channels/telegram.mdx

2.1.566.6 KB
Original Source

Connect LobeHub to Telegram

By connecting a Telegram channel to your LobeHub agent, users can interact with the AI assistant through Telegram private chats and group conversations.

Prerequisites

  • A LobeHub account with an active subscription
  • A Telegram account

Step 1: Create a Telegram Bot

<Steps> ### Open BotFather

Open Telegram and search for @BotFather — the official Telegram bot for managing bots. Start a conversation and send the /newbot command.

Set Bot Name and Username

BotFather will ask you to:

  1. Choose a display name for your bot (e.g., "LobeHub Assistant")
  2. Choose a username — it must end with bot (e.g., lobehub_assistant_bot)

Copy the Bot Token

After creating the bot, BotFather will send you an API token (format: 123456789:ABCdefGhIjKlmNoPQRsTuVwXyZ). Copy and save this token.

Important: Your bot token is a secret credential. Never share it publicly.

</Steps>

Step 2: Configure Telegram in LobeHub

<Steps> ### Open Channel Settings

In LobeHub, navigate to your agent's settings, then select the Channels tab. Click Telegram from the platform list.

Enter the Bot Token

Paste the bot token you received from BotFather into the Bot Token field.

The Bot User ID will be automatically derived from your token — no need to enter it manually.

Optional: Set a Webhook Secret

You can optionally enter a Webhook Secret Token for additional security. This is used to verify that incoming webhook requests originate from Telegram.

Save Configuration

Click Save Configuration. LobeHub will automatically register the webhook URL with Telegram — no manual URL copying is required.

Your token will be encrypted and stored securely. </Steps>

Step 3: Test the Connection

Click Test Connection in LobeHub's channel settings to verify the integration. Then open Telegram, find your bot by searching its username, and send a message. The bot should respond through your LobeHub agent.

Adding the Bot to Group Chats

To use the bot in Telegram groups:

  1. Add the bot as a member of the group
  2. By default, the bot responds when mentioned with @your_bot_username
  3. Send a message mentioning the bot to start interacting

<Callout type={'warning'}> About Group Privacy Mode: Telegram bots have privacy mode enabled by default, which means they only receive messages that @mention the bot, reply to the bot, or contain /commands. If you change the privacy mode setting after creating the bot, you must remove and re-add the bot to the group for the new setting to take effect in that group. </Callout>

Access Policies

Two independent policies gate inbound traffic. Both default to Open.

Allowed User IDs (global)

A populated Allowed User IDs field acts as a global gate — DMs and group @mentions are restricted to listed Telegram numeric user IDs. Empty means "no user-level filter". Grab a user's numeric ID via @userinfobot, or read the from.id field from the bot's incoming update.

DM Policy

  • Open (default) — Anyone on Telegram can DM the bot (subject to the global allowlist when set).
  • Allowlist — DMs require the sender to be in Allowed User IDs. Differs from Open only when the list is empty: Allowlist then fails closed (no DMs).
  • Disabled — The bot ignores all DMs and only responds to group @mentions.

Group Policy

Controls which Telegram groups / channels the bot will respond in.

  • Open (default) — Respond in any group / channel the bot has been added to.
  • Allowlist — Respond only in chats whose ID is listed in Allowed Channel IDs. Forward a message from the chat to @userinfobot to grab the chat ID (group IDs are negative).
  • Disabled — Ignore all group traffic; the bot only responds to DMs.

See the Channels overview for cross-platform details.

Configuration Reference

FieldRequiredDescription
Bot TokenYesAPI token from BotFather
Bot User IDAutoAutomatically derived from the bot token
Webhook Secret TokenNoOptional secret for verifying webhook requests
Allowed User IDsNoComma- or whitespace-separated Telegram numeric user IDs. Global gate — applies to DMs and group @mentions
DM PolicyNoopen (default), allowlist, or disabled — who is allowed to DM the bot
Group PolicyNoopen (default), allowlist, or disabled — where the bot responds in groups
Allowed Channel IDsNoComma- or whitespace-separated Telegram chat IDs (group IDs are negative). Used when Group Policy is Allowlist

Troubleshooting

  • Bot not responding: Verify the bot token is correct and the configuration is saved. Click Test Connection to diagnose.
  • Bot ignores DMs: Open Advanced Settings and check DM Policy. If it is Disabled, switch to Open or Allowlist. If it is Allowlist, confirm the sender's Telegram user ID (from @userinfobot) is listed in Allowed User IDs.
  • Webhook registration failed: Ensure your LobeHub subscription is active. Telegram requires HTTPS endpoints for webhooks, which LobeHub provides automatically.
  • Group chat issues: Make sure the bot has been added to the group and has permission to read messages. Mention the bot with @username to trigger a response. If the bot doesn't respond in a group, try removing the bot from the group and re-adding it — Telegram's privacy mode changes require re-joining the group to take effect.