Send and update context in an existing conversation

Beyond the basics topic

Learn how to send and update data in existing conversations by using Microsoft Lync 2013 SDK methods.

Applies to: Lync 2013 | Lync Server 2013

In this article
Context overview
Send and update data in an existing conversation
Add context to a conversation
Send a context link
Additional resources

Context overview

Method

Description

BeginSendInitialContext(IEnumerable<KeyValuePair<ContextType, Object>>, AsyncCallback, Object)

BeginSendInitialContext is the setup method. Call it first. This method can be used multiple times in a single conversation, for example, if there is a change in subject and additional data is needed. The data limit's 2,000 characters.

BeginSendContextData(String, String, String, AsyncCallback, Object)

Use BeginSendContextData for more advanced scenarios, such as implementing a command and response protocol, or exchanging large amounts of data. It can only be used after a session is established. However, it can be used again in an existing conversation as often as needed. The data limit's 64,000 characters.

BeginStartConversation(String, Int32, AsyncCallback, Object)

Use the BeginStartConversation method and the values of the AutomationModalitySettings enumerator to add rich context to Lync SDK conversations.

Send and update data in an existing conversation

The following example shows how to use the Conversation.BeginSendInitialContext method.

Dictionary<ContextType, object> context = new Dictionary<ContextType, object>();
context.Add(ContextType.ApplicationId, "{d0722164-f660-470f-a933-e4853f215b77}");
context.Add(ContextType.ApplicationData, "Some data string");
IAsyncResult res = conversation.BeginSendInitialContext(context, null, null);

The following example implements the Conversation.BeginSendContextData method.

string appId = "{d0722164-f660-470f-a933-e4853f215b77}";
string appData = "Some additional data";
IAsyncResult res = conversation.BeginSendContextData(appId, "text/plain", appData, SendAdditionalContextCallback, null);

// Callback method
public void SendAdditionalContextCallback(IAsyncResult res)
{
  conversation.EndSendAdditionalContextData(res);
}

Events

Use the OnInitialContextReceived and OnInitialContextSent events on the Conversation object to notify the application that the conversation received and sent data.

Add context to a conversation

The following example shows how to use the BeginStartConversation method and the values of the AutomationModalitySettings enumerator to add rich context to Lync SDK conversations. Also, use the Conversation.BeginSendInitialContext method.

Dictionary<AutomationModalitySettings, object> _ModalitySettings = new Dictionary<AutomationModalitySettings, object>(); 

// Add the process ID to the modality settings for the conversation.
_ModalitySettings.Add(ApplicationId, "{40499119-4B60-45a6-9A7A-DC7A384D5670}";

// Add application data.
_ModalitySettings.Add(AutomationModalitySettings.ApplicationData, "some application data with you.");

// Declare the string array.
string[] invitees = {″elise@contoso.com"};

IAsyncResult ar =  _Automation.BeginStartConversation(
                    _ChosenMode
                    , invitees
                    , _ModalitySettings
                    , null
                    , null);

// Block main thread until the conversation starts.
_Automation.EndStartConversation(ar);

To send a context link, use the ContextType.HyperLink enumeration.

Dictionary<ContextType, object> context = new Dictionary<ContextType, object>();
context.Add(ContextType.HyperLink, "http://contoso.com");
IAsyncResult res = conversation.BeginSendInitialContext(context, SendContextCallback, null);

See also