Pass calls from SIP trunk through a certain context

In my current config I have two contexts for calls to my phones. Each one basically decides which ringing cadence will play when a call is received. I want to know if it is possible to do what I have here:

I have these contexts…

[call-extension-external] and [call-extension-internal]

Each of those contains a few unrelated things and then the SIPAddHeader command that chooses the ringing cadence.

I am trying to use this in the actual extensions/phones context:

exten => 102,1,GotoIf($["${CHANNEL}" = "SIP/12345678"]?ext:int)
same => n(ext),Goto(call-extension-external,${EXTEN},1)
same => n(int),Goto(call-extension-internal,${EXTEN},1)

“SIP/12345678” is just an example name for the sip trunk. It appears the CHANNEL variable picks up the name of the channel, but I want to know if there’s any way I can match the name, and based on whether or not it matches, it’s either going to do the external context, or the internal.

I’m also sure there’s probably a better way of doing this…I just don’t know it. :confused:

Would appreciate any advice. Thanks!

Try testing to see if ${CHANNEL(peername)} = the peer you have defined for your trunk in sip.conf

1 Like

Okay I tried this:

GotoIf($[$"{CHANNEL(peername)}" = “SIP/trunkname”]?ext:int)

It seems to be skipping the part of matching the channel and peername to what I’ve defined as “SIP/trunkname”

Asterisk is also complaining about “non-numeric arguments” when I’m running this.
I’m guessing something is off with my syntax.

Your peer won’t be SIP/trunknameit’ll just be ‘trunkname’

Try doing a NoOP(Peer is ${CHANNEL(peername)}) before the GotoIf and see what is output.

You could also do a Dumpchan() to see all the info on the channel.

1 Like

I just got it actually before you posted that.

Ended up with: GotoIf($[${CHANNEL(peername)}=trunkname]?ext:int)

And it works! Thanks for your help!

1 Like

The expected way of doing this is by using context= in the sip.conf definition of the device corresponding to the “trunk”.

I have that configured as being in the “incoming” context, but not sure how to use that in extensions.conf to control my ringing cadences.

Either directly add the header from that context, or set a variable that is then tested later. Either include it in a subroutine you use for the details of each extension, match all extensions and do it, then goto another context that actually calls the extensions. The only disadvantage in matching all is that you may not reject invalid numbers as early as might otherwise be the case.