This seems pretty basic, but I couldn’t find on the web how to do this.
I have the following code:
public static void StartChatWithUser(Microsoft.Lync.Model.Contact imContact, string title = null)
{
try
{
var lyncClient = Microsoft.Lync.Model.LyncClient.GetClient();
var conversation = lyncClient.ConversationManager.AddConversation();
conversation.AddParticipant(imContact);
if (!string.IsNullOrEmpty(title))
{
conversation.Properties[Microsoft.Lync.Model.Conversation.ConversationProperty.Subject] = title;
}
var im = conversation.Modalities[Microsoft.Lync.Model.Conversation.ModalityTypes.InstantMessage];
if (im.CanInvoke(Microsoft.Lync.Model.Conversation.ModalityAction.Connect))
{
im.BeginConnect((ar) => { if (ar.IsCompleted) { ((Microsoft.Lync.Model.Conversation.InstantMessageModality)ar.AsyncState).EndConnect(ar); } }, im);
}
}
catch( Exception x )
{
//Handle exception
}
}
This “sort-of” works, since it opens the contact window and starts a chat – meaning the other side is requested to join the chat.
Is there a way for me to open the Conversation Window without initiating the chat with the other user (I want it the same way as when I double click a user in the Lync contact list).
posted the same question at the Lync Client Dev. TechNet forum: http://lksz.me/s8Yn8a.
Thanks in advance.
My final result
Thanks to the answer provided by MOHAMED A. SAKAR and ckeller, I fixed my code, and here is my new method.
Thanks guys
The following using clause is needed:
using Microsoft.Lync.Model.Extensibility;
And here is the new code:
public static void StartChatWithUser(Microsoft.Lync.Model.Contact imContact, string title = null)
{
try
{
var lyncAutomation = Microsoft.Lync.Model.LyncClient.GetAutomation();
var inviteeList = new string[] { imContact.Uri };
var modalitySettings = new Dictionary<AutomationModalitySettings, object>();
modalitySettings.Add(AutomationModalitySettings.SendFirstInstantMessageImmediately, false);
if (string.IsNullOrEmpty(title))
{
modalitySettings.Add(AutomationModalitySettings.Subject, title);
}
lyncAutomation.BeginStartConversation(
AutomationModalities.InstantMessage,
inviteeList,
modalitySettings,
(ar) => { if (ar.IsCompleted) { ((Automation)ar.AsyncState).EndStartConversation(ar); }},
lyncAutomation);
}
catch( Exception x )
{
//Handle exception
}
}
you should first create Dictionary of AutomationModalitySettings and their values:
After that you should initiate these modalities:
after that you could initiate the call
I hope this helps you