Any help getting my regex in place to extract the correct DDI on my SIP trunk?

Status
Not open for further replies.
My SIP provider provides incoming destination/DDI information in a weird way. Instead of providing the DID in the DID value it provides the SIP account username. The DDI data is in the SIP To: part of the header. This is the Asterisk code I use to extract the correct DDI and then pass the call on:

[custom-get-did-from-sip]
exten => _.,1,Noop(Getting DID from SIP header)
exten => _.,n,Set(pseudodid=${SIP_HEADER(To)})
exten => _.,n,Set(pseudodid=${CUT(pseudodid,@,1)})
exten => _.,n,Set(pseudodid=${CUT(pseudodid,:,2)})
exten => _.,n,Goto(from-trunk,${pseudodid},1)

Is there a way to manipulate the incoming header to extract this information in FusionPBX? I tried adjusting caller-details in the Dialplan section but it didn't make a difference.
 

KonradSC

Active Member
Mar 10, 2017
166
99
28
uuid_dump the channel or look in the CDR details to see if the DDI is a freeswitch variable. If it's already a FS variable then you can manipulate that variable or set other things like destination equal to that value. That's the easiest place to start.
 
Hey KonradSC, many thanks for the response. I'm ex-Asterisk so please forgive my newbie stumbling.
I've got a log of an entire call coming in here: https://pastebin.com/7Cr6NbBY

From what I can see it's picking up caller_destination incorrectly: [caller_destination]=[5e0107773a]
It should be the same as destination_number which is mentioned in the log:


2019-01-23 07:01:30.571219 [DEBUG] switch_channel.c:1296 EXPORT (export_vars) [call_direction]=[inbound]
Dialplan: sofia/external/07931828049@proxy.voip.co.uk Action set(caller_destination=${destination_number}) INLINE
EXECUTE sofia/external/07931828049@proxy.voip.co.uk set(caller_destination=5e0107773a)
2019-01-23 07:01:30.571219 [DEBUG] mod_dptools.c:1598 SET sofia/external/07931828049@proxy.voip.co.uk [caller_destination]=[5e0107773a]
Dialplan: sofia/external/07931828049@proxy.voip.co.uk Action set(caller_id_name=${caller_id_name}) INLINE
EXECUTE sofia/external/07931828049@proxy.voip.co.uk set(caller_id_name=07931828049)
2019-01-23 07:01:30.571219 [DEBUG] mod_dptools.c:1598 SET sofia/external/07931828049@proxy.voip.co.uk [caller_id_name]=[07931828049]
Dialplan: sofia/external/07931828049@proxy.voip.co.uk Action set(caller_id_number=${caller_id_number}) INLINE
EXECUTE sofia/external/07931828049@proxy.voip.co.uk set(caller_id_number=07931828049)
2019-01-23 07:01:30.571219 [DEBUG] mod_dptools.c:1598 SET sofia/external/07931828049@proxy.voip.co.uk [caller_id_number]=[07931828049]
Dialplan: sofia/external/07931828049@proxy.voip.co.uk parsing [public->02392008648] continue=false
Dialplan: sofia/external/07931828049@proxy.voip.co.uk Regex (FAIL) [02392008648] destination_number(5e0107773a) =~ /^(02392008648)$/ break=on-false
Dialplan: sofia/external/07931828049@proxy.voip.co.uk parsing [public->442392008648] continue=false
Dialplan: sofia/external/07931828049@proxy.voip.co.uk Regex (FAIL) [442392008648] destination_number(5e0107773a) =~ /^(442392008648)$/ break=on-false
Dialplan: sofia/external/07931828049@proxy.voip.co.uk parsing [public->5e0107773a] continue=false
Dialplan: sofia/external/07931828049@proxy.voip.co.uk Regex (PASS) [5e0107773a] destination_number(5e0107773a) =~ /^(5e0107773a)$/ break=on-false
Dialplan: sofia/external/07931828049@proxy.voip.co.uk Action export(call_direction=inbound) INLINE
EXECUTE sofia/external/07931828049@proxy.voip.co.uk export(call_direction=inbound)
 

KonradSC

Active Member
Mar 10, 2017
166
99
28
Look for 442392008648 (I believe that is your DID) in the variables portion of the CDR's. Is it set anywhere? Paste the SIP INVITE too. That would be helpful. You can use sngrep to easily get it.
 
Thank you KonradSC.

sngrep appears to show a correct interaction:
INVITE 07931828049@proxy.voip.co 02392008648@proxy.voip.co 6 193.203.210.29:6060 xx.xx.xx.xx:5080 COMPLETED

