Monday, December 17, 2012

C# to start Lync group conversation and send message

Lunch with colleagues is really fun. We can get tasty food from different homes and different cultures. Some items we can try preparing in home and also will be sharing tips to increase taste and keep food undamaged etc… 1 PM is the time for lunch and somebody will initiate a group chat requesting the group to assemble in the pantry. Obviously we cannot have lunch with all 300 people so there are some local groups formed. Our group is little big of size around 8 and its little difficult to add people one by one in to group chat.

Around a year back company introduced Lync replacing old Office Communicator. One of the advantage of Lync we found is the client side programmatic support. But the chance to program for Lync, came recently. Installed the prerequisite 2010 Lync SDK and started coding using C# console application. Note that the Silverlight 4.0 sdk referred as prerequisite in some sites, is not needed or at least I didn’t install to program Lync.

There is not much code involved .We can summarize the steps as below.

The code explains everything else.

private static void SendLyncMessage()
{
//Uri format in my environement works with sip: protocol'
string[] targetContactUris = { "sip:<email1>", "sip:<email2>" };
LyncClient client = LyncClient.GetClient();
Conversation conv = client.ConversationManager.AddConversation();
foreach (string target in targetContactUris)
{
conv.AddParticipant(client.ContactManager.GetContactByUri(target));
}
InstantMessageModality m = conv.Modalities[ModalityTypes.InstantMessage] as InstantMessageModality;
m.BeginSendMessage("Hi this is from C#", null, null);
}



2 comments:

saiju mathew stephen said...

Joy,

Add all your lunch friends to a group and initiate chat with the group and you can get all your lunch friends in one chat window without adding one by one :)

But good coding otherwise...

Saiju

Joymon said...

Actually that was the motive behind scripting Lync :-)