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

  1. Sign in to Microsoft Lync 2010.

  2. 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.

  3. Add a project reference to Microsoft.Lync.Model. The default location is %ProgramFiles%\Microsoft Lync\SDK\Assemblies\WPF.

  4. In Form1.cs add the following using statements.

      Copy imageCopy Code
    using Microsoft.Lync.Model;
    using Microsoft.Lync.Model.Extensibility;
    
  5. Add the following declaration to the Form class.

      Copy imageCopy Code
    ConversationWindow cWindow;
    
  6. In the Form1 constructor, following the InitializeComponent method, add the following code.

      Copy imageCopy 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);
    }
    
  7. Add a Button to the form, name it EndConversation and double-click it to add an event handler for the Click event.

      Copy imageCopy Code
    //End the conversation.
    private void EndConversation_Click(object sender, EventArgs e)
    {
      try
      {
    	this.cWindow.Close();
      }
      catch (Exception) { }
      this.Close();
    }
    
  8. Build and run the application.

  9. 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.

  10. Click the button on the Form to end the conversation.

See Also