Custom Status and Status Tokens-Publishing presence with UCMA 2.0

Publishing presence for a user in OCS is a reasonably common thing to do with an application endpoint, but most of the samples that I found online were restricted to setting the user’s availability.  This is usually one of the following values:

  • 3000 (Available)
  • 6000 (Busy)
  • 9000 (Do Not Disturb)
  • 12000 (Be Right Back)
  • 15000 (Away)
  • 18000 (Offline)

What if you want to publish something a little more detailed though.  Michael Greenlee wrote a great blog post on setting a custom status in a UCMA that I found really useful, and I’d suggest that anyone reading this go check that out first to get a basic application up and running…  After all, the internet only needs a certain number of posts that detail how to set up a basic application endpoint in UCMA. 

OK, so there’s two things that I’d like to add to the discussion, and both were made much clearer after digging through the MS-Pres spec that details the presence document.  If you look at the XML that you publish for a presence state, it looks something like this:

<state xmlns="http://schemas.microsoft.com/2006/09/sip/state" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="userState">
  <availability>6000</availability>
</state>

Now, if you want to add a custom status string to the mix, you can change the XML to be something like this:

<state xmlns="http://schemas.microsoft.com/2006/09/sip/state" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="userState">
  <availability>6000</availability>
  <activity>
    <custom LCID="1033">Really, really busy</custom>
  </activity>
</state>

Which will display the custom status text beside your name in Communicator.  What’s really handy though is that if you need to support users in multiple languages, you can add as many custom strings as you want to the messages:

<state xmlns="http://schemas.microsoft.com/2006/09/sip/state" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="userState">
  <availability>6000</availability>
  <activity>
    <custom LCID="1033">Really, really busy</custom>
    <custom LCID="3084">Très, très occupé</custom>
  </activity>
</state>

If there are multiple strings in the message, Communicator will decide what to display based on the OS language, which means that your app can be localized without a whole lot of effort. 

The other thing that I wanted to try to do was get the status that Communicator publishes for some states (On Call, In a Meeting etc), where the availability is still set to a standard value.  There’s a post on Chris Mayo’s blog that details this in the Communicator automation API, but I wasn’t able to find anything on doing this in UCMA.  As it turns out, there’s another attribute you can set in the presence message:

<state xmlns="http://schemas.microsoft.com/2006/09/sip/state" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="userState">
  <availability>6000</availability>
  <activity token=”on-the-phone”/>
</state>

The token attribute on the activity node can be used for a bunch of standard tags that force Communicator to render your status based on its own string table.  Sure, you could publish “On the Phone” as your own custom presence state, but this way you don’t have to translate anything for different languages.  The list of tokens is in the MS-Pres spec:

  • on-the-phone
  • in-a-conference
  • in-a-meeting
  • out-of-office
  • urgent-interruptions-only

So, in addition to being able to publish presence with one of these “built in” status strings, you’re also able to look for these values in an application that monitors presence of a user from an ApplicationEndpoint.  This means that by just monitoring the presence of the user, you should be able to discern whether they’re on a call, in a conference, or out of the office (yes, there are other ways to do this, but this just uses the user’s presence).  Here’s a simple handler for a presence change that looks for the activity tokens and custom presence states

private static void handlerPresenceNotificationReceived(object sender, RemotePresenceNotificationEventArgs e)
{
    //Multiple presence notifications may be received in one event
    foreach (RemotePresentityNotificationData notification in e.Notifications)
    {
        foreach (PresenceCategoryWithMetaData category in notification.Categories)
        {
            PresenceState state = PresenceState.Create(category);
            string status=string.Empty;

            if (state.Activity!=null && state.Activity.ActivityToken != string.Empty)
                status = state.Activity.ActivityToken.ToString();  //constant values like on-the-phone
            else if (state.Activity != null && state.Activity.CustomTokens != null)
            {
                status = "custom Status";
                int lcid = System.Threading.Thread.CurrentThread.CurrentCulture.LCID;
                foreach (LocaleString l in state.Activity.CustomTokens)
                {
                    if (l.LocaleId == lcid)
                        status = l.Value;
                }                       
            }
            Console.WriteLine("user: " + notification.Uri + " state: " + state.Availability.ToString() + " status:" + status);
        }
    }
}

Advertisements
This entry was posted in Uncategorized. Bookmark the permalink.

2 Responses to Custom Status and Status Tokens-Publishing presence with UCMA 2.0

  1. jibin mathew says:

    Hi can you please give me some links or tutorial sources or some sample codes to start with writing web service that utilizes the functionalities of ucma 3.0 SDK.
    What i want is a webservice that returns the status of a user .But the problem is its the first time that i am working on an application like this and i am not getting a starting point
    If possible can you please help me
    Thanks
    Jibin Mathew

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s