I’m working with Asterisk (PJSIP) and I need to extract specific information from the incoming SIP INVITE — for example, headers like Reason, Diversion, or any custom X-Header provided by the provider — and then store these values in the CDR.
I’ve tried reading headers using PJSIP_HEADER(read,HeaderName) inside the dialplan and setting them via Set(CDR(field)=value), but this only works for the calling channel. I need to reliably capture data from the original INVITE that comes from the provider side, not from the internal channel created later by Dial().
In short:
I want to get data from the INVITE (e.g. “480 Account is LOCKED” or custom SIP fields);
Save that data as part of the CDR record (to database or CDR file);
Ideally, handle this automatically for all inbound calls.
Has anyone implemented this before or can suggest the best practice — maybe using PJSIP_HEADER(), res_pjsip_logger, or CEL events?
Any examples or recommendations would be greatly appreciated.
This confuses me. PJSIP_HEADER can read the SIP headers from an incoming INVITE, that’s the way it works and this reads as though it both works, and doesn’t work.
480 Account is LOCKED is not from the INVITE. It’s a SIP response to the INVITE. That’s different then getting headers, and you can’t get headers from it. You could probably get the SIP response code using hangupcause[1].
This isn’t an INVITE header. Asterisk only gives access to INVITE headers, not response headers. Actually this isn’t a header at all. Also it isn’t associated with the original INVITE, from the providers side, but with the outgoing INVITE, which is, potentially, to a provider.
This is very confused, and is not consistent with your detailed example.