December 21, 2024

Setting up WhatsApp Telegram Bridge Using wat-bridge bot

Sponsored

This Solution is not working Anymore. please read the new solution here

Telegram is a popular Instant Messenger application. Also, it is very feature-rich than WhatsApp. But the most popular chat application is still WhatsApp. WhatsApp is fully closed-source and it does not allow any user-modifications. On the other hand, Telegram client is open-source and Telegram Bot APIs are a powerful tool to build our own applications on top of Telegram. Mirroring the conversations between WhatsApp and telegram is possible by setting up WhatsApp Telegram Bridge Using wat-bridge bot.

Are you a Telegram fan? Want to detach yourself from WhatsApp? Or do you want to read WhatsApp group messages in Telegram group? Then you are at the right place.

Sponsored

 

Contents

Setting up WhatsApp Telegram Bridge using wat-bridge bot

WhatsApp as of now is not allowing user-bots at all. But a CLI library called Yowsup can do the tricks. It actually acts as a WhatsApp API. A user could register a mobile number with WhatsApp and chat using that number with Yowsup. We could also automate some messaging tasks this way and thus it becomes to act like a user-bot.

Rafael Medina (rmed) created a Telegram WhatsApp bridge using Yowsup and Telegram bot. You can find the wat-bridge repo here. This bot basically interacts with WhatsApp accounts and it could be used to bridge groups too.

Cons of wat-bridge

  • Can’t send media messages
  • Will not receive reply messages from Whatsapp
  • No username along with the WhatsApp message (You have to identify the user using mobile number instead, see the below section for more details)

Don’t worry, solution is here

A fork of wat-bridge is capable of solving the above-mentioned cons. This fork can overcome all the issues that the original bot has. The modified bot is available in the repository here. But getting media files from WhatsApp is in pre-alpha stage and you will need some additional works to do with the server.

How to Setup a Whatsapp Telegram bridge

if you are not capable of running your own bot I will suggest a working bot for you. follow this post in telegram channel 

WhatsApp number, Telegrambot, Now go to this part of the tutorial to connect groups.

Let’s continue to build the bot

As the fork having more features but media file transfer isn’t in a good condition to test. So I am using the official repo here. You can also test the forked one if you are interested, it’s just that the cloning step is different.

  1. First, create a Telegram bot by using @botfather. i.e. send /newsbot command to @botfather and then the botfather bot will give you a token number

    Botfather in Telegram
    Botfather
  2. Clone the wat-bridge repository at https://github.com/rmed/wat-bridge.git
    git clone https://github.com/rmed/wat-bridge.git
  3. Enter the cloned directory
    cd wat-bridge
  4. Setup python virtual environment
    virtualenv -p python3 venv
    . venv/bin/activate
  5. Install the required packages from requirements.txt
    pip install -r requirements.txt
  6. Install latest yowsup
    git clone https://github.com/tgalal/yowsup.git
    cd yowsup
    # Install dependencies to build yowsup
    sudo apt-get install ncurses-dev python3-dev
    python setup.py install

Registering a number with yowsup

Now that we have installed yowsup, let’s register a phone number using yowsup.

NB: This number may get banned by WhatsApp, so use at your own risk! Also, don’t use your primary WhatsApp number for this, use a number which isn’t registered with WhatsApp yet.

Register a number

  • yowsup-cli registration --request sms --phone 49XXXXXXXX --cc 49 --mcc 123 --mnc 456

    Provide phone number, CC, MCC & MCN. CC is the Country pre, you can know more about MCC and MNC from here. Now you will get an OTP to your number. Use that OTP in the next step for registration.

  • yowsup-cli registration --register 123456 --phone 49XXXXXXXX --cc 49

    Now you will receive a password. Store this password anywhere securely.

  • Now let’s go to wat-bridge directory. Copy development.conf into another file
    cp development.conf config.conf
  • Open config.conf in any text editor and change the parameters
    [tg]
    owner = ONWER_ID - this is the bot creator ID
    token = TOKEN - Token got from @botfather
    
    [wa]
    phone = PHONE_NUMBER - registred phone number
    password = PASSWORD - password obtained from yowsup registration
    
    [db]
    path = PATH_TO_DB - create a .db file in wat-bridge folder and give its path
  • Save and exit
  • Now run the bot
    WAT_CONF=config.conf python watbridge.py

Yes, you are done! The bridge will be running now.

Bridge WhatsApp and Telegram groups

  1. Add the Whatsapp number to required WhatsApp group and send any message
  2. Add telegram bot in required telegram group  send /me and copy the message get from bot
  3. Go to your bot now you will get a message from the added Whatsapp group with a number in it (that number is WhatsApp group id)
/add  <group name> <that number from  step3>

/bind <group name> <number get from 2 step>

Now both groups are linked.

Binding groups
Binding groups

Bridge WhatsApp and Telegram groups using forked bot

  • Add the WhatsApp number to required WhatsApp group and send /getID
  • Now you will receive a message with random numbers starting with /link, copy that entire message
  • Add Telegram bot in respective Telegram group
  • Send the message received from WhatsApp group to Telegram group
  • Now both the groups should be linked and you are all done!

Cons of wat-bridge forked bot

  • Receiving messages from Telegram to large WhatsApp groups having more than 200 people will crash the bot
  • Latest pre contains media support which needs to be documented, for developers I suggest to checkout to previous commits for better results.

Bonus: You can also bridge Telegram with Riot (A popular Matrix client) as mentioned here!

Sponsored

15 thoughts on “Setting up WhatsApp Telegram Bridge Using wat-bridge bot

  1. I get an erroe when trying to do step 4
    (Setup python virtual environment)
    virtualenv -p python3 venv
    . venv/bin/activate

    it says command not found…. what can I do? Is there a video tutorial for the setup?

          1. doesn’t work :/ it says:

            MYCOMPUTER MINGW64 ~/wat-bridge (master)
            $ virtualenv -p python3 venv
            bash: virtualenv: command not found

            MYCOMPUTER MINGW64 ~/wat-bridge (master)
            $ . venv/bin/activate
            bash: venv/bin/activate: No such file or directory

            I’m using Git Bash for Windows and just copy-paste the things written here but something is wrong…
            maybe the author thinks about recording a video tutorial…

          2. i am not familiar with windows workspace. i have used Gnu/linux. please use Gnu/linux and continue 🙂

  2. wasn’t able to do this step:
    cp development.conf config.conf
    I copied the development.conf file manually and renamed it to config.conf. Is that correct?

    Also, I can’t run the bot when I type WAT_CONF=config.conf python watbridge.py.
    I told me:
    “can’t open file ‘watbridge.py’: [Errno 2] No such file or directory”

    I tried again, then it told me:
    “Traceback (most recent call last):
    File “watbridge.py”, line 35, in
    from wat_bridge.static import SIGNAL_TG, SIGNAL_WA, init_bridge
    ImportError: No module named ‘wat_bridge'”

    Very strange…

    1. “can’t open file ‘watbridge.py’: [Errno 2] No such file or directory”
      Where did you run this command ? run ls see if there watbridge.py file. it is in the wat-bridge folder

Share your Opinion

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