Creating a Phone Support Portal with the 3CX Call Flow Designer – Part 2
On this topic
In the previous article of this series Creating a Phone Support Portal with 3CX Call Flow Designer – Part 1, we explained how to create the application callflow, to validate whether a customer has a support contract, and then transfer the call to the appropriate department. We have left the validation using different data sources for subsequent articles.
In this article we will show how to perform the validation using a web service.
How to invoke the web service
The 3CX Call Flow Designer includes the “HTTP Requests” and “Web Services (POST)” components out of the box, which both allow invoking web services. The “Web Services (POST)” component is a simplification of the “HTTP Requests” component, which sets the HTTP method to POST, and creates the URL concatenating the provided URL and the web service name, so for example if the URL is “http://www.example.com” and the web service name is “MyWebMethod”, then the HTTP POST request will be sent to “http://www.example.com/MyWebMethod”.
For the purpose of this article, we’ll use the “HTTP Requests” component, which is more flexible for modern REST web services which require other HTTP methods than POST.
Open the user component created in the previous article to perform the customer validation (ValidateData), drag an “HTTP Requests” component from the toolbox and drop it into the design surface. Rename the component to “validateDataWS” and configure the URL, the request type, the content type and the content data to send. Add headers to the request if needed. In this case, we’ll send the data as “application/x-www-form-urlencoded”, and therefore we’ll use the following expression to create the data to send:
The configuration dialog looks like this:
Then we need to set the HTTP request result to the output property “ValidationResult”. Assuming that the web service returns the value 1 when the validation is successful, and 0 when it’s not, we can use an “Assign a Variable” component to set the result to the variable “callflow$.ValidationResult” using the following expression:
The resulting diagram will look like this:
Analyzing web service response
In this case we simplified our scenario, and defined that the web service returns a number “1” or “0” depending on the validation result. This is usually not the case, and the response in most common cases is XML or JSON. In that case the response needs to be parsed, and to do that it’s necessary to use a “Launch External Script” component. Using this component we can execute C# code, and use the XML classes from .NET core to parse XML, or the Newtonsoft library to parse JSON.
In this article we have shown how to invoke a web service to validate the data entered by the customer. The next articles in the series will show how to perform this validation through the following external data sources:
- XML File
- CSV Text File
- SQL Server Database
The third part of the series Creating a Phone Support Portal with the 3CX Call Flow Designer – Part 3 shows how to perform the validation using XML and CSV text files.