Lync 2010 SDK: how do I get the user's voicemail URI?

1.2k Views Asked by At

I'm writing a simple C# application that answers a Lync call and depending on a database value, forwards it to another phone number. That works perfectly. However, sometimes I want to forward the call to the user's voicemail. I can't figure out how to get the URI for the voicemail box :(

Assuming I'm in the handler for a ConversationAdded event. I've tried this:

Conversation conv = args.Conversation;
string voicemailURI = String.Format("{0};opaque=app:voicemail",conv.SelfParticipant.Contact.Uri);
// the contact returned here, however, does not contain the opaque=app:voicemail
Contact forwardContact = lync.ContactManager.GetContactByUri(voicemailURI);

Also:

Conversation conv = args.Conversation;
// following throws ArgumentException: Value does not fall within the expected range
Phone voicemail = lync.Self.GetPhone(ContactEndpointType.VoiceMail);
string voicemailURI = voicemail.Endpoint.Uri
Contact forwardContact = lync.ContactManager.GetContactByUri(voicemailURI);

UC voicemail is setup and working otherwise. I'm not sure what the term is exactly, but it's handled by Exchange and the messages appear in my Inbox. If I just let the phone ring it will eventually end up in voicemail, but my app knows it should go there right away so I'd like to forward it immediately.

1

There are 1 best solutions below

0
On

I guess I'm not quite sure why you care about getting the contact? Your first example will give you the URI to go directly to voicemail. At that point you can just do this:

        var automation = LyncClient.GetAutomation();
        var conversationModes = AutomationModalities.Audio;
        var conversationSettings = new Dictionary<AutomationModalitySettings, object>();
        List<string> participants = new List<string>();
        Conversation conv = args.Conversation;            
        string voicemailURI = String.Format("{0};opaque=app:voicemail",conv.SelfParticipant.Contact.Uri);
        participants.Add(voicemailUri);
        automation.BeginStartConversation(AutomationModalities.Audio, participants, null, StartConversationCallback, automation);