System information
Custom device states can be used as a way to directly control the state shown on a
device that has subscribed to the state of an extension. Just map an extension to a
custom device state using a hint in the dialplan:
exten => example,hint,Custom:example
An Example
There are a number of interesting use cases for custom device states. In this section we
will build an example that implements a custom “do not disturb” (DND) button on a
SIP phone. This same approach could be applied to many other things that you might
like to be able to toggle at the touch of a button. For example, this approach could be
used to let members know if they are currently logged into a queue or not.
The first piece of the example is the hint in the dialplan. This is required so BLF can be
configured on a SIP phone to subscribe to this extension. In this case, the phone must
be configured to subscribe to the state of DND_7015:
exten => DND_7015,hint,Custom:DND_7015
Next, we will create an extension that will be called when the user presses the key
associated with the custom DND feature. It is interesting to note that this extension
does nothing with audio. In fact, the user of the phone most likely will not even know
that a call is placed when he presses the button. As far as the user is concerned, pressing
that key simply turns on or off the light next to the button that reflects whether or not
DND is enabled. The extension should look like this:
exten => DND_7015,1,Answer()
same => n,GotoIf($["${DEVICE_STATE(Custom:DND_7015)}"="BUSY"]?turn_off:turn_on)
same => n(turn_off),Set(DEVICE_STATE(Custom:DND_7015)=NOT_INUSE)
same => n,Hangup()
same => n(turn_on),Set(DEVICE_STATE(Custom:DND_7015)=BUSY)
same => n,Hangup()
The final part of this example shows how the DND state is used in the dialplan. If DND
is enabled, a message is played to the caller saying that the agent is unavailable. If it is
disabled, a call will be made to a SIP device:
exten => 7015,1,GotoIf($["${DEVICE_STATE(Custom:DND_7015)}"="BUSY"]?busy:available)
same => n(available),Verbose(3,DND is currently off for 7015.)
same => n,Dial(SIP/exampledevice)
same => n,Hangup()
same => n(busy),Verbose(3,DND is on for 7015.)
same => n,Playback(vm-theperson)
same => n,Playback(digits/7&digits/0&digits/1&digits/5)
same => n,Playback(vm-isunavail)
same => n,Playback(vm-goodbye)
same => n,Hangup()
308 | Chapter 14: Device States