In my project I am using sip.js to connect to asterisk via websocket and asterisk is configured to use chan_pjsip driver. The goal is to create a call log entry when the user accepts an invitation and update the call log entry with the help of a dialplan hook at the end of the call.
The problem I am currently facing is that the Call-ID received by the sip.js client does not match the Call-ID that I read using PJSIP_HEADER(read,Call-ID)
is there any solution to send a unique id to the sip.js client that can be accessed at the end of the call on the asterisk side ?
That returns the Call-ID of the channel it is invoked on. If you invoke it on the incoming side, it’ll be the incoming Call-ID. If you invoke it on the outgoing side, it’ll be the outgoing Call-ID.
Custom SIP headers can be retrieved or set using the PJSIP_HEADER dialplan function[1].
[macro-dialout-one-predial-hook]
exten => s,1,Noop(Entering user defined context macro-dialout-one-predial-hook in extensions_custom.conf)
exten => s,n,Set(CHANNEL(hangup_handler_push)=do-this-on-hangup,s,1)
exten => s,n,MacroExit
[do-this-on-hangup]
exten => s,1,NoOp(Entering my-hook)
same => n,Set(UID_LONG=${PJSIP_HEADER(read,Call-ID)})
same => n,NoOp(${SIPCALLID})
same => n,NoOp(Exiting my-hook)
this is the content of my extensions_custom.conf
this should happen at the of the call
I know that is a FreePBX dialplan macro from perusing the FreePBX forum when I’m categorizing things and passing through there.
You don’t choose the channel at the end of the call. That hook is presumably setting it on the outgoing channel, if it follows the Asterisk meaning of what pre-dial is, so when the outgoing channel hangs up the logic would be executed.
If you want it to occur on the incoming channel then the hangup_handler_push would need to be executed on the incoming channel instead.
What you can do - e.g. if you want to do correlation - is to read the CallId value of the caller and set that into an X-Header on the outgoing call leg. We do that to enable correlation in HOMER between incoming and outgoing call legs. The best place to do that would be in a pre-dial handler.