
I'm sure many people wondered: here is Telegram, a year ago he got calls, he has an open API, but for some reason, so far no one has made a bundle with the SIP protocol. After all, it gives unlimited possibilities: from replacing SIP-dialers to organizing another channel of communication with users of your business. Today I will tell the story of the appearance of the first such gateway, which is now accessible to absolutely everyone!
Once upon a time I got to the resource Talk37 (now it is
ruVoIP.net ) and I really liked it. Despite the fact that lately he has gained notoriety due to the efforts of darknet lovers, the active community of the project is still people who support him with a soul. I separately thank its creator Dmitry Serov for his responsiveness and hard work.
ruVoIP.net is a free virtual PBX, and almost any commercial PBX would envy its functionality. Each user registered in it receives at registration his own internal number, which can be reached in
many ways . And so, on September 24, 2017, the first prototype of the gateway
saw the light : now it became possible to reach ruVoIP.net users via Telegrams! Or rather ... what does it mean possible? We created a separate user Telegram, who learned how to receive calls and greet callers with a request to enter an internal number. But where to enter? How to enter? In general, something earned and caused all active participants great joy akin to launching a rocket into space. It doesn’t matter that it fell often, there was no DTMF, and the sound was like an old HF receiver.
As time went on, the gateway improved, and ruVoIP.net came out in the TOP of search engines for the “sip telegram” request. I started to receive requests from different people who want to make
the same gateway ; were including commercial offers. Unfortunately, the prototype architecture did not allow its expansion and was too complicated for use by end users, so I had to refuse everyone with promises to do something. I really wanted to otrelizit something for the new year, but I was not able to do it.
')
By February 12, 2018, the new version of the gateway finally reached the level when it was already possible to touch it - closed beta testing began. I do this project for the first time for the first time, so not everything worked out in an orderly manner, but it did me good: in the end, I managed to fix about a couple of dozen other bugs in those cases that I hadn’t even thought about.
What happened
I can not say that I managed to fix absolutely all the bugs. In the process of work, I actively communicated with those who wanted to make
the same gateway and I had a picture of what users need. On the other hand, each function very much depends on the capabilities of the Telegram itself. Not everything could be done conveniently (and something could not be done at all) due to platform limitations.
The result was two main modes:
Operators and
Gateways . The settings of both modes are made via the
@siptg_bot bot.
Operators
This is the SIP Softphone replacement mode with the Telegram messenger. If you already have an account with some SIP provider, but you do not want to install (on the phone) the next Softphone, which takes up memory, consumes the battery, requires fine-tuning of codecs and poorly adjusts to the quality of the data channel, then this mode is for You. It is allowed to create up to 20 independent connections to SIP-providers from one Telegram account (artificial restriction, maybe later will be corrected). Calls for each provider work in both directions: both incoming and outgoing calls are possible. Editing an account looks like this:
The buttons contain either the current value of the option or its name if the value is not set (the exception is the
Password ). On each settings page there is a help, which is invoked by clicking the
Help button.
How to receive calls?
Since the bots in Telegram do not know how to call, the service has a separate account
@siptg , which performs this function. With an incoming call, the number and name of the caller are taken from the SIP-headers and come in a separate message; along with the message also comes the DTMF keyboard:

Note: I understand that the current implementation looks strange and inconvenient, but this is a necessary measure: Telegram's API does not allow determining the name of the subscriber using the local address book; for the same reason, it is not possible to place the information about the caller’s number on the call screen.
How to call?
Here we are again confronted with the restrictions Telegrams: you can not dial an arbitrary phone number, you can only call another user. Therefore, there are two ways to call any number:
- send a phone number as a message;
- attach the contact containing the phone number to the message.
For convenience, both methods can be applied both to the bot (@siptg_bot) and to the account for calls (@siptg). If several operator accounts are configured, you will be asked to select the operator for the call:
Next comes the incoming call to Telegram and, after lifting the handset, the connection with the dialed number begins.
Note: for each operator, you can specify the transformation rules of the dialed number and limit its use for the numbers corresponding to the regular expression. If the dialed number does not correspond to the regular expression of the restriction, the operator is excluded from the request to select the operator for the call. In the case of non-alternative choice, the request does not appear. More information is available at the time of editing the Dialing Rules .
Gateways
The most interesting mode of operation is the
Gateways mode. This mode allows you to use Telegram account via SIP: receive calls and make calls from your Telegram account to other users. For example, you can create a special Telegram account for your business, communicate it to your customers as a contact and receive calls, integrating them into a common virtual PBX queue. And since calls are possible in both directions, your operators will also have the opportunity to call the customer back if necessary; while the client sees the call on behalf of your company.
What is a separate Telegram session for?
Messenger Telegram allows the use of one account from different devices, and a separate session is created on each device. Since when using sip.tg in gateway mode, integration with SIP is performed on behalf of your account, you need to create a new Telegram session. Creating a session is available through the settings of the bot: in the
Gateways section, click the
Login button and follow the instructions.
Note. The Telegram API does not allow you to get limited access to your account, in connection with which, by creating a new session, you give your consent to transfer full rights over your account to Telegram to the sip.tg service. The administration of the service makes every effort to limit the use of your account to Telegrams by third parties, does not transfer information about your session to Telegrams to third parties and does not use your account to Telegrams for purposes other than those stated, but is not responsible for any damage that may occur as a result theft of this information by third parties by hacking or physical access to the service equipment.
How to connect Telegrams to a virtual PBX?
After creating the session, you can configure your Telegram account to connect to a virtual PBX. To do this, create a new SIP connection in the
Gateway Settings section of the bot:
There are two ways to connect: incoming (
New In button: you configure a virtual PBX to connect to sip.tg servers) and outgoing (
New outgoing button: sip.tg servers connect to a virtual PBX). You can create several inbound and outbound connections and use them independently on different devices (in this case, the total number of connections should not exceed 20).
DTMF flags
in. and
DTMF ref. Allows you to control the display of the extension dialing keypad and the display of the caller's number during an incoming call.
How to make and receive calls?
Regardless of the chosen method of connecting to a virtual PBX, incoming and outgoing calls are made in the same way: when an incoming call to a virtual PBX is sent, the
number and name of the calling user Telegrams are sent, and for an outgoing call, it is enough to dial
the user
number Telegrams. You can use one of the following values ​​as a Telegram user
number :
- the real phone number of the user associated with his account;
- username ;
- * User ID .
Here I also note the following features:
- For an incoming call, if only a part of the data is known about the user, the number of the available values ​​is specified as the number: phone number, username or ID. That is, if the user's phone number is not known, but the user has specified username, then the username will be returned as the number. If the user does not know the phone number or set the username, then the ID number will be specified as * ID.
- You can call a user by his ID only if you have previously had direct or indirect interaction with him: messaging, previous calls, etc.
Something else
The account for calls
@siptg is registered to a real phone number. Why not use it for something else? The first thing that comes to mind is to organize an access gateway to Telegrams from the PSTN. Yes, I already thought about it, but for now I didn’t do it. And did the following.
Sometimes when leaving for roaming, you need to stay in touch. Since receiving calls to a Russian SIM card is very expensive, I thought it would be nice to receive incoming calls in Telegram! All that is required is to set up call forwarding on the Russian number and buy a local SIM card for Internet access.
To forward incoming calls to Telegrams, you need to make a USSD request
**21*+79581006789# 
**21*+79581006789# 
before the trip. After the trip, run the command
##21# 
##21# 
to disable forwarding.
Notes:
- The cost of the call forwarding service is paid according to your tariff plan as a call to the mobile number of the city of Moscow.
- The telephone number to which the Telegram account is registered must match the telephone number on which the redirection is set.
- The correct operation of this function depends on your service provider. In particular, work with non-Russian telecom operators is not guaranteed.
What will happen next?
Speaking frankly, the uncertainty regarding Telegrams in Russia both was and remains. In addition, the fate of the project entirely depends on the Telegram team. I do not know what will be the reaction of the team, because, having a bad experience of contacting technical support earlier, I did not contact again. If approved, it will be possible to significantly improve the current implementation and I see absolute benefits for everyone from this: the project opens up new opportunities for Telegrams as platforms, which, ultimately, should attract a new audience.
I also have a clear understanding of what needs to be done next, I know well the bottlenecks that need to be addressed. I also understand that as a result of habraeffect, everything can break, because I didn’t pick out large capacities at the start, but I hope that the inherent possibility of scaling will reduce the recovery time. However, if everything is really bad - come back in 2-3 days :).
I have no specific plans for the commercialization of the project, at first all the functionality will be completely free. However, if you expect a large load on your operator or gateway, please inform us in advance by contacting technical support: it is already possible to transfer your accounts to a separate server. If there is a request for specific functionality - also contact: together we will think about how this can be solved most optimally.
In conclusion I will leave links to all project resources: