Retrieving Lync Presence

6.1k views Asked by At

My requirement is I need to create a windows service which retrieves the Lync presence status(Available, Busy, Do not disturb ....) of each user in the Active directory.

I googled and found that below SDKs can retrieve the Lync Presence. Lync Client 2010 SDK, Unified Communications Managed API, Lync Server 2010 SDK, Unified Communications Client API.

Please suggest the best SDK among them to achieve my requirement.

Thanks in Advance.

2

There are 2 answers

1
Dinesh Haraveer On

I also tried to find the presence state of the User and come out with the below code to achieve this requirement.

                string _transferUserURI="pass your sipaddress";
                RemotePresenceView _RemotePresence;

                RemotePresenceViewSettings settings = new RemotePresenceViewSettings();
                settings.SubscriptionMode = RemotePresenceViewSubscriptionMode.Default;
                settings.PollingInterval = new TimeSpan(0, 0, 10);
                _RemotePresence = new RemotePresenceView(_appEndpoint, settings);
                _RemotePresence.PresenceNotificationReceived += new EventHandler<RemotePresentitiesNotificationEventArgs>(_RemotePresence_PresenceNotificationReceived);
                //_RemotePresence.SubscriptionStateChanged += new EventHandler<RemoteSubscriptionStateChangedEventArgs>(_RemotePresence_SubscriptionStateChanged);

                RemotePresentitySubscriptionTarget target = new RemotePresentitySubscriptionTarget(_transferUserURI);
                List<RemotePresentitySubscriptionTarget> targets = new List<RemotePresentitySubscriptionTarget>() { target };
                _RemotePresence.StartSubscribingToPresentities(targets);

and _RemotePresence_PresenceNotificationReceived event

       void _RemotePresence_PresenceNotificationReceived(object sender, RemotePresentitiesNotificationEventArgs e)
    {
        try
        {
            // Extract the RemotePresenceView that received the notification.
            RemotePresenceView view = sender as RemotePresenceView;
            // A RemotePresentityNotification will contain all the
            // categories for one user; Notifications can contain notifications
            // for multiple users.


            foreach (RemotePresentityNotification notification in e.Notifications)
            {
                Console.WriteLine("\nView: " + view.ApplicationContext
                    + " Received a Notification for user "
                    + notification.PresentityUri + ".");

                // If a category on notification is null, the category
                // was not present in the notification. This means there were no
                // changes in that category.
                if (notification.AggregatedPresenceState != null)
                {
                    Console.WriteLine("Aggregate State = " + notification.AggregatedPresenceState.Availability + ".");

                    string Availblity = notification.AggregatedPresenceState.Availability.ToString();
                }

                if (notification.PersonalNote != null)
                {
                    Console.WriteLine("PersonalNote: " + notification.PersonalNote.Message + ".");
                }

                if (notification.ContactCard != null)
                {
                    // A ContactCard contains many properties; only display
                    // some.
                    ContactCard contactCard = notification.ContactCard;
                    Console.WriteLine("ContactCard Company: " + contactCard.Company + ".");
                    Console.WriteLine("ContactCard DisplayName: " + contactCard.DisplayName + ".");
                    Console.WriteLine("ContactCard EmailAddress: " + contactCard.EmailAddress + ".");
                }
            }
        }
        catch
        {

        }
    }

I hope this was the answer you are looking otherwise correct me if i was wrong.

3
Tom Morgan On

There's a good write-up of each SDK and where you would use them here: http://www.codelync.com/an-overview-of-the-lync-apis/

For what you want to achieve, I would recommend using UCMA - the Unified Communications Client API. The way it works it that you give it a list of users you want to monitor status of, and it will then call back on an event each time their presence changes. You get a presence event as soon as you start subscribing, so you could then unsubscribe if you don't want to have ongoing notification.

An example of subscribing to lots of users might be:

  var _remotePresenceView = new RemotePresenceView(_endpoint);
_remotePresenceView.PresenceNotificationReceived += _remotePresenceView_PresenceNotificationReceived;
List<RemotePresentitySubscriptionTarget> subscriptions = new List<RemotePresentitySubscriptionTarget>();

subscriptions.Add(new RemotePresentitySubscriptionTarget("sip:first_user@domain));
subscriptions.Add(new RemotePresentitySubscriptionTarget("sip:second_user@domain));
...
subscriptions.Add(new RemotePresentitySubscriptionTarget("sip:nth_user@domain));

_remotePresenceView.StartSubscribingToPresentities(subscriptions);

There's a couple of tips, tricks and gotchas when using the Remote Presence View: check out MSDN here.