Create Inbound Route for specific TrunkID?

I have some details for setting up an Inbound SIP Trunk from Twilio… The details have been added to my sip_custom.conf file as I couldn’t see how to add them through the FreePBX Gui.

The Trunk works… when I dial my Twilio number the call is routed to my PBX but my PBX doesn’t know what to do with the call after that. I get 'call from twilio to extension ‘xxxx’ is rejected because the extension is not found in the context ‘fromtwilio’. The context is set in sip_custom.conf so I know where that is but…

How is the Trunk ‘context’ linked to an Inbound Route? As far as I can see it isn’t…Inbound Routes look like they rely on DID from the inbound call???

Can I create an Inbound Route based on the ‘context’ rather than DID as my provider doesn’t supply DID?


Can I set the ‘Trunk’ to pass all calls received through it directly to a specific extension? If so, how? I’m guessing this will have to go into sip_custom.conf as well???

I’ve read the wiki and umpteen pages of stuff on google and nothing covers these basic concepts so all help is much appreciated.


OK… for those of you wanting to do this but not yet figured it out…this is how I did it…

modify the following file by…:

nano extensions_custom.conf

Add in…


6001 is the inbound extension, 1234 is where the call is diverted.

Make sure that, in the Twilio admin page, you specify the Twilio number to go to extension 6001 (or change the value for your inbound extension.

What would be really helpful though is if someone can explain how I set this up using the FreePBX Gui as I’d rather all my settings were in there.


The extension number of an inbound trunk call is called the “DID Number” field in the GUI inbound routes. Unless I misunderstand what you are trying to do, using 6001 as a DID number will route the call correctly.

the ‘context’ is important though…

The Inbound Trunk assigns a context of ‘fromtwilio’ to the inbound call.
I need to define a link between ‘fromtwilio’ AND ‘6001’ so I would need to specify 6001 as the DID but…which field do I add ‘fromtwilio’ to in order to define the context?

Quite right. Inbound routes will handle calls in contexts named “from-trunk” and “from-pstn” and a handful of other reserved names.

…but I need extension 6001 to be in a ‘context’ of it’s own. I’m not really sure where to create that in FreePBX.

The Asterisk config is nice and simple…it defines context, inbound extension and Permanent Call forward, all in 2 lines…


I’m struggling to figure out how to do the call forwarding without setting up a SIP client for the extension, dialling it and using a ‘feature code’ to set it. I would have thought there would be a simple… ‘preset call forward’ option against the extension itself (like in most other PBX systems.)

Is the context of your trunk “fromtwilio” ?

yep. the trunk is defined in the SIP_CUSTOM.conf file.

Just can’t figure out how, in FreePBX, to link the context and a specific extension number.

You can’t do that in the GUI. It is done in the context that’s why twilio needs it’s own custom context because it works in a non-standard, call it custom, fashion. Make a ringgroup numbered 6001 and put 1234 in it.


cool. thanks for that. now I know it’s not possible in the Gui I’ll stop trying. :smile:

I don’t suppose you’re familiar at all with setting up elastic trunks between Twilio and FreePBX? I’ve got inbound working by using a twiml statement against my twilio number but am banging my head against the wall a bit trying to get outbound to work…


Glad things are working for you. I guess I don’t really understand why you have defined your trunk context as “fromtwilio”. My suggestion was meant to indicate that if you use the reserved context “from-trunk” for your custom defined trunk, that incoming calls will be handled normally like any other inbound call.

I’m a bit of a noob to be honest…
I’m following a guide by Matthew Jenkinson…
In that he says to add the following to sip.conf… as it’s freepbx I added to sip_custom.conf instead…

context = fromtwilio
type = peer


It’s this that sets the context, as well as allowing inbound calls from multiple IP address sources. I could have named the context differently but thought it would be best keeping it different from the inbuilt contexts that FreePBX uses.

I suppose I could have created a Trunk in FreePBX to do this but I wasn’t sure where to add the multiple incoming IP addresses???

Thanks for replying though…if there’s a better way to do it I would love to know.



What @Igaetz is saying if all the calls being sent from Twilio come to 6001 then use from-trunk as your context and as I say add a RG numbered 6001 to redirect where you want your calls to go.

Thanks for that. I gave it a try…

I renamed the context in Sip_Custom.conf to be from-trunk instead fromtwilio.
I removed my entries in Extensions_Custom.conf
I added a RingGroup called 6001 and redirected it to extension 1234.

When I dial in from my Twilio number I now get…

[2015-05-15 08:36:27] VERBOSE[3328][C-0000000c] pbx.c: Executing [[email protected]:8] Set(“SIP/twilioip-2-00000001”, “__CALLINGPRES_SV=allowed_not_screened”) in new stack
[2015-05-15 08:36:27] VERBOSE[3328][C-0000000c] pbx.c: Executing [[email protected]:9] Set(“SIP/twilioip-2-00000001”, “CALLERPRES()=allowed_not_screened”) in new stack
[2015-05-15 08:36:27] VERBOSE[3328][C-0000000c] pbx.c: Executing [[email protected]:10] Goto(“SIP/twilioip-2-00000001”, “from-did-direct,6001,1”) in new stack
[2015-05-15 08:36:27] VERBOSE[3328][C-0000000c] pbx.c: Goto (from-did-direct,6001,1)
08:36:27] WARNING[3328][C-0000000c] pbx.c: Channel
’SIP/twilioip-2-00000001’ sent to invalid extension but no invalid
handler: context,exten,priority=from-did-direct,6001,1

I’m guessing this recognises that a RingGroup is not an Extension and fails???