Can App Receive Phone Status Event

Is it possibe for an app to receive an event when the phones status changes. For example when the status changes to Do not disturb.

We have a service center that would like to track the time available on the phone, i would like to create an app on the phone for the users to see each day how long they were on Do not disturb and how long they were available to take calls.

Yes. A phone subscribes to it’s own status updates. For example if you ran the following on your phone:

var app = require('app');
app.init();
var util = require('util');

// Allows this application to run in the background.
digium.app.exitAfterBackground = false;

var presenceChanged = function(param) {
    util.debug("Presence Changed: ");
    util.debug(JSON.stringify(param));
};

digium.event.observe({
    'eventName'     : 'digium.phone.contact_presence',
    'callback'      : presenceChanged
});

util.debug("Presence monitored");

You could get output on the debug console when switching to DND and back to available like:

Presence monitored
Presence Changed: 
{"eventName":"digium.phone.contact_presence","eventData":{"url":"sip:auto_hint_6003@10.19.135.2:5060","onlineStatus":"online","note":"Ready","subscriptionState":"ACTIVE","type":"dnd","subtype":"","text":""},"messageId":"ae501522"}
Presence Changed: 
{"eventName":"digium.phone.contact_presence","eventData":{"url":"sip:auto_hint_6003@10.19.135.2:5060","onlineStatus":"online","note":"Ready","subscriptionState":"ACTIVE","type":"available","subtype":"","text":""},"messageId":"ae501538"}

You can see that param.eventData.type changed to ‘dnd’ and back to ‘available’. You would need to parse the url in order to know it was the users phone that changed state and not another phone.

thank you for your quick reply, i am going to try it now