How to retrieve SIP Header Information from FreePBX/Asterisk when incoming call with FreePBX ACD/RingAll Strategy

I’m trying to retrieve SIP Header Information from FreePBX/Asterisk when incoming call with FreePBX/Asterisk ACD/RingAll Call Strategy. The objective is that 3rd party UserApplication(CTI Application) needs to retrieve SIP Header Information when call established through FreePBX/Asterisk.

PSTN User (Phone Number: 81-3-1111-1111 CLI/ANI) -> Cloud PSTN/SIP Gateway with Phone Number (Phone Number: 81-3-8888-8888) -> SIP Trunk -> FreePBX/Asterisk(ACD/RingAll) — > SIP Endpoints

In this scenario, Cloud PSTN/SIP Gateway will send SIP INVITE to Asterisk with CLI/ANI 81-3-8888-8888 overwritten by PSTN/SIP Gateway, instead of User’s Phone Number CLI/ANI 81-3-1111-1111.

Therefore we have added PSTN User’s Information into SIP Header from the Gateway to FreePBX/Asterisk and looking for the way how to retrieve SIP Header information from Asterisk .

I’ve found the following information, but it may not help because this is for dialplan purpose.
Func SIP Header:

Is there any good way to retrieve SIP Header Information by 3rd party UserApplication from FreePBX/Asterisk? AGI might help to do it, but I’m not sure. Any tips, it is appreciated.

I am assuming that your incoming trunk is sending e.g.
INVITE sip:[email protected] SIP/2.0
From: "SomeName" <sip:[email protected]>
X-Magic: <sip:[email protected]>

If that’s your situation, set the Context for your trunk to fixcallerid and add this code to /etc/asterisk/extensions_custom.conf

exten => _X!,1,Set(CALLERID(num)=${CUT(CUT(SIP_HEADER(X-Magic),@,1),:,2)}) 
exten => _X!,n,Goto(from-trunk,${EXTEN},1)

Use PJSIP_HEADER instead of SIP_HEADER if it’s a pjsip trunk.

You will need additional modifications for your specific case.

If I have not understood your situation, please provide a detailed example.

1 Like

Great thanks! If we use your suggested fixcallerid method, target SIP Endpoint should be able to capture PSTN User’s CLI/ANI.

The another challenging point is that, if using ACD/RingAll call Strategy, how can 3rd party User Application that is associated to Cloud PSTN/SIP Gateway retrieve this specific voice session information ( Target SIP extension number of the called SIP Endpoint & fixed CallerID information) from Asterisk/FreePBX… If we can retrieve this voice session information using webhook or API in realtime, it can be the solution.

Our Scenario is that, Asterisk ACD/RingAll strategy will loadbalance among multiple Agents(target SIP endpoints) these are Zoiper free edition.

Is this what you want? If not, please describe desired call flow, with an example.

1 Like

Thank you for your advice. Sounds good.

Sorry one more question. Is there any good way for 3rd party UserApplication to retrieve Asterisk ACD call mapping status in realtime?

                                   3rd Party User Application

Users/Caller -> Cloud PSTN/SIP GW --> Representative SIP Number: 5000 FreePBX/ACD(RingAll) —> Operator SIP ext.100, ext. 200, ext. 300 (e.g. Zoiper free SIP endpoint)

In our use case, 3rd Party User Application needs to sync or hook ACD call status to map incoming call to SIP:5000 and to which target Operator pick-up phone with SIP ext. information in realtime.
Is there any good way to retrieve or hook this FreePBX ACD realtime session status information from FreePBX/Asterisk ?

I believe that the AMI interface to Channel Event Logging can give you the needed data, but I have no expertise in this area and don’t know if there is any free or commercial software that will interface it to your app. You may have to write your own code for this.

1 Like

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