Saturday, June 21, 2008

The first steps of programming Office Communicator

Hi there.

The last three weeks has been very exciting and the future is going to bring even greater things. You will probably ask you self why I would write this and to answer this I will use a few lines to explain.

My name is Peter and for the last few years been working in the telecommunication business. A month ago I was lucky enough to get employed by Inceptio to do consulting and development on the UC platform (E.g. OCS and Exchange).

For some time I have being reading and fooling around with the Office Communicator 2007 API SDK and it has been fun and at times frustrating. The reason for this post is to share ideas and possibilities provided by Microsoft UC platform. So to start from the beginning I thought of bringing a small and simple example and I will then continue to post more advanced samples based upon my own experiences with UC development. Below is my first example that shows how to hookup to some of the events that the Office Communicator 2007 Client exposes. Basically it writes a message in the console every time a new conversation windows starts or closes.

The example down below can be the foundation for an application that helps in retrieving information about the incoming caller. Information like calling history, email conversations, location information, billing information, project information. As one se the possibilities is endless.

In my next blog entry I will start to add functionality to retrieve some of the above mentioned information types.

Until then... 

using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
namespace EventFun
{
class EventHookUp
{
CommunicatorAPI.Messenger mCommunicator = null;
static void Main(string[] args)
{
EventHookUp hu = new EventHookUp();
hu.InitializeEventHocks();
Console.ReadKey();
}
public void InitializeEventHocks()
{
mCommunicator = new CommunicatorAPI.Messenger();
mCommunicator.OnIMWindowCreated += new CommunicatorAPI.DMessengerEvents_OnIMWindowCreatedEventHandler(mCommunicator_OnIMWindowCreated);
mCommunicator.OnIMWindowDestroyed += new CommunicatorAPI.DMessengerEvents_OnIMWindowDestroyedEventHandler(mCommunicator_OnIMWindowDestroyed);
}
void mCommunicator_OnIMWindowCreated(object pIMWindow)
{
CommunicatorAPI.IMessengerConversationWndAdvanced stpIMWindow = pIMWindow as CommunicatorAPI.IMessengerConversationWndAdvanced;
long Hwnd = (long)stpIMWindow.HWND;
Console.WriteLine("New IM Window Created : {0}", Hwnd);

//Listing Frindly name of the caller.
CommunicatorAPI.IMessengerContacts contactList = (CommunicatorAPI.IMessengerContacts)stpIMWindow.Contacts;
StringBuilder sb = new StringBuilder();
foreach (CommunicatorAPI.IMessengerContact imc in contactList)
{
sb.Append(imc.FriendlyName);
sb.Append(Environment.NewLine);
}
Console.WriteLine(sb.ToString());
}
void mCommunicator_OnIMWindowDestroyed(object pIMWindow)
{
Console.WriteLine("IM Window Destroyed.");
}
}
}



If you want to read more about the API’s then take a look at these posts/blogs



Chris Mayo -> http://blogs.msdn.com/cmayo/



Michael Dunn -> http://blogs.msdn.com/midunn/



George Durzi -> http://blogs.claritycon.com/blogs/george_durzi/default.aspx

5 comments:

Anonymous said...

Hi, is it possible to get phone number of an incoming call before starting a conversation window?

Thanks,
Chatura

Peter Lyck Ingerslev said...

Hi Chatura,
For the moment I honestly do not know. For the last weeks I have only look into the Microsoft Office Communicator Automation API SDK and for what I can see there it is not supported by this SDK. It would surprise me if it was not possible. For the future I will have your request I mind and try to find you the better answer. But until then what you can do(not pretty but works) is when DMessengerEvents::OnIMWindowCreated is firing you can check the incoming call id with IMessengerConversationWnd::Contacts. If the windows should not be visible you can call the IMessengerWindow::Close.

Kind regards

Peter

Greg said...

How about initiating a new Office Communicator Conversation by clicking a link on a web page?

How would I construct such a link?
(Just to get the conversation opened, and maybe a first line sent...)

Thanks

T-Lo said...

Hi there :)

Nice article!

What i want to do is to develop an Console Application which takes one argument - a name of a person. It should initiate/open up a chat window with that person.

While googling around for the MOC API SDK i found your article.
From which reference/namespace is the class EventHookUp coming? Is it part of the SDK?

Cheers!

Anonymous said...

I added the above two events in Console Application. But lo luck. These two function are not getting called at all.


mCommunicator.OnIMWindowCreated += new CommunicatorAPI.DMessengerEvents_OnIMWindowCreatedEventHandler(mCommunicator_OnIMWindowCreated);
mCommunicator.OnIMWindowDestroyed += new CommunicatorAPI.DMessengerEvents_OnIMWindowDestroyedEventHandler(mCommunicator_OnIMWindowDestroyed);

Can any one help me what I'm missing?

Thank You,
Javed