Share via


Consume Data and Handle Events in a Lync 2010 Contextual Conversation

Use Microsoft .NET Framework code and the Microsoft Lync 2010 SDK to consume contextual data and handle events in a Microsoft Lync 2010 conversation. This topic and the accompanying video demonstrate how to use methods and events provided in the Lync SDK to send and receive contextual data.

Send and Access Contextual Data

Use Conversation object methods and events to send and access contextual data in a Lync 2010 conversation.

Sending Data

Use the BeginSendInitialContext and BeginSendContextData methods to send and update data in existing conversations. For more information, see Send and Update Context in an Existing Conversation with Lync 2010 SDK.

Accessing Data

On the receiver side, use the InitialContextReceived event to access data.

public void OnInitialContextReceived(Microsoft.Lync.Model.Conversation.Conversation eventSource, Microsoft.Lync.Model.Conversation.ContextEventArgs eventData)
        {
            try
            {
                string appId = eventData.ApplicationId;
                string appData = eventData.ApplicationData;
                Log(Color.Blue, string.Format(
                    "ContextualConversation_OnContextReceived AppId={0}, AppData={1}",
                    appId, appData
                    ));
            }
            catch (Exception ex)
            {
                Log(ex);
            }
        }

On the sender side, use the InitialContextSent event to access data.

public void OnInitialContextSent(Microsoft.Lync.Model.Conversation.Conversation eventSource, Microsoft.Lync.Model.Conversation.ContextEventArgs eventData)
        {
            try
            {
                string appId = eventData.ApplicationId;
                string appData = eventData.ApplicationData;
                Log(Color.Blue, string.Format(
                    "ContextualConversation_OnContextSent AppId={0}, AppData={1}",
                    appId, appData
                    ));
                string sourceAppData = eventSource.GetApplicationData(appId);
            }
            catch (Exception ex)
            {
                Log(ex);
            }
        }

Use the GetApplicationData method on the Conversation object to access the most recent initial context. The most recent initial context is what the user has just sent or received using the BeginSendInitialData or BeginStartConversation methods. GetApplicationData returns no other context sent or received through BeginSendContextData.

Each launch link has data embedded in the start URL. Clicking the link starts the application together with the corresponding application data and raises the ConversationContextLinkClicked event. LaunchLink appears in the conversation history when a user sends or receives a contextual conversation tied to a contextual application whose registration data contains a Path value. Clicking the link executes the Path+Parameters values. If there is a %AppData% parameter in the Parameters value it will be replaced with the data embedded in the LaunchLink. The click also raises the LinkClicked event which delivers the application data to the application if it is running. If the application is not running the event is missed.

public void OnConversationContextLinkClicked(uc.Conversation eventSource, uc.ContextEventData eventData)
        {
            try
            {
                Log(Color.Blue, string.Format("ContextualConversation_OnLaunchLinkClicked AppId={0}, AppData={1}",
                    eventData.ApplicationId, eventData.ApplicationData
                    ));
            }
            catch (Exception ex)
            {
                Log(ex);
            }
        }

Handle the ConversationAdded Event

Use the ConversationAdded() event for conversation handling. ConversationAdded provides access to Conversation and ConversationWindow objects. To review example code that shows how to use the ConversationAdded event, see Walkthrough: Start an IM Conversation (Lync 2010 SDK).

See Also

Other Resources

Video: Lync Contextual Data Part 2: Methods and Events

Lync Extensibility API Contextual Conversations (Lync 2010 SDK)