FreePBX | Register | Issues | Wiki | Portal | Support

[Solved] Pattern matching on DID / rewriting DIDs in Inbound routes


(Thomas Herrmann) #1

On my SIP-Trunk, 99% of the inbound calls send the DID in E.164 format (e.g., +4912349876), but very few send 012349876 (from other parts of germany) or even 9876 (from our own town).

I already have one inbound route per extension, the only solution that I currently see are 3 different inbound routes for each extension.

Or is there a pattern matching, that matches +4912349876, 012349876 and 9876?

Or is it possible to change the DIDs before they enter the inbound routing?

Regards
Thomas


(Lorne Gaetz) #2

I see two possibilities:

  1. It’s possible the To: header on inbound invites has more consistently formatted DID strings in which case you can set the trunk context to from-pstn-toheader and filter calls that way.

  2. Otherwise you want to pre-process inbound invites with a block of custom dialplan that will adjust DID for more consistency. You can get the basic framework from this post, but I’m sure there are posts here that more accurately match what you’re trying to accomplish.


(Thomas Herrmann) #3

Good point, but I am already using context=from-pstn-toheader, because otherwise I don’t geht the dialled extensions at all.

I will look into this.


(Thomas Herrmann) #4

This is what I tried, and it seems to work (cannot really test all possibilities, though):

I set context=from-pstn-toheader-telekom in my incoming trunk configuration, and added this to extensions_custom.conf:

[from-pstn-toheader-telekom]
exten =>  _.,1,NoOp(Attempting to extract DID from Telekom SIP To header)
exten =>  _.,n,gotoif($["${CHANNEL(channeltype)}"="SIP"]?SIP)
exten =>  _.,n,gotoif($["${CHANNEL(channeltype)}"="PJSIP"]?PJSIP)
exten =>  _.,n,NoOp(Unable to determine SIP channel type)
exten =>  _.,n,goto(from-pstn,${EXTEN},1))
exten =>  _.,n(SIP),Goto(from-pstn-toheader-sip,${CUT(CUT(SIP_HEADER(To),@,1),:,2)},1)
exten =>  _.,n(PJSIP),Goto(from-pstn,${CUT(CUT(PJSIP_HEADER(read,To),@,1),:,2)},1)

[from-pstn-toheader-sip]
exten =>  _00Z.,1,NoOp(Replace 00 to + in Telekom SIP To header)
exten =>  _00Z.,n,Goto(from-pstn,+${EXTEN:2},1)
exten =>  _0Z.,1,NoOp(Replace 0 to +49 in Telekom SIP To header)
exten =>  _0Z.,n,Goto(from-pstn,+49${EXTEN:1},1)
exten =>  _Z.,1,NoOp(Replace X to +496251X in Telekom SIP To header)
exten =>  _Z.,n,Goto(from-pstn,+496251${EXTEN},1)
exten =>  _.,1,NoOp(Replace in Telekom SIP To header fallthrough)
exten =>  _.,n,Goto(from-pstn,${EXTEN},1)

Do you see any major flaws in this?


(Lorne Gaetz) #5

Looks okay to me assuming you are not using it for any pjsip trunks.


(Thomas Herrmann) #6

My internal devices are all pjsip, the external trunk is sip. So I should be fine.

Thanks for your help!

This whole “programming by jumping through contexts” is relatively new to me, but I am getting used to it…


(system) closed #7

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.