📜 ⬆️ ⬇️

Working with databases in the 3CX Call Flow Designer development environment

Introduction


In this article we will explain how to query SQL Server database from 3CX Call Flow Designer using Database Access. Note that the Database Access component can also work with the PostgreSQL database, which is used by 3CX Phone System.

The demo project of this voice application comes with the 3CX CFD distribution and is located in the Documents \ 3CX Call Flow Designer Demos folder. If you want to use it - just specify the location of your database and access credentials.

Our voice application will request the user PIN (it can be a client number, insurance policy, etc.), checks it in the database and transfers it to the specified extension number (it can be a service employee, a voice menu prepared in advance or another voice application ) if pin is found.
')

Project creation


To create a CFD project, go to File → New → Project , specify the folder where the project is located and its name, for example, DatabaseAccessDemo .



Request PIN from user


User PIN is requested using the User Input component. Add the component to the voice application:




Validation of the entered PIN in the database


After receiving the PIN from the user, it should be checked in the database. To do this, add the Database Access component to the branch of the Valid Input component, assuming the correct input. Rename the component to validatePIN and double click on it to set the properties:


Now enter the query string to the database. Use the small button to the right of the input box to insert the value of the id variable . Our line has the form:

  SELECT count (*) FROM customers WHERE id = {0} 

The properties of the Database Access component should look like this:



Checking the result of an SQL query and choosing further actions


After configuring the Database Access component, we proceed to the PIN verification. To do this, add the Create a Condition component with two conditions (branches) - successful and unsuccessful validation.

Drag the component from the left side and rename it to validateDatabaseResult . Rename the branch to success and error . The development environment window should look like this:



In order for the success branch to be executed, the database request must return 1, which means that a client with such a PIN code was found (one record was found). To do this manually or using the expression constructor, we introduce a conditional operator:

  EQUAL (validatePIN.ScalarResult, 1) 

image

After you have specified the conditions for the success branch, add the Prompt Playback components for all possible voice application branches: PIN found, PIN not found, and the PIN is not entered correctly the allowed number of times (we have User Retract Max Retry Count = 3 ). In the parameters of the components, specify the appropriate WAV notification file.

After that, add the Transfer component to the success branch, which will transfer the call to the employee. The voice application will look something like this:



Compiling and installing the application on the 3CX server


Voice application is ready! Now it should be compiled and uploaded to the 3CX server. For this:




You can check the operation of the application by calling the Queue extension number and entering the PIN for verification. If it is found in the database, the call will be transferred to the operator.

Downloads and Documentation


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


All Articles