📜 ⬆️ ⬇️

PBX applications on the Communigate Pro server. We analyze the simplest example - an application for recording customer contact phone



The main advantage of CommunigatePro over other systems is a single server language for all modules - calls, mail, calendars. That is, we can take a call in one program, play the voice menu, accept DTMF and form letters, SMS, calendar events based on this DTMF.

As an example, we will write a program for recording the contact phone of the client.
')
The program should:
  1. Play the start menu with a choice of specialists by last name.
  2. During working hours, a specialist phone rings, the program “We will call you back” is switched on.
  3. We offer to enter the contact phone. After input we send the letter to the user whom the client called.



To fully understand the material in this article, you must have an idea of ​​the main server interfaces - WebAdmin, WebUser and Pronto. C them and the installation process of the free version can be found in this article.

First, a little theory.

Signals


In CommunigatePro, this is a server that provides communications in “real time” (hereinafter referred to as real-time) - IM, SMS, voice communication. The signal is an elementary task performed by the server for real-time communications, they are used by all modules providing real-time communications - SIP, XMPP, SMPP, XIMSS to transfer information about the beginning, discontinuity, and change of the connection status.

To determine the recipients in all of these protocols, AOR (address of registration) is used, which in format corresponds to an email address, so on the AOR server for signals it matches the email address and is simply the full name of the account.

As well as for letters for signals, a set of settings is available, allowing you to change destinations - the routing table, forwarders, custom rules for incoming signals.

Running programs. CG / PL language


CommunigatePro can execute programs in the simple and powerful CommuniGate Programming Language (CG / PL). For each module and functionality there is a set of functions built into the language. Two styles are supported:

// // A simple CG/PL application // Basic style // entry Main is myName = "Jim" + " " + "Smith"; if length(myName) > 10 then myName = Substring(myName,0,8) + ".."; end if; end; 


 /* * A simple CG/PL application * C style */ entry Main { myName = "Jim" + " " + "Smith"; if(myName.length() > 10) { myName = myName.substring(0,8) + ".."; } } 


PBX programs are also written in CG / PL and organized into the environment / environment - a set of files from CG / PL programs, auxiliary files (for example, audio) and folders to support various languages.

There is a server-wide PBX environment (the Users-> PBX page in the WebAdmin interface) and domain domains for each domain (Users-> Domains -> [Domain] -> PBX). Moreover, when the PBX program, launched on behalf of a certain account, requests a file from the environment, the search is performed in the beginning in the domain environment, and then in the server environment.

The easiest way to run a CG / PL program is to send a signal to the format address: pbxAppName#account@domain.com , and the server will start the task execution program recorded in the pbxAppName.sppr file (this file must be located either in the PBX environment of the domain.com domain, or in the server environment) on behalf of account account@domain.com (the signal will be transmitted to the newly created task).

Pbx user


This user is intended for the functioning of most PBX programs installed by default on the server.
This user initially already has one real-time rule:



The rule is triggered on any signal that has entered the account and calls the program from the file “pbx.sppr” (PBX center) on behalf of the pbx account. The pbx.sppr program is quite complex and provides different functions depending on how you call it.
Since the start signal is transmitted to the program, we can set different behavior of the program depending on the name / alias of the user who made the call, for example, when calling pbx#pbx@domain.com the auto-secretary is started, and when calling pbx#conference@domain.com it works conference center.

In addition, the user pbx has an alias of 200, which is an extension number. Designed for calls from the "iron" phones.

Auto secretary


Auto-secretary is a program that implements a standard hierarchical menu with a choice. Since it comes bundled with the server, WebAdmin has an interface for interacting with it on the [Account page , in this case pbx] -> Real-Time-> Advanced . Let's see how this page looks by default:



The program algorithm is as follows:

  1. loses welcome.wav and dialknownextension.wav
  2. loses for [name] .wav for each [name] item in the department menu. Each department should be placed in accordance with the number in the order of transfer. In this case, the digits from Directory Prefix are skipped (they are reserved for extensions) and if the list contains the word operator , then this item is always played last and the number 0 corresponds to it.
  3. After selecting a department, the call is sent to an account with the same name as the department.


We will configure it in such a way that the following message will be played at startup:
Hello, this is the company "Specialists", for a specialist Ivanov, press 1 for a specialist Petrov, press 3 or wait for the answer of the secretary.
Since the messages will be in Russian, you need to create a separate folder for the language in the PBX environment of the domain and switch the user interface language pbx, on behalf of which the program is launched, to Russian. On the pbx-> Preferences page, in the “Language” setting, set “Russian”. On the [Domain] -> PBX page, click on the “Create Custom Environment” button to change the PBX environment in the domain:

