TryLearn More

Use SIP trunks, WebRTC & Apps

Slash your Phone Bill by 80%

Creating a Phone Support Portal with the 3CX Call Flow Designer – Part 3

On this topic

Creating a Phone Support Portal with the 3CX Call Flow Designer – Part 3

Performing the validation using an XML file

Reading the contents of the file

Analyzing the contents of the file

Setting the validation result

Performing the validation using a CSV text file

Conclusion

Introduction

In the previous articles Creating a Phone Support Portal with the 3CX Call Flow Designer – Part 1 and Part 2, we explained how to create an application to validate whether a customer has a support contract, and then transfer the call to the appropriate department.

In the first part we have shown how to create the application call flow, while in the second part we focused on how to validate the information using a web service.

In this article we will show how to perform the validation using the information available in text files:

  • XML File
  • CSV Text File

Let’s start!

Performing the validation using an XML file

Let’s suppose that we have an XML file with the following contents:

<customers>
 <customer id="100001" pin="111111"/>
 <customer id="100002" pin="222222"/>
 <customer id="100003" pin="333333"/>
 <customer id="100004" pin="444444"/>
 <customer id="100005" pin="555555"/>
</customers>

We will use that file to validate our customers. We need to do this in two steps:

  1. First we need to read the file. To do this we will use a Read / Write to File component.
  2. Then we need to analyze if the customer ID and PIN are in this file. To do this we need to execute a piece of C# code using a Launch External Script component.

Reading the contents of the file

Add a Read / Write to File component, dragging it from the toolbox to the designer, into the component ValidateData created in the Part 1 of this series. Rename this component to readXML, and configure it as follows:

Analyzing the contents of the file

Now that the file has been read, we need to analyze its content. To do this, we’ll use a Launch External Script component. Add this component below the readXML component, and rename it to analyzeXML.

It’s time to create the C# file to include in the project. Create a new text file TextFileValidator.cs, and add the following code inside:

using System.Xml;

namespace TextFileValidator
{
 public class Validator
 {
   public bool ValidateXML(string fileContent, string id, string pin)
   {
     XmlDocument xmlDocument = new XmlDocument();
     xmlDocument.LoadXml(fileContent);

     XmlNodeList customerElementList = xmlDocument.GetElementsByTagName("customer");
     foreach (XmlNode xmlNode in customerElementList)
     {
       string customerID = xmlNode.Attributes["id"].Value;
       string customerPIN = xmlNode.Attributes["pin"].Value;

       if (id == customerID && pin == customerPIN)
         return true;
     }

     return false;
   }
 }
}
 

Now configure the Launch External Script component as follows:

Setting the validation result

Now that our C# code has done the job, we just need to assign the validation result to the output property ValidationResult. To do this, we’ll use an Assign a Variable component to set the result to the variable callflow$.ValidationResult using the following expression:

analyzeXML.ReturnValue

The component will look like in the following screenshot:

Performing the validation using a CSV text file

Other possible file format to use is CSV (Comma Separated Values). Let’s suppose that the file has the format “ID,PIN”, for example:

100001,111111

100002,222222

100003,333333

100004,444444

100005,555555

We can extend the previous C# class by adding a method “ValidateCSV”. The code for this new method could be:

public bool ValidateCSV(string fileContent, string id, string pin)

{

  foreach (string line in fileContent.Split('\n'))

  {

    string[] lineParts = line.Trim().Split(',');

    if (lineParts.Length == 2)

    {

      string customerID = lineParts[0];

      string customerPIN = lineParts[1];

      if (id == customerID && pin == customerPIN)

        return true;

    }

  }

  return false;

}

Then we just need to invoke this new method from the Launch External Script component, in the same way we did for XML File.

Conclusion

In this article we explained how to validate the data entered by the customer using an XML file and a CSV text file, using C# code and calling this code from a Launch External Script component. The next article in this series will show how to perform this validation through the following external data sources:

  • SQL Server Database

The fourth and final part of the series Creating a Phone Support Portal with the 3CX Call Flow Designer – Part 4  shows how to perform the validation using the information available in a database.

Free for up to 1 year! Select preferred deployment:

On-Premise

for Linux on a $200 appliance or as a VM

Get the ISO

On-Premise

for Windows as a VM

Download the setup file

On the cloud

In your Google, Amazon, Azure account

Take the PBX Express