Showing posts with label Lync Programming. Show all posts
Showing posts with label Lync Programming. Show all posts

Monday, December 24, 2012

PowerShell to start Lync group conversation and send message

In previous blog post I had described how I wrote code for myself to achieve a personal task. As people says “Code for yourself before you code for others”, I took that opportunity to improve my life, before I go to solve problems and improve other’s life with my code. But did my problem solved with that small C# code?
I would say 50/50 .Its really difficult to add one more person on the go. I had to open the solution in VSTS then modify the list and run again. I can add users manually with less time than the time taken for Visual Studio to open. I love VS as developer.But as a user I hate as a user. Again keeping an app.config and editing it is equally time consuming like keeping a script which can also be edited on the fly. So what is best.
I would say script. More general PowerShell which has the capability to seamlessly interact with .net.In simple words its very easy to convert a C# / VB.Net code PS. Here goes the PS equivalent of what I posted last week in C#.
cls
$lyncDLLPath = “C:\Program Files\Microsoft Lync\SDK\Assemblies\Desktop\Microsoft.Lync.Model.DLL”
Import-Module $lyncDLLPath
$contactUris="sip:<email1>","sip:<email2>"
 
$client = [Microsoft.Lync.Model.LyncClient]::GetClient()

$conv = $client.ConversationManager.AddConversation()

foreach ($contactUri in $contactUris)
{
    $conv.AddParticipant($client.ContactManager.GetContactByUri($contactUri))
}
$m = $conv.Modalities[[Microsoft.Lync.Model.Conversation.ModalityTypes]::InstantMessage]
$m.BeginSendMessage("Hi guys this is Joy from Powershell,,,Shall we have lunch....", $null, $null);



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);
}