Hello all,
I get from my provider the DID in quotes. How can I evaluate them?
sip header:
To: “9999DID9999” sip:101@sip.provider.de
Where 9999DID9999 is the line being called (DID) and 101 is the extension number on the provider’s pbx system.
What I need is the part in quotes as DID so Asterisk can handle it.
Thanks a lot in advance.
https://wiki.asterisk.org/wiki/display/AST/Asterisk+18+Function_PJSIP_HEADER
https://wiki.asterisk.org/wiki/display/AST/Manipulating+Variables+Basics
asterisk
The following extracts it from the To URI user part, which is a more common situation, but should show most of the general principles:
;-------------------------------------------------------------------------------
; 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:2125551212@172.31.74.25>
;
; 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)
;-------------------------------------------------------------------------------
;-------------------------------------------------------------------------------
1 Like
Dear david,
thank you. maybe i’m too stupid for this (or it’s just too late today), but i need the part which is just in quotes before the sip:2125551212@172.31.74.25 .
To: “9999DID9999” sip:101@sip.provider.de
tried exten => _.,n(PJSIP),Goto(from-pstn,${CUT(CUT(PJSIP_HEADER(read,To),“,1),”,2)},1) to get the part in Quotes, but without success.
You’d need to quote the ". I assume \ will work, but the way Asterisk handles quotes is a bit funny, so one might have to experiment.
You could also try regular expressions.
Please mark up code as pre-formatted text, e.g.
<sip:2125551212@172.31.74.25>.
To: “9999DID9999” sip:101@sip.provider.de
The last line was invalid even in the raw version, although you did have it correct in the raw version of your first post.
To: "9999DID9999" <sip:101@sip.provider.de>
tried exten => _.,n(PJSIP),Goto(from-pstn,${CUT(CUT(PJSIP_HEADER(read,To),",1),",2)},1)
to get the part in Quotes, but without success.
Note, whilst I would hope the FreePBX people would have found and fixed it if that example were wrong, I would have used ${} around the nested CUT.
I got it working now, but I am not sure why
exten => _.,n,Set(CALLERID(dnid)=${CUT(CUT(PJSIP_HEADER(read,To),@,1),\",2)})
Let’s start again from the beginning.
The provider transmits the following information in the To Field
To: “1234567890” sip:101@sip.provider.de
Where 1234567890 is the phone number of the trunk line (the number dialed from the caller). And 101 is the extension that is defined in my provider’s pbx for the sip account that the asterisk/freePBX uses to register there.
In the CUT command above, I replaced the : with a \", after which it now seems to work without any problems.
I would prefer a regular expression to be on the safe side, but unfortunately I have no idea about that.
Suggestions are always welcome.
system
Closed
January 11, 2023, 1:04pm
9
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.