Testing, Debugging & Migrating Apps Βuilt with 3CX CFD

Introduction

The 3CX Call Flow Designer is a powerful tool for creating voice applications quickly and easily, without the need to have great programming or telephony skills. These applications are deployed on the 3CX Phone System server, implemented as Call Flow Apps. Through the management interface it is possible to define the conditions for which each of these applications is activated, e.g. for a specific inbound rule.

While creating these applications using the CFD is significantly easier than doing it programmatically, you can always make mistakes. In these cases it is necessary to correctly diagnose the problem to resolve it.

Building your CFD Project

When your CFD project is ready, you need to build it:

  1. Go to “Build” > “Build All” or press
    Ctrl + B
    .
  2. If needed, assign an extension number to the project, otherwise leave the Extension field empty.
  3. CFD creates a “Release” folder in the CFD Project “Output” folder, containing a ZIP archive with a manifest file, a C# script and project WAV files, ready for upload to 3CX.
  4. Upload the generated ZIP archive to 3CX and the 3CX Call Flow Server compiles your script.
  5. A green icon indicates a succesful compilation and the CFD app is ready for use. Otherwise, click to open the app to check for any compilation error(s).

Fixing Project Compilation Errors

These are examples of the various possible compilation errors that may occur:

An Error Occurs when the CFD Tries to Create the C# Script

This may happen for example if some component is not properly configured, a component property has not been set, etc.

For example, using a “Transfer” component without the “Destination” property set, we get an error.

Error message in Error List panel in 3CX CFD

When building this project the error message appears in the “Error List” panel. Double-click on the error to show the designer with the problematic component selected.

An Error Occurs Compiling the C# Script

After successfully building your CFD app, on upload to 3CX a compilation error may occur, due to various reasons like errors in component configured expressions or missing references.

Fixing Errors in the C# scripts provided

One of the most common errors is providing C# code that causes errors. For example, when using an Execute C# Code component with the following configuration:

Execute C# Code component in 3CX CFD

When this project is built from the CFD, no error is detected, as the C# code is not being compiled yet. However, when the generated ZIP is uploaded to the 3CX Management Console, this error occurs:

Voice application C# code error in 3CX Management Console

As you can see, in this case the errors shown are the errors reported by the C# compiler. These errors provide a good hint for what needs to be adjusted to get the app working.

Fixing Errors Caused by Nested Namespaces

When using the “Execute C# File” component, if your script has a namespace declaration, the resulting script is not compiled by 3CX. For example, if we include the following script in our project via an “Execute C# File” component:

namespace MyNamespace

{

  public class MyClass

  {

    public int DoSomething(int a, int b)

    {

      return a + b;

    }

  }

}

When we upload the project to 3CX, an

Invalid Script Structure
error occurs. This error is easily fixed by removing the namespace declaration, leaving our C# script as follows:

public class MyClass

  {

    public int DoSomething(int a, int b)

    {

      return a + b;

    }

  }

Fixing Errors Caused by Missing References

When you use an Execute C# Script of Execute C# Code component, you provide the C# code to execute. This C# code may need external DLL references, not included in the 3CX server. In this case, when 3CX builds your CFD app scripts, you see an error like “Error CS0246: The type or namespace name 'YourCustomLibrary' could not be found (are you missing a using directive or an assembly reference?)”.

