November 22, 2024

Setting up WhatsApp Telegram Bridge Using Matterbridge 2020

Sponsored

Two years ago I wrote an article about bridging WhatsApp and Telegram groups together. But that solution isn’t working anymore. So I figured out another method using WhatsApp web. The brdiging software we are going to use for this is called matterbridge. the software we use is matterbrige. This bridge is not only for Whatsapp and Telegram but for So many messaging protocols.

Contents

Natively supported apps

  • Discord
  • Gitter
  • IRC
  • Keybase
  • Matrix
  • Mattermost 4.x, 5.x
  • Microsoft Teams
  • Nextcloud Talk
  • Rocket.chat
  • Slack
  • Ssh-chat
  • Steam
  • Telegram
  • Twitch
  • WhatsApp
  • XMPP
  • Zulip

The whatsapp linking part is based on go-whatsapp which is a Go version of  whatsapp-web-reveng.

I think that’s enough for the intro, let’s get back to the main point 🙂

Sponsored

Install and Run

Download the latest version from here
select the required package. im using linux for this tutorial so i select matterbridge-1.18.3-linux-64bit (this version will change)
then move to the Configuration part

Step 1

Create an empty matterbridge.toml file inside a folder contains downloaded matterbridge binary file.

Step 2

Copy the following contents to the newly created matterbridge.toml file:

[telegram.mytelegram]
#See https://core.telegram.org/bots#6-botfather 
#and https://www.linkedin.com/pulse/telegram-bots-beginners-marco-frau
Token="Yourtokenhere"
RemoteNickFormat="({PROTOCOL}) <{NICK}> "
MessageFormat="HTMLNick"

[whatsapp.mywhatsapp]
# Number you will use as a relay bot. Tip: Get some disposable sim card, don't rely on 
# your own number.
Number="+48111222333"

# First time that you login you will need to scan QR code, then credentials will be saved in 
# a session file. 
# If you won't set SessionFile then you will need to scan QR code on every restart.
# optional (by default the session is stored only in memory, till restarting matterbridge)
SessionFile="session-48111222333.gob"

# If your terminal is white we need to invert QR code in order for it to be scanned properly
# optional (default false)
QrOnWhiteTerminal=false

# Messages will be seen by other WhatsApp contacts as coming from the bridge. 
# Original nick will be part of the message.
RemoteNickFormat="[{PROTOCOL}] @{NICK}: "
Step 3

Change the Token and Server keys above to yours. For more details you may watch this video.

In Telegram, go to botfather and create a bot and paste the token as Token="Yourtokenhere"
Enter your whatsapp number as Number="+48111222333"

Step 4

Add the gateway configuration to your config file.

[[gateway]]
name="gateway1"
enable=true

[[gateway.inout]]
account="whatsapp.mywhatsapp"
channel="[email protected]"

[[gateway.inout]]
account="telegram.mytelegram"
channel="-xxxxx"
Step 5

Now your configuration file should look like this:

[telegram.mytelegram]
#See https://core.telegram.org/bots#6-botfather 
#and https://www.linkedin.com/pulse/telegram-bots-beginners-marco-frau
Token="1279548291:AAFg3s7F-JQlQQlucSBf3PGwyOss2Vog0J4"
RemoteNickFormat="({PROTOCOL}) <{NICK}> "
MessageFormat="HTMLNick"

[whatsapp.mywhatsapp]
# Number you will use as a relay bot. Tip: Get some disposable sim card, don't rely on 
# your own number.
Number="+48111222333"

# First time that you login you will need to scan QR code, then credentials will be saved in 
# a session file. 
# If you won't set SessionFile then you will need to scan QR code on every restart.
# optional (by default the session is stored only in memory, till restarting matterbridge)
SessionFile="session-48111222333.gob"

# If your terminal is white we need to invert QR code in order for it to be scanned properly
# optional (default false)
QrOnWhiteTerminal=false

# Messages will be seen by other WhatsApp contacts as coming from the bridge. 
# Original nick will be part of the message.
RemoteNickFormat="[{PROTOCOL}] @{NICK}: "

[[gateway]]
name="gateway1"
enable=true

[[gateway.inout]]
account="whatsapp.mywhatsapp"
channel="[email protected]"

[[gateway.inout]]
account="telegram.mytelegram"
channel="-xxxx"
Step 6

Find channel ID for Telegram and WhatsApp. Finding Telegram group ID is relatively easy.  You can use the Telegram bot API to get the group ID. But I’m taking a simple shortcut here.  Adding another bot to retrieve group ID, which is @tchncs_bot. This is a bot that bridges Matrix and Telegram groups. Just add the bot and sending the message /id (including the forward slash, which makes the message a command) will return the group ID.

Unlike in Telegram’s case, finding channel name in WhatsApp isn’t that easy. I couldn’t find any easier method from matterbridge documentation as well. So enter your WhatsApp group name there and run the bridge (Warning: you will definitely get an error!)

Step 7

Run it with the following command (change the version number if you are using later version)
./matterbridge-1.18.3-linux-64bit -conf matterbridge.toml

Now you can see a QR code in terminal. If it is too big that you weren’t able to scan it, then zoom in the terminal and try again. Then scan the QR code with WhatsApp web option from your mobile phone. Now your WhatsApp web is connected with the matterbridge. Next step is to identify the channel name for WhatsApp. By checking the terminal output you can see your group name and a number that ends with @g.us. Copy that and paste it in the channel part of WhatsApp and run again. Now your bridge is ready and it will start working. You can also share image, files and audios using this bridge. If you want to bridge multiple groups the gateway part can be changed to

[[gateway]]
name="gateway1"
enable=true

[[gateway.inout]]
account="whatsapp.mywhatsapp"
channel="[email protected]"

[[gateway.inout]]
account="telegram.mytelegram"
channel="-xxxx"

[[gateway]]
name="gateway2"
enable=true

[[gateway.inout]]
account="whatsapp.mywhatsapp"
channel="[email protected]"

[[gateway.inout]]
account="telegram.mytelegram"
channel="-xxxx"

 

Drawbacks

This brdige reies on WhatsApp web. So if you have to make this solution work, you should be online on both mobile as well as on WhatsApp web all the time. Other solution you could try is to run any emulator on server. Also, the matterbridge should be running all the time. So you have to choose a server for that. Cloudcone provides low cost servers with good quality. You can use this link to using cloudcone.

Sponsored

6 thoughts on “Setting up WhatsApp Telegram Bridge Using Matterbridge 2020

  1. Have you tried or know if Telegram bots functionaity does sync correctly to whatsapp groups by this method?

  2. Hello! Could you PLEASE make a new tutorila on how to run matterbridge since they changed to GO language? I just dont get it to work after happily using it for month now

Share your Opinion

This site uses Akismet to reduce spam. Learn how your comment data is processed.