Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| matrix:telegram [2025/03/10 14:34] – created willy | matrix:telegram [2026/04/12 16:16] (current) – willy | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ====== Matrix Telegram Bridge ===== | + | ====== |
| - | The Mautrix Telegram bridge is currently the best (only?) option. More info | + | [[https://telegram.org/|Telegram]] is the well known chat app which started as the main competitor to Whatsapp and it's finally gaining some traction. Most known for it's piracy and porn angles, it's getting more and more popular to replace Whatsapp itself also for private chats. |
| - | [[https://docs.mau.fi/bridges/ | + | |
| - | Create subfolder | + | Telegram can be easily |
| + | |||
| + | At the time of writing this page, the full rewrite in Go of the bridge is the way to go and the older python-based bridge is now officially deprecated. | ||
| + | |||
| + | |||
| + | ===== Installation ===== | ||
| + | |||
| + | I asusme you are installing the bridge directly together with the Matrix server, as user // | ||
| + | |||
| + | Create a subfolder to install the bridge: | ||
| <code bash> | <code bash> | ||
| su - conduwuit | su - conduwuit | ||
| mkdir mautrix-telegram | mkdir mautrix-telegram | ||
| cd mautrix-telegram | cd mautrix-telegram | ||
| - | # Enable PIP like in the link above | + | wget -O mautrix-telegram.zip ' |
| - | # - create ~/.config/pip/pip.conf | + | unzip mautrix-telegram.zip |
| - | # - add ~/.local/bin to the .bashrc | + | chmod +x mautrix-telegram |
| - | python | + | |
| - | source ./bin/activate | + | |
| - | # Now flip include-system-site-packages = true in pyvenv.cfg | + | |
| - | # Install: | + | |
| - | pip install --upgrade | + | |
| </ | </ | ||
| - | You need to create API keys to connect to Telegram. Go to [[https:// | + | |
| - | Grab the example config file [[https:// | + | ===== Telegram Setup ===== |
| + | |||
| + | First of all, you cannot create a new telegram account from the bridge, you need to do so from the official telegram app, it's the one and only way. | ||
| + | |||
| + | Now, assuming you have a Telegramn account, you need to create API keys to connect to Telegram. | ||
| + | |||
| + | From the page that pops up, generate and take note of **api_id** and **api_hash** as you will need to configure | ||
| + | |||
| + | |||
| + | ===== Bridge setup ===== | ||
| + | |||
| + | Let the bridge generate the basic configuration file, and move it to the / | ||
| <code bash> | <code bash> | ||
| - | wget -O / | + | ./ |
| - | mv / | + | mv config.yaml / |
| </ | </ | ||
| - | This file is huge, here are the most relevant changes needed: | + | Now edit it. You should take a good look at it, the following are only hints and pointers to what you aboslutely need to change: |
| - | <file - config.yaml> | + | <code> |
| + | network: | ||
| + | # This is very important to have usernames instead of phone numbers! | ||
| + | displayname_template: | ||
| + | |||
| + | database: | ||
| + | type: sqlite3-fk-wal | ||
| + | uri: file:/ | ||
| + | |||
| + | homeserver: | ||
| address: https:// | address: https:// | ||
| domain: chat.mydomain.com | domain: chat.mydomain.com | ||
| - | verify_ssl: true | + | |
| - | | + | appservice: |
| - | telegram: | + | |
| - | | + | |
| - | api_id: << put your id here >> | + | |
| - | api_hash: << put your hash >> | + | |
| - | # (Optional) Create your own bot at https://t.me/ | + | |
| - | bot_token: disabled | + | |
| - | permissions: | + | |
| - | " | + | |
| - | " | + | |
| - | " | + | |
| | | ||
| - | encryption: | + | permissions: |
| + | " | ||
| + | " | ||
| + | " | ||
| + | |||
| + | backfill: | ||
| + | enabled: true # to populate chats with older messages | ||
| + | |||
| + | | ||
| # Whether to enable encryption at all. If false, the bridge will not function in encrypted rooms. | # Whether to enable encryption at all. If false, the bridge will not function in encrypted rooms. | ||
| allow: true | allow: true | ||
| - | + double puppeting | + | double_puppet: |
| - | </file> | + | # Servers to always allow double puppeting |
| - | More details | + | # This is only for other servers and should NOT contain the server the bridge is on. |
| + | servers: | ||
| + | anotherserver.example.org: | ||
| + | # Whether to allow client API URL discovery for other servers. When using this option, | ||
| + | # users on other servers | ||
| + | # explicitly added to the servers map above. | ||
| + | allow_discovery: | ||
| + | # Shared secrets for automatic double puppeting. | ||
| + | # See https:// | ||
| + | secrets: | ||
| + | chat.mydomain.com: | ||
| + | |||
| + | logging: | ||
| + | filename: / | ||
| + | </ | ||
| - | I choose | + | Note that backfill is disabled by default, you need to enable it to see older messages. Also note that messages **cannot** be backfilled for already created rooms, so don' |
| - | At this point you need to register the bridge: | + | Since my server will have just a few users, i decided |
| - | <code bash> | + | |
| - | python -m mautrix_telegram -g -c / | + | |
| - | </ | + | |
| - | This step will create a **registration.yaml** file that you need to perform the registration of the bridge as an appservice in Conduwuit. Conduwuit is different from Synapse (the most common Matrix server) because the appservice must be registered from the admin chat with the following command: | ||
| - | < | ||
| - | !admin appservices register << shift+enter >> | ||
| - | ``` << shift+enter >> | ||
| - | [ ... copy here the content of registration.yaml ... ] | ||
| - | ``` << enter >> | ||
| - | </ | ||
| - | When you see **<< shift enter >>** you need to press those two keys in order to create a new line in the same command. The three **```** (backthicks) are the markdown token to create a code block. | + | ===== Bridge Registration ===== |
| - | The **<< autogenrated >>** are secret strings found in the // | + | |
| - | The chat should reply with a message like: | + | At this point you need to register the bridge |
| - | < | + | |
| - | Appservice registered with ID: telegram | + | First of all, generate the // |
| + | < | ||
| + | ./ | ||
| </ | </ | ||
| - | More details on registering | + | Then perform |
| - | You need to create the **telegrambot** user, again from the admin chat: | + | |
| - | < | + | ===== Usage ===== |
| - | !admin users create-user telegrambot | + | |
| - | </ | + | The **whatsappbot** user should have been created automatically. |
| Good! Now you can run the bridge: | Good! Now you can run the bridge: | ||
| <code bash> | <code bash> | ||
| - | python | + | / |
| </ | </ | ||
| If all is well, your bridge should be up and running now. | If all is well, your bridge should be up and running now. | ||
| + | |||
| + | ===== Login ===== | ||
| To login into telegram you need to: | To login into telegram you need to: | ||
| - | * Start a chat with telegrambot: | + | * Start a chat with //@telegrambot: |
| * type " | * type " | ||
| * when prompted, type your telegram registered phone number with country code | * when prompted, type your telegram registered phone number with country code | ||
| Line 96: | Line 125: | ||
| You will start seeing your telegram chats appear in Matrix now! It takes time, even hours, and also most chats will only appear the first time the other person messages you. | You will start seeing your telegram chats appear in Matrix now! It takes time, even hours, and also most chats will only appear the first time the other person messages you. | ||
| - | |||
| - | **Note:** Telegram does not allow registration from third party clients, so to register a **new** telegram account, you must use Telegram official app. | ||
| General documentation on the Telegram bot can be found [[https:// | General documentation on the Telegram bot can be found [[https:// | ||
| To manage animated sticker [[https:// | To manage animated sticker [[https:// | ||
| + | |||
| + | |||
| + | ===== Autostart ===== | ||
| + | |||
| + | Since i use OpenRC, simply drop the following script to / | ||
| + | <file - / | ||
| + | # | ||
| + | # Copyright 2025 Gentoo Authors | ||
| + | # Distributed under the terms of the GNU General Public License v2 | ||
| + | |||
| + | name=" | ||
| + | description=" | ||
| + | pidfile="/ | ||
| + | command_background=true | ||
| + | command="/ | ||
| + | command_args="/ | ||
| + | command_user=" | ||
| + | output_log="/ | ||
| + | output_err="/ | ||
| + | |||
| + | start_pre() { | ||
| + | cd / | ||
| + | } | ||
| + | |||
| + | depend() { | ||
| + | need net | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | Make it executable and add to the proper runlevel: | ||
| + | <code bash> | ||
| + | chmod +x / | ||
| + | rc-update add conduwuit-telegram default | ||
| + | </ | ||
| + | |||
| + | |||
| + | |||
| + | |||