Consume data and handle events in a contextual conversation
Use Microsoft .NET Framework code and Microsoft Lync 2013 SDK to consume contextual data and handle events in a Lync 2013 conversation.
Applies to: Lync 2013 | Lync Server 2013
In this article |
Send and access contextual data
Use Conversation object methods and events to send and access contextual data in a Lync 2013 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.
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.
Use LaunchLink to access application data
Each LaunchLink 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's 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's 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 How to: Start a Lync IM conversation.