Asterisk 14: Publishing Extension State

Asterisk 14 now has the ability to publish extension state using PJSIP PUBLISH requests to another entity acting as an event state compositor. For larger installations, the advantage of this ability is to offload from Asterisk the SUBSCRIBE and NOTIFY responsibility for state changes to the other entity.

What can be used as an event state compositor? Kamailio! Kamailio is a frequent companion to Asterisk which oddly enough has the ability to act as an event state compositor for the extension states published by Asterisk.

Configuring Asterisk to publish extension state

Publishing extension state is configured by a type=outbound-publish section in pjsip.conf. The standard options for the type=outbound-publish section are documented on the Asterisk wiki [1] by the res_pjsip_outbound_publish configuration page [2]. In addition to the standard section options, the following option values and extended options are available for publishing extension state.

event=
dialog – Publish extension state events
presence – Publish extension presence state events

multi_user=yes
Should be set to yes to allow the other entity to determine what user the published extension state event is for.

@body=
application/cpim-pidf+xml
application/dialog-info+xml
application/pidf+xml
application/xpidf+xml

Specifies the format of the extension and presence state PUBLISH bodies. The PUBLISH will contain the same body that a SUBSCRIBE NOTIFY would. The option is required.

@context=
Regular expression to select the dialplan contexts the section will publish events from. The option is optional. If not specified then events from any context are published. The section’s @context and @exten selection filters must agree to publish an event for it to get published.

@exten=
Regular expression to select the dialplan extensions the section will publish events from. The option is optional. If not specified then events from any exten are published. The section’s @context and @exten selection filters must agree to publish an event for it to get published.

[pub_user]
type=outbound-publish
server_uri=sip:192.0.0.10
from_uri=sip:192.0.0.20
event=dialog
multi_user=yes
@body=application/dialog-info+xml
@context=^users
@exten=^1000
[pub_users]
type=outbound-publish
server_uri=sip:192.0.0.10
from_uri=sip:192.0.0.20
event=dialog
multi_user=yes
@body=application/dialog-info+xml
@context=^users

You can have as many type=outbound-publish sections as you want provided the sections have different names. Each one can specify what to publish and where.

Give me a hint

The extension state PUBLISH requests from Asterisk are triggered by state changes made through dialplan hints. How you create the hints is up to you. You can explicitly create each hint or you can have extension state hints automatically created for you.

The companion autohints functionality can create extension state hints automatically as needed. You simply add the autohints=yes line to the dialplan context in extensions.conf where you want the automatic hints created.

[users]
autohints=yes

When enabled, if a device state change happens on technology/resource and no hint named resource exists then a hint is created.

exten = resource,hint,technology/resource

For example, given the device PJSIP/alice then the hint below is created.

exten = alice,hint,PJSIP/alice

Why couldn’t extension pattern hints be used to create the hints instead? The answer is what triggers the creation of hints from the extension pattern. Specific extension hints are created from the extension pattern hint when someone explicitly SUBSCRIBEs to an extension. Since we are trying to offload handling of these subscriptions to another entity it isn’t going to help.

exten = _XXXX,hint,PJSIP/${EXTEN}

Asterisk 14 has some great new features with the extension state publishing [3] being one of them.

[1] https://wiki.asterisk.org

[2] https://wiki.asterisk.org/wiki/display/AST/Asterisk+14+Configuration_res_pjsip_outbound_publish

[3] https://wiki.asterisk.org/wiki/display/AST/Publishing+Extension+State

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?