The 3CX Call Flow Server includes ONLY these reference assemblies when compiling a CFD script:

  • mscorlib
  • System
  • System.Core
  • System.Runtime
  • System.Collections
  • System.Core
  • System.IO
  • System.IO.FileSystem
  • System.Runtime
  • System.Collections
  • Microsoft.CSharp
  • netstandard
  • System.Linq
  • System.Linq.Expressions
  • System.Linq.Parallel
  • System.Linq.Queryable
  • System.Net.Http
  • Newtonsoft.Json
  • System.Xml
  • System.Xml.Linq
  • System.Xml.ReaderWriter
  • System.Xml.Serialization
  • System.Xml.XDocument
  • System.Xml.XmlDocument
  • System.Xml.XmlSerializer
  • System.Xml.XPath
  • System.Xml.XPath.XDocument
  • System.Xml.XPath.XmlDocument
  • System.Xml.XDocument
  • System.Private.Xml
  • System.Private.Xml.Linq
  • System.Private.Uri
  • 3cxpscomcpp2
  • MailKit
  • MimeKit
  • MySqlConnector
  • Npgsql
  • System.ComponentModel
  • System.ComponentModel.Primitives
  • System.Data
  • System.Data.Common
  • System.Data.SqlClient
  • System.Net.Primitives
  • System.Net.Sockets
  • System.Security.Cryptography.Algorithms
  • System.Security.Cryptography.Primitives
  • System.Text.RegularExpressions
  • TcxMail
  • System.Threading
  • System.Threading.Timer
  • System.Threading.Tasks
  • System.Threading.Tasks.Dataflow
  • AWSSDK.Core
  • AWSSDK.Polly
  • CallFlow.CFD

You can use any class from those assemblies in your C# code. Unfortunately, additional libraries cannot be included as compilation references. If you need to use other third-party DLLs, you need to create a separate program to use those DLLs, and connect to this program by different means, e.g. using a web service interface.

Fixing Project Runtime Errors

Once you have built your project with the CFD, uploaded it to 3CX with successful script compilation, the voice app is ready to be used.

If the app is not doing what it is designed to do, you need to check the logs to investigate the app’s operation. Call Flow Apps write log messages to the “3CXCallFlow.log” file:

  • on Windows in: “C:\ProgramData\3CX\Instance1\Data\Logs”
  • on Linux in: “/var/lib/3cxpbx/Instance1/Data/Logs”

Designer view with Launch External Script component

Our example is based on a very simple application with the above callflow, playing a file “Hello.wav”, then tries to execute some C# code which throws an exception, and finally transfers the call to the operator. The transfer fails due to the error in the “Execute C# File” component. Deploying this app to 3CX and then calling it, we notice these log entries:

  1. 2019/04/04 16:59:07.306|26728|0009|Trc|CallPair._mytestapp.Main_59.Main.915.[C:23.2]-From script: MyTestApp - CallID 00000C011AA560F5_23 - Callflow - Start executing main flow...
  2. 2019/04/04 16:59:07.321|26728|0013|Trc|CallPair._mytestapp.Main_59.Main.915.[C:23.2]-From script: MyTestApp - CallID 00000C011AA560F5_23 - Callflow - Start executing component 'playHello'
  3. 2019/04/04 16:59:07.322|26728|0013|Trc|CallPair._mytestapp.Main_59.Main.915.[C:23.2]-From script: MyTestApp - CallID 00000C011AA560F5_23 - PromptQueue - Start playing file: C:\ProgramData\3CX\Instance1\Data\Ivr\Prompts\Callflows\mytestapp\Hello.wav
  4. 2019/04/04 16:59:07.323|26728|0013|Trc|CallPair._mytestapp.Main_59.Main.915.[C:23.2]-C:\ProgramData\3CX\Instance1\Data\Ivr\Prompts\Callflows\mytestapp\Hello.wav
  5. 2019/04/04 16:59:11.600|26728|0003|Trc|CallPair._mytestapp.Main_59.Main.915.[C:23.2]-From script: MyTestApp - CallID 00000C011AA560F5_23 - Callflow - OnPromptPlayed for component 'playHello'
  6. 2019/04/04 16:59:11.601|26728|0003|Trc|CallPair._mytestapp.Main_59.Main.915.[C:23.2]-From script: MyTestApp - CallID 00000C011AA560F5_23 - CallFlow.CFD.PromptPlaybackComponent 'playHello' - No more files to play, moving to the next component...
  7. 2019/04/04 16:59:11.601|26728|0003|Trc|CallPair._mytestapp.Main_59.Main.915.[C:23.2]-From script: MyTestApp - CallID 00000C011AA560F5_23 - Callflow - Start executing component 'executeSomeCode'
  8. 2019/04/04 16:59:11.603|26728|0003|Trc|CallPair._mytestapp.Main_59.Main.915.[C:23.2]-From script: MyTestApp - CallID 00000C011AA560F5_23 - _mytestapp.Main_59.Main+executeSomeCodeExternalCodeExecutionComponent 'executeSomeCode' - Start executing external script
  9. 2019/04/04 16:59:11.833|26728|0003|Err|CallPair._mytestapp.Main_59.Main.915.[C:23.2]-From script: MyTestApp - CallID 00000C011AA560F5_23 - Callflow - Error executing last component: System.Exception: This is an exception thrown from my code

