A lightweight and fast, full-featured bridge between XMPP and Telegram. Was originally written for personal use, so may not be very flexible in configuration.
The bridge supports all of the base capabilities:
- Forwarding between multiple pairs of chats at once instance (see below for usage)
- Forwarding of plain text messages
- Forwarding of attachments (videos, images, audio, etc)
- Stickers (from Telegram -> XMPP)
- Native replies to messages in Telegram
- Round-trip message edit changes
- Forwards events between bridged chats, such as mebmers join/exit, etc.
For the bridge to work, you need to use Python 3.8+, and install all the
dependencies specified in the requirements.txt
(slixmpp, aiohttp) file:
git clone https://github.com/ventureoo/jabagram
cd jabagram
pip install -r requirements.txt
Before you start the bridge, you need to do some basic configuration. An
example configuration is given in the form of the file config.example.ini
.
Rename it to config.ini
and specify the following data:
- Create a bot in Telegram via @botfather on behalf of which messages will be
forwarded and specify its token in the
token
field of the[telegram]
section. - Create an XMPP account on behalf of which the bridge will forward messages
in MUC rooms, specify its JID (login) and password in the
login
andpassword
fields in the[xmpp]
section respectively. - Come up with a secret key that will be used when linking new Telegram and XMPP chats. This key must be passed as a reason to invite a bot in XMPP to the MUC room, otherwise the bot will not accept the invitation. This is a security measure if you don't want your bridge instance to be used to bind other chats. Otherwise, leave this field blank.
- If you have done everything correctly, the bridge should start without
errors or exceptions and will create a database
jabagram.db
inside data folder, which will store information about the "bound" chats in Telegram and XMPP. See Usage further below.
An example of a config file that is given as config.example.ini
:
# Telegram bot token, get it from @botfather
[telegram]
token=XXXXXXXXXX:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
# Login and password from the bot account in XMPP
[xmpp]
login=your_xmpp_user@example.org
password=YoUr_SEcReT_PaSs
# The secret key specified in the user's invitation to the MUC for linking two
# chats. PLEASE change it from the default key if you don't want your bridge
# instance to be used by whoever you want. Otherwise, leave it blank.
[general]
key=SUxvdmVYTVBQ
You can also use Docker to deploy the bridge. Here you don't need to pre-install dependencies on the host system, just build a container image:
git clone https://github.com/ventureoo/
cd jabagram
docker build -t jabagram .
The following command is used to start it:
docker run --restart always -d --name jabagram -v "$(pwd)/data:/app/data:rw" jabagram
Note about the -v
key. It specifies that the database file be stored
outside the container environment, i.e. on your host system. The --restart
option is needed if you want the bridge to automatically restart on critical
errors or when your system is powered on.
Once you have successfully started your own bridge instance or found an existing one, you can perform chat binding using the following algorithm:
- Invite your bot to the Telegram chat you want to bridge.
- Run the
/jabagram
command with the MUC address of the room you want to bridge.- If the address was entered incorrectly, simply repeat the command with the corrected address.
- The bot will queue your chats and then wait for you to invite the bot into the XMPP room.
- Invite the XMPP bot into the room and as a reason, specify the secret key
that you previously specified in the config or received from the admin of an
existing instance. For example, in the Gajim client, this is done with the
command:
/invite <XMPP_JID> <SECRET_KEY>
- Once the bot successfully joins an XMPP room, messages should be sent between your room and the chat room in Telegram.
If you want to "unbridge" chats, just kick the bot from your Telegram chat or
XMPP room. It will automatically remove the entry from the database. Note that
losing the ./data/jabagram.db
file will unbridge all chats and you will need to
re-bridge them.
To re-bridge chats follow the steps above.
This bridge has some limitation that will probably never be properly fixed.
This bridge cannot forward messages that have been encrypted using OMEMO or OpenPGP. This will never be implemented because:
- slixmpp does not support encryption via OMEMO
- Forwarding encrypted messages is probably a bad idea in the first place, you are actually passing the body of your message unencrypted to the Telegram API, it will be visible to all Telegram chat members to see it. Which calls into question the whole point of encrypting messages.
Bridge cannot delete a forwarded message in XMPP if it has been deleted in Telegram. The Telegram API doesn't allow the bot to receive any updates about deleted messages, so this simply can't be implemented. In the case of XMPP, message deletion is a feature that can only be implemented on the client side, not at the protocol or XEP level. Use editing of message with a stub as a workaround.
Telegram has a proprietary format for animated stickers that probably can't be properly previewed by XMPP clients. However, the bridge still sends them as unorganized files.
Sorry, but at the moment I only want to support forwarding messages from group chats or MUCs. But this may be implemented in the future.
Some mobile clients like Conversations and Blabber don't show nicknames in MUC for users you have in your contacts [1]. Please, after inviting a bot to XMPP, make sure you remove it from your contacts, otherwise it will not accept Telegram sender nicknames for you.
[1] - https://github.com/iNPUTmice/Conversations/commit/ef1429c9a6983c101da41a277bd9353374dc89e7
Licensed under GPL 3.0. If you'd like to help with improvements or fixes to this shitty code, I'd be happy to consider your patches ;D
If you have any issues with how the bridge works/is configured, feel free to contact me:
- Telegram: t.me/ventureoo
- XMPP: ventureo@5222.de