Dynamic inbound-to-outbound routing to a different SIP trunk (V20)

aman-pandey

Trial User
Joined
Aug 21, 2026
Messages
3
Reaction score
0
Hi team,

I'm using Telnyx's API to originate calls into our 3CX (V20, self-hosted). I need these inbound calls to route back out through a different SIP trunk to a phone number that's different each time — not a fixed number.

I've tried using %DialedNum% and %CalledNum% in an Inbound Rule and in a trunk's Default Route ("Forward to Outside Number"), but both get treated as literal text instead of the actual dialed number, and the call fails. Is there a supported way to do this, or do I need to use DISA or a Call Processing Script instead?
 
Can you explain what the aim is in a bit more detail? Are the Outgoing numbers matched 1-to-1 with the Incoming (per-extension forwarding), or do they change over time (CFD or some other automation)?
 
Thanks for looking into this.

To clarify: it's neither. The outgoing number isn't tied 1-to-1 to any extension, and it's not a schedule/time-based change either — it's decided dynamically, per call, by our own backend application before the call is even placed.

Here's the actual flow: our backend calls Telnyx's API to originate a call, specifying a destination number that varies every single time (different number per call, chosen by our application logic). That call lands on 3CX. We then need 3CX to take that same destination number and dial it back out through a different SIP trunk (Twilio in our case).

So essentially: 3CX needs to read "who was this call actually for" from the inbound leg, and re-dial that same number outbound through a specific trunk — with the number being different on every call, not following any fixed pattern or schedule.

Is there a way to access the inbound call's destination number as a true runtime variable (not a static field), either via CFD or another mechanism?
 
And what exactly is the purpose of this?

It looks like a sequence intended to make calls using spoofed Caller IDs, which raises some concerns.

I can help you with this, but could you first explain the purpose of this setup and what you’re trying to achieve? I simply want to make sure I’m not assisting with or enabling any fraudulent use of the system.

Please provide us with a bit more context.
 
Completely understandable, happy to explain.

This is for a technology demonstration/proof-of-concept, not caller ID spoofing. We're a company building on Telnyx's platform, and we're working with Telnyx directly (their MENA/APAC sales and engineering team) to demonstrate a specific capability: Telnyx's Voice API originating a call, routing it through our 3CX PBX, and terminating it via a third-party carrier — with the correct, legitimate CLI (our own verified business number) passed through the whole chain.

The reason we need the destination number to be dynamic rather than fixed: this is meant to prove the routing mechanism works for any destination, not just one hardcoded test number. In our actual production use case, this pattern will be used for a UAE-specific setup where local regulations require call termination through a licensed local carrier rather than Telnyx directly — Twilio is just standing in as a generic third-party trunk for this POC, to prove the architecture before we connect the real local carrier.

The caller ID used throughout is our own legitimate business number (not spoofed) — the concern is purely about correctly routing calls to arbitrary destinations, not disguising who's calling.

Happy to share more context on the business use case if useful, or loop in Telnyx's team directly if that helps confirm this.
 
So, it’s actually fairly simple, but I’m a bit concerned about the security of your setup now.

If the trunk configuration in 3CX does not properly validate the source of incoming calls, you could be exposed to toll fraud. For example, if someone sends a SIP INVITE to:

number_of_my_choice@public_ip_of_the_pbx

and 3CX automatically routes that call out through another trunk, they could potentially place calls to arbitrary destinations without ever using the Telnyx API.

In any case, please be aware that this type of configuration can be very risky. Make sure the setup is properly locked down and that only SIP traffic originating from Telnyx IP addresses is accepted for this routing scenario.

Otherwise, if calls coming from any source, rather than only from Telnyx, can be forwarded to another trunk such as Twilio, you could very quickly become a victim of fraudulent outbound calls.

I’ve attached a Call Script that does exactly what you’re trying to achieve.

That said, this creates a significant security risk and could leave your system wide open to toll fraud, but ultimately, that decision is yours.

Configure and force the Caller ID on the SIP Trunk.
Add the Call Script and point the default route to it. https://www.3cx.com/docs/sip-trunk-inbound-calls/#h.vestk0owj1of
Then, create an outbound rule based on the number of digits in the destination number and route those calls through the second trunk.

That’s it.


Guillaume Bourgeois
 

Attachments

Forum statistics

Threads
111,876
Messages
589,517
Members
164,726
Latest member
ChapplePM