Inbound Routes patten matching issue

I am working on a PBX system in Italy and having issues matching an inbound call to an extension due to the way the sip provider is sending the call.

Looking at the output of asterisk -rvvvv I see this:
– Executing [+3907751437197;trunk-context=3907751437197.ims.vf.it;[email protected]:1] Set(“PJSIP/vodafone_pjsip_1-0000007b”, “__FROM_DID=+3907751437197;trunk-context=3907751437197.ims.vf.it;tgrp=tg3907751437197”) in new stack

My inbound route DID is set to 07751437197 but because my sip provider is formatting the call in from the trunk as
+3907751437197;trunk-context=3907751437197.ims.vf.it;[email protected]:1 - the pbx does not know where to send the call and says “the number you have dialled is not in service”

I need to edit the way the call comes in from the trunk so it is formatted as: [email protected]:1

Can anyone help me with where I would need to configure the incoming call to strip anything except the last bit [email protected]:1 so that it matches my inbound route (DID: 07751437197 --> EXT:1234)

Thanks

You can try setting your trunk context to from-pstn-toheader in case your provider puts the DID in the SIP To: header. Otherwise you will need to create your own context in extensions_custom.conf to process the string into a proper DID.

1 Like

Thanks for the quick reply.
Setting the context to from-pstn-toheader still fails with the below verbose output

