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

Introduction

The previous guides Creating a Phone Support Portal with the 3CX Call Flow Designer – Part 1 and Part 2, described how to create an application to validate a customer’s support contract info, and then transfer the call to the appropriate department.

Part 1 described how to create the application call flow, while in the Part 2 focused on how to validate the information using a web service.

This guide describes how to validate using information available in text files:

  • XML Text File
  • CSV Text File

💡 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”.

Validating Using an XML file

Our example is based on an XML file with these 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>

To use this file for validating our customers, we need to:

  1. Read the file using a Read / Write to File component.
  2. Verify that the customer ID and PIN are contained in this file, by using an Execute C# File” component to execute a piece of C# code.

Reading the File Contents

  1. Add a Read / Write to File component, dragging it from the toolbox to the designer, into the component ValidateData created in Part 1 of this series.

Read / Write to File component configuration in 3CX CFD

  1. Rename this component to readXML, and configure it as in the example above.

Note: The “File Name” property needs to be adjusted to the file location on the 3CX Server.

Analyzing the File Contents

After reading the file, we need to analyze its contents:

  1. Add an “Execute C# File” component under the “readXML” component, and rename it to analyzeXML”.
  2. Create a new text file TextFileValidator.cs” to include in the project, using this C# code:

using System.Xml;

 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;
   }
 }

Execute C# File component configuration in 3CX CFD

  1. Configure the Execute C# File component as in the above example.

Setting the Validation Result

After our C# code analyzed the file contents, we need to assign the validation result to the output property ValidationResult”. To do this, we use an Assign a Variable” component to set the result to the variable callflow$.ValidationResult” using this expression:

analyzeXML.ReturnValue

 Example flow and component configuration in 3CX CFD

Consider the above example flow and component configuration.

Validating Using a CSV File

Alternatively, you can validate using a CSV (Comma Separated Values) file containing “ID,PIN” value pairs, e.g.:

100001,111111

100002,222222

100003,333333

100004,444444

100005,555555

To do this:

  1. We can extend the previously created C# class by adding a new method “ValidateCSV”, using this code:

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;

}

  1. Then we need to invoke this new method from the Execute C# File” component, in the same way described for the XML File.

Conclusion

This guide presented how to validate the data entered by the customer, using an XML or a CSV text file, and an Execute C# File” component to execute C# code. The fourth and final part of the series Creating a Phone Support Portal with the 3CX Call Flow Designer – Part 4  describes how to validate using an SQL database.

See Also

Last Updated

This document was last updated on 29th April 2021

https://www.3cx.com/docs/cfd-creating-phone-support-portal-3/