at _mytestapp.Main_59.Main.MyClass.DoSomething()

at _mytestapp.Main_59.Main.executeSomeCodeExternalCodeExecutionComponent.ExecuteCode()

at CallFlow.CFD.ExternalCodeExecutionComponent.ExecuteStart()

at CallFlow.CFD.ExternalCodeExecutionComponent.Start(TimerManager timerManager, Dictionary`2 variableMap, TempWavFileManager tempWavFileManager, PromptQueue promptQueue)

at _mytestapp.Main_59.Main.ProcessStart()

  1. 2019/04/04 16:59:11.836|26728|0003|Trc|CallPair._mytestapp.Main_59.Main.915.[C:23.2]-From script: MyTestApp - CallID 00000C011AA560F5_23 - Callflow - Start executing error handler flow...
  2. 2019/04/04 16:59:11.836|26728|0003|Trc|CallPair._mytestapp.Main_59.Main.915.[C:23.2]-From script: MyTestApp - CallID 00000C011AA560F5_23 - Callflow - Start executing component 'errorHandlerAutoAddedFinalDisconnectCall'
  3. 2019/04/04 16:59:11.837|26728|0003|Trc|CallPair._mytestapp.Main_59.Main.915.[C:23.2]-From script: MyTestApp - CallID 00000C011AA560F5_23 - CallFlow.CFD.DisconnectCallComponent 'errorHandlerAutoAddedFinalDisconnectCall' - No more files to play, disconnecting call...
  4. 2019/04/04 16:59:11.964|26728|0009|Trc|CallPair._mytestapp.Main_59.Main.915.[C:23.2]-From script: Main - Switching executing mode from Active to Wrapup
  5. 2019/04/04 16:59:11.971|26728|0003|Trc|CallPair._mytestapp.Main_59.Main.915.[C:23.2]-From script: MyTestApp - CallID 00000C011AA560F5_23 - Callflow - OnCallTerminated for component 'errorHandlerAutoAddedFinalDisconnectCall'
  6. 2019/04/04 16:59:11.971|26728|0003|Trc|CallPair._mytestapp.Main_59.Main.915.[C:23.2]-From script: MyTestApp - CallID 00000C011AA560F5_23 - CallFlow.CFD.DisconnectCallComponent 'errorHandlerAutoAddedFinalDisconnectCall' - Processing OnCallTerminated
  7. 2019/04/04 16:59:11.971|26728|0003|Trc|CallPair._mytestapp.Main_59.Main.915.[C:23.2]-From script: MyTestApp - CallID 00000C011AA560F5_23 - Callflow - Start executing disconnect handler flow…

Note that:

  1. Every log line from a CFD app starts with “From script: ProjectName”, in our case “From script: MyTestApp”, as highlighted in bold on line 1.
  2. The “CallID” is shown on each line, identifying which log line belongs to each call.
  3. On line 2, we see that the component “playHello” is being executed.
  4. On line 7, we see that the component “executeSomeCode” is being executed.
  5. On line 9, we see that an error occurs while executing component “executeSomeCode”.
  6. On line 10, we see that the error handler flow is executed, but as it is empty, no user component is executed.

In this example application the error occurs when trying to execute the component “executeSomeCode”, so we need to check what that component is doing.

See Αlso

Last Updated

This document was last updated on 25th May 2023

https://www.3cx.com/docs/manual/cfd-troubleshooting/