But the CDR data shows the To: as 5e0107773a which is the account username:Screen Shot 2019-01-23 at 16.54.17.png

Here's a grep of the freeswitch.log as a call comes in. Clearly the DDI is in there but, as you say, it just needs to be assigned to the correct field.


b88be714-b14d-4d9a-bf22-a6277888f8a5 2019-01-23 12:00:35.431218 [INFO] mod_dialplan_xml.c:637 Processing 07931828049 <07931828049>->5e0107773a in context public
b88be714-b14d-4d9a-bf22-a6277888f8a5 EXECUTE sofia/external/07931828049@proxy.voip.co.uk set(caller_destination=5e0107773a)
b88be714-b14d-4d9a-bf22-a6277888f8a5 2019-01-23 12:00:35.431218 [DEBUG] mod_dptools.c:1598 SET sofia/external/07931828049@proxy.voip.co.uk [caller_destination]=[5e0107773a]
b88be714-b14d-4d9a-bf22-a6277888f8a5 Dialplan: sofia/external/07931828049@proxy.voip.co.uk parsing [public->02392008648] continue=false
b88be714-b14d-4d9a-bf22-a6277888f8a5 Dialplan: sofia/external/07931828049@proxy.voip.co.uk Regex (FAIL) [02392008648] destination_number(5e0107773a) =~ /^(02392008648)$/ break=on-false
b88be714-b14d-4d9a-bf22-a6277888f8a5 Dialplan: sofia/external/07931828049@proxy.voip.co.uk parsing [public->442392008648] continue=false
b88be714-b14d-4d9a-bf22-a6277888f8a5 Dialplan: sofia/external/07931828049@proxy.voip.co.uk Regex (FAIL) [442392008648] destination_number(5e0107773a) =~ /^(442392008648)$/ break=on-false
b88be714-b14d-4d9a-bf22-a6277888f8a5 Dialplan: sofia/external/07931828049@proxy.voip.co.uk parsing [public->5e0107773a] continue=false
b88be714-b14d-4d9a-bf22-a6277888f8a5 Dialplan: sofia/external/07931828049@proxy.voip.co.uk Regex (PASS) [5e0107773a] destination_number(5e0107773a) =~ /^(5e0107773a)$/ break=on-false
b88be714-b14d-4d9a-bf22-a6277888f8a5 Dialplan: sofia/external/07931828049@proxy.voip.co.uk Regex (FAIL) [caller-details] ${caller_destination}(5e0107773a) =~ /^$/ break=never


Would you be prepared to work with me on this to get it sorted at all? How much would you charge for an hour or two of your time?
 

KonradSC

Active Member
Mar 10, 2017
166
99
28
If you click on the CDR it should show a lot more information. Also, can you post the complete SIP INVITE?
 
The complete SIP invite:


INVITE sip:gw+2141c506-de0a-4fd8-9c74-dfd134407499@77.74.195.12:5080;transport=udp;gw=2141c506-de0a-4fd8-9c74-dfd134407499 SIP/2.0

193.203.210.29:6060 77.74.195.12:5080 │Via: SIP/2.0/UDP 193.203.210.29:6060;rport;branch=z9hG4bK-sYn-0-r.nwo.fv-%gy!pwl*uh_vwccn_%aeskm

──────────┬───────── ──────────┬─────────│Max-Forwards: 15

12:29:02.191837 INVITE (SDP) │ │Contact: <sip:uab6e95348@193.203.210.29:6060;transport=udp>

+0.002044 │ ──────────────────────────> │ │From: <sip:07931828049@proxy.voip.co.uk>;tag=3572264730

12:29:02.193881 │ 100 Trying │ │To: <sip:02392008648@proxy.voip.co.uk;user=phone>

+0.035233 │ <────────────────────────── │ │Call-ID: 60911f7e-1f34-11e9-9223-1daf01f298ce

12:29:02.229114 │ 200 OK (SDP) │ │CSeq: 252817480 INVITE

+0.017129 │ <────────────────────────── │ │Supported: from-change

12:29:02.246243 │ ACK │ │Accept: application/sdp

+8.461104 │ ──────────────────────────> │ │Allow: INVITE, ACK, BYE, CANCEL

12:29:10.707347 │ BYE │ │User-Agent: Synergy/1.9.9.5967

+0.012480 │ ──────────────────────────> │ │Content-Type: application/sdp

12:29:10.719827 │ 200 OK │ │Content-Length: 318

│ <────────────────────────── │ │Date: Wed, 23 Jan 2019 17:29:03 GMT

│ │ │

│ │ │v=0

