UCMA如何检测呼叫振铃的持续时间并在忙音和终止之前转接呼叫?

时间:2019-02-04 13:44:46

标签: c# ucma

我有一个具有自我转移功能的b2b呼叫。如果没有应答或座席变得忙碌而无法接听电话,我想重定向到另一个自由座席。我已为传出呼叫分支订阅了ProvisionalResponseReceived,还订阅了StateChanged。因此,我可以看到呼叫何时响铃以及何时从响铃过渡到终止。在呼叫进入终止状态之前,如何将该呼叫转移/转发给另一个座席。有什么方法可以计算出振铃持续时间?还是在我进一步转移之前设置响铃限制?

// Create the outbound call between UCMA and the agent.
        _outboundAVCall = new AudioVideoCall(_outboundConversation);
        // Register for notification of the StateChanged event on the outbound call. 
        _outboundAVCall.StateChanged += new EventHandler<CallStateChangedEventArgs>(outboundAVCall_StateChanged);
        _outboundAVCall.ProvisionalResponseReceived += new EventHandler<CallProvisionalResponseReceivedEventArgs>(OnOutProvisionalResponseReceived);
        //_outboundAVCall.

        InitiateBackToBackCall(incomingCall, _outboundAVCall);

        _outboundCallLeg = new BackToBackCallSettings(outboundCall, _destinationSipUrit);

        incomingCall.StateChanged += new EventHandler<CallStateChangedEventArgs>(inboundAVCall_StateChanged);
        incomingCall.ProvisionalResponseReceived += new EventHandler<CallProvisionalResponseReceivedEventArgs>(OnInProvisionalResponseReceived);

        // incomingCallLeg.StateChanged += OnCallStateChanged;

        // Create a new conversation for the incoming call leg.
        _inboundConversation = new Conversation(incomingCall.Conversation.Endpoint);

        _inboundCallLeg = new BackToBackCallSettings(incomingCall);

        LogHelper.Log(LogTarget.FileEvent, "Status of incomming call:" + incomingCall.State.ToString());
        LogHelper.Log(LogTarget.FileEvent, "Status of incommoutgoing call:" + outboundCall.State.ToString());

        // Create the back-to-back call instance.
        // Note that you need a Destination URI for the outgoing call leg, but not for the incoming call leg.
        _b2bCall = new BackToBackCall(_inboundCallLeg, _outboundCallLeg);
        // Begin the back-to-back session; provide a destination.
        try
        {
            IAsyncResult result = _b2bCall.BeginEstablish(BeginEstablishCB, _b2bCall);
            /* IAsyncResult result = _b2bCall.BeginEstablish(
                delegate(IAsyncResult ar)
            {
                _b2bCall.EndEstablish(ar);
                _waitForB2BCallToEstablish.Set();
            }, _b2bCall);*/
        }
        catch (InvalidOperationException ioe)
        {
            LogHelper.Log(LogTarget.FileEvent, "_b2bCall must be in the Idle state." + ioe.Message.ToString(),1);
        }
        _waitForB2BCallToEstablish.WaitOne();

1 个答案:

答案 0 :(得分:0)

