User Tools

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
matrix:telegram [2025/03/10 14:34] – created willymatrix:telegram [2025/03/12 07:23] (current) – [Bridge Setup] willy
Line 1: Line 1:
 ====== Matrix Telegram Bridge ===== ====== 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/python/setup.html?bridge=telegram|here]].+
  
-Create subfolder and Python venv inside (see [[gentoo:pip|PIP]]):+Telegram can be easily and fully bridged with Matrix using the Mautrix-Telegram bridge [[https://docs.mau.fi/bridges/python/setup.html?bridge=telegram|here]]. 
 + 
 +At the time of writing this page, a full rewrite in Go of the bridge is undergoing but not yet officially released, so i will show you how to install the //older// python-based bridge. When the rewrite will be complete, the instructions will be a mirror of the ones for the Whatsapp and Signal bridges, which have already migrated to Go. 
 + 
 + 
 +===== Installation ===== 
 + 
 +I asusme you are installing the bridge directly together with the Matrix server, as user //conduwuit//
 + 
 +Create subfolder in which you need to initialize a Python venv inside (see [[gentoo:pip|PIP]]):
 <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+# Enable PIP like described in the link above:
 # - create ~/.config/pip/pip.conf # - create ~/.config/pip/pip.conf
 # - add ~/.local/bin to the .bashrc # - add ~/.local/bin to the .bashrc
 python -m venv . # Note the dot at the end! python -m venv . # Note the dot at the end!
 source ./bin/activate source ./bin/activate
-# Now flip include-system-site-packages = true in pyvenv.cfg+# Now set "include-system-site-packages = truein pyvenv.cfg
 # Install: # Install:
 pip install --upgrade mautrix-telegram[all] pip install --upgrade mautrix-telegram[all]
 </code> </code>
 +Please follow the instructions to enable PIP venvs as described in the link above.
  
-You need to create API keys to connect to Telegram. Go to [[https://my.telegram.org/auth?to=apps|this page]] and  +This will install the bridge itself.  
-Grab the example config file [[https://raw.githubusercontent.com/mautrix/telegram/refs/heads/master/mautrix_telegram/example-config.yaml|here]]save it as **config.yaml** in the /data/conduwuit/ folder and create a link to the //mautrix-telegram// folder and customize it to your needs:+ 
 + 
 +===== 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.  Go to [[https://my.telegram.org/auth?to=apps|this page]] and login with your phone number and the code that will be delivered to your telegram account. 
 + 
 +From the page that pops up, generate and take note of **api_id** and **api_hash** as you will need to configure the bot. You should also give a name like //MatrixBot// or whatever you like. 
 + 
 + 
 +===== Bridge Setup ===== 
 + 
 +Unfortunately, the python bridge doesn't generate the configuration file skeleton automatically and you need to download the example one from [[https://raw.githubusercontent.com/mautrix/telegram/refs/heads/master/mautrix_telegram/example-config.yaml|here]] and save it to the conduwuit data folder:
 <code bash> <code bash>
-wget -O /data/conduwuit/mautrix-telegram-config.yaml +cd /data/conduwuit 
-mv /data/daemons/conduwuit/mautrix-telegram/config.yaml /data/conduwuit/mautrix-telegram-config.yaml+wget -O /data/conduwuit/mautrix-telegram-config.yaml https://raw.githubusercontent.com/mautrix/telegram/refs/heads/master/mautrix_telegram/example-config.yaml
 </code> </code>
 +
 +For an organizational reason, i prefer to keep all the stuff that needs to be backupped into /data/conduwuit instead of under /data/daemons/conduwuit.
  
 This file is huge, here are the most relevant changes needed: This file is huge, here are the most relevant changes needed:
 <file - config.yaml> <file - config.yaml>
 +appservice:
 +    address: http://localhost:29317
 +
     address: https://chat.mydomain.com     address: https://chat.mydomain.com
     domain: chat.mydomain.com     domain: chat.mydomain.com
Line 43: Line 70:
   "@myself:chat.mydomain.com": "admin" # who can admin the bot   "@myself:chat.mydomain.com": "admin" # who can admin the bot
      
-encryption:+  encryption:
     # 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_server_map: 
 +        example.com: https://chat.gardiol.org 
 +  double_puppet_allow_discovery: false 
 +  login_shared_secret_map: 
 +      chat.gardiol.org: << here the double pupper as_token >> 
 +       
 +logging: 
 +    handlers: 
 +        file: 
 +            filename: /var/log/conduwuit/mautrix-telegram.log
 </file> </file>
-More details on configuration can be found [[https://docs.mau.fi/bridges/general/initial-config.html|here]].+ 
 +More details on configuration can be found [[https://docs.mau.fi/bridges/general/initial-config.html|here]]. To setup double-puppeting, see [[matrix:doublepuppeting|here]].
  
 I choose to use SQLite as database because i only have a few users and don't want to spin a PostreSQL instance for that. I choose to use SQLite as database because i only have a few users and don't want to spin a PostreSQL instance for that.
  
-At this point you need to register the bridge:+===== Bridge Registration ===== 
 + 
 +At this point you need to register the bridge with the Matrix server. 
 + 
 +First of all, generate the //registration.yaml// file:
 <code bash> <code bash>
 python -m mautrix_telegram -g -c /data/conduwuit/mautrix-telegram-config.yaml python -m mautrix_telegram -g -c /data/conduwuit/mautrix-telegram-config.yaml
 </code> </code>
  
-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: +Then perform the actual appservice registration, see [[matrix:appservices|here]].
-<code> +
-!admin appservices register << shift+enter >> +
-```  << shift+enter >> +
-[ ... copy here the content of registration.yaml ... ] +
-``` << enter >> +
-</code>+
  
-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. 
-The **<< autogenrated >>** are secret strings found in the //registration.yaml// file. 
  
-The chat should reply with a message like: +===== Usage  =====
-<code> +
-Appservice registered with ID: telegram +
-</code>+
  
-More details on registering the appservice can be found [[https://docs.mau.fi/bridges/general/registering-appservices.html|here]].+You need to create the **telegrambot** user, again from the admin chatthis step could be skipped if the user has been already created, it seems to be hit and miss with these Python bridges. 
  
-You need to create the **telegrambot** user, again from the admin chat:+In case the user is missing, from the Matrix server admin chat type:
 <code> <code>
 !admin users create-user telegrambot !admin users create-user telegrambot
Line 87: Line 117:
  
 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:chat.mydomain.com+  * Start a chat with //@telegrambot:chat.mydomain.com//
   * type "login"   * type "login"
   * 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 129:
  
 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://docs.mau.fi/bridges/python/telegram/index.html|here]]. General documentation on the Telegram bot can be found [[https://docs.mau.fi/bridges/python/telegram/index.html|here]].
  
 To manage animated sticker [[https://github.com/sot-tech/LottieConverter|here]] To manage animated sticker [[https://github.com/sot-tech/LottieConverter|here]]
 +
 +
 +===== Autostart =====
 +
 +Since i use OpenRC, simply drop the following script to /etc/init.d:
 +<file - /etc/init.d/conduwuit-telegram>
 +#!/sbin/openrc-run
 +# Copyright 2025 Gentoo Authors
 +# Distributed under the terms of the GNU General Public License v2
 +
 +name="conduwuit telegram bridge"
 +description="Conduwuit Telegram Matrix Bridge"
 +pidfile="/run/conduwuit-telegram.pid"
 +command_background=true
 +command="/data/daemons/conduwuit/mautrix-telegram/bin/python"
 +command_args=" -m mautrix_telegram -c /data/conduwuit/mautrix-telegram-config.yaml"
 +command_user="conduwuit:conduwuit"
 +output_log="/var/log/conduwuit/conduwuit-telegram.log"
 +output_err="/var/log/conduwuit/conduwuit-telegram.log"
 +
 +start_pre() {
 +        cd /data/daemons/conduwuit/mautrix-telegram
 +}
 +
 +depend() {
 +        need net
 +}
 +</file>
 +
 +Make it executable and add to the proper runlevel:
 +<code bash>
 +chmod +x /etc/init.d/conduwuit-telegram
 +rc-update add conduwuit-telegram default
 +</code>
  
  

This website uses cookies. By using the website, you agree with storing cookies on your computer. Also, you acknowledge that you have read and understand our Privacy Policy. If you do not agree, please leave the website.

More information