A list of files forming the PBX environment in the domain was displayed. The word “parent” to the left of the file name means that the file is taken from the server-wide environment.
Scroll to the bottom of the interface and create a subfolder for the Russian language:


We write down 4 files and we load them into the russian folder just created.

welcome.wav // Hello
dialknownextension.wav // you called the company. Specialists dial the short number of the subscriber if you know him.
forivanov.wav // for specialist Ivanov
press.wav // click
0.wav, 1.wav, 3.wav // numbers
forpetrov.wav // for Petrov specialist
tospeakopertator.wav // or wait for the secretary’s response
tryingextension.wav // dial the subscriber
failure.wav // error

For the files for ***. Wav to be played, you need to change the settings [pbx] -> Real-Time-> Advanced to these:



You also need to add to the domain accounts with the names ivanov, pertrov and operator.
For verification, open any account in Pronto and type in Dialer module 200 or pbx.

We set up visiting hours for specialists


We want that outside business hours for a specialist calls are sent to a PBX program with a specific name, for example callback (which asks the user for a contact phone number and promises to call back).

To do this, in all ivanov, petrov and operator accounts, go to the [account] -> Preferences page and set the working hours setting in the Calendars settings group.



Next you need to go to the [account] -> Real-time-> Incomming call Rules section and enable Divert calls -> when: afterhours, To: #callback:



Since it’s more convenient for us to set up calls, we’ll temporarily set Divert Call -> When: always, To: #callback .

If you call the user after these settings, then Pronto will generate an error “Failed to load PBX application code” (when calling through the auto-secretary, failure.wav will be lost).

It is connected with the fact that the callback program does not yet exist in the PBX environment of the domain, we will deal with it in the next paragraph.

Writing CG / PL program



The program performs 3 sets of actions:
  1. Plays the intro:
    “At the moment, a specialist can not pick up the phone. (callbackbusy.wav)
    If you want, we can call you back soon. (Callbacklater.wav)
    Dial your contact phone number and press the grid, (callbacknumber.wav)
    in case of error, press the star and dial the number again ”(callbackclearnumber.wav)
  2. Reads the phone.
  3. We form email and end the conversation.
    “Your phone is recorded, our employees will contact you shortly” (create the file callbacktrailer.wav)
    If the letter could not be sent we warn about it and stop:
    “Error, service is not available, call back later” (failure.wav + callbacknotavailable.wav)


The program can be typed in any text editor, the file is saved in Plain Text format with the name "callback.sppr".
The text of the program is not complicated, about 20 lines, additional explanations in the comments:

 // "entry Main"      CG/PL  entry Main is //   ,     if AcceptCall() != null then stop; end if; //  .wav  PlayFile("CallbackBusy"); PlayFile("CallbackLater"); PlayFile("CallbackNumber"); PlayFile("CallbackClearNumber"); //        accumulator = ""; loop //        DTMF    20  input = ReadInput(20); //     DTMF  ( ReadInput    DTMF)    exitif not IsString(input) or input == "#"; //      ,     "*" if input == "*" then accumulator = "";PlayFile("CallbackClearNumber"); end if; accumulator = accumulator + input; //    end loop; //     -       , : if accumulator == "" then stop; end if; //         if SendEmail("CallbackMailer@"+ MyDomain(),"    :"+ accumulator,MyEmail(),null,"") != null then PlayFile("Failure"); PlayFile("CallbackNotAvailable"); else PlayFile("CallbackTrailer"); end if; end; 


By analogy with the pbx account, on the pages [ivanov and petrov] -> Preferences, “Language” set “Russian”. The callback program is played on behalf of these accounts and the audio files are recorded in Russian.

To complete the installation, callback.sppr is loaded into [Domain] -> PBX, and all .wav files are loaded into the “russian” language subfolder on the same page. It is convenient to load a large number of files with a single .tar archive (the server will unpack it and add files to the environment)

Brief summary

CG / PL programs can be very complex, but in this article we deliberately demonstrated only basic functionality (receiving calls and DMTF + sending text mail).

Our version of the .wav files used in the article can be found on Dropbox , as well as the final callback.sppr .

We plan to write several more articles with more functional examples in the future, so if someone has an interesting case when they had to integrate PBX with mail, cadders or IM, send in PM, we will try to demonstrate how to perform this task using CGPro .

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


All Articles