Add Office Communicator Presence and Communication to Any App

From my post yesterday on the Office Communicator Automation API, I can use the API to add presence and communication features to my apps, including:

  1. Embed Presence with Application Specific Contact Lists – use the API to build contact lists specific to my application and show Office Communicator presence for those contacts.
  2. Launch Communications – add IM, voice and video communications directly in my application to allow users to communicate and collaborate directly from the application.
  3. Application Context Specific Communication – use the API to integrate data from the application into conversations the application launches to provide application specific context for the conversation.

An Example: Office Communicator Integration into Outlook 2007

The integration of Office Communicator 2007 R2 into Outlook 2007 provides a great example of how the OC API can be used to build compelling presence and communication features into an app. 

If you look an an email in Outlook 2007 after Office Communicator 2007 R2 has been installed, you can see two interesting new features.  First, the From:, To: and Cc: lines now show the contact presence and a context menu similar to what you see in Office Communicator for everyone on the email thread. 

 

EmailWithPresAndRespondMenus

 

Second, in the email Ribbon you can see that the Respond area of the Message tab now has options for responding with both IM and voice.

 

EmailWithShowingRespondMenu

 

I can use these options to start a conversation with the sender of the mail or the entire email thread.  For example, if I select the “Call all” menu item the API will use Office Communicator to start a conference call with everyone on the thread.

 

LaunchedConCall

 

When each recipient accepts the concall invitation, they get a link back to the email that was used to start the conversation.  This is often called the context of the conversation (why Chris is calling).  For example, Adam would see the following.

 

ConcallOnAdamsComputer

When Adam, or anyone on the concall, clicks that link the email that was used to launch the call is opened so each participant can start the conversation with the same context.

 

EmailOnAdamsComputer

 

The Outlook 2007 example above provides a concrete example of the features you can build using the Office Communicator Automation API, including:

  1. Embed Presence with Application Specific Contact Lists – the contacts shown in the email on the From:, To: and Cc: lines are an example of an application specific contact list.  Note these contacts aren’t necessarily contacts in the local user’s Office Communicator contact list.
  2. Launch Communications – the presence context menus and the IM and Call menus in the ribbon allow Outlook 2007 users to start conversations directly from Outlook 2007.
  3. Application Context Specific Communication – the link to the IM conversation and the opening of the email from that link are examples of using application data as context for a conversation and building a feature for interpreting that context (such as opening the email).

The WPF Presence Controls Sample

I talk to a lot of developers who want to embed Office Communicator presence and communications into their apps.  While you can build a solution from scratch using the Office Communicator Automation API, there’s a great WPF control sample to help you build these features into your apps quickly.

The WPF Presence Controls for Office Communicator 2007 sample provides WPF controls with full source code to allow you to build these features into your apps quickly.  The sample provides a number of interesting controls, including:

  • MyPersona – used to show the presence of the local user signed in to Office Communicator.
  • Persona – used to show the presence icon and context menu for a given contact based on their SIP URI.
  • PersonaList – a list of Persona controls used to display application specific contact lists.

For example, after downloading and installing the sample, I can build a simple application to show the presence of the local user and a custom contact list.

 

SimpleWPFPresApp

 

The Persona control shows a context menu similar to what you see in Office Communicator.  Note the custom menu item titled “Inventory Request” at the bottom of the context menu.  Custom menu items allow you to extend the control with custom communication features.

 

The XAML for this Window is pretty straightforward:

 

<Window x:Class="WpfPresenceControls.Window1"

   xmlns="https://schemas.microsoft.com/winfx/2006/xaml/presentation"

   xmlns:x="https://schemas.microsoft.com/winfx/2006/xaml"

   xmlns:presence="clr-namespace:Microsoft.Samples.Office.UnifiedCommunications.PresenceControls;assembly=WPFMOCPresenceControls"

   Title="WPF Presence Controls" Height="187" Width="300">

    <Grid ShowGridLines="False">

        <Grid.ColumnDefinitions>

            <ColumnDefinition Width="*" />

        </Grid.ColumnDefinitions>

        <Grid.RowDefinitions>

            <RowDefinition Height="50" />

            <RowDefinition Height="100" />

        </Grid.RowDefinitions>

 

        <presence:MyPersona x:Name="myPersona" Grid.Column="0" Grid.Row="0"/>

        <presence:PersonaList x:Name="personaList1" Grid.Column="0" Grid.Row="1"

                         ShowContextMenu="True"

                         ShowDisplayName="True"

                         ShowAvailability="True"

                         ShowToolTip="True"

                         ShowDetailedToolTipText="True"/>

    </Grid>

</Window>

 

The MyPersona control uses the API to get the presence information for the local user.  The Persona and PersonaList controls need the SIP URIs for a contact to display that same presence information.  For example, the following code was used to populate the PersonaList control and create the custom context menu item:

 

using System;

using Microsoft.Samples.Office.UnifiedCommunications.PresenceBase;

 

namespace WpfPresenceControls

{

    /// <summary>

    /// Interaction logic for Window1.xaml

    /// </summary>

    public partial class Window1 : Window

    {

        public Window1()

        {

            InitializeComponent();

 

      // Create a list of contacts specific to your application.

            // Note: They don't have to be contacts in the

            // local user's contact list.

            List<string> sipUris = new List<String>()

            {

                "adamb@uc.contoso.com",

                "rl@uc.contoso.com",

                "jamesa@uc.contoso.com"

            };

 

            // Add the list of contacts to the SipUris property

            // to populate the control.

            personaList1.SipUris = sipUris;

 

            // Create a new menu item for your application specific

            // communication feature.

            List<MenuItem> customItems = new List<MenuItem>();

 

            MenuItem customMenuItem1 = new MenuItem();

            customMenuItem1.Header = "Inventory Request";

            customMenuItem1.Name = "inventoryRequest";

 

            customItems.Add(customMenuItem1);

 

            personaList1.CustomMenuItemList = customItems;

 

            personaList1.CustomMenuItemClicked +=

                new EventHandler<CustomMenuItemClickedEventArgs>

                    (personaList1_CustomMenuItemClicked);

 

        }

 

        void personaList1_CustomMenuItemClicked(object sender, CustomMenuItemClickedEventArgs e)

        {

 

        }

    }

}

 

If I clicked on the “Communicator Call” menu item in the image above, the API would use Office Communicator to place the call between Rebecca and Chris.

 

SimpleWPFAppCall

 

In the image above, the sample application and Chris’s conversation window are on the left.  On the right, you can see running Rebecca’s desktop including her conversation window from Chris. 

Embedding application data into the conversation as context and interpreting that context in your application deserves it’s own post, so I’ll come back to that subject. 

 

There are also sample controls for WinForms and Win32 shipping in the Microsoft Office Communicator 2007 Presence Controls.