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:
<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:
- Read the file using a “Read / Write to File” component.
- 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
- 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.
- 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:
- Add an “Execute C# File” component under the “readXML” component, and rename it to “analyzeXML”.
- Create a new text file “TextFileValidator.cs” to include in the project, using this C# code:
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;
}
}
- 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:
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.:
100002,222222 100003,333333 100004,444444 100005,555555
To do this:
- We can extend the previously created C# class by adding a new method “ValidateCSV”, using this code:
{ 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 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
- Learn more about CFD components.
- Automated Telephone Ordering Voice app with CRM integration via the 3CX API.
- Sending emails from a CFD voice app.
- Routing Calls Based on the Time of Day.
- Using the Authentication Component to Validate Customers.
- Using the Credit Card Component.
- Text to Speech with the 3CX Call Flow Designer.
- Using the Loop component to navigate upwards
- Registering and making callbacks
- Using the survey component
- Using the CRM Lookup component
- See how to integrate your PBX with a CRM via the 3CX API.
Last Updated
This document was last updated on 29th April 2021
https://www.3cx.com/docs/cfd-creating-phone-support-portal-3/