PJSIP set SIP Header's From Field


#1

To properly bill my customers, the From field in the SIP header has to be set accordingly. The correct value is setup in my database, and the callfile is dynamically created by a PHP script that is run as webservice.

My SIP Invite Header begins like this:

INVITE sip:+myphonenr@mysiptrunk SIP/2.0
Via: SIP/2.0/UDP [-- cut --]
From: "Anonymous" <sip:myphonenr@mysiptrunk>;tag=[-- cut --]

I want the “From:” Field to look like this:

From: customerphonenr <sip:myphonenr@mysiptrunk>;tag=...

This should be possible to be controlled by the callfile. As far as I understand, this is a pre-call setting and must therefore be in the callfile, the dialplan is too late within the flow.

What I have done so far: My callfile has lines like these:

Setvar:CALLERID(name)="Test customer"
Setvar:CALLERID(num)=customerphonenr

also with num, name-pres and num-pres. Nothing worked.

What do I have to set there? If this really does not work, billing can also be done by use of the field P-Preferred-Identity - which I also tried with no success, the field did not appear in the header. According to Stackexchange,

Setvar: __SIPADDHEADER1=X-Preferred-Identity: customerphonenr

#2

Check out the ‘b’ option to DIal

https://wiki.asterisk.org/wiki/display/AST/Asterisk+13+Application_Dial

’ Before initiating an outgoing call, Gosub to the specified location using the newly created channel. The Gosub will be executed for each destination channel’

I have a subroutine that I jump into where I add needed headers like this:

same => n,Set(PJSIP_HEADER(add,X-FAX)=${ARG3})


#3

@johnkiniston The b option of the Dial application already crossed my eyes. I just wonder: Where do I have to place it? The Channel line of the call file does not seem to be right place. I already tried something that looks like the parameter list to Dial:

Channel: PJSIP/mysiptrunk/sip:+43999999@mysiptrunk,,b(fax_outgoing^myinit^1)

However, this seemed to be syntactically wrong.

Am I on the right track with this?

Otherwise, I will try to modify my dialplan according to this suggestion on Stackexchange:

[caller]
exten => 3000,1,Wait(1)
exten => 3000,2,SIPAddHeader(P-Preferred-Identity: <sip:${prefID}@sip.provider.it>)
exten => 3000,3,NoOp(${tocall})
exten => 3000,4,NoOp(${testVar})
exten => 3000,n,Dial(SIP/prov1/${tocall})

#4

This won’t work with PJSIP. It’s for CHAN_SIP and the way you add a header for PJSIP is different.

You are correct as you can’t put it as part of the Channel line, You need to handle this in dialplan where the channel is being directed to.


#5

Maybe I am misunderstanding, but can’t you just set the “from_user” field on the endpoint? See the following for more info:

res_pjsip configuration
call party, privacy and header presentation


#6

No, I can’t. This is a web service for dozens of customers on a single SIP endpoint. We are telephone service provider on our own.


#7

@johnkiniston Of course, I need the appropriate PJSIP commands, i.e. set(PJSIP_HEADER(...)...).

[fax_caller]
exten => faxout,1,NoOp(** Fax caller **)
same => n,Dial(PJSIP/sip_atms/sip:${ReceiverPhoneNr}@mysipprovider.com:5084,,b(fax_outgoing_init^faxout^1(${CustomerPhoneNr})))

[fax_outgoing_init]
exten => faxout,1,NoOp(** Pre dial settings **)
same => n,Set(PJSIP_HEADER(add,P-Preferred-Identity)="<sip:${ARG1}@mysipprovider.com:5084>")
same => n,Return()

#8

The last contribution is in fact the solution to this problems. Thanks so far… I already stumbled into a new one which is closely relate to these lines. However, I explain this in a new post.


#9

same => n,Set(PJSIP_HEADER(add,P-Preferred-Identity)="<sip:${ARG1}@mysipprovider.com:5084>")


#10

@ecosmobtechnologies The SIP-Header P-Preferred-Identity is used by my trunk provider to determine the customer of its customers.