Did you know you can use “@” variables in pjsip.conf?

Did you know you can use “@” variables in pjsip.conf?

You probably already know that you can use the “set_var” parameter on pjsip endpoints to add variables to a channel using that endpoint but did you know you can set custom variables using the “@” prefix?  They aren’t available via the CHANNEL function but they _are_ available using the PJSIP_ENDPOINT and PJSIP_AOR dialplan functions and they show in the CLI “pjsip show” commands.   Actually, you can set “@” variables on any pjsip object but only endpoint and aor have dialplan functions to retrieve them.


Based on some feedback, here’s more info about both types of custom variables:

Channel Variables

As with many other channel drivers, chan_pjsip allows you to set variables on an endpoint that will be available on any channel using that endpoint.  For instance, with the following  endpoint snippet in pjsip.conf:


You could do the following in the dialplan  in extensions.conf:


Then when endpoint myendpoint dialed 1000, you could take some action based on the variable value, like deny international calls for that endpoint.

You can also see those variables with pjsip show endpoint:

CLI> pjsip show endpoint myendpoint
ParameterName : ParameterValue
100rel : yes
accept_multiple_sdp_answers : false

Sorcery Custom (“@”) Variables:

These variables are set a little differently:


And retrieved a little differently:


So what’s the difference between the two types?

With a channel variable, you have to already have a channel up to that endpoint before you can get the variable value.   That works if the value of interest is attached to the endpoint of an incoming call.  It doesn’t work if you need to know the value before you create an outgoing call to that endpoint.  With a custom variable, all you need to know is the endpoint’s id.

Simple Use Case:

Back when chan_pjsip was first introduced (and while I was still a community developer), I was working an an Asterisk GUI and needed an easy way to perform “simulring” functionality where dialing extension 1000, for example, also dialed extension 1001 and a mobile phone.  I didn’t want to create a separate conf file to store the relationships, nor did I want to have to manipulate extensions.conf to add or delete extension-specific rules but I already had an easy way to programatically manipulate pjsip.conf.  So here’s what I did:

exten = _1XXX,1,NoOp(LocalExtension)
same  = n,Dial(${PJSIP_ENDPOINT(${EXTEN},@dialstring)},15)

There was other logic in there to handle if there was no @simulringvalue of course but now I could set up any extension for “simulring” by modifying 1 entry in pjsip.conf.


What happens if your endpoints aren’t named the same as your extensions???

Here’s a hint.

(get it?)


Here’s another little tidbit…   If you use Realtime, you can create a column in your database with an “@” variable and it will work fine.  🙂


8 Responses

  1. It’s very useful feature, especially Realtime!
    Which version of asterisk does it support?
    I think the info about “@” variables should be added to configs/samples/pjsip.conf.sample

  2. While testing Realtime “@” variable if the value is NULL or empty
    there is WARNING func_pjsip_endpoint.c:135 pjsip_endpoint_function_read: Unknown property ‘@test_id’ for PJSIP endpoint.
    And the variable is missing in the result of CLI ‘pjsip show endpoint’

  3. The “@” variables have been supported since the first release of Asterisk 13.
    Good idea about updating the samples. I’ll try and do that this week.

  4. Would you mind opening an issue for the WARNING if the value is NULL or empty?

Leave a Reply

Your email address will not be published. Required fields are marked *

The reCAPTCHA verification period has expired. Please reload the page.

About the Author

What can we help you find?