Versions Compared


  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: clarity on what devices support Presence State notification, and Presence State vs SIP presence notifications used for extension/device state.


The only provider of presence state in Asterisk 11 is the CustomPresence provider. This provider is supplied by the module, which grants access to the PRESENCE_STATE dialplan function. The documentation for PRESENCE_STATE can be found here. CustomPresence is device-agnostic within the core and can be a handy way to set and query presence from dialplan, or APIs such as the AMI.

A simple use case for CustomPresence in dialplan is demonstrated below.

No Format
exten => 2000,1,Answer()
same => n,Set(CURRENT_PRESENCE=${PRESENCE_STATE(CustomPresence:Bob,value)})
same => n,GotoIf($[${CURRENT_PRESENCE}=available]?set_unavailable:set_available)
same => n(set_available),Set(PRESENCE_STATE(CustomPresence:Bob)=available,,)
same => n,Goto(finished)
same => n(set_unavailable),Set(PRESENCE_STATE(CustomPresence:Bob)=unavailable,,)
same => n(finished),Playback(queue-thankyou)
same => n,Hangup

exten => 2001,1,GotoIf($[${PRESENCE_STATE(CustomPresence:Bob,value)}!=available]?voicemail)
same => n,Dial(SIP/Bob)
same => n(voicemail)VoiceMail(Bob@default)


Configuring Presence Subscription with Hints

As is mentioned in the phone support section, at the time of writing this will only work with a Digium phone.

Like with device state, presence state is associated to a dialplan extension with a hint. Presence state hints come after device state in the hint extension and are separated by a comma (,). As an example:

No Format
exten => 2000,hint,SIP/2000,CustomPresence:2000
exten => 2000,1,Dial(SIP/2000)
same => n,Hangup()

The hint definition must contain both a device and presence state provider for presence state notifications to be generated. You cannot define a hint referencing a presence state provider by itself.

The above Or alternatively, you could define the presence state provider without a device.

No Format
exten => 2000,hint,,CustomPresence:2000

The first example would allow for someone subscribing to the extension state of 2000@default to be notified of device state changes for device SIP/2000 as well as presence state changes for the presence provider CustomPresence:2000.

The second example would allow for the subscriber to receive notification of state changes for only the presence provider CustomPresence:2000.

The CustomPresence presence state provider will be discussed further on this page.


When a SIP device is subscribed to a hint you have configured in Asterisk and that hint references a presence state provider, then upon change of that state Asterisk will generate a notification. That notification will take the form of a SIP NOTIFY including XML content. In the expanding panel below I've included an example of a presence notification sent to a Jitsi softphoneDigium phone. This particular presence notification happened when we changed presence state for CustomPresence:6002 via the CLI command 'presencestate change'.

titleClick here to see the NOTIFY example
No Format
myserver*CLI> presencestate change CustomPresence:6002 UNAVAILABLE
Changing 6002 to UNAVAILABLE
set_destination: Parsing <sip:6002@;ob> for address/port to send to
set_destination: set destination to
Reliably Transmitting (no NAT) to
NOTIFY sip:6002@;ob SIP/2.0
Via: SIP/2.0/UDP;branch=z9hG4bK68008251;rport
Max-Forwards: 70
From: sip:6002@;tag=as722c69ec
To: "Bob" <sip:6002@>;tag=4DpRZfRIlaKU9iQcaME2APx85TgFOEN7
Contact: <sip:6002@>
Call-ID: JVoQfeZe1cWTdPI5aTWkRpdqkjs8zmME
CSeq: 104 NOTIFY
User-Agent: Asterisk PBX SVN-branch-12-r413487
Subscription-State: active
Event: presence
Content-Type: application/pidf+xml
Content-Length: 602

<?xml version="1.0" encoding="ISO-8859-1"?>
<presence xmlns="urn:ietf:params:xml:ns:pidf" 
<tuple id="6002">
<contact priority="1">sip:6002@</contact>
<tuple id="digium-presence">
<digium_presence type="unavailable" subtype=""></digium_presence>

  == Extension Changed 6002[from-internal] new state Idle for Notify User 6002 

<--- SIP read from UDP: --->
SIP/2.0 200 OK
Via: SIP/2.0/UDP;rport=5060;received=;branch=z9hG4bK68008251
Call-ID: JVoQfeZe1cWTdPI5aTWkRpdqkjs8zmME
From: <sip:6002@>;tag=as722c69ec
To: "Bob" <sip:6002@>;tag=4DpRZfRIlaKU9iQcaME2APx85TgFOEN7
CSeq: 104 NOTIFY
Contact: "Bob" <sip:6002@;ob>
Supported: replaces, 100rel, timer, norefersub
Content-Length: 0



Phone Support for Presence State via SIP presence notifications

At the time of writing, only Digium phones have built-in support for interpreting Asterisk's Presence State notifications (as opposed to SIP presence notifications for extension/device state). The CustomPresence provider itself is device-agnostic and support for other devices could be added in. Or devices themselves (soft-phone or hardphone) could be modified to interpret the XML send out in the Presence State notification.

Digium Phones

This Video provides more insight on how presence can be set and viewed on Digium phones.