Skip to content

Telegram

The Telegram driver uses python-telegram-bot with long polling to receive messages and the Bot API to send.

Setup

  1. Message @BotFather on Telegram and create a new bot with /newbot.
  2. Copy the bot token it gives you.
  3. Add the bot to your group and give it permission to read messages.
  4. Get the group's chat ID (tip: forward a message to @userinfobot, or use the bot API /getUpdates endpoint).

Config keys

Add under telegram.<instance_id> in config.json:

KeyRequiredDefaultDescription
bot_tokenYesBot token from @BotFather
max_file_sizeNo52428800 (50 MB)Maximum bytes per attachment when sending
rich_header_hostNoBase URL of your Cloudflare rich-header worker (see Rich Header)
json
{
  "telegram": {
    "tg_main": {
      "bot_token": "123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11",
      "max_file_size": 52428800,
      "rich_header_host": "https://richheader.yourname.workers.dev"
    }
  }
}

Rule channel keys

Use under channels or from/to in rules.json:

KeyDescription
chat_idTelegram chat ID. Use a negative number for groups (e.g. "-1002206757362")
json
{
  "tg_main": { "chat_id": "-1002206757362" }
}

Received message types

Telegram typeAttachment type
Photoimage
Videovideo
Voicevoice
Audiovoice
Documentfile
Animation (GIF)video

Media messages may include a caption, which becomes the message text.

Sending

Attachment typeTelegram API method
imagesend_photo
voicesend_voice
videosend_video
filesend_document

The message text is sent as the caption of the first attachment. If there are no attachments (or all fail), it is sent as a plain send_message. Text for subsequent attachments is omitted.

Rich Header

When a msg_format contains a <richheader title="..." content="..."/> tag and rich_header_host is configured, NextBridge shows a small link-preview card above the message text on Telegram. The card displays the sender's avatar, name (title), and a secondary line (content) — visually compact and distinct from the message body.

This works by serving a tiny HTML page with Open Graph meta tags from a Cloudflare Worker. Telegram fetches those tags and renders the result as a prefer_small_media link preview shown above the text.

Cloudflare Worker setup

Public endpoint

We provides a public endpoint, https://richheader.siiway.top. Feel free to use it.

  1. Go to the Cloudflare dashboardWorkers & PagesCreate.
  2. Paste the contents of cloudflare/richheader-worker.js into the editor and deploy.
  3. Copy the worker's URL (e.g. https://richheader.yourname.workers.dev).
  4. Set rich_header_host in your Telegram instance config to that URL.

msg_format example

json
{
  "my_tg": {
    "chat_id": "-100987654321",
    "msg": {
      "msg_format": "<richheader title=\"{username}\" content=\"id: {user_id}\"/> {msg}"
    }
  }
}

Fallback behaviour

ConditionBehaviour
rich_header_host is not setBold/italic HTML header prepended to the message text
Message includes media attachmentsSame bold/italic HTML fallback (Telegram captions cannot carry link previews)

Notes

  • Telegram bots cannot initiate conversations with users. Make sure the bot is already in the target group before running NextBridge.
  • The bot's own messages are not echoed back (Telegram does not send bot message events to the bot itself).
  • Avatar URLs are not fetched for incoming messages (doing so would require an extra API call per message).