PBX applications on the Communigate Pro server. We analyze the simplest example - an application for recording a contact phone number of a client



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

As an example, we will write a program for recording a contact phone number of a client.

The program will have to:
  1. Play the start menu with a selection of specialists by last name.
  2. During working hours, the specialist’s phone rings and the “We will call you back” program is activated during non-working hours.
  3. We offer to enter a contact phone. After entering, we send a letter to the user whom the client called.



For a complete understanding of the material in this article, you must have an idea of ​​the main server interfaces - WebAdmin, WebUser and Pronto. You can familiarize yourself with them and the installation process of the free version in this article.

First, a little theory.

Signals


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

To determine the addressees in all these protocols, AOR (address of registration) is used, which corresponds in format to the email address, therefore, 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 that allows you to change the recipients - routing table, forwarders, user rules for incoming signals.

Launching Programs. CG / PL Language


CommunigatePro can run 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 in an environment / environment - a set of files from CG / PL programs, auxiliary files (eg audio) and folders to support various languages.

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

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

User pbx


This user is designed to operate 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 got into 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 pbx#pbx@domain.com is called , auto-secretary is started, and when pbx#conference@domain.com is called, it works conference center.

In addition, the user pbx has an alias 200, which is an extension. Designed for calls from "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, in this case pbx] -> Real-Time-> Advanced page . Let's see how this page looks by default:



The program algorithm is as follows:

  1. plays welcome.wav and dialknownextension.wav
  2. plays for [name] .wav for each item [name] from the department menu. Each department is assigned a number according to the order of listing. At the same time, numbers from Directory Prefix are skipped (they are reserved for extensions) and if the word operator is in the list , then this item is always played last and the number 0 corresponds to it.
  3. After selecting a department, the call is sent to the account with a name that matches the name of the department.


We configure it so that the following message is played at startup:
Hello, this is the company Specialists, for specialist Ivanov, press 1 for specialist Petrov, press 3 or wait for the secretary to answer.
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 language of the user interfaces 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 is displayed. The word “parent” to the left of the file name means that the file is taken from a server-wide environment.
Scroll to the bottom of the interface and create a subfolder for the Russian language:


Write 4 files and load them into the just created Russian folder.

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

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



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

We set reception hours for specialists


We want the calls to be sent to a PBX program with a specific name, outside the working time for the specialist, for example, callback (which asks the user for a contact phone 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, 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 always forward calls when setting up, we’ll set Divert Call temporarily - > When: always, To: #callback .

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

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

Writing a CG / PL program



The program performs 3 sets of actions:
  1. Losing the introduction:
    “At the moment, the specialist cannot pick up the phone. (callbackbusy.wav)
    If you want, we can call you back soon. (callbacklater.wav)
    Dial your contact number and press the bar, (callbacknumber.wav)
    in case of an error, press the asterisk and redial the number »(callbackclearnumber.wav)
  2. Reads the phone.
  3. We form an email and end the conversation.
    “Your phone number has been recorded, our staff will contact you shortly” (we create a callbacktrailer.wav file)
    If we didn’t receive the letter, 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 uploaded to [Domain] -> PBX, and all .wav files are placed in the “russian” language subfolder on the same page. It is convenient to download a large number of files with one .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 intentionally demonstrated only the 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, calendars or IM, send them in a personal email, try to demonstrate how to accomplish this task using CGPro .

Also popular now: