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 [2026/04/12 16:16] (current) willy
Line 1: Line 1:
-====== Matrix Telegram Bridge =====+====== B) 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/go/telegram/index.html|here]]
 + 
 +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 //conduwuit//
 + 
 +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 'https://mau.dev/mautrix/telegram/-/jobs/artifacts/main/download?job=build%20amd64'  
-create ~/.config/pip/pip.conf +unzip mautrix-telegram.zip 
-# - add ~/.local/bin to the .bashrc +chmod +x mautrix-telegram
-python -m venv . # Note the dot at the end! +
-source ./bin/activate +
-# Now flip include-system-site-packages = true in pyvenv.cfg +
-# Install: +
-pip install --upgrade mautrix-telegram[all]+
 </code> </code>
  
-You need to create API keys to connect to Telegram. Go to [[https://my.telegram.org/auth?to=apps|this page]] and  + 
-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 upgenerate 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 ===== 
 + 
 +Let the bridge generate the basic configuration file, and move it to the /data/conduwuit folder:
 <code bash> <code bash>
-wget -O /data/conduwuit/mautrix-telegram-config.yaml +./mautrix-telegram -e 
-mv /data/daemons/conduwuit/mautrix-telegram/config.yaml /data/conduwuit/mautrix-telegram-config.yaml+mv config.yaml /data/conduwuit/mautrix-telegram-config.yaml
 </code> </code>
  
-This file is hugehere 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: "{{or .FullName .BusinessName .PushName .Phone}} (Tg)"  
 +     
 +database: 
 +    type: sqlite3-fk-wal 
 +    uri: file:/data/conduwuit/mautrix-telegram.db?_txlock=immediate 
 +  
 +homeserver:
     address: https://chat.mydomain.com     address: https://chat.mydomain.com
     domain: chat.mydomain.com     domain: chat.mydomain.com
-    verify_ssl: true + 
-    database: sqlite:/data/conduwuit/mautrix-telegram.db # place the database into the /data/conduwuit folder +appservice
-telegram+    hostname127.0.0.1
-    # Get your own API keys at https://my.telegram.org/apps +
-    api_id: << put your id here >> +
-    api_hash: << put your hash >> +
-    # (Optional) Create your own bot at https://t.me/BotFather +
-    bot_token: disabled +
-permissions: +
-  "*": "relaybot"                      # non-local users can only see messages +
-  "chat.mydomain.com": "full"          # full access to all local users +
-  "@myself:chat.mydomain.com": "admin" # who can admin the bot+
      
-encryption:+permissions: # this is probably not needed, but anyway... 
 +  "*": "relay"                      # non-local users can only see messages 
 +  "chat.mydomain.com": "admin"          # full access to all local users 
 +  "@myself:chat.mydomain.com": "admin" # who can admin the bot 
 + 
 +backfill: 
 +    enabled: true  # to populate chats with older messages 
 +     
 +    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: 
-</file> +    # Servers to always allow double puppeting from. 
-More details on configuration can be found [[https://docs.mau.fi/bridges/general/initial-config.html|here]].+    # This is only for other servers and should NOT contain the server the bridge is on. 
 +    servers: 
 +        anotherserver.example.org: https://matrix.anotherserver.example.org 
 +    # Whether to allow client API URL discovery for other servers. When using this option, 
 +    # users on other servers can use double puppeting even if their server URLs aren'
 +    # explicitly added to the servers map above. 
 +    allow_discovery: false 
 +    # Shared secrets for automatic double puppeting. 
 +    # See https://docs.mau.fi/bridges/general/double-puppeting.html for instructions. 
 +    secrets: 
 +        chat.mydomain.com: as_token:<< here the double-puppet token >> 
 +         
 +logging: 
 +      filename: /var/log/conduwuit/mautrix-telegram.log 
 +</code>
  
-I choose to use SQLite as database because i only have a few users and don'want to spin a PostreSQL instance for that.+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'forget to enable backfill before the first start!
  
-At this point you need to register the bridge: +Since my server will have just a few users, i decided to use an SQLite database
-<code bash> +
-python -m mautrix_telegram -g -c /data/conduwuit/mautrix-telegram-config.yaml +
-</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: 
-<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. +===== Bridge Registration =====
-The **<< autogenrated >>** are secret strings found in the //registration.yaml// file.+
  
-The chat should reply with a message like+At this point you need to register the bridge with the Matrix server. 
-<code> + 
-Appservice registered with ID: telegram+First of all, generate the //registration.yaml// file
 +<code bash
 +./mautrix-telegram -c  /data/conduwuit/mautrix-telegram-config.yaml -g
 </code> </code>
  
-More details on registering the appservice can be found [[https://docs.mau.fi/bridges/general/registering-appservices.html|here]].+Then perform the actual appservice registration, see [[matrix:appservices|here]].
  
-You need to create the **telegrambot** user, again from the admin chat: + 
-<code> +===== Usage ===== 
-!admin users create-user telegrambot + 
-</code>+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 -m mautrix_telegram -c /data/conduwuit/mautrix-telegram-config.yaml+/data/daemon/mautrix-telegram/mautrix-telegram -c /data/conduwuit/mautrix-telegram-config.yaml
 </code> </code>
  
 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 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://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/mautrix-telegram"
 +command_args="/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>
 +
 +
 +
 +