Skip to content

🀯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

9.3 KB
Raw Blame
---
title: Connect LobeHub to Telegram
description: >-
  Learn how to create a Telegram bot and connect it to your LobeHub agent as a
  message channel, enabling your AI assistant to chat with users on Telegram
  private and group conversations.
tags:
  - Telegram
  - Message Channels
  - Bot Setup
  - Integration
---

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

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

## Set Your Platform Identity (Recommended)

One optional field under **Advanced Settings** carries a lot of weight in day-to-day use β€” fill it in once and most surprises go away.

### Your Platform User ID

This is your own Telegram numeric user ID, used by:

- **Pairing approval** β€” required when **DM Policy** is set to **Pairing**, since `/approve <code>` is the owner's command and the runtime checks the sender against this ID.
- **AI tools push** β€” lets the agent reach you proactively (reminders, notifications) by mapping its internal user reference to your Telegram account.
- **Anti-lockout** β€” auto-trusted by **Allowed Users**, so scoping the bot to friends won't accidentally lock you out.

To get it: open Telegram, message [@userinfobot](https://t.me/userinfobot), and it will reply with your numeric user ID. Paste it into **Your Platform User ID** in LobeHub's Advanced Settings.

> Telegram doesn't have a "default server" concept (each chat is its own surface), so the **Default Server** field is not exposed for Telegram channels.

## 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>

## Guest Mode (summon without joining)

Telegram [Guest Mode](https://core.telegram.org/bots/features#guest-bots) lets people `@mention` your bot in any group or private chat **without adding it as a member**. The bot sees only the summoning message (and the message it was replying to, if any) and can post one reply.

1. Open [@BotFather](https://t.me/BotFather)'s Mini App β†’ your bot β†’ enable **Guest Mode**
2. Anyone can then write `@your_bot_username …` in a chat the bot has never joined
3. Replies to that guest message summon the bot again in the same chat

Guest summons use their own **Guest Policy** and are not gated by **Group Policy**. Keyword watch and always-on group traffic still require adding the bot as a member.

## Access Policies

Three independent policies gate inbound traffic. All default to **Open**.

### Allowed User IDs (global)

A populated **Allowed User IDs** field acts as a global gate β€” DMs, group `@mentions`, and Guest Mode summons are restricted to listed Telegram numeric user IDs. Empty means "no user-level filter". Grab a user's numeric ID via [@userinfobot](https://t.me/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).
- **Pairing** β€” Same gate as `Allowlist`, but a non-listed sender receives a one-time pairing code instead of a flat rejection. Approve via `/approve <code>` and the applicant is auto-appended to **Allowed User IDs**. Requires **Your Platform User ID** to be set (the runtime checks the `/approve` sender against it) and a configured Redis backend.
- **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](https://t.me/userinfobot) to grab the chat ID (group IDs are negative).
- **Disabled** β€” Ignore all group traffic; the bot only responds to DMs.

### Guest Policy

Controls who can summon the bot through Telegram Guest Mode without adding it to the chat.

- **Open (default)** β€” Accept Guest Mode summons from anyone. A populated **Allowed User IDs** list still acts as a global user gate.
- **Allowlist** β€” Only users in **Allowed User IDs** can summon the bot. An empty list fails closed.
- **Pairing** β€” Non-listed users receive a one-time pairing code in the Guest reply. Approve via `/approve <code>` and ask them to summon the bot again. Requires **Your Platform User ID** and Redis.
- **Disabled** β€” Reject all Guest Mode summons. This does not affect DMs or groups the bot has joined.

See the [Channels overview](/docs/usage/channels/overview#direct-message-policy) for cross-platform details.

## Configuration Reference

| Field                    | Required | Description                                                                                                             |
| ------------------------ | -------- | ----------------------------------------------------------------------------------------------------------------------- |
| **Bot Token**            | Yes      | API token from BotFather                                                                                                |
| **Webhook Secret Token** | No       | Optional secret for verifying webhook requests                                                                          |
| **Allowed User IDs**     | No       | Comma- or whitespace-separated Telegram numeric user IDs. Global gate β€” applies to DMs, group @mentions, and Guest Mode |
| **DM Policy**            | No       | `open` (default), `allowlist`, `pairing`, or `disabled` β€” who is allowed to DM the bot                                  |
| **Group Policy**         | No       | `open` (default), `allowlist`, or `disabled` β€” where the bot responds in groups                                         |
| **Guest Policy**         | No       | `open` (default), `allowlist`, `pairing`, or `disabled` β€” who can use Telegram Guest Mode                               |
| **Allowed Channel IDs**  | No       | Comma- 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](https://t.me/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.