Dismiss Notice
We would like to remind you that we’re updating our login process for all 3CX forums whereby you will be able to login with the same credentials you use for the Partner or Customer Portal. Click here to read more.

How to get started writing C# code for 3CX Call flow designer CFD

Discussion in 'Call Flow Designer' started by SECOIT GmbH, Jul 7, 2017.

Thread Status:
Not open for further replies.
  1. SECOIT GmbH

    Apr 3, 2017
    Likes Received:
    Getting started with C# for CFD might cause some headaches especially when someone’s not writing a lot programs. This means quite some effort with correcting syntax errors. Time to make it easier. :)
    There is a useful feature within Microsoft’s IDEs which is called IntelliSense that helps by underlining errors during the creation of the code (like a spell checker in Word) and also helps with auto completion suggestions.

    There are a lot great tools out there but many of them will require loads of configuration and sometimes a bunch of gigabytes of files to be installed on the PC so I was looking for an easier/lightweight way to write code for CFD but at the same time using the help of IntelliSense.

    If you are not interested in IntelliSense don’t continue reading! You’ll waste your time. :)
    You can use any text editor to create your C# code for CFD. The manual below is only a help for coding with that kind of “spell checker”.

    Disclaimer: Anything described here might change or might not run on all Versions of Windows. The examples here are done on a Windows 7 x64 PC but should work similar on other Windows OS. And there might be a lot easier ways of getting started that I’m not aware of. So don’t blame me if you wasted your time.
    Also… If something of it is breaking your PC – I’m not responsible!

    How to get started writing C# code for 3CX Call flow designer CFD:

    1. Install .NET via “Turn Windows features on or off” and via Windows Update

    2. Download and Install Call Flow Designer (CFD) from 3CX (http://downloads.3cx.com/downloads/3CXCallFlowDesigner.exe)

    3. Download “3CX API Documentation Package for 3CX V15 from 3CX” http://downloads.3cx.com/downloads/misc/callcontrolapi/3CXCallControlAPI_v15.zip
    (you’ll require the “3CXObjectModel.” file within the .ZIP package which gives an overview of classes/methods/properties available)

    4. Download Visual Studio Code from https://code.visualstudio.com
    VS Code is a lightweight yet powerful code editing software.

    Install VS Code, select the additional following two options to make opening files a bit easier (I personally prefer it this way at least).


    5. Download and install .NET Core SDK:

    Download and install .NET 4.6.1 SDK:

    6. Download the .ZIP package which is attached to this forum entry. This contains the necessary files and settings to get started. Extract it into a folder somewhere on your PC.
    (the included “Project1.csproj” is mainly copied from 3CX’s OMSamples in 3CXCallControlAPI_v15.zip)

    Double-click the Project1.csproj file

    7. This will start VS Code and it will recommend you to install the C# extension.
    So hit the button “Show Recommendation” and it will show you two extensions but you only need C# so go ahead and install it.



    After installing it will show a blue “Reload” button. Please hit that button.
    (btw. we are nearly done)

    8. Last step will be installing some C# dependencies which will run automatically.
    a) Click on the file explorer
    b) Expand Libraries
    c) Double-click Project1.cs
    This will install the dependencies.


    If you have made it this far – congratulations!

    Now we actually get started coding. If you have never done object oriented programming you will need to find some (online) training to get started. So you’ll require basic knowledge from here.

    Now you got a working code editor with IntelliSense. That means it helps you with auto-complete, error check, etc. This will make your life writing C# code for CFD a lot easier.


    The program that you see is a very simple program that actually does what the name says:
    It Adjusts Call Queue parameters.
    The function requires three values and doesn’t return a value:
    public void SetQueueParams(string strQueueNumber, bool bPosAnnounce, ushort usTimeout)
    is the extension number of the Call Queue you want to adjust
    bPosAnnounce is to enable or disable the queue position announcement
    usTimeout is the call queue timeout

    The classes you will find in the CHM file that I mentioned earlier.

    So make sure there is nothing red underlined and let’s use it in a CFD project.
    If you haven’t so far: Go ahead and read the Administrator Manual (https://www.3cx.com/docs/manual) chapters 26 - 33.

    ... to be continued ...

    Attached Files:

    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
    LtFrankDrebin and jed like this.
  2. SECOIT GmbH

    Apr 3, 2017
    Likes Received:
    For this demonstration I want to achieve a modification of a call queue (ext. 801) based on the time of the day.
    From 00:00 till 11:59 I want to announce the position to the caller and have a 5:00 Min timeout.
    From 12:00 till 23:59 I don’t want to announce the position and have a 2:00 Min timeout.

    The following steps explain how to use your C# code in CFD but it will not cover any basics so make sure you read the Admin Manual before (see link above).

    1. Open CFD and start a new project:


    2. Put your components on the right position, in this case it’s a condition for time of day, the C# code and a transfer of the call to the queue:


    3. When you created your new CFD project it automatically created a Libraries subfolder within the project folder:


    4. Place your C# file(s) there (in our example it is Project1.cs) and give it a reasonable name. I called it QueueAdjust.cs.
    Open your “Launch External Script” component and you’ll find the C# file.


    5. Fill in the other required values and populate the variables (remember? I mentioned them earlier…)


    6. Let’s do the same for the time after 12:00 hrs.
    Now we don’t announce the position (“false”) and want a 2 Minute timeout (“120” seconds)


    7. You shouldn’t see any red exclamation marks anymore so go ahead and build your voice app


    8. This should give you a success message and when you click “Yes” you’ll see your finished voice app that you can upload to your 3CX PBX



    You can find the full C# example project for 3CX CFD here: https://www.secoit.de/files/3cx/AdjCallQueue.zip
    (Simply double-click the .cfdproj file after extracting)

    That’s it from my side.

    Happy coding!
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
    #2 SECOIT GmbH, Jul 7, 2017
    Last edited: Jul 8, 2017
    XanthiZ and jed like this.
  3. edossantos

    edossantos Support Team
    Staff Member 3CX Support

    Jun 27, 2007
    Likes Received:
    Hi Michael,

    Thanks for sharing! This is very valuable information! Hope many users find it useful!

    Kind regards.
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  4. jed

    jed New Member

    Feb 1, 2010
    Likes Received:
    Hi Michael

    Thank you for your time it is just GREAT WORK :)

    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
    XanthiZ likes this.
  5. SECOIT GmbH

    Apr 3, 2017
    Likes Received:
    Hi Jesper,

    You are welcome!
    This is in fact a slightly modified version of a manual that I wrote for one of my customers anyway. They are using 3CX but the German 3CX gold partner where they bought it from either isn't able to help or doesn't want to share knowledge so they asked me.

    I was interested in 3CX anyway so my customer's questions were a good point to get started with it and do some intense testing.
    And since 3CX is sharing basically all documentation and even video training free of charge (not typical for a PBX manufacturer) I thought I could give something back.
    So... Glad to help!

    Best Regards,
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
    XanthiZ and jed like this.
Thread Status:
Not open for further replies.