Freigeben über


How to get an incoming PSTN phone no. from communicator window (UC/OCS)

Unified Communication gives you option to configure your PBAX with OCS Server and Communicator. This way you can receive incoming calls using Communicator and it shows a balloon with the incoming phone no. Recently I receive a request to deliver a sample code capable to extract the telephone no. from the Communicator. The person has an ERP application for a support call center. In one of the Win-Form they enter customer’s phone no. to get the details. With this code they can automate it such a way that whenever a rep receives a call, customer’s detail will be automatically available with him/her by a mouse click.

This requirement can be achieved using either UCCA or Communicator Automation API. I preferred Communicator Automation API because it’s easier to implement and very limited coding is required to get the job done. Here is a sample code for a simple console application. Actual application is bigger and complex in nature. But you can easily understand what to do by going through the code:

using System;

using System.Collections.Generic;

using System.Text;

using CommunicatorAPI;

using System.Threading;

using System.Runtime.InteropServices;

using System.Windows.Forms;

namespace ConsoleAppCommunicatorTest

{

    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.SigninName);

            }

            Application.Run(new MainForm(sb.ToString()));

            Console.WriteLine(DateTime.Now.ToString());

            Console.WriteLine(sb.ToString());

          

        }

        void mCommunicator_OnIMWindowDestroyed(object pIMWindow)

        {

            Console.WriteLine("IM Window Destroyed.");

        }

    }

 }

Once you keep this console application running in background, and click on the balloon with incoming phone no. in IM, the time of the incoming call and the phone no. should show up in the console window. Well, the exact phone no. does not show up. It shows like tel:866-425-7701;phone-context=dialstring (SIP URI). But extracting the phone no. from this string should be an easy task for a regular C# programmer.

Comments

  • Anonymous
    September 25, 2010
    Can you perform this same type of method using Visual Basic (including Visual Basic Express)?  I can never find samples using Visual Basic. Thanks.