Cookie CSS

Saturday, August 8, 2015

Basic Call Control Using the Lync Client SDK VII

As I start writing part VII of my series on Basic Call Control in the Lync (Skype for Business) SDK I am beginning to wonder if I shouldn't combine these and more into an eBook and post it on Technet.  Last week we talked about "The Safe Transfer" which keeps the caller engaged with a human being rather than voicemail.  This week we'll explore off system transfers, specifically how do I transfer a call to someones cellphone?



One thing about the learning the SDK is it does some things for you, which in this example makes it a bit harder.  For example you would think we could call GetContactFromUri(cellphone) and get the URI of the users cellphone, say tel:17015554444, and call or transfer to it, like any phone number your Lync client doesn't know about right?  Well since Lync can pull AD info if that cellphone number is tied to a user, it will actually return the SIP uri and the call won't go to the cellphone, but the Lync client instead.  So how do we overcome this and transfer to the mobile?  Don't sweat it, it's a simple 3 step process and I will go through each step below.

1.  Get the Contact

Let's get a contact object first by doing a search

Conversation c;  //the conversation to transfer
Contact num = LyncClient.ContactManager.GetContactByUri(string search);

 public static void BlindTransferCallCell(Conversation c, Contact num, TransferOptions topt)
        {

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

2.  Browse the Contact's endpoints


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.MobilePhone)
                    {
                        ce = cone;
                    }
}

3.  Transfer the call to the mobile endpoint

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

                    try
                    {

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

                        c.Modalities[ModalityTypes.AudioVideo].EndTransfer(out ms, out _contextProperties, 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 = "BlindTransferCallCell: 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);

The takeaway here is when we are tying to transfer a call to a specific contact's number, not the sip uri, we need to transfer to the ContactEndpoint object instead of the Contact.

Thanks for tuning in and I will see you next week.

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

3 comments:

  1. This is great, is there a powershell equivialnt?

    ive gotten as far as making a call I need to transfer the call

    ReplyDelete
  2. This is great, is there a powershell equivialnt?

    ive gotten as far as making a call I need to transfer the call

    ReplyDelete
    Replies
    1. I personally have not used it with powershell, but it is possible. Check out this blog post http://trevorsullivan.net/2014/06/26/automating-the-lync-client-with-powershell/

      Delete

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