Tuesday, July 17, 2012

Microsoft Lync Group Chat integration using C#

Recently we've been playing around with different ways of integrating and re-purposing Microsoft Lync and it's various server/client components into interesting applications with valuable and useful features. Over the past few weeks we've been working internally with the Lync Group Chat SDK, developing some prototypes for applications that could extend the functionality of the Group Chat rooms for other organizations.

For example, we are developing some applications that will monitor various services, such as email accounts or twitter feeds, and automically dispatch alerts into a Lync 2010 group chat room. 

Before we start with the code samples, I'll outline the system requirements below for packages to have installed.

Below is an example of a simple Group Chat task. This console application will log in to the Lync Server, log in to the Group Chat server, search for the chat room specified, join the chat room, send a sample chat message, and then disconnect from the room, chat server, and Lync server. This example provides a pretty comprehensive look at all the steps needed to perform simple to complex tasks on the Group Chat server using the Lync SDK and the Group Chat SDK.

For this application, we'll use the NDesk.Options library to parse our command line options to build up our message. Additionally, the configuration for the Group Chat settings is stored in an app.config file, which I'll outline below.

First, we build our Common class. This class holds some common variables which we'll use throughout the application, and some Group Chat specific functionality.

Some points about Common.cs:
  1. When building our UserEndpoint, we specify this application using the ClientPlatformSettings class, which for our console application, will give use a bit more ease of use and flexibility, rather than using the ServerPlatformSettings class.
  2. When joining a chat room, we first search for the room, and return a ChatRoomSnapshot. This snapshot provides us the information we need to then join the room using our Common.RoomJoinExisting method.

Next, we'll build up our actual program logic in Program.cs. This file holds 2 classes, our DispatchMessage class, and our Chat class. DispatchMethod is a simple object to hold the values that we'll be chatting into the chat room. This includes the message body, subject (if a story), if this message is an alert, and the name of the room we are looking to join. Our Chat class holds some various methods that we use at runtime, as well as our Main() program.

Some notes about Program.cs:

  1. After the NDesk.Options library parses the command line arguments, it populates the DispatchMessage class/object. Once this is complete, it runs through it's main try/catch block, which logs in to Lync, logs in to the Group Chat server, finds the room, and joins it.
  2. Once we have our session established, we move through our RoomChat method. This method reads from the DispatchMessage class/object and builds the actual chat message, then pushes it to the room.
  3. After the message has been posted, we leave room and disconnect our sessions.
In your app.config file, make sure to add the keys/values below to configure the environment settings for the application. We'll discuss what these keys mean below.

  <add key="OcsServer" value="######" />
  <add key="LookupServerUri" value="sip:###@###.###" />
  <add key="UserSipUri" value="sip:###@###.###" />
  <add key="Username" value="###@###.###" />
  <add key="Password" value="###" />
  • OcsServer
    • This is the server name to the Lync Front End Pool (probably something like 'lync.you.com' or 'lync.company.local'
  • LookupServerUri
    • This is the service account in SIP format that was setup with the Group Chat server. In our environment sip://ocschat@instant.local
  • UserSipUri
    • This is the account you'd like to send messages into the chat room as, in SIP format. This should be different than the LookupServerUri, and should be on the list of members for the chat room.
  • Username
    • The Active Directory user name that the user logs in to Lync as. Generally DOMAIN\username or username@domain.com or local.
  • Password
    • The users Active Directory password. Should be hashed or stored in some other fashion, but for our example, its plain-text in the file.
Once the program is built, run the .exe with the -? option to see the full help text, which will give you the parameters and syntax to run the program.

Using this core functionality we've wired up some protypes using Exchange Web Services, as well as Twitter's API. In Exchange, we monitor an inbox, when something arrives we parse out it's information, and send it to the appropriate chat room. Below, on the left you'll see the email drafted to the designated box, and on the right, the message as it appears as a story in the chat room.

For Twitter, we have the ability to watch user's Tweets, and track hashtags or other search queries. Below you'll see the tweet, as well as the message from our watched Twitter user in the chat room, complete with clickable links and some basic information.


Anonymous said...

I love seeing this. I worked at the company that made the Lync group chat component which MSFT acquired in 2007. Please don't judge the product based on what you see today as MSFT has done a horrible job bringing in the full functionality. For example, the email integration you created with the SDK was a feature we included with our product that we simply called "email bridge". There are still customers out there using the original Parlano product that have several systems directly integrated into the chat rooms publishing content.

Still great to see this. I only stumbled on this as my current firm is deploying Lync and I'm shocked that the IM and group chat interface is not integrated...simply absurd. It is very sad to see how great innovation died at MSFT.

Anonymous said...

Hello everybody,

I want to make a web chat which can communicate with Lync group of our company (like a LiveChat). Can somebody help me how I do that?

Instant said...

Thanks for the question! We've explored a few ways of doing web chat within Lync, but as of now, we only have this functionality with communicating with single users, not groups of users. We've been looking to add this functionality into a product currently in development. For some information about staging a web client for use with Lync, take a look at a previous blog entry we did about the subject here.

nitin said...

How to find LookupServerUri in Lync Server?

Mary Petter said...

Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here. Kindly keep blogging. If anyone wants to become a .Net developer learn from .Net Core Training in Chennai. or learn thru .Net Core Training in Chennai. Nowadays Dot Net has tons of job opportunities on various vertical industry.
or Es6 Training in Chennai. Nowadays JavaScript has tons of job opportunities on various vertical industry.

Transfer Abha said...

شركة نقل عفش بابها من افضل شركات نقل العفش والاثاث بمدينة ابها بخصومات كبيره للعملاء ارخص اسعار سيارات نقل الاثاث بابها

AK Gamer said...

Wow, What a Excellent post. I really found this to much informatics. It is what i was searching for.I would like to suggest you that please keep sharing such type of info.Thanks chatrooms

Accident Lawyer said...

Accident Need Save Yourself, Save the World For any car automobile accident personal injury Lawyer and Attorney Advice Also, all automobile and car insurance quotes guidance for free

tamilsasi said...

Some us know all relating to the compelling medium you present powerful steps on this blog and therefore strongly encourage
contribution from other ones on this subject while our own child is truly discovering a great deal.
Have fun with the remaining portion of the year.
Selenium training in bangalore
Selenium training in Chennai
Selenium training in Bangalore
Selenium training in Pune
Selenium Online training

Maria said...

My first online casino solely best casino in which I played. Just want to highlight a very beautiful design and convenience and beauty in all games. The presence of public tables testifies first of all to casino honesty - nobody twists the roulette wheel specially - at least =).

jones elizabeth said...

I am impressed by the information you have on this blog. It shows how well you understand this subject. stranger chat free

Iprint Calendar said...

What you require to do is to click on any of the 2019 monthly calendar template word shared here as per your choice