Telegram Bridge Setup Guide
This guide will help you set up the Telegram bridge for your Synapse Matrix server.
Prerequisites
Before starting, ensure that:
- Synapse is properly configured and running.
- The
telegram
database was created during the initial setup. - You have your domain name ready.
- You have your Telegram API credentials (we'll cover this below).
Obtaining Telegram API Credentials
Before configuring the bridge, you'll need to obtain API credentials from Telegram:
- Visit my.telegram.org and log in.
- Go to "API development tools".
- Create a new application if you haven't already.
- Note down your
api_id
andapi_hash
- you'll need these later.
Setup Steps
- Navigate to the Telegram configuration directory:
cd config/mautrix-telegram
- Generate the initial configuration file:
docker run --rm -v `pwd`:/data:z dock.mau.dev/mautrix/telegram
- Edit the generated
config.yaml
file. You may need administrative privileges (sudo) to edit this file.
Required Configuration Changes
Make the following modifications to your config.yaml
:
Homeserver Settings
homeserver:
address: http://monolith:8008 # Internal Docker network address
domain: your.domain.com # Replace with your actual domain
Appservice Settings
appservice:
address: http://telegram:29317 # Internal bridge address
hostname: 0.0.0.0 # Listen on all interfaces
Bridge Settings
bridge:
permissions:
'*': relaybot
public.your.domain.com: user # Replace with your domain
your.domain.com: full
"@yourusername:your.domain.com": admin # Replace with your Matrix ID
# Add your Telegram API credentials
telegram:
api_id: 123456 # Replace with your api_id
api_hash: "abcdef" # Replace with your api_hash
Database Connection
Update the database URI to use the Telegram-specific database:
# Original:
# postgres://synapse:password@postgres/synapse?sslmode=disable
# Modified (note 'telegram' database name):
postgres://synapse:password@postgres/telegram?sslmode=disable
- Generate the registration file:
docker run --rm -v `pwd`:/data:z dock.mau.dev/mautrix/telegram
- Configure Synapse to use the Telegram bridge by editing
config/synapse/homeserver.yaml
:
app_service_config_files:
- "/etc/telegram/registration.yaml"
- Start the bridge service:
docker compose up -d mautrix-telegram
- Restart Synapse to load the new bridge configuration:
docker compose restart monolith
Verifying the Setup
Check if the bridge is running:
docker compose logs mautrix-telegram
You should see messages indicating the bridge has started successfully. If the configuration files aren't present, the service will remain stopped - this is normal and prevents unnecessary restarts.
Using the Bridge
- Start a chat with
@telegrambot:your.domain.com
in your Matrix client. - Send the command
!tg login
to start the login process. - Follow the bot's instructions to:
- Provide your phone number.
- Enter the verification code sent to your Telegram app.
- Complete two-factor authentication if enabled.
Double Puppeting
Double puppeting allows messages sent from Telegram to appear as coming from your Matrix account. To enable it:
- You'll need the access token that was displayed when you created your Matrix user with the create-user.sh script.
- Start a private chat with
@telegrambot:your.domain.com
. - Send the command:
login-matrix
(without the access token). - When prompted, send your access token in a separate message. (This is the access token that was saved from create-user.sh).
- The bot should confirm successful double puppeting setup.
Note: If you've lost your access token, you can generate a new one using Element or another Matrix client in Settings > Help & About > Access Token.
Troubleshooting
-
Bridge Not Starting
- Verify that both config.yaml and registration.yaml exist.
- Check file permissions.
- Review logs with
docker compose logs mautrix-telegram
. - Verify API credentials are correct.
-
Login Issues
- Confirm your phone number format (including country code).
- Check if your account has 2FA enabled.
- Verify API credentials are correct.
-
Message Delivery Problems
- Verify bridge service is running.
- Check bridge permissions in config.
- Ensure Telegram session is still valid.
Next Steps
- Proceed to set up the Discord Bridge.
For more detailed information about bridge features and configuration options, visit the mautrix-telegram documentation.