JensB
JensB

Reputation: 6850

C# Automatically answer calls in LYNC

I would like to automatically answer ANY incomming call in LYNC.

Using the SDK I can detect an incomming call. The method below gets called if any one is calling me with voice or video.

void AVModalityStateChanged(object sender, ModalityStateChangedEventArgs e)
{
    if (e.NewState == ModalityState.Notified)
    {
        // someone is calling me
    }
}

But i now need help with how to answer this call.

My entire Lync connection class can be viewed here: http://www.pastebucket.com/2293

This is going to be used in a conference room setting where it would be nice if it was enough to just dial the room and the people at the other end dont have to do anything.

Upvotes: 2

Views: 3273

Answers (1)

Tom Morgan
Tom Morgan

Reputation: 2365

Your better bet will be to subscribe to an event which gets raised on an incoming call, rather than on the state change. That's because the incoming event contains a handle to the call object, which you can then use to accept the call.

Have a look at the ConversationManager.ConversationAdded event. This gets raised for incoming IM and AV conversations (including AV calls).

The slightly tricky bit to grasp is that you get notified about an incoming Conversation but it's actually the Call which you want to accept. That's OK though, because the Call object is contained within the Conversation object, which is part of the EventArgs that get passed.

Let's assume for a moment that you only want to accept AV calls, and not IM calls. So, the first thing you need to do is see whether the Conversation you've just been notified is actually an AV Call. You can tell this by looking at the Modalities of the Conversation using the ConversationManagerEventArgs which is passed from the event. e.Conversation.Modalities contains all the modalities of the incoming conversation.

Assuming it was an AV call (and to finally answer your original question!), you can then accept the call with:

e.Conversation.Modalities[ModalityTypes.AudioVideo].Accept();

Hope this helps. I'm going to be doing a blog post about this soon with a bit more detail, so I'll try and remember to update this answer with that once it's done.

edit: Blog post written with a bit more detail, and is here: http://thoughtstuff.co.uk/2012/06/answering-the-call-accepting-incoming-calls-in-lync-client-sdk/

Upvotes: 5

Related Questions