Lync Client, PowerShell, Scripting
comments 3

Auto answering incoming calls in Lync only from a specific contact using PowerShell

In my last post, I showed how to auto answer incoming Lync calls in PowerShell. I also mentioned that the code provided there does not really care about who is calling you. It simply auto answers calls from anyone. This may not be a desired thing in real-life.

If you don’t have Lync SDK installed (it comes with a lot of unnecessary baggage), you can just copy the model DLL at ”C:\Program Files (x86)\Microsoft Lync\SDK\Assemblies\Desktop\Microsoft.Lync.Model.Dll” from a machine that has Lync SDK installed. This should be sufficient for the task outlined in this post.

As I’d mentioned in the post, the Lync Conversation namespace provides the necessary properties to detect who is calling us. We can use the Participants property of this namespace to enumerate the contact information for an incoming conversation.

Before we dive deep into the details here, let us see a technique to easily walk-through the Conversation namespace when we receive a ConversationAdded event. The idea is simple. Whenever this event gets triggered, we assign the event details to a global variable that we can access outside of the event subscriber. In fact, this is a technique I use to understand several eventing methods.

So, with the above code in place, we can see the event details in the $myEvent variable in the global scope. Now, let us see some properties that we can use to examine the details of an incoming call:

gives us the information about the Lync user logged on to the local system.

gives the information about all the participants in the newly started Lync conversation or incoming call.

Now, within the Participant namespace, the contact property has the information about the SIP Uri for all the participants. The participant property also includes another piece of information that tells us if a participant is self participant or not. Self participant here means that the given contact is a locally logged on user. This is represented by Participant.IsSelf or in the case of event subscriber’s -Action script block, it will be:

Now, there are two ways to retrieve all participants of an incoming conversation who are not self participants. This can be done using a simple if statement or a Compare-Object. And, then, we can either accept or reject the incoming call.

Let us see the first method:

Simple. Right? in this case, we reject any incoming calls that do not include the specified SIP Uri.

Now, let us put this back in the event subscriber -Action script block to see if we can auto-answer calls only from a specific contact. For that, we need to change Register-ObjectEvent command to reflect the following:

The Reject Method takes a set of reasons. You cannot just specify any value. The reason should be a part of the ModalityDisconnectReason Enumeration.

This is it for now. We shall see more on working with Lync contacts in the upcoming posts. Stay tuned.

Filed under: Lync Client, PowerShell, Scripting

by

Ravikanth is a principal engineer and the lead architect for Microsoft and VMware virtualized and hybrid cloud solutions within the Infrastructure Solutions Group at Dell EMC. He is a multi-year recipient of Microsoft Most Valuable Professional (MVP) award in Windows PowerShell (CDM) and Microsoft Azure. Ravikanth is the author of Windows PowerShell Desired State Configuration Revealed (Apress) and leads Bangalore PowerShell and Bangalore IT Pro user groups. He can be seen speaking regularly at local user group events and conferences in India and abroad.