How to get value of SIP header in Freeswitch?

I need to get value of CALLED_DID header and do some actions in dialplan, but i don't know how.

I've tried to use ${sip_h_CALLED_DID} but it's empty, because have no X- prefix before header name.

Is there any other method to extract value from SIP header?

Please help me, i've read allover the internet but can't find answer.

INVITE sip:[email protected]:65000;transport=udp;gw=zadarma-rbcrm SIP/2.0
Record-Route: <sip:185.45.152.161;lr=on;ftag=as6a38207b>
Via: SIP/2.0/UDP 185.45.152.161;branch=z9hG4bK26d.6cf33cf5d2cdd6683e8de9503870f397.0
Via: SIP/2.0/UDP 185.45.152.148:5060;rport=5060;branch=z9hG4bK74d97ef6
Max-Forwards: 69
From: "+79630495339" <sip:[email protected]>;tag=as6a38207b
To: <sip:[email protected]>
Contact: <sip:[email protected]:5060>
Call-ID: [email protected]:5060
CSeq: 102 INVITE
User-Agent: Zadarma Voip
Date: Thu, 07 Mar 2019 07:38:22 GMT
Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY, INFO, PUBLISH, MESSAGE
Supported: replaces
CALLED_DID: 73433023519
Content-Type: application/sdp
Content-Length: 415
hostname: sipbalancer-1
cc_num: 346127
cc_counter: 1
728x90

2 Answers How to get value of SIP header in Freeswitch?

Sip values can not be easily extracted. Prefix the header with X-. Anything else is invalid.

You can recompile mod_sofia - add an extra header reader:

https://freeswitch.org/stash/projects/FS/repos/freeswitch/browse/src/mod/endpoints/mod_sofia/sofia.c Example line 11297.

Add this:

} else if (!strcasecmp(un->un_name, "CALLED_DID")) {
    switch_channel_set_variable(channel, "called_did", un->un_value);

Between:

} else if (!strcasecmp(un->un_name, "Geolocation")) {
    switch_channel_set_variable(channel, "sip_geolocation", un->un_value);

And:

} else if (!strcasecmp(un->un_name, "Geolocation-Error")) {`
    switch_channel_set_variable(channel, "sip_user_location", un->un_value);

And retrieve this header in dialplan like this:

<action application="log" data="DEBUG Called Did -> ${called_did}"/> 

1 weeks ago

After reading a ton of material, I came to the conclusion:

Reading of custom header without X- prefix is not possible without modifying of source code.

But this is not acceptable way in my case.

5 days ago