Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / productivity / Office

Microsoft Lync - Dial and Passcode Automation

5.00/5 (3 votes)
6 Jun 2012CPOL1 min read 23.6K  
Microsoft Lync auto dial and auto passcode.

Introduction

This article covers a quick example of how to use a Windows Forms application in C# to dial a telephone number via Microsoft Lync and then systematically enter a passcode to be used in a conference bridge or other. 

Background

I find myself in 5-10 conference bridges daily. Each one having a different participant passcode. This solution is just a handy way to bypass having to enter those manually each time.

Using the code 

You'll need the Lync SDK downloaded.

http://www.microsoft.com/en-us/download/details.aspx?id=18898 

You'll need to have references to the DLLs of the SDK to the following:

Microsoft.Lync.Controls 

Microsoft.Lync.Controls.Framework 

Microsoft.Lync.Model 

Microsoft.Lync.Utilities. 

This is a Windows Forms application with a single form. 

 

Here are the usings for your class:  

using Microsoft.Lync.Model;
using Microsoft.Lync.Model.Extensibility;
using Microsoft.Lync.Model.Conversation;
using Microsoft.Lync.Model.Conversation.AudioVideo; 

Define these at the class level: 

C#
ConversationWindow globalConv = null;
Automation _Automation = LyncClient.GetAutomation();

For your initial dialing out, you could do this a couple different ways, but this is my current implementation. The txtNum is a form field that contains the phone number being dialed. Note the Async call from BeginStartConversation will goto StartConversationCallback

C#
private void btnDial_Click(object sender, EventArgs e)
{
    List<string> inviteeList = new List<string>();
    inviteeList.Add(txtNum.Text.Trim().ToString());

    // Create a generic Dictionary object to contain conversation setting objects.
    Dictionary<AutomationModalitySettings, object> _ModalitySettings = 
           new Dictionary<AutomationModalitySettings, object>();
    AutomationModalities _ChosenMode = AutomationModalities.Audio;

    _Automation.BeginStartConversation(
        _ChosenMode
        , inviteeList
        , _ModalitySettings
        , StartConversationCallback  //add async method name here
        , null);

}

private void StartConversationCallback(IAsyncResult asyncop)
{
    // this is called once the dialing completes..
    if (asyncop.IsCompleted == true)
    {
        ConversationWindow newConversationWindow = _Automation.EndStartConversation(asyncop);
        globalConv = newConversationWindow;

    }
}

At this point, Lync should have brought up an audio conversation window, dialed the number. So assuming we are calling a conference bridge that requires a passcode to enter. I have a list of possible passcodes on the form and a button to submit passcode. The user would essentially select the passcode in the list and click the button, the event of the button will enter the tones for the passcode to the call converstation window we created earlier.

C#
private void btnSendCode_Click(object sender, EventArgs e)
{
    // first check if globalConv is null
    if (globalConv != null)
    {
        AVModality avModality = globalConv.Conversation.Modalities[ModalityTypes.AudioVideo] as AVModality;
        // get the passcode from the list
        int location = listPassCodes.SelectedIndex;
        if (location != -1)
        {
             string passcodenum = listPassCodes.SelectedItem.ToString().Trim();
             foreach (char c in passcodenum)
             {
                avModality.AudioChannel.BeginSendDtmf(c.ToString(), null, null);
                System.Threading.Thread.Sleep(300);
             }
        }
    }
}

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)