我必须添加代码来处理将要发生的异常

 private void SelfTransferCompleted(IAsyncResult asyncResult)
        {
            Exception exceptionCaught = null;
           // bool exceptionEncountered = true;
            try
            {
                _flow.Call.EndTransfer(asyncResult);
                //Self Transfer has completed. successfully.
                exceptionEncountered = false;
                LogHelper.Log(LogTarget.FileEvent, "IVR Menu Ended self tranfer for call>" +_flow.Call.CallId);
                // cleaning up atten
                string sqlstring = "update astsxqueue set uniqueid ='" + _server.b2bCallDelId + "' where uniqueid='" + _flow.Call.CallId + "';";
                LogHelper.Log(LogTarget.FileEvent, sqlstring);
                _server.mconnector.Mysqlqueryruner(sqlstring);

            }
            catch (OperationTimeoutException orte)
            {
                LogHelper.Log(LogTarget.FileEvent, "IVR SelfTransferCompleted Operation Timeout Exception: " + orte.ToString(), 2);
                exceptionCaught = orte;
                exceptionEncountered = true;
                LogHelper.Log(LogTarget.FileEvent, "IVR SelfTransferCompleted  Trying to transfer to other agent...", 2);
                RetrieveCallAfterTransferFailure();
                //_flow.Call.BeginTransfer("tel:+123456", null/*transferOptions*/, this.SelfTransferCompleted, _flow.Call);
                // _inboundAVCall.Flow.Call.BeginTransfer("tel:+123456", _server.EndTransferCall, _inboundAVCall.Flow.Call);
                //_flow.Call.BeginTransfer("tel:+123456", _server.EndTransferCall, _flow.Call);
                // Wait for the call to complete the transfer.
                LogHelper.Log(LogTarget.FileEvent, "IVR SelfTransferCompleted  Waiting for transfer to complete...");
                _server._waitForTransferComplete.WaitOne();
                LogHelper.Log(LogTarget.FileEvent, "IVR SelfTransferCompleted  Transfer completed.");

            }


            catch (FailureResponseException frte)
            {
                LogHelper.Log(LogTarget.FileEvent, "IVR SelfTransferCompleted  Failure Exception = {0}" + frte.ToString(), 2);
                exceptionCaught = frte;
                exceptionEncountered = true;
                LogHelper.Log(LogTarget.FileEvent, "IVR SelfTransferCompleted  Trying to transfer to other agent...", 2);
                //_flow.Call.BeginTransfer("tel:+123456", null/*transferOptions*/, this.SelfTransferCompleted, _flow.Call);
                // _inboundAVCall.Flow.Call.BeginTransfer("tel:+123456", _server.EndTransferCall, _inboundAVCall.Flow.Call);
                //_flow.Call.BeginTransfer("tel:+123456", _server.EndTransferCall, _flow.Call);
                // Wait for the call to complete the transfer.
                RetrieveCallAfterTransferFailure();
                LogHelper.Log(LogTarget.FileEvent, "Waiting for transfer to complete...");
                _server._waitForTransferComplete.WaitOne();
                LogHelper.Log(LogTarget.FileEvent, "Transfer completed.");

            }

            catch (RealTimeException rte)
            {
                LogHelper.Log(LogTarget.FileEvent, "IVR SelfTransferCompleted  Realtime Exception = {0}" + rte.ToString(),2);
                exceptionCaught = rte;
                exceptionEncountered = true;
                LogHelper.Log(LogTarget.FileEvent, "IVR SelfTransferCompleted  Trying to transfer to other agent...", 2);
                RetrieveCallAfterTransferFailure();
                LogHelper.Log(LogTarget.FileEvent, "IVR Call is retreived waiting a bit...", 2);
               // Thread.Sleep(2000);
                LogHelper.Log(LogTarget.FileEvent, "IVR Call is retreived time passed...", 2);
               // _flow.EndHold(null);

             //   _speechSynthesizer.Speak("We did not get to a green agent. Please retry your option!");  //TEXT TO SPEEECH!
              // SpeakMenuOptions();
             // toneController.ToneReceived += toneController_ToneReceived;
                // Wait for the call to complete the transfer.
                LogHelper.Log(LogTarget.FileEvent, "Waiting for transfer to complete...");
                //_server._waitForTransferComplete.Set();
                LogHelper.Log(LogTarget.FileEvent, "Transfer completed.");

            }

        }
        private void RetrieveCallAfterTransferFailure()
        {
            // Take the call off of hold after a transfer fails.
            LogHelper.Log(LogTarget.FileEvent, "IVR Trying to retrive from Self transfer ...", 2);

            try
            {
                _flow.BeginRetrieve(retrieveResult =>
                {
                    try
                    {
                        LogHelper.Log(LogTarget.FileEvent, "IVR  Trying to retrive from Self transfer ...", 2);
                        Thread.Sleep(1000);

                        _flow.EndRetrieve(retrieveResult);

                        LogHelper.Log(LogTarget.FileEvent, "IVR  Successfully retrieved call. Waiting a bit");
                        LogHelper.Log(LogTarget.FileEvent, "IVR Call is retreived time passed...", 1);
                        //_flow.EndHold(retrieveResult);
                        Thread.Sleep(2000);
           //             _flow.EndRetrieve(retrieveResult);
               //         _speechSynthesizer.Speak("A green agent is busy. Please retry your option!");  //TEXT TO SPEEECH!
                 //       SpeakMenuOptions();
                   //    toneController.ToneReceived += toneController_ToneReceived;


                    }
                    catch (RealTimeException rtex)
                    {
                        LogHelper.Log(LogTarget.FileEvent, "IVR  Failed retrieving call." + rtex);
                    }
                },
                null);
            }
            catch (InvalidOperationException ioex)
            {
                LogHelper.Log(LogTarget.FileEvent, "IVR Failed retrieving call."+ ioex);
            }
        }

添加以上代码后,我就可以使用它。

谢谢。