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.
- 1 Setting up WhatsApp Telegram Bridge using wat-bridge bot
- 2 Cons of wat-bridge
- 3 Don’t worry, solution is here
- 4 How to Setup a Whatsapp Telegram bridge
- 5 Registering a number with yowsup
- 6 Register a number
- 7 Bridge WhatsApp and Telegram groups
- 8 Bridge WhatsApp and Telegram groups using forked bot
- 9 Cons of wat-bridge forked bot
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
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.
- 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
- Clone the wat-bridge repository at https://github.com/rmed/wat-bridge.git
git clone https://github.com/rmed/wat-bridge.git
- Enter the cloned directory
- Setup python virtual environment
virtualenv -p python3 venv . venv/bin/activate
- Install the required packages from requirements.txt
pip install -r requirements.txt
- 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
- Add the Whatsapp number to required WhatsApp group and send any message
- Add telegram bot in required telegram group send /me and copy the message get from bot
- 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.
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.