│ │ │o=root 221612266 221612266 IN IP4 10.200.208.11

│ │ │s="V4U SBC v2.0"

│ │ │c=IN IP4 193.203.210.29

│ │ │t=0 0

│ │ │m=audio 16712 RTP/AVP 8 0 18 101

│ │ │a=rtpmap:8 PCMA/8000

│ │ │a=rtpmap:0 PCMU/8000

│ │ │a=rtpmap:18 G729/8000

│ │ │a=fmtp:18 annexb=no

│ │ │a=rtpmap:101 telephone-event/8000

│ │ │a=fmtp:101 0-16

│ │ │a=ptime:20

│ │ │a=maxptime:150

│ │ │a=sendrecv

│ │ │
 

KonradSC

Active Member
Mar 10, 2017
166
99
28
There ya go!

Go to Inbound Routes. Edit caller-details.

Change caller_destination=${destination_number} to caller_destination=${sip_to_user}
 
Hmm. I changed it so it looks like this now:

Screen Shot 2019-01-23 at 17.47.23.png

I removed all the various combinations of destinations I had tried and just have a single destination of 02392008648. I get busy tone now. Here's the SIP invite:

INVITE sip:gw+2141c506-de0a-4fd8-9c74-dfd134407499@77.74.195.12:5080;transport=udp;gw=2141c506-de0a-4fd8-9c74-dfd134407499 SIP/2.0

193.203.210.39:6060 77.74.195.12:5080 │Via: SIP/2.0/UDP 193.203.210.39:6060;rport;branch=z9hG4bK-sYn-0-omyk..r-aeaqtd*m%%gbklwtzng_ptbp

──────────┬───────── ──────────┬─────────│Max-Forwards: 15

12:45:57.896874 INVITE (SDP) │ │Contact: <sip:uaef3b20a0@193.203.210.39:6060;transport=udp>

+0.002384 │ ──────────────────────────> │ │From: <sip:01752422950@proxy.voip.co.uk>;tag=043b590075

12:45:57.899258 │ 100 Trying │ │To: <sip:02392008648@proxy.voip.co.uk;user=phone>

+0.004047 │ <────────────────────────── │ │Call-ID: bdf7f898-1f36-11e9-9b63-1daf01f298ce

12:45:57.903305 │ 480 Temporarily Unavailabl │ │CSeq: 699103890 INVITE

+0.004435 │ <────────────────────────── │ │Supported: from-change

12:45:57.907740 │ ACK │ │Accept: application/sdp

│ ──────────────────────────> │ │Allow: INVITE, ACK, BYE, CANCEL

│ │ │User-Agent: Synergy/1.9.9.5967

│ │ │Content-Type: application/sdp

│ │ │Content-Length: 318

│ │ │Date: Wed, 23 Jan 2019 17:45:58 GMT

│ │ │

│ │ │v=0

│ │ │o=root 981789526 981789526 IN IP4 10.200.208.11

│ │ │s="V4U SBC v2.0"

│ │ │c=IN IP4 193.203.210.39

│ │ │t=0 0

│ │ │m=audio 13314 RTP/AVP 8 0 18 101

│ │ │a=rtpmap:8 PCMA/8000

│ │ │a=rtpmap:0 PCMU/8000

│ │ │a=rtpmap:18 G729/8000

│ │ │a=fmtp:18 annexb=no

│ │ │a=rtpmap:101 telephone-event/8000

│ │ │a=fmtp:101 0-16

│ │ │a=ptime:20

│ │ │a=maxptime:150

│ │ │a=sendrecv

│ │ │
 
The call isn't getting as far as being entered into the CDR, this is the call in freeswitch.log:


----------------------<SNIP>--------------------
b3cf173a-8184-406c-b861-eebac754035f 2019-01-24 01:31:21.209854 [DEBUG] switch_channel.c:1296 EXPORT (export_vars) [call_direction]=[inbound]

b3cf173a-8184-406c-b861-eebac754035f 2019-01-24 01:31:21.209854 [DEBUG] mod_dptools.c:1598 SET sofia/external/07931828049@proxy.voip.co.uk [caller_destination]=[02392008648]

b3cf173a-8184-406c-b861-eebac754035f 2019-01-24 01:31:21.209854 [DEBUG] mod_dptools.c:1598 SET sofia/external/07931828049@proxy.voip.co.uk [caller_id_name]=[07931828049]

b3cf173a-8184-406c-b861-eebac754035f 2019-01-24 01:31:21.209854 [DEBUG] mod_dptools.c:1598 SET sofia/external/07931828049@proxy.voip.co.uk [caller_id_number]=[07931828049]

