Matrix Bridges-Bot

Matrix bridge

We have already described Matrix on this digital notebook.

You can install bridges or bots for Matrix.

There are several bridges for Matrix; basically, these are applications by which you can create a link (a bridge) with other messaging apps.

In this contribution we will refer only to the following mautrix-bridges:

  1. Signal
  2. Telegram

Basically, by installing one of the mentioned bridges, you can use the Matrix client (in our case Element) also to send and receive messages with Telegram and Signal. Eventually, except for a few cases, opening the reference app is no longer necessary.

Mautrix-Telegram Bridge

You can find instructions on installing and configuring the Telegram bridge on the set up page.

Requirements

Requirements for the installation of the Matrix-Telegram bridge are in the paragraph (Requirements) that any way we report below:

  • Python 3.8 or higher with pip and virtualenv.
  • A Matrix homeserver that supports application services (e.g. Synapse). You need access to register an appservice, which usually involves editing the homeserver config file.
  • A PostgreSQL server, v10 or higher (which you should already have for Synapse).
    • Make sure you don’t share databases between unrelated programs. Shared postgres instance is fine, but shared database is not.
  • If installing optional dependencies, see the optional dependencies page.
  • Telegram app ID and hash (get from my.telegram.org).
  • LottieConverter if you want animated stickers to be converted to something viewable on Matrix.
  • ffmpeg to transcode audio files (just install it with your system package manager).

Installation

Follow the instructions (points 0 to 7) in the Production setup section for installation.

Upgrade

When a new version of the bridge is released, you should upgrade it. It is straightforward because it is enough to do what is indicated in points 1 and 2 of the installation instructions.

Regarding the upgrade procedure, we have realized a bash script for Ubuntu server 20.04 that speeds up the activities significantly when you should upgrade several bridges.

The script is the following:

#!/bin/bash

echo '################################'
echo '### Upgrade mautrix-telegram ###'
echo '################################'

cd PATH #(indicate the path where the bridge has been installed - e.g. /opt/mautrix-telegram)

systemctl stop mautrix-telegram
source ./bin/activate
pip install --upgrade mautrix-telegram[all]
deactivate
chown -R mautrix-telegram PATH #(indicare il percorso dov'è stato installato il bridge - es. /opt/mautrix-telegram)
systemctl start mautrix-telegram

To execute the script, you have before to:

  1. create a file like mautrix-telegram_upgrade.sh by the command touch mautrix-telegram_upgrade.sh
  2. run nano mautrix-telegram_upgrade.sh
  3. past the script content
  4. close the editor with CRTL+X and select Y to save the file in a folder different from where the bridge is installed (for example, in /opt if the bridge is in /opt/mautrix-telegram).
  5. attribute the permissions with the command chmod 777 -R mautrix-telegram_upgrade.sh

To execute the script, run ./mautrix-telegram_upgrade.sh

Please, note we choose the file name mautrix-telegram_upgrade.sh but you can choose another one.

Mautrix-Signal Bridge

For the Mautrix-Signal bridge, the procedure is very similar - if not identical - to that for the Mautrix-Telegram bridge.

You can find Requirements and Installation instructions at this page.

Upgrade

To Upgrade the Mautrix-Signal bridge, something changes.

Here is the script we have prepared:

#!/bin/bash

echo '#############################'
echo '## Upgrade mautrix-signal  ##'
echo '#############################'
cd PATH #(indicate the path where the bridge has been installed - e.g. /opt/mautrix-signal)
systemctl stop mautrix-signal
git pull
source .venv/bin/activate
pip install --upgrade -r optional-requirements.txt -r requirements.txt
deactivate
systemctl start mautrix-signal

As you can see, to Mautrix-Signal bridge requires that you must first run the git pull command.

To execute the script, you have before to:

  1. create a file like mautrix-signal_upgrade.sh by the command touch mautrix-signal_upgrade.sh
  2. run nano mautrix-signal_upgrade.sh
  3. past the script content
  4. close the editor with CRTL+X and select Y to save the file in a folder different from where the bridge is installed (for example, in /opt if the bridge is in /opt/mautrix-signal).
  5. attribute the permissions with the command chmod 777 -R mautrix-signal_upgrade.sh

To execute the script, run ./mautrix-signal_upgrade.sh

Please, note we choose the file name mautrix-signal_upgrade.sh but you can choose another one.

Matrix bot

Bots have also been developed for Matrix.

In particular, the maubot bot has been developed to which you can use plugins.

Available plugins for maubot are listed at this page.

Maubot Upgrade

To upgrade Maubot we created the following script:

#!/bin/bash

echo '#############################'
echo '###### Upgrade maubot #######'
echo '#############################'

cd /opt/maubot

systemctl stop maubot
source ./bin/activate
pip install --upgrade maubot
deactivate
chown -R maubot /opt/maubot
systemctl start maubot

To execute the script, you have before to:

  1. create a file like maubot_upgrade.sh by the command touch maubot_upgrade.sh
  2. run nano maubot_upgrade.sh
  3. past the script content
  4. close the editor with CRTL+X and select Y to save the file in a folder different from where the bridge is installed (for example, in /opt if the bridge is in /opt/maubot).
  5. attribute the permissions with the command chmod 777 -R maubot_upgrade.sh

To execute the script, run ./maubot_upgrade.sh

Please, note we choose the file name maubot_upgrade.sh but you can choose another one.


If this resource was helpful, you could contribute by

Buy me a coffee

Or donate via

Liberapay


Follow us on Mastodon

Stay tuned!