A bot that acts as a bridge between Delta Chat groups and Telegram groups. It relays messages sent in mapped Telegram groups to corresponding Delta Chat groups, and vice-versa.
Built using deltabot-cli-py and python-telegram-bot (asyncio).
- Python 3.9+ (for local/venv setup)
- Telegram Bot token (create a new bot and obtain one from @BotFather)
- Delta Chat account (can be automatically created during setup by providing a valid email address, e.g. from one of public chatmail relays, and a random password)
-
Clone or navigate to this directory:
cd deltachat_telegram_bridge -
Create a virtual environment and install dependencies:
python3 -m venv venv source venv/bin/activate pip install -r requirements.txt
-
Initialize the Delta Chat account Configure your bot's Delta Chat account using
init dc:venv/bin/python bot.py init dc YOUR_DELTA_CHAT_EMAIL YOUR_EMAIL_PASSWORD
This saves the account configuration locally, by default in your OS config directory under
tgbridge(e.g. on linux it is located at~/.config/tgbridge, on macOS it is located at~/Library/Application\ Support/tgbridgeetc). -
Initialize the Telegram Token Configure your bot's Telegram API token. You can pass it as an argument or enter it interactively to keep it out of your command history:
venv/bin/python bot.py init tg
This saves the token locally in the
bridge.dbdatabase. -
Start the bridge bot Once initialized, run the
servecommand to start the relay:venv/bin/python bot.py serve
Instead of using a local virtual environment, you can run the bot using Docker Compose:
-
Initialise the database and accounts using
docker-compose run:docker-compose run --rm bridge python bot.py init dc me@example.com MyPassword docker-compose run --rm bridge python bot.py init tg
-
Start the bridge:
docker-compose up -d
-
To update the bot manually after pulling new code:
docker-compose up -d --build
Your configuration and message history will be preserved since they are stored in the mounted
bridge.dband configuration volumes.
The repository includes an update.sh script that automates the update process. It performs the following steps:
- Runs
git fetchto check for new commits on the remote repository. - Compares the local version with the remote version.
- If new changes are found, it runs
git pull, rebuilds the Docker container (--build), and cleans up old images.
To have the bot automatically check for updates every 15 minutes, you can set up a cron job:
- Open your crontab:
crontab -e
- Add the following line (replace
/path/to/with the actual absolute path to the project directory):*/15 * * * * /path/to/deltachat_telegram_bridge/update.sh >> /path/to/deltachat_telegram_bridge/update.log 2>&1
Tip
You can find the absolute path by running realpath update.sh inside the directory.
-
Maintenance and Cleanup:
To stop the bot and remove containers:
docker compose down
To remove old, unused images (reclaim disk space):
docker image prune -f
To view logs in real-time:
docker compose logs -f
The bot needs to be added to the Telegram group. When you bridge from Telegram, the bot automatically creates the corresponding Delta Chat group.
Note: By default, management commands (
/bridge,/unbridge,/id) are restricted to group admins. However, if you configure a global admin usinginit admin_dcorinit admin_tg, only the configured bot owner (and designated sub-admins) will be able to manage the bot. The bot's help message will indicate its current state as Mode: Private (bot owner only) or Mode: Public (group admins only).Important: You must disable Group Privacy for your Telegram bot via @BotFather → Bot Settings → Group Privacy → Turn off. Otherwise the bot cannot read normal group messages. After changing this, re-add the bot to the group.
- Add your Telegram bot to the target Telegram group.
- Send
/bridgein the group (admin only). The bot will automatically create a Delta Chat group with the same name and avatar, link them, and reply with an invite link to join the DC group. - To remove the bridge, send
/unbridgein the Telegram group.
- Get the Telegram Group ID by sending
/idin the TG group. - Add your Delta Chat bot to the target Delta Chat group.
- Send
/bridge -100123456789in the DC group (owner only in private mode). - To remove the bridge, send
/unbridgein the DC group.
Note: Group mappings are saved locally in the bridge.db SQLite file.
Reactions: For reaction bridging (TG → DC) to work, the bot must be an administrator in the Telegram group. No special permissions are needed — just the admin role. When a basic group is promoted, Telegram may migrate it to a supergroup (changing the chat ID). The bot detects this automatically and updates its stored mappings.
- The
bridge.dbfile contains your Telegram bot token in plaintext. Protect it with appropriate file permissions (e.g.chmod 600 bridge.db). - Management commands (
/bridge,/unbridge,/id) are restricted to group admins or bot owner (see below). - Messages are rate-limited to 30 messages per minute per chat to prevent flooding.
- Sender names are HTML-escaped before being sent to Telegram to prevent injection.
- Bot messages from both sides are filtered out to prevent echo loops.
-
Set Global Admin (Telegram): Configures a Telegram user ID to receive all bot error logs via direct message. (You can find your Telegram ID by sending
/startto the bot in a private message). Important Note: Settingadmin_tglocks the Telegram management commands so that only this user can manage the bot (the help text will dynamically change to Mode: Private (bot owner only)).docker-compose exec bridge python bot.py init admin_tg YOUR_TELEGRAM_ID -
Set Global Admin (Delta Chat): Configures a Delta Chat email to receive all bot error logs via direct message. Important Note: Setting
admin_dclocks the/bridgeand/unbridgecommands so that only this user can use them (the help text will dynamically change to Mode: Private (bot owner only)).docker-compose exec bridge python bot.py init admin_dc admin@example.com
Since the bot depends on deltabot-cli-py, you have access to a variety of other management commands. These commands do not require the --telegram-token argument.
If you are using Docker, run these commands using docker-compose exec bridge python bot.py ... (if the bot is running) or docker-compose run --rm bridge python bot.py ... (if stopped).
If you are running locally, use venv/bin/python bot.py ....
Here are the commands (shown for Docker, assuming the container is running):
-
Get Invite Link (QR Code data): Print the bot's invitation link so you can add it to Delta Chat groups.
docker-compose exec bridge python bot.py link -
List accounts: View the IDs and addresses of configured Delta Chat accounts.
docker-compose exec bridge python bot.py list -
Config: View or set configuration options for the bot account.
docker-compose exec bridge python bot.py config -
Remove account: Remove a specific Delta Chat account if you accidentally created multiple. Replace
IDwith the account number (e.g.2).docker-compose exec bridge python bot.py --account ID remove -
Admin: Generates a setup QR code to join an Admin control group where you can manage the bot remotely.
docker-compose exec bridge python bot.py admin
For more details on management commands, see the deltabot-cli-py repository.
In private mode (admin_tg is set), the bot owner can designate sub-admins who can independently manage their own bridges and channels.
Sub-admins can:
- Use
/bridgeand/unbridgein Telegram groups - Use
/channeladdand/channelremovefor channels - View their own bridges via
/statsand/channels
Sub-admins cannot see or manage resources created by the owner or other sub-admins.
| Command | Description |
|---|---|
/adminadd <user_id> |
Add a sub-admin (owner only, private chat) |
/adminremove <user_id> |
Remove a sub-admin (owner only, private chat) |
/admins |
List all sub-admins (owner only, private chat) |
The bot can bridge Telegram channels and groups to Delta Chat broadcast channels (one-way, read-only).
Note: By default, the bot requires being an administrator in a Telegram channel to receive posts. If you cannot make the bot an admin, or you want to bridge a regular group in "stealth" read-only mode, you can enable Userbot Mode.
-
Add the bot as an admin to the Telegram channel you want to bridge.
-
In a private chat with the bot, use
/channeladd @channel_usernameor/channeladd -1001234567890(numeric ID) to create the bridge.- Tip: When you add the bot as an administrator to a channel, it will automatically send a private message to the configured
admin_tgwith the channel's numeric ID and a ready-to-use bridging command.
- Tip: When you add the bot as an administrator to a channel, it will automatically send a private message to the configured
-
The bot will create a DC broadcast channel (with the same name and avatar) and return an invite link for subscribing.
| Command | Description |
|---|---|
/channeladd <target> |
Create a bridge for a Telegram channel or group |
/channelremove <target> |
Remove a channel bridge |
/channels |
List bridged channels (as admin, private chat) |
/channel N |
Get invite link for channel by its internal number |
/channelqr N |
Get QR code image for channel by its internal number |
/userbotsync |
Force re-sync Userbot subscriptions |
/groups |
List technical account's groups for easy bridging |
Any Delta Chat user (not just admins) can use these commands in a private chat with the bot or in a group:
/channels— List all available public Telegram channels (shows TG and DC stats)./channelN— Get the text invite link for channel #N (e.g.,/channel5)./channelNqr— Get the QR code invite for channel #N.
/channeladd @username— Bridge a new channel (admin email check)./channelremove N— Remove bridge for channel #N./channelNqr— Get the QR code image for channel #N (for easy sharing/onboarding)./stats— Show bridge statistics for the current chat./help— Show Delta Chat bot help.
If you want to bridge channels where you cannot add the bot as an administrator, you can configure Userbot Mode. This allows the bot daemon to act as a regular Telegram client using your personal account.
- Go to my.telegram.org and log in.
- Go to API development tools.
- Create a new application (e.g., "DC-TG-Bridge").
- Copy your App api_id and App api_hash.
Run these commands inside your environment (or via docker-compose exec bridge python bot.py ...):
python bot.py init api_id YOUR_API_ID
python bot.py init api_hash YOUR_API_HASHThis step requires entering your phone number and the SMS/Telegram validation code. If using Docker, you must run it interactively:
docker-compose exec bridge python bot.py init userbotCaution
Using your personal account for Userbot Mode comes with risks:
- Session Security: A file named
userbot_session.sessionwill be created. This file is essentially a "master key" to your Telegram account. Never share it. Ensure your server has strict file permissions. - Account Activity: The bot will join channels on your behalf to read posts.
- API Limits: While safe for moderate use, intensive API operations can theoretically lead to temporary rate limits or account flags from Telegram's anti-spam systems. It is recommended to use a dedicated "feeder" account if you plan to bridge a very large number of channels.
If a channel is bridged via both the core bot (as admin) and Userbot Mode, the bridge will automatically deduplicate messages, ensuring Delta Chat users receive only one copy of each post.
See CHANGELOG.md for a detailed history of changes.