Connected to Asterisk 13.22.0 currently running on IT-FE-PBX-1 (pid = 2750)
== Setting global variable ‘SIPDOMAIN’ to ‘3907751437197.corporate.vodafone.it’
– Executing [+3907751437197;trunk-context=3907751437197.ims.vf.it;[email protected]:1] NoOp(“PJSIP/vodafone_pjsip_1-0000007e”, “Attempting to extract DID from SIP To header”) in new stack
– Executing [+3907751437197;trunk-context=3907751437197.ims.vf.it;[email protected]:2] GotoIf(“PJSIP/vodafone_pjsip_1-0000007e”, “0?SIP”) in new stack
– Executing [+3907751437197;trunk-context=3907751437197.ims.vf.it;[email protected]:3] GotoIf(“PJSIP/vodafone_pjsip_1-0000007e”, “1?PJSIP”) in new stack
– Goto (from-pstn-toheader,+3907751437197;trunk-context=3907751437197.ims.vf.it;tgrp=tg3907751437197,7)
– Executing [+3907751437197;trunk-context=3907751437197.ims.vf.it;[email protected]:7] Goto(“PJSIP/vodafone_pjsip_1-0000007e”, “from-pstn,+3907751437197,1”) in new stack
– Goto (from-pstn,+3907751437197,1)
– Executing [[email protected]:1] Set(“PJSIP/vodafone_pjsip_1-0000007e”, “__FROM_DID=+3907751437197”) in new stack
– Executing [[email protected]:2] NoOp(“PJSIP/vodafone_pjsip_1-0000007e”, “Received an unknown call with DID set to +3907751437197”) in new stack
– Executing [[email protected]:3] Goto(“PJSIP/vodafone_pjsip_1-0000007e”, “s,a2”) in new stack
– Goto (from-pstn,s,2)
– Executing [[email protected]:2] Answer(“PJSIP/vodafone_pjsip_1-0000007e”, “”) in new stack
> 0x7f52987be760 – Strict RTP learning after remote address set to: 192.168.100.3:19814
> 0x7f52987be760 – Strict RTP learning after remote address set to: 192.168.100.3:19814
[2018-12-19 12:48:45] WARNING[28879][C-0000004b]: chan_sip.c:22996 func_header_read: This function can only be used on SIP channels.
– Executing [[email protected]:3] Log(“PJSIP/vodafone_pjsip_1-0000007e”, "WARNING,Friendly Scanner from ") in new stack
[2018-12-19 12:48:45] WARNING[28879][C-0000004b]: Ext. s:3 @ from-pstn: Friendly Scanner from
– Executing [[email protected]:4] Wait(“PJSIP/vodafone_pjsip_1-0000007e”, “2”) in new stack
> 0x7f52987be760 – Strict RTP switching to RTP target address 192.168.100.3:19814 as source
– Executing [[email protected]:5] Playback(“PJSIP/vodafone_pjsip_1-0000007e”, “ss-noservice”) in new stack
– <PJSIP/vodafone_pjsip_1-0000007e> Playing ‘ss-noservice.slin16’ (language ‘en’)
> 0x7f52987be760 – Strict RTP learning complete - Locking on source address 192.168.100.3:19814
– Executing [[email protected]:6] SayAlpha(“PJSIP/vodafone_pjsip_1-0000007e”, “+3907751437197”) in new stack
– <PJSIP/vodafone_pjsip_1-0000007e> Playing ‘letters/plus.slin16’ (language ‘en’)
– <PJSIP/vodafone_pjsip_1-0000007e> Playing ‘digits/3.slin16’ (language ‘en’)
– <PJSIP/vodafone_pjsip_1-0000007e> Playing ‘digits/9.slin16’ (language ‘en’)
– <PJSIP/vodafone_pjsip_1-0000007e> Playing ‘digits/0.slin16’ (language ‘en’)
– <PJSIP/vodafone_pjsip_1-0000007e> Playing ‘digits/7.slin16’ (language ‘en’)
– <PJSIP/vodafone_pjsip_1-0000007e> Playing ‘digits/7.slin16’ (language ‘en’)
– <PJSIP/vodafone_pjsip_1-0000007e> Playing ‘digits/5.slin16’ (language ‘en’)
– <PJSIP/vodafone_pjsip_1-0000007e> Playing ‘digits/1.slin16’ (language ‘en’)
– <PJSIP/vodafone_pjsip_1-0000007e> Playing ‘digits/4.slin16’ (language ‘en’)
– <PJSIP/vodafone_pjsip_1-0000007e> Playing ‘digits/3.slin16’ (language ‘en’)
– <PJSIP/vodafone_pjsip_1-0000007e> Playing ‘digits/7.slin16’ (language ‘en’)
– <PJSIP/vodafone_pjsip_1-0000007e> Playing ‘digits/1.slin16’ (language ‘en’)
– <PJSIP/vodafone_pjsip_1-0000007e> Playing ‘digits/9.slin16’ (language ‘en’)
– <PJSIP/vodafone_pjsip_1-0000007e> Playing ‘digits/7.slin16’ (language ‘en’)
– Executing [[email protected]:7] Hangup(“PJSIP/vodafone_pjsip_1-0000007e”, “”) in new stack
== Spawn extension (from-pstn, s, 7) exited non-zero on ‘PJSIP/vodafone_pjsip_1-0000007e’
– Executing [[email protected]:1] Macro(“PJSIP/vodafone_pjsip_1-0000007e”, “hangupcall,”) in new stack
– Executing [[email protected]:1] GotoIf(“PJSIP/vodafone_pjsip_1-0000007e”, “1?theend”) in new stack
– Goto (macro-hangupcall,s,3)
– Executing [[email protected]:3] ExecIf(“PJSIP/vodafone_pjsip_1-0000007e”, “0?Set(CDR(recordingfile)=)”) in new stack
– Executing [[email protected]:4] NoOp(“PJSIP/vodafone_pjsip_1-0000007e”, " monior file= ") in new stack
– Executing [[email protected]:5] AGI(“PJSIP/vodafone_pjsip_1-0000007e”, “attendedtransfer-rec-restart.php,”) in new stack
– Launched AGI Script /var/lib/asterisk/agi-bin/attendedtransfer-rec-restart.php
– <PJSIP/vodafone_pjsip_1-0000007e>AGI Script attendedtransfer-rec-restart.php completed, returning 0
– Executing [[email protected]:6] Hangup(“PJSIP/vodafone_pjsip_1-0000007e”, “”) in new stack
== Spawn extension (macro-hangupcall, s, 6) exited non-zero on ‘PJSIP/vodafone_pjsip_1-0000007e’ in macro ‘hangupcall’
== Spawn extension (from-pstn, h, 1) exited non-zero on ‘PJSIP/vodafone_pjsip_1-0000007e’

Can you please help me creating the context?
Is it possible to pass regular expression commands to strip out the text or will it have to be in the format as per below:

;-------------------------------------------------------------------------------
; from-pstn-to-did:
;
; The context is designed for providers who send the DID in the TO: SIP header
; only. The format of this header is:
;
; To: sip:[email protected]
;
; So the DID must be extracted between the sip: and the @, which this does
;
[from-pstn-toheader]
exten => _.,1,NoOp(Attempting to extract DID from 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,${CUT(CUT(SIP_HEADER(To),@,1),:,2)},1)
exten => _.,n(PJSIP),Goto(from-pstn,${CUT(CUT(PJSIP_HEADER(read,To),@,1),:,2)},1)
;-------------------------------------------------------------------------------

The from-pstn-toheader context got you most of the way to your goal. At present the DID is normal, but has a leading +39, which you need to include in your DID match string on your inbound routes. Otherwise, you will need to copy the context to extensions_custom.conf, rename it to something unique and modify it to strip the leading +39.

1 Like

Thanks! Adding the leading +39 in the inbound routes worked.
When the number is dialled in country (without the +39 this works) and when dialled with the +39 it also works!

Thanks very much for all your help!

1 Like

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