📜 ⬆️ ⬇️

Telegram Call Notification

imageimage
Quite often, companies using Asterisk are faced with the need to automatically transfer a call to an employee’s mobile phone. Of course, the ideal solution would be to install a softphone on the phones, but far from everywhere the quality of the mobile Internet satisfies the needs of voice transmission, so the call is transferred to the mobile phone number. In accordance with the law and internal rules, telecom operators often do not allow the substitution of an arbitrary number as a Caller ID, so employees who are transferred to a call do not see the number of the calling client, but the number of the office. In some cases it is even convenient, but it also happens that the customer needs to call back immediately. Of course, the employee can enter the statistics interface (if, of course, he is) and find the caller’s number there, but this is not always possible and is always completely inconvenient.

To solve the problem of transferring the caller's number to an employee on a mobile phone, various methods were used: sending SMS (costs extra money, requires equipment or an agreement with a service like sms.ru), voicing the number on a call to the office and adding an extension number (for a long time, it costs money , and it is difficult to remember 11 numbers on the fly), and finally, jabber (which few people use today).
Faced with a similar task, we wanted to use a telegram. On the official website, in the Apps section there is an unofficial console client for Linux - telegram-cli, which is what we need! However, due to its unofficial nature, this application cannot boast of a one-click installation, so you will have to compile it from source. In the network you can find the same instruction, which roams from site to site, however, following it, we failed, and more than once.

So, the sequence of correct actions is as follows:
As usual, we update the system
apt-get update  yum update. 

For telegram-cli to work correctly, python version 2.7 and higher is required. You can check which version is installed (unless, of course, it is installed at all) like this:
 python -V 

Still need the following packages
for ubuntu server 14.04
 libreadline-dev libconfig-dev libssl-dev lua5.2 liblua5.2-dev libevent-dev libjansson-dev libpython-dev make 

for centos 6.X
 lua-devel openssl-devel libconfig-devel readline-devel libevent-devel libjansson-devel python-devel 

as well as git
Once the necessary packages are installed, you can install the telegram-cli itself.
Choose a directory where it will be.
 cd /usr/src 

And we get the source
 git clone --recursive https://github.com/vysheng/tg.git 

Now you can go to the directory and start assembling
 cd ./tg ./configure 

but before make we recommend opening the ./tgl/mtproto-utils.c file and commenting out or deleting lines 101 and 115 there:
 assert (0); // As long as nobody ever uses this code, assume it is broken. 

Otherwise, there is a risk to get an error like this.
 tgl/mtproto-utils.c:101: BN2ull: Assertion 0' failed. SIGNAL received 

at the first attempt to launch telegram-cli.
Finally, you can run make and have a cup of coffee while the application is being built.
When the assembly is completed, you need to start the application and enter your phone number, as well as a confirmation code that will come to it or to another running telegram client:
  /usr/src/tg/bin/telegram-cli -k /usr/src/tg/tg-server.pub -W 

and then go out as a team
quit
From this moment you can use the console telegram! In addition to the quit command, the help command deserves attention, which will show all other commands. We are primarily interested in sending messages. This is done like this:
 msg _   

Please note that between the name and the surname is _ and not a space, as well as the fact that the name is always in front of the surname.
And this is what a telegram-cli call will look like to send a single message and complete
  /usr/src/tg/bin/telegram-cli -k /usr/src/tg/tg-server.pub -U root -W -e "msg _ , !" 

For convenience, we write a simple script
telegram.sh
 #!/bin/bash name=$1 #_ text=$2 # path=/usr/src/tg ${path}/bin/telegram-cli -k ${path}/tg-server.pub -U root -W -e "msg $name $text" exit 0 

We will definitely give him the right to perform
 chmod +x telegram.sh 

and try to run it from the console. Note that the message is likely to contain spaces, so you need to put it in quotes:
 ./telegram.sh _ "  " 

Of course, before connecting an account to a console telegram, it is advisable to add all user contacts from a mobile or desktop application.
The matter remains for small: to call our script from dialplan. This is done easily:
 exten => 333,n,Set(name=_) exten => 333,n,System(/home/asterisk/telegram.sh ${name} "   ${CALLERID(num)}") 

Something like this will look like on the phone
image
It makes sense to call the script even before forming the Dial: the mobile phone can be busy, disconnected, and the person can simply not hear the call, and information about it will immediately come to the telegram.
Of course, if the lists of redirection mobile phones are already stored in the database, it makes sense to keep the names of the telegram contacts there too.
So, in less than an hour we are able to send the number of the caller to the mobile phone directly from the Asterisk dialplan, and of course, we can transmit any additional information through this encrypted communication channel.
Text writer: Asterisk specialist from centos-admin.ru Alexey Dmitriev

')

Source: https://habr.com/ru/post/303490/


All Articles