SIP-connector Telegram + Voximplant = calls to cellular and softphones


A SIP connector (@siptg) was developed for the telegram. Voximplant is a telephony platform. That's right, they can work perfectly together and today we will show how. Welcome to cat!

Register softphone in Voximplant


SIP-connector can work in two modes: softphone and SIP-gateway. We will consider the first option, since it allows you to register the bot "under the guise" of the internal user of your Voximplant application. That is why you first need to create the Voximplant application and the users inside it.

  1. Log into your account https://manage.voximplant.com/ .
  2. Go to the Applications section and create an application called sip.
  3. While inside the application, go to the "Users" tab and create a usertelegram user. Do not forget the password, it will be needed soon:

  4. Create a userbob user here (it will come in handy a bit later).

. @siptg : . Voximplant : usertelegram, userbob .. camelCase, , .
Now we go to the side of the messenger. The softphone itself is under the name @siptg, and its settings under the name @siptg_bot - open them. We press Start, then enter the / tariff command and select Free (for demonstration it is more than enough, but it has limitations - for example, after 5 unsuccessful calls, a temporary block occurs. The exact unlock time can also be seen using the / tariff command).

Then use the / softphone command and click the New button. Here, one by one, enter the Voximplant user data and click Apply. The server field consists of sip. + Voximplant account name + .voximplant.com:


If everything is entered correctly, the registered client will be highlighted in green.


Well, now we can check if they come to telegrams ...

โ€ฆ incoming calls


To do this, you need to go into the sip application on the Voximplant side to create a script and a rule for processing calls. The scenario is simple: when a call comes from the user of the sip application to the cloud, the cloud calls the second user of the same application and connects them. It looks like this:

VoxEngine.addEventListener(AppEvents.CallAlerting, e => {
   const inc = e.call
 
   const out = VoxEngine.callUser(e.destination, e.callerid)
 
   VoxEngine.easyProcess(inc, out)
})

Save the script as callUser. Staying there, in the sip application, switch to the โ€œRulesโ€ tab and create a call user rule with these settings (note the mask):


Remember the userbob user created at the very beginning? Great, log in with his username and password in our webphone :


Enter usertelegram and click โ€œCallโ€ - you will receive an incoming call from the @siptg bot on all devices where you have an instant messenger.


Outgoing calls to Voximplant users


The scenario and rule are the same; nothing new needs to be created.
The only nuance I mentioned above is that Voximplant usernames must be lowercase. If the username is userBob, then when you specify it, the @siptg bot will eventually convert it to userbob, and there is simply no such user in your Voximplant application. As a result, a dial-up error.
Open the @siptg bot, send him a userbob message and you will see an allegedly incoming call from the bot (counterintuitively, but as it is).


Click on the green handset and after that the call will go to the softphone in the browser, that is, to userbob.


Outgoing calls to cell numbers


In order for the telegram bot to call landline numbers, you will need:

  • one more scenario and rule;
  • Valid callback phone number (Caller ID). This can be either your personal phone number, which you confirmed in the panel , or the number purchased from Voximplant. Please note that test numbers are not suitable for this purpose.

In the sip application, create a callPSTN script with this code (pay attention to line 4 - here you need to substitute a valid number):

VoxEngine.addEventListener(AppEvents.CallAlerting, e => {
   const inc = e.call
 
   const out = VoxEngine.callPSTN(e.destination, "real callback number")
 
   VoxEngine.easyProcess(inc, out)
})

Then create a call rule PSTN rule, you can leave the mask by default:


Important: move this new rule down in the list of rules. Thus, his priority will decrease and it will work only if the rule for user is not followed. *


Ok, now you can call: send the target phone number to the @siptg bot, it shows you the call interface, press the green handset and the call goes to the specified mobile / city number.

Conclusion


Integrating a telegram with cloud telephony can be convenient for business, because this is another way to reach out to customers - read omnichannel. It can also be applied internally if telegram is your corporate messenger. Perhaps, for personal needs this may also be in demand. The ability to make telegram calls is relevant in any case when you use this messenger, and the one you want to call does not use. As a result, you donโ€™t need to change the environment for communication - the call goes directly from the messenger, and nothing changes for your interlocutor, he will receive a call to his softphone / phone.

All Articles