Call processing script

zahir sirag

Titanium Partner
Joined
May 20, 2025
Messages
10
Reaction score
10
Hi, I need to know how I can forward or divert a call to an external number through a call processing script.

Code:
destination = "Extension."+"605"+"."; // it's work normally as it should i need same function for external calls

var has_valid_destination = DestinationStruct.TryParse(
                        destination,
                        out var destination_struct
                    );
                    if (has_valid_destination)
                    {
                        var result = await MyCall
                            .AssureMedia()
                            .ContinueWith(
                                x =>
                                {
                                    MyCall.SetBackgroundAudio(
                                        true,
                                        new string[]
                                        {
                                            "/var/lib/3cxpbx/Instance1/Data/Ivr/Prompts/USProgresstone.wav",
                                        }
                                    );
                                    return MyCall.RouteToAsync(destination_struct);
                                },
                                TaskContinuationOptions.OnlyOnRanToCompletion
                            )
                            .Unwrap();
                        return true;
                    }
 
  • Like
Reactions: Evolute IT
I need to know how I can forward or divert a call to an external number through a call processing script.

a possible solution:
C#:
string external = "+49308888888";
int timeout = 30;
var result = await MyCall
    .AssureMedia()
    .ContinueWith(
        x =>
        {
            MyCall.SetBackgroundAudio(
                true,
                new string[]
                {
                    "/var/lib/3cxpbx/Instance1/Data/Ivr/Prompts/USProgresstone.wav",
                }
            );
            return MyCall.RouteTo(external, "", timeout);
        },
        TaskContinuationOptions.OnlyOnRanToCompletion
    )
    .Unwrap();
return true;

edit:
3CX Call Control API v20 documentation: Callflow / Interface: ICall / Method: RouteTo(String, String, Int32)
 
Last edited:
  • Like
Reactions: Martin Behrens
Hi, I figured out how to make external calls — it’s simpler than I thought.
I followed the code provided here: https://www.3cx.com/blog/call-flow-scripts/call-routing-did/
However, the guide only shows how to forward calls to extensions using strings like "Extension.100." or to voicemail using "VoiceMail.."
I thought that for external calls there would be a similar string format, for example: "External.333444222."

Here’s my code

Code:
if (MyCall.Caller.DN is ExternalLine externalLine && MyCall.IsInbound){
                string Number = "3338899933";
                    var result = await MyCall
                        .AssureMedia()
                        .ContinueWith(x =>{
                                MyCall.SetBackgroundAudio(true, new string[]{"/var/lib/3cxpbx/Instance1/Data/Ivr/Prompts/Empty.wav",});
                                return MyCall.ReplaceWithAsync(Number);
                            },
                            TaskContinuationOptions.OnlyOnRanToCompletion
                    )
                    .Unwrap();
                return true;
            }
 

Latest Posts

Forum statistics

Threads
111,953
Messages
589,915
Members
164,850
Latest member
masvty