Telegram Bridge
This guide explains how to use the Telegram bridge from the EMS Integration Manager to integrate your Telegram chats with your EMS server.
It requires your EMS server to have federation on.
The following instructions are done with the Element Desktop on the Element side and on Element iOS for the Telegram side. Element Android should be almost identical to Element Web.
Purchase the Telegram integration
-
Open the EMS control panel at: https://ems.element.io/user/hosting
-
Click the
Integrations
tab and if you have more than one server, select the server you wish to add the Telegram integration to.
-
Enter the maximum number of users in
Maximum Telegram users
.
Please note: this is the maximum number of Telegram users who actually send messages over the bridge each month. You are only billed for the number of Telegram users who are active. Once you exceed the maximum, then the bridge will be disabled until you increase the maximum. -
If you wish to allow Matrix users who aren't logged in to Telegram to participate in bridged Telegram chats, follow the steps in this section.
Once you have entered Maximum Telegram users
, click Purchase
(remember you can always go back to this step and increase the maximum number of Telegram users if you need more in the future).
-
A dialogue will remind you of the price per user and ask if you wish to proceed. Click
Purchase
if you wish to proceed with the Telegram Integration.
-
You will have to wait a few minutes while your host is reprovisioned. Once reprovisioning is finished, you are able to bridge Telegram to your EMS server using your Element client.
Bridge Telegram to your Element account
-
Once the bridge is running, open your Element app. Click on the
+
next toPeople
.
-
Create a Direct Message conversation by typing
@telegram:example.ems.host
(replace the domain with the one of your homeserver). Then clickGo
. -
Wait for the bridge account to join your room.
-
Open Telegram on your mobile device (iOS or Android) and tap on ≡, go to
Settings
, and thenDevices
, and thenLink Desktop Device
to start the Telegram QR code scanner. You will use this QR code scanner to scan a QR code displayed by your Element client in the next step. -
From your Element client, send a
login-qr
message to the bot to connect to your Telegram account. -
A QR code will be displayed. Quickly scan the QR code with Telegram on your mobile device.
-
On your Element client, you will see
Successfully logged in as <username>
, and you will see invitations for each of your Telegram channels, groups, and DMs in your Element client. Each Telegram chat is a separate Matrix room. Join one or more chats and start chatting from either your Element app on desktop, iOS or Android or your Telegram on mobile.
Sending a message to a Telegram User
To send a message to a Telegram user, you must first be connected to the bridge (see above).
-
On your Element client, open the "Telegram bridge bot" room.
-
Say
pm
followed by the phone number or username. The phone number must exist in your Telegram contacts. -
You will be invited to a DM with that user, and can send messages to them.
Bridging Matrix users without a Telegram account
By default, a Matrix user will have to connect their Telegram account for their messages to be bridged to Telegram. If you provide a bot token, we will use this bot to relay the messages of any Matrix users to Telegram. (Note: relaying is supported for Telegram groups, but is not yet supported for Telegram channels.)
Follow these steps to register a bot account with Telegram.
-
With your Telegram account, message
@BotFather
. If talking to BotFather via the bridge using Element, note that all "slash" command messages (eg./start
) sent to BotFather must begin with two slashes instead of one (eg.//start
). -
Create a new bot by sending the message
/newbot
to BotFather. The created bot will be the Telegram relay bot used by your bridge. Follow the subsequent prompts to give your bot a display name and a username. -
Wait for BotFather to provide you a bot token.
-
Send the message
/setprivacy
to BotFather and follow the prompts to set your new bot's privacy settings to "Disabled". This allows your relay bot to bridge all messages sent in a Telegram group, not just messages that mention the bot by name. -
Open the EMS control panel for your Telegram bridge and enter the token you received from BotFather in the "Bot token" field, then wait for the page to notify you when your bridge is ready.
-
In your Element client, view your DM with the Telegram bridge bot and send the
ping-bot
command. The bot should respond with the ID of your relay bot in Matrix, which indicates that the relay bot has been set up correctly. -
In your Element client, invite the Matrix relay bot to any room that bridges a Telegram group that should relay Matrix users' messages to Telegram. A convenient way to do so is to send a message of
!tg ping-bot
in such a room (which will be intercepted by the bridge bot & won't appear in Telegram), wait for the bridge bot to respond with a "pill" of the relay bot's Matrix ID, click on the pill, and then click "Invite" on the sidebar that appears. -
In Telegram, confirm that your Telegram relay bot has joined the group. If it hasn't, you may manually invite your bot to the group (as long as you have permissions to do so) by viewing the group's details, selecting "Add Members", and entering the username of your relay bot that you chose in step 2.
Using the Telegram bridge
See our documentation here.