3CX checking DIDs with call script or CFD custom MOH

zahir sirag

Titanium Partner
Joined
May 20, 2025
Messages
10
Reaction score
10
Hello,
I need to create a script similar to https://www.3cx.com/blog/call-flow-scripts/call-routing-did
The issue I’m facing is the following: when I check the number and transfer the call to the extension, no audio is played until the extension answers.

Instead, I would like the file USProgresstone.wav to be played during this phase.
I tried replacing the code RouteToAsync(...) with ReplaceWithAsync(...), but in that case, onhold.wav is played, which is not correct.


The desired behavior is:
  • USProgresstone.wav should be played when the call comes from outside and the extension has not yet answered.
  • onhold.wav should only be played when a direct call to an extension is actually put on hold.
I cannot manage this logic through queues, extensions with time checks, or departments because the customer has more than 2000 DIDs. The requirement is:
  • If the call comes from outside and it’s during office hours, it should be transferred directly to the extension.
  • If it’s outside office hours, it should go through an IVR.
  • Internal calls must always be available.
In short, I need to replicate the Inbound Rules function from version V18.
 
Ok, you are doing it wrong.

Is the IVR the same for every DID?

If so, you only need to interact with the call outside of hours. Inside, it should just follow the DIDs routes, which should be going to their regular destinations.

Then, you use a call script in passive mode (Upon receiving a call on trunk) to only reroute outside of hours. See the Holiday.cs script for examples.
 
The issue I’m facing is the following: when I check the number and transfer the call to the extension, no audio is played until the extension answers.
If the call script is set up to trigger on incoming DID (Run this script - When this DID is called), then this behavior is to be expected.

We use such call scripts exclusively in conjunction with binding to the SIP trunk (Run this script - Upon receiving a call on a trunk). In this case, the call only starts when it is answered somewhere in the 3CX system. Until then, the caller will hear the ringtone from the provider. There is generally no need for the script to answer the call. If I were you, I would change it like this.

Regardless of that, the question was
Instead, I would like the file ... to be played during this phase.
how to play arbitrary audio as MOH (Music on Hold) when transferring a call in this call script - even when the call script is triggered by an incoming DID.

Replace the corresponding part of inbounddidrouting.cs with the following example:
C#:
if (has_valid_destination)
{
    PhoneSystem ps = MyCall.PS as PhoneSystem;
    var result = await MyCall.AssureMedia().ContinueWith(
        x =>
        {
            MyCall.SetBackgroundAudio(true, new string[] { ps.GetParameterValue("IVRDIALINGTONE") });
            return MyCall.RouteToAsync(destination_struct);
        }, TaskContinuationOptions.OnlyOnRanToCompletion).Unwrap();
    //we are here when forwarding is successful, so we set returned value to true and put log message to CallFlow service log
    MyCall.Info($"{DIDNumber} has been redirected to {route} ({result}");
    return true;
}
I think you can adjust the rest as you wish yourself.


Ok, you are doing it wrong.
*like :)
 
Last edited:
Thank you so much @fxbastler, it's, everything is working as it should now with this piece of code
 

Forum statistics

Threads
111,972
Messages
590,064
Members
164,886
Latest member
784