Cookie CSS

Saturday, July 25, 2015

Basic Call Control Using the Lync Client SDK V

Last week we looked at how to blind transfer a call using the Lync client SDK, which also works on Skype for business.  This week we'll dig a little deeper into the transfers and expose another method.  Back in the old days of the pbx, you would have lines, say line 1, 2,  and 3.  A call would come in, you would put it on hold, and then call the internal user and tell them which line to pickup.  This was fine, for small companies, but what if you had 2 T1 lines coming in?  Joe you have a call on line 47, image the training involved and the size of the phone that would be occupying your desk.  Yuck.  Then IP telephony came alone, and we got an easier way to communicate with the internal caller to see what they wanted to do with the outside call, the supervised transfer was born.  So what are the mechanics involved in the Lync SDK to make a supervised transfer?

1.  The consult call

A consult call is the call from you to the person the call is for, it occurs while the waiting caller is placed on hold.  The code can look something like this.

string destination = "1234";

Conversation myco = MakeCallConsult(destination);

2.  The supervised transfer

Once this call is dialed and connected you can as the caller at dn 1234 what they would like you do with the outside caller.  If they want the call the supervised transfer procedure below works, where you pass the outside conversation first, and the consult call conversation last.

SupervisedTransfer(Outsideconv, null, TransferOptions.None, myco);

private void SupervisedTransfer(Conversation c, Contact num, TransferOptions topt, Conversation b)
{

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

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




                c.Modalities[ModalityTypes.AudioVideo].BeginConsultativeTransfer(b, topt, myar =>
                {

                    try
                    {

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

                        c.Modalities[ModalityTypes.AudioVideo].EndConsultativeTransfer(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 = "SupervisedTransferCall: 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);
            }

}

Once it reaches the EndConsultativeTransfer section you will be disconnected from the outside call and the original source and preferred destination user and now connected on the audio call.

That's a wrap for this week, next week we'll work are way further down the rabbit hole.

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

1 comment:

  1. Hi Doug, thanks for the brilliant blog posts on Lync. Do you have a sample running of the consultative transfer call, to share it? Thanks

    ReplyDelete

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