Asterisk Project : Presence State This page last changed on Sep 04, 2012 by mmichelson. # Overview Asterisk 11 has been outfitted with support for presence states. An easy way to understand this is to compare presence state support to the device state support Asterisk has always had. Like with device state support, Asterisk has a core API so that modules can register themselves as presence state providers, alert others to changes in presence state, and query the presence state of others. The biggest difference between the concepts is that device state reflects the current state of a physical device connected to Asterisk, while presence state reflects the current state of the user of the device. For example, a device may currently be `not in use` but the person is `away`. This can be a critical detail when determining the availability of the person. Asterisk offers the following presence states: `not set`: No presence state has been set for this entity. `unavailable`: This entity is present but currently not available for communications. `available`: This entity is available for communication. `away`: This entity is not present and is unable to communicate. `xa`: This entity is not present and is not expected to return for a while. `chat`: This entity is available to communicate but would rather use instant messaging than speak. `dnd`: This entity does not wish to be disturbed. In addition to the basic presence states provided, presence also has the concept of a subtype and a message. The subtype is a brief method of describing the nature of the state. For instance, a subtype for the `away` status might be "at home". The message is a longer explanation of the current presence state. Using the same `away` example from before, the message may be "Sick with the flu. Out until the 18th". Like with device state, presence state can be placed in hints. Presence state hints come after device state hints and are separated by a comma (`,`). As an example:
    [default]
    exten => 2000,hint,SIP/2000,CustomPresence:2000
    exten => 2000,1,Dial(SIP/2000)
    same => n,Hangup()
This 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 device `CustomPresence:2000`. The `CustomPresence` presence state provider will be discussed further on this page. Also like with device state, there is an Asterisk Manager Interface command for querying presence state. Documentation for the AMI `PresenceState` command can be found here. # Differences Between Presence State and Device State Support While the architectures of presence state and device state support in Asterisk are similar, there are some key differences between the two. Asterisk cannot infer presence state changes the same way it can device state changes. For instance, when a SIP endpoint is on a call, Asterisk can infer that the device is being used and report the device state as `in use`. Asterisk cannot infer whether a user of such a device does not wish to be disturbed or would rather chat, though. Thus, all presence state changes have to be manually enacted. Asterisk does not take presence into consideration when determining availability of a device. For instance, members of a queue whose device state is `busy` will not be called; however, if that member's device is `not in use` but his presence is `away` then Asterisk will still attempt to call the queue member. Asterisk cannot aggregate multiple presence states into a single combined state. Multiple device states can be listed in an extension's hint priority to have a combined state reported. Presence state support in Asterisk lacks this concept. # `func_presencestate` And The `CustomPresence` Provider The only provider of presence state in Asterisk 11 is the `CustomPresence` provider. This provider is supplied by the `func_presencestate.so` module, which grants access to the `PRESENCE_STATE` dialplan function. The documentation for `PRESENCE_STATE` can be found here. `CustomPresence` is device-agnostic and can be a handy way to set and query presence. A simple use for `CustomPresence` is demonstrated below.
| The following dialplan is meant strictly for demonstration. It is not intended to be used as-is in a production environment.
    [default]
    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)
With this dialplan, a user can dial `2000@default` to toggle Bob's presence between `available` and `unavailable`. When a user attempts to call Bob using `2001@default`, if Bob's presence is currently not `available` then the call will go directly to voicemail.
| One thing to keep in mind with the `PRESENCE_STATE` dialplan function is that, like with `DEVICE_STATE`, state may be queried from any presence provider, but `PRESENCE_STATE` is only capable of setting presence state for the `CustomPresence` presence state provider.
# Digium Phone Support Digium phones have built-in support for Asterisk's presence state. This Video provides more insight on how presence can be set and viewed on Digium phones. When using Digium phones with the Digium Phone Module for Asterisk, you can set hints in Asterisk so that when one Digium phone's presence is updated, other Digium phones can be notified of the presence change. The DPMA automatically creates provisions such that when a Digium Phone updates its presence, `CustomPresence:<line name>` is updated, where `<line name>` is the value set for the `line=` option in a `type=phone` category. Using the example dialplan from the Overview section, Digium phones that are subscribed to `2000@default` will automatically be updated about line 2000's presence whenever line 2000's presence changes.

Document generated by Confluence on Nov 02, 2012 17:42