b3cf173a-8184-406c-b861-eebac754035f 2019-01-24 01:31:21.209854 [DEBUG] switch_channel.c:1296 EXPORT (export_vars) [call_direction]=[inbound]

b3cf173a-8184-406c-b861-eebac754035f 2019-01-24 01:31:21.209854 [DEBUG] mod_dptools.c:1598 SET sofia/external/07931828049@proxy.voip.co.uk [call_direction]=[inbound]

b3cf173a-8184-406c-b861-eebac754035f 2019-01-24 01:31:21.209854 [DEBUG] mod_dptools.c:1792 routes] 404 not found 193.203.210.39

b3cf173a-8184-406c-b861-eebac754035f 2019-01-24 01:31:21.209854 [DEBUG] switch_core_state_machine.c:286 (sofia/external/07931828049@proxy.voip.co.uk) State Change CS_ROUTING -> CS_EXECUTE

b3cf173a-8184-406c-b861-eebac754035f 2019-01-24 01:31:21.209854 [DEBUG] switch_core_state_machine.c:643 (sofia/external/07931828049@proxy.voip.co.uk) State ROUTING going to sleep

b3cf173a-8184-406c-b861-eebac754035f 2019-01-24 01:31:21.209854 [DEBUG] switch_core_state_machine.c:584 (sofia/external/07931828049@proxy.voip.co.uk) Running State Change CS_EXECUTE (Cur 2 Tot 4191)

b3cf173a-8184-406c-b861-eebac754035f 2019-01-24 01:31:21.209854 [DEBUG] switch_core_state_machine.c:650 (sofia/external/07931828049@proxy.voip.co.uk) State EXECUTE

b3cf173a-8184-406c-b861-eebac754035f 2019-01-24 01:31:21.209854 [DEBUG] mod_sofia.c:209 sofia/external/07931828049@proxy.voip.co.uk SOFIA EXECUTE

----------------------<SNIP>--------------------

So is it trying to use the IP of the provider as the destination?
 
Here's the SIP invite:


xINVITE sip:gw+2141c506-de0a-4fd8-9c74-dfd134407499@77.74.195.12:5080;transport=udp;gw=2141c506-de0a-4fd8-9c74-dfd134407499 SIP/2.0
193.203.210.39:5060 77.74.195.12:5080 xVia: SIP/2.0/UDP 193.203.210.39:5060;rport;branch=z9hG4bK-sYn-0-qyxdfjev%gjru!w_dlbo_jxkeffify-.
qqqqqqqqqqwqqqqqqqqq qqqqqqqqqqwqqqqqqqqqxMax-Forwards: 15
04:14:45.149194 x INVITE (SDP) x xContact: <sip:ua7e1dfff8@193.203.210.39:5060;transport=udp>
+0.001630 x qqqqqqqqqqqqqqqqqqqqqqqqqq> x xFrom: <sip:02089034714@proxy.voip.co.uk>;tag=22bc3600d7
04:14:45.150824 x 100 Trying x xTo: <sip:02392008648@proxy.voip.co.uk;user=phone>
+0.014773 x <qqqqqqqqqqqqqqqqqqqqqqqqqq x xCall-ID: 7e1b18cc-1fb8-11e9-af6b-c959720adc38
04:14:45.165597 x 480 Temporarily Unavailabl x xCSeq: 745929340 INVITE
+0.007397 x <qqqqqqqqqqqqqqqqqqqqqqqqqq x xSupported: from-change
04:14:45.172994 x ACK x xAccept: application/sdp
x qqqqqqqqqqqqqqqqqqqqqqqqqq> x xAllow: INVITE, ACK, BYE, CANCEL
x x xUser-Agent: Synergy/1.9.9.5967
x x xContent-Type: application/sdp
x x xContent-Length: 319
x x xDate: Thu, 24 Jan 2019 09:14:46 GMT
x x x
x x xv=0
x x xo=root 1371805273 1371805273 IN IP4 10.200.208.7
x x xs="V4U SBC v2.0"
x x xc=IN IP4 193.203.210.39
x x xt=0 0
x x xm=audio 13036 RTP/AVP 8 0 18 101
x x xa=rtpmap:8 PCMA/8000
x x xa=rtpmap:0 PCMU/8000
x x xa=rtpmap:18 G729/8000
x x xa=fmtp:18 annexb=no
x x xa=rtpmap:101 telephone-event/8000
x x xa=fmtp:101 0-16
x x xa=ptime:20
x x xa=maxptime:150
x x xa=sendrecv
 
Status
Not open for further replies.