⬆️ ⬇️

IP PBX Askozia and Push Notifications in Telegram

Some employees of our company work outside the office: visits to customers, work at home. To communicate with such employees, we use a GSM gateway connected to our PBX Askozia. Any call from the client can be forwarded to the employee “in the field”.



In such conditions, an uncomfortable situation arises: an employee, on an incoming call, sees the SIM card number, not the client number. There is no possibility to promptly call back on a missed call.



We decided to use Telegram to notify about calls. The result was an interesting bundle of Askozia + Telegram + 1C: Enterprise software products.



')

How things work



The employee accesses the service via Telegram. By writing a bot, you can subscribe to notifications.

The greeting format is “ I <Phone number> ”:

image



The bot saves the phone number, and from that moment knows to which chat to send alerts.

If someone tries to call or forward the call to the employee’s number, messages come to the chat:

image



Please note information about the caller's name and his phone number is displayed. Submission (name) of the caller can be taken from 1C: CRM, if necessary. In this example, callerid (name) was installed after receiving information from 1C: CRM, an example of the implementation was described by jorikfon in his article (see the section "useful materials").



Additionally, the “ (call back) ” hyperlink is displayed. The hyperlink initiates a callback to the employee’s mobile number. As soon as the call on the mobile is accepted, the set will start dialing the subscriber whose call was previously received.



An interesting and unexpected feature - the call alert comes faster than a mobile call. Dialing through a GSM line is delayed 4-5 seconds. Notification in Telegram comes much faster.



Service installation on IP PBX Askozia



Telegram API, AMI Asterisk, SOAP web services 1C: Enterprise are used. All services implemented in PHP 5.



Connect to PBX via SSH:

#  ,  . mount -o remount,rw /offload; #  ,        . mkdir /offload/rootfs/usr/www_provisioning/telegram/; #  ,    . mkdir /storage/usbdisk1/askoziapbx/astlogs/asterisk/telegram/; 




Connect to PBX via SFTP

Download distribution by reference . Copy scripts from distribution to directory: “ / storage / usbdisk1 / askoziapbx / astlogs / asterisk / telegram / ”

image



We continue to work through SSH

 #       : #     URL "http://HOST:56080/telegram/miko_callback.php" ln -s /storage/usbdisk1/askoziapbx/astlogs/asterisk/telegram/miko_callback.php /offload/rootfs/usr/www_provisioning/telegram/miko_callback.php #  ,         telegram echo >> /storage/usbdisk1/askoziapbx/astlogs/asterisk/telegram/subscription.db #      " ". mount -o remount,ro /offload; 




Define the settings in the settings.json file



Example settings.json
 { "ami_host": "127.0.0.1", "ami_port": 5038, "ami_username": "1cami", "ami_secret": "PASSWORD1cami", "telegram_API_key": "171119210:AAHo-000000000000000000000", "subscription_file": "subscription.db", "dst_context": "SIP-PHONE-0000000000feaad021c", "res_callback": "http://HOST:56080/telegram/miko_callback.php", "local_context": "localchannels" } 








How to get AMI connection parameters
  • ami_host - if the script is run locally, then the address is 127.0.0.1
  • ami_port - default value 5038
  • ami_username is the default admin
  • ami_secret - default askozia




How to get Telegram API key
He should be asked from “ BotFather ”:

Create a new dialogue with the contact “BotFather” in the telegram

  1. Send the command "/ newbot"
  2. In the second step, enter the name of the new bot.
  3. In the third step, enter the "username" of the bot, it should contain the string "bot"


In response, the bot will send a message with the key

Use this token to access the HTTP API:

171119299:AAHo-y2Ps4-ZTblLRHbjBHG5pG-0cpN





Configuring Contexts
  • local_context is the context where internal numbers are defined, and our employees' mobiles, by default “localchannels”
  • dst_context - to get this context, you need to open one of the accounts of the “Phone” type and in the address bar of the browser copy the type identifier " SIP-PROVIDER-196627525951ab38268552a ", this will be the context






Running scripts in cron



It is necessary to open the “integrator console” by clicking “ESC” in the web interface:

image



  1. Click on the " Configuration Files " tab
  2. Select the " crontabs " file
  3. Add a line to run the script as in the image above.


 */5 * * * * /bin/sh /storage/usbdisk1/askoziapbx/astlogs/asterisk/telegram/starter.sh 




Results of implementation



Employees received a useful service for incoming call alerts:





Useful materials



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



All Articles