Cookie CSS

Saturday, August 22, 2015

Basic Call Control Using the Lync Client SDK VIIII

There may come a time due to circumstances, you would like a ringing call to just go to your voicemail so you can deal with it later.  Normally hitting ignore on the call is enough to accomplish this, unless you have delegate or call forwarding set up, in which case you can end up with a peer talking to personal caller.  Ooops.  How do we avoid this situation using the Lync (Skype for Business) SDK?

lyncClient lc = LyncClient.GetClient();

1.  Get the conservation in question.

Conversation c = //your ringing conversation

2.  Find your voicemail endpoint

Contact num = lc.self.Contact;

if (c.Modalities[ModalityTypes.AudioVideo].CanInvoke(ModalityAction.Forward))
            {

                List<string> _context = new List<string>();
                Object[] asyncState = { ModalityState.Transferring, _context, c.Modalities[ModalityTypes.AudioVideo] };

                ContactEndpoint ce = null;

                foreach (ContactEndpoint cone in (List<object>)num.GetContactInformation(ContactInformationType.ContactEndpoints))
                {
                    if (cone.Type == ContactEndpointType.VoiceMail)
                    {
                        ce = cone;
                    }
               }

3.  Forward the conversation

                c.Modalities[ModalityTypes.AudioVideo].BeginForward(ce, myar =>
                {

                    try
                    {

                        Object[] _asyncState = (Object[])myar.AsyncState;
                        ModalityState ms = (ModalityState)_asyncState[0];
                        IList<string> _contextProperties = (List<string>)_asyncState[1];

                        c.Modalities[ModalityTypes.AudioVideo].EndForward(myar);

                    }
                    catch (ArgumentException)
                    {
                        Console.WriteLine("Entered Uri is not valid " + num.Uri);
                    }
                    catch (ItemNotFoundException)
                    {
                        Console.WriteLine("Entered Uri could not be resolved to a Contact " + num.Uri);
                    }
                    catch (Exception ex)
                    {
                        System.Diagnostics.StackTrace trace = new System.Diagnostics.StackTrace(ex, true);
                        string er;
                        er = "BlindTransferCallVMMine: Error Trapped in " + Dlib.ProgramSource + ".\r\n";
                        er = er + trace.GetFrame(0).GetMethod().Name + "\r\n" + ex.Message.ToString();
                        er = er + "Line: " + trace.GetFrame(0).GetFileLineNumber();
                        er = er + "Column: " + trace.GetFrame(0).GetFileColumnNumber();
                       Console.WriteLine(er);
                    }


                }, asyncState);

There you have it, next week we'll explore how to forward a ringing call to another user.

Doug Routledge, C# Lync, Skype for Business, SQL, Exchange, UC Developer  BridgeOC
Twitter - @droutledge @ndbridge

No comments:

Post a Comment

Any spam comments will be deleted and your user account will be disabled.