Pages Menu

Posted by on Jun 4, 2012 in Skype for Business® (Lync®) | 4 comments

Answering the Call : accepting incoming calls in Lync Client SDK

Answering the Call : accepting incoming calls in Lync Client SDK

Hello? Is that the 1940s?

One of the things you can do with the Lync Client SDK is be notified of incoming calls, and if you wish, answer them.

Although I don’t think automatically answering would necessarily be a good idea (unless you have a dedicated machine, such as in a meeting room), you may have a Screen Pop which appears on incoming calls, and you want the user to be able to click a button to accept the call.

You’d think it would outrageously obvious to do this (and in a way it is), but it can be a bit confusing due to the terminology.

Calls & Conversations

You want to answer a Call. Specifically, you want to answer an AudioVideo (AV) call.

However (and apologies if you already know this), a call is presented to you in a container, called a Conversation. That’s because a Conversation can contain one or many Calls.

Before that starts to sound confusing, it’s important to know that trading messages in a IM session is also a type of Call : specifically a Instant Message Call.

When you start an IM session with another Lync user, a Conversation is created, with a single Call in it – the Instant Message Call. If you then add audio or video, another Call type is created within the same Conversation.

Add desktop sharing? That’s just adding a new Application Sharing Call to your Conversation.

Event Driven

All of this explains why you won’t find a NewAVCall event in the Lync SDK. However, you will find a new Conversation event: ConversationManager.ConversationAdded Event.

This will fire for every new conversation which gets added. This means when someone phones you, a new conversation will be added, and this will fire. However, it also means that if someone sends you an Instant Message, it will fire for that also.

Assuming you only want to accept AV calls, you need a way of separating AV calls from everything else. Within the Conversation object that gets passed from the event is a Modalities IDictionary, containing all the modalities of the conversation.


At first, I just checked in this IDictionary, and if I saw the AudioVideo modality, assumed it must be an AV call. However, this isn’t always the case. It seems that the AV modality will be included on IM-only conversations, if both the sender and receiver can support AV. Not helpful. 😉

However, there is a way to identify whether the AV modality is the one that’s active – by looking at the State of the modality. For an incoming Call the state will move through a couple of different states, but when you look at it will probably be Notified. One of the things it won’t be though is Disconnected – unless it’s an IM-only call. So, I’m checking for AV Calls using:

private bool ContainsAVCall(Conversation c)

return c.Modalities.ContainsKey(ModalityTypes.AudioVideo) && c.Modalities[ModalityTypes.AudioVideo].State != ModalityState.Disconnected;

 Pick Up

Once you’re happy that you want to answer the call, do so! Accepting an incoming AV Call from within a Conversation is as easy as:


Existing Conversations

Because of the way that events are fired at the beginning of a Conversation, and the way that a Conversation can contain multiple Calls, it a conversation starts on IM and is then upscaled to AV, this event won’t fire and the call won’t be picked up. You’ll have to use an alternative method to detect the change in modality/state and react accordingly. (this may become another blog post)


Written by Tom Morgan

Tom is a Microsoft Teams Platform developer and Microsoft MVP who has been blogging for over a decade. Find out more.
Buy the book: Building and Developing Apps & Bots for Microsoft Teams. Now available to purchase online with free updates.


  1. Thanks, that helped me. Now I can also pick up phone calls with my LyncDeviceControl Lync extension. Still testing it but looks good 🙂

  2. Hello Tom,
    I’ve have sloowly been working on a side project and had a question. Not sure if this is possible but, here goes. I added a menu choice to a conversation window. The buttons caption is “Send To TFS”. What is should do it take the current conversation (IM only for now), Brings up the TFS workitem selector window, allow the user to choose a workitem, then save the current conversation into a field in the selected tfs item. I have the tfs stuff worked out already. I am having an issue with capturing the current windows text. Is this even possible?

    Thanks in advanced

  3. Hello Tom.
    Do you know of a way to detect if call is incoming or outgoing?

    I’m using ConversationManagerEventArgs to detect the conversation
    and modalitytypes to know if the call is AV.

    my code:
    void ConversationManager_ConversationAdded(object sender, Microsoft.Lync.Model.Conversation.ConversationManagerEventArgs e)
    if (ModalityIsNotified(e.Conversation, ModalityTypes.AudioVideo))
    //do stuff.

    private bool ModalityIsNotified(Conversation conversation, ModalityTypes modalityType)
    return conversation.Modalities[modalityType].State == ModalityState.Connected;

  4. Hi,
    In the above code, you don’t tell if the Call is incoming or outgoing. I can listen to the Modality.State, at the same time, Open Lync Client and start a new AV Call with someone.

    Is there a way to detect I have an incoming or outgoing AV Call?



  1. Detecting Modality change on Existing Conversations | Developing Lync - [...] change on Existing Conversations2012 July 31tags: lync, lync2013by TomRecently I blogged about how to accept an incoming AV call…
  2. Tracking Lync Conversations in Code using Lync Client SDK | thoughtstuff | Tom Morgan - [...] The first concept to grasp is that calls of any type (such as Instance Message calls, Audio/Video calls, Desktop…
  3. Developing Lync: Tracking Lync Conversations in Code « Lync News - [...] The first concept to grasp is that calls of any type (such as Instance Message calls, Audio/Video calls, Desktop…
  4. Lync Desktop Development: Finding your way around the Client SDK | thoughtstuff | Tom Morgan - […] of communication within a conversation, such as IM, Audio/Video, DesktopShare etc. See my article: Accepting Incoming Calls in Lync…

Post a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.