SIP header uniqueId injection

Description of My Environment

  • CLIENT is an extension using sipml5.
  • FREEPBX is FreePBX 15 with Asterisk 16.30.
  • TRUNK is the telecom provider’s trunk.

I am making outbound calls from CLIENT through FREEPBX to TRUNK. Now, I want FREEPBX to include its unique call ID in the SIP header when responding to CLIENT during the call. The information should be related only to FREEPBX and should have nothing to do with TRUNK.

I have added the following configuration in extensions_custom.conf:

[from-internal-custom]
exten => _X.,1,NoOp(=== FreePBX Custom UniqueID Injection ===)
exten => _X.,n,ExecIf($["${UNIQUE_CALL_ID}" = ""]?Set(UNIQUE_CALL_ID=${CHANNEL(uniqueid)}))
exten => _X.,n,ExecIf($["${PJSIP_HEADER(read,X-UniqueID)}" = ""]?Set(PJSIP_HEADER(add,X-UniqueID)=${UNIQUE_CALL_ID}))
exten => _X.,n,NoOp(=== X-UniqueID: ${UNIQUE_CALL_ID} ===)
exten => _X.,n,NoOp(=== CALLERID: ${CALLERID(num)} ===)

I have also confirmed from the logs that this script is executing.

However, when checking CLIENT, I do not see the X-UniqueID in the received headers, and it is also missing from the SIP logs on FREEPBX (but log shows dialplan executed).

Is there anything I did wrong?
Thank you!

The add header needs to be run on the outgoing channel, which doesn’t exist at that point. I think FreePBX has a mechanism to take outgoing headers from variables. but I’d have to look through the code to be sure of the details. The actual header add needs to be done in a subroutine that is run from the b option of Dial, and FreePBX does have such a subroutine. (It may be a macro, in your unsupported version. Asterisk 16 is signficantly beyond end of life, and FreePBX 15 is either end of life or security fixes only.

1 Like

The fpbx sub for adding headers

GoSub(func-set-sipheader,s,1(<headername>,<headervalue)

so you want to modify your dialplan above to use gosubif with this format. Also note that you CANNOT use _X. in from-internal-custom to hook all calls like you’re doing, you must use the dialplan hooks that exist for this purpose. See Hooking for fun and income

1 Like