Skip to main content

Need to set a custom SIP header on every outbound call

Posted by JaredBusch on Fri, 10/27/2023

One of our SIP trunk providers handles breakout of the tenant billing by use of a sip header on all outbound calls over a trunk.

I need to set X-Tenant to a value that matches a tenant id at the carrier.
A closed source, PBX I have used simply has that built in when you choose this SIP trunking provider in their system.
FreePBX has a hook in their dialplan that you can use like this.

[macro-dialout-trunk-predial-hook]
; Set x_tenant = to test.stl by default.
exten => s,n,Set(x_tenant=test.stl)
; Change it if the call is on a Cape, Jeff City, or Quincy outbound route.
exten => s,n,ExecIf($["${OUTBOUND_ROUTE_NAME:0:4}"=="Cape"]?Set(x_tenant=test.cape))
exten => s,n,ExecIf($["${OUTBOUND_ROUTE_NAME:0:9}"=="Jeff City"]?Set(x_tenant=test.jeffcity))
exten => s,n,ExecIf($["${OUTBOUND_ROUTE_NAME:0:6}"=="Quincy"]?Set(x_tenant=test.quincy))
exten => s,n,NoOp(Based on the outbound route name of ${OUTBOUND_ROUTE_NAME}, the X-Tenant is being set to ${x_tenant}.)
exten => s,n,GoSub(func-set-sipheader,s,1(X-Tenant,${x_tenant}))
exten => s,n(exit_macro),MacroExit()

With Thirdlane, I would like to make use of the "tag" field in the Tenant settings. It is also available on a per extension basis if I need a specific override it seems. My question is where in the dial plan is there a spot I can hook in to outbound calls and what is the syntax to add a sip header?
I looked through /etc/asterisk/scripts_db.include and did not see any obvious example of a place I could call in a customer include.

 

 

 


Submitted by JaredBusch on Tue, 10/31/2023 Permalink

Adding a value in the trunk is not useful when I need the value to be different per tenant. Nothing in the guide shows how a variable could be used either.
I looked at the idea of a duplicate of the dial 1 trunk script, but could not determine how that would be useful to be used in the trunk setting.

 

Submitted by JaredBusch on Thu, 11/02/2023 Permalink

If I clone this script, it there something I can add that would be visible once it gets to the trunk?Can the trunk header section even take a variable?

screenshot of script

screenshot of trunk setting