Using the Survey component

Introduction

The Survey component lets a CFD app ask questions to the caller, and automatically store the user’s feedback to a CSV file. However, storing the information in a CSV file in the 3CX server is not always the best approach, and we need to send the information somewhere else, for example a database or a web service. In this demo we will show how to create an application with the 3CX Call Flow Designer to accomplish this.

💡 Tip: The project for this example application is available via the CFD Demos GitHub page, and is installed along with the 3CX Call Flow Designer in your Windows user documents folder, i.e. “C:\Users\YourUsername\Documents\3CX Call Flow Designer Demos”.

In this demo we will use the Survey component to ask 3 questions to the caller:

  1. Have we resolved the issue you called about? For yes press 1, for no press 2.
  2. How would you rate the attention received? Please use a number from 1 to 5, where 1 is bad and 5 is excellent.
  3. Please leave your comments as a recorded message, and press # to finish the recording.

Then we will send this information to a database for further processing.

Step 1: Create the Project

First, we need to create a new project. Open the CFD and go to “File” > “New” > “Callflow Project”, select the folder where you want to save it, and enter a name for the project, e.g. SurveyDemo.

Step 2: Add the Survey component

Let’s add a Survey component and configure the options we need:

  1. Drag a “Survey” component from the toolbox, and drop it into the design surface of the “Main” callflow. Then select the component added, go to the “Properties Window” and rename it to “CustomerFeedback”.

Adding the Survey component

  1. Double-click on the “Survey” component to configure these properties:
  • Recordings Path: specify a folder in your 3CX server to store the customers’ recordings.
  • Export to CSV File: specify the name of a CSV file in which the component will store the results.
  • “Introductory Prompts” - configure an Audio File Prompt to play a WAV file with a welcome message, e.g. “Welcome to this survey demo app”.
  • “Goodbye Prompts” - configure an Audio File Prompt to play a WAV file when the survey ends, e.g. “Thanks for your feedback, have a nice day.”.
  • “Timeout Prompts” - configure an Audio File Prompt to play a WAV file that explains that no digit was detected, e.g. “Sorry, we didn’t receive any digit”.
  • “Invalid Digit Prompts” - configure an Audio File Prompt to play a WAV file that explains that the digit entered is invalid, e.g. “Sorry, the selected option is not valid”.
  • Configure 3 questions:
  1. A Yes/No question, with Tag set to “solved”, and the following prompt: “Have we resolved the issue you called about? For yes press 1, for no press 2.”
  2. A Range question, with Tag set to “rating”, and the following prompt: “How would you rate the attention received? Please use a number from 1 to 5, where 1 is bad and 5 is excellent.”
  3. A Recording question, with Tag set to “comments”, and the following prompt: “Please leave your comments as a recorded message, and press # to finish the recording.”. Set this question to offer playing it back to the caller, and configure the Pre Recording Prompt to a message saying “This is your recording.”, and Post Recording Prompt to a message saying “To keep it press 2, to discard it and record another message press 2”.
  • Add the caller’s number as an additional output field, so it’s included in the generated CSV file. To do this, set the name to
    caller
    and the value to the variable
    session.ani
    .
  1. Press “OK” to save the changes.

Step 3: Use a C# script to get the value for each answer

The Survey component automatically adds users’ responses to the CSV file. However, in this case we want to send this information to a database. To do this, we have the

Result
property, which will contain the configured “Output Fields” and also the responses provided by the user, in a comma separated list of values. For example, these could be some lines from the generated CSV file:

1234567890,YES,5,/surveydemo/recordings/SurveyRecording_20210420130306_1157558616.wav

1234567891,NO,3,/surveydemo/recordings/SurveyRecording_20210420130525_1157558617.wav

Then, the

Result
property will have a single line from that file (caller number, solved response, rating response and recording path). In order to split the
Result
in each value, we will do the following:

  1. We will use a very simple C# script to extract the first value (solved response). The script is the following:

return surveyResult.Split(',')[1];

Execute C# Code - GetSolvedResponse

  1. We repeat the procedure for the other two values:
  1. For the rating response we use the code:
    return surveyResult.Split(',')[2];
  2. For the recording we use the code:
    return surveyResult.Split(',')[3];
  1. So far, the callflow will look like the following:

Callflow Example

Step 4: Store the values in a database

Now that we have each value splitted from the original

Result
property, we can use them in an SQL statement to add the information to a database. Proceed as follows:

  1. Drag a Database Access component from the toolbox to the designer, just under the last Execute C# Code component added in the previous step. Rename the component to “AddResultToDatabase”.
  2. Double click the component to open the configuration dialog. Configure the component as follows:
  • Database Type: select your database type (the supported databases are Microsoft SQL Server, MySQL and PostgreSQL).
  • Server: use the Expression Editor to create an expression that returns the database server IP address or server name. This could be a constant string or you can use for example a variable to store the information.
  • Port: specify the port number to which the database connection should be established.
  • Database: specify the name of the database to which you want to connect.
  • User Name: specify the username to use to connect to the database.
  • Password: specify the password to use to connect to the database.
  • Statement Type: we will use NonQuery in this case, because we want to execute a statement that will not return any data.
  • Timeout: leave the default value of 30 seconds, or specify a reasonable value to wait for the statement execution.
  • SQL Statement: here we will build the SQL statement using the Expression Editor, so we can concatenate static text and variables. The expression we will use is the following:

CONCATENATE("INSERT INTO survey_results\r\n(caller, solved, rating, recording)\r\nVALUES ('",session.ani,"', '",GetSolvedResponse.ReturnValue,"', '",GetRatingResponse.ReturnValue,"', '",GetRecordingResponse.ReturnValue,"')")

Expression Editor

  1. Press “OK” to save the changes.

Step 5: Build and Deploy to 3CX Phone System

The project is ready to build and upload to our 3CX Phone System server, with these steps:

  1. Select “Build” > “Build All” and the CFD generates the file “SurveyDemo.zip”.
  2. Go to the “3CX Management Console” > “Advanced” > “Call Flow Apps” > “Add/Update”, and upload the ZIP file generated by the CFD in the previous step.
  3. The Call Flow app is ready to use. Make a call to the application, answer the questions and check your answers in the database.

See Also

Last Updated
This document was last updated on 29th April 2021
https://www.3cx.com/docs/cfd-survey-component/