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 using
s 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:
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
:
private void btnDial_Click(object sender, EventArgs e)
{
List<string> inviteeList = new List<string>();
inviteeList.Add(txtNum.Text.Trim().ToString());
Dictionary<AutomationModalitySettings, object> _ModalitySettings =
new Dictionary<AutomationModalitySettings, object>();
AutomationModalities _ChosenMode = AutomationModalities.Audio;
_Automation.BeginStartConversation(
_ChosenMode
, inviteeList
, _ModalitySettings
, StartConversationCallback
, null);
}
private void StartConversationCallback(IAsyncResult asyncop)
{
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.
private void btnSendCode_Click(object sender, EventArgs e)
{
if (globalConv != null)
{
AVModality avModality = globalConv.Conversation.Modalities[ModalityTypes.AudioVideo] as AVModality;
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);
}
}
}
}