This topic demonstrates how to add context to an instant messaging (IM) conversation using .NET Framework managed code with Microsoft Lync 2010 SDK.
Prerequisites
For a list of prerequisites, see Walkthrough: Start an Instant Message Conversation .
Creating the Contextual Conversation Application
Use the AutomationModalitySettings enumeration to specify conversation context type. This walkthrough specifies ContextualLink as the enumerated type, and a URL as the value. For more information, see Extensibility Enumerations .
To create the contextual conversation application
-
Sign in to Microsoft Lync 2010.
-
In Visual Studio, create a new application. The application can be any type of managed code application. In this procedure you create a Windows Forms application.
-
Add a project reference to Microsoft.Lync.Model. The default location is %ProgramFiles%\Microsoft Lync\SDK\Assemblies\WPF.
-
In Form1.cs add the following using statements.
Copy Code using Microsoft.Lync.Model; using Microsoft.Lync.Model.Extensibility;
-
Add the following declaration to the Form class.
Copy Code ConversationWindow cWindow;
-
In the Form1 constructor, following the InitializeComponent method, add the following code.
Copy Code LyncClient client; client = LyncClient.GetClient(); if (client.State != ClientState.SignedIn) { MessageBox.Show("Lync is not signed in!"); } else { // Create the major API automation object. automation = LyncClient.GetAutomation(); // Create a generic List object to contain a contact URI. // Ensure that a valid URI is added. List<string> inviteeList = new List<string>(); inviteeList.Add("elise@contoso.com"); // Create a generic Dictionary object to contain context objects. Dictionary<AutomationModalitySettings, object> _ModalitySettings = new Dictionary<AutomationModalitySettings, object>(); //Specify that the IM is sent immediately, and the initial text. _ModalitySettings.Add(AutomationModalitySettings.FirstInstantMessage, "good morning"); _ModalitySettings.Add(AutomationModalitySettings.SendFirstInstantMessageImmediately, true); //Specify HyperLink as the modality type, and add a URL. _ModalitySettings.Add(AutomationModalitySettings.HyperLink, "http://www.microsoft.com/en/us/default.aspx"); //Start the conversation. IAsyncResult ar = automation.BeginStartConversation( AutomationModalities.InstantMessage , inviteeList , _ModalitySettings , null , null); //Block the UI thread until the conversation is started and the conversation window is displayed by Lync. cWindow = automation.EndStartConversation(ar); }
-
Add a Button to the form, name it EndConversation and double-click it to add an event handler for the Click event.
Copy Code //End the conversation. private void EndConversation_Click(object sender, EventArgs e) { try { this.cWindow.Close(); } catch (Exception) { } this.Close(); }
-
Build and run the application.
-
A conversation window appears with the text "A contextual link has been provided with this conversation. If the link below looks suspicious do not click on it." followed by the URL provided by the ContextualLink enumeration.
-
Click the button on the Form to end the conversation.