Exemplo n.º 1
0
 public JObject TransferCall(String connection, int agentId, int accountId, int callId, int toAgentId, Boolean isWarmTransfer)
 {
     try
     {
         Press3.DataAccessLayer.Calls callsObject = new Press3.DataAccessLayer.Calls(connection);
         DataSet ds = callsObject.TransferCall(agentId, accountId, callId, toAgentId, isWarmTransfer);
         if (ds == null)
         {
             helper.CreateProperty(UDC.Label.MESSAGE, "No data returned from database");
             helper.CreateProperty(UDC.Label.SUCCESS, false);
         }
         else
         {
             JObject hangupResponse = new JObject();
             JObject dialResponse   = new JObject();
             if (ds.Tables[0].Rows.Count > 0)
             {
                 if (ds.Tables["OutputParameters"].Rows[0]["Success"].ToString() == "True")
                 {
                     dialResponse = Dial(ds, connection, isWarmTransfer, toAgentId);
                     if (Convert.ToBoolean(dialResponse.SelectToken("Success").ToString()))
                     {
                         //if (ds.Tables[0].Rows[0]["OriginationUrl"].ToString() == "user/")
                         if ((ds.Tables[0].Rows[0]["OriginationUrl"].ToString() != null) && (!ds.Tables[0].Rows[0]["OriginationUrl"].ToString().Contains("verto")))
                         {
                             string callType = "";
                             if (!isWarmTransfer)
                             {
                                 callType = "2";
                             }
                             else
                             {
                                 callType = "3";
                             }
                             Logger.Info("AgentWarmTransferId:" + toAgentId.ToString());
                             StringBuilder publishData = new StringBuilder();
                             JObject       messageJobj = new JObject(new JProperty("Channel_Name", "Agent_" + toAgentId.ToString()),
                                                                     new JProperty("CallId", callId),
                                                                     new JProperty("ConferenceRoom", ds.Tables[0].Rows[0]["ConferenceRoom"].ToString()),
                                                                     new JProperty("FromNumber", ds.Tables[0].Rows[0]["Source"].ToString()),
                                                                     new JProperty("IsAgent", false),
                                                                     new JProperty("CallType", callType),
                                                                     new JProperty("RequestUUID", ""),
                                                                     new JProperty("Event", "enter"));
                             Press3.DataAccessLayer.WebSocketController WSCObj = new Press3.DataAccessLayer.WebSocketController(connection);
                             WSCObj.InsertWsNofificationQueue(messageJobj.ToString());
                             ds.Trace(messageJobj);
                         }
                     }
                 }
             }
             helper.ParseDataSet(ds);
             helper.CreateProperty("ToAgentRequestUUID", dialResponse.SelectToken("RequestUUID").ToString());
         }
     }
     catch (Exception ex)
     {
         helper.CreateProperty("RetMessage", ex.ToString());
         Logger.Error("Exception In AgentLogout " + ex.ToString());
     }
     return(helper.GetResponse());
 }
Exemplo n.º 2
0
        public JObject UpdateCallDetails(HttpContext context, string connectionString, string outboundCallBackUrl, bool isCustomer, int agentId, string voiceClipPath)
        {
            JObject  resObj = new JObject();
            Gateways gatewayObj = new Gateways();
            DataSet  ds = null;
            string   conferenceRoom = ""; string gatewayURL = "";

            try
            {
                ParseParameters(context);
                UDC.OutboundCall callObj = new UDC.OutboundCall();
                Press3.DataAccessLayer.OutboundCall outboundCallObj = new Press3.DataAccessLayer.OutboundCall(connectionString);

                if (httpParameters.Event == "newcall")
                {
                    callObj.Event      = httpParameters.Event;
                    callObj.Id         = httpParameters.SequenceNumber;
                    callObj.IsCustomer = isCustomer;
                    if (!isCustomer)
                    {
                        JObject messageJobj = new JObject(new JProperty("Channel_Name", "Agent_o_" + httpParameters.CallUUid),
                                                          new JProperty("Message", httpParameters.CallStatus),
                                                          new JProperty("CallId", httpParameters.SequenceNumber),
                                                          new JProperty("Event", httpParameters.Event));
                        Press3.DataAccessLayer.WebSocketController WSCObj = new Press3.DataAccessLayer.WebSocketController(connectionString);
                        WSCObj.InsertWsNofificationQueue(messageJobj.ToString());
                    }
                    Logger.Info("WebSocket newcall event");

                    ds = outboundCallObj.UpdateCallDetails(callObj);
                    if (ds == null)
                    {
                        helper.CreateProperty(UDC.Label.MESSAGE, "No data returned from database");
                        helper.CreateProperty(UDC.Label.SUCCESS, false);
                    }
                    else
                    {
                        ds = outboundCallObj.GetAgentConferenceRoom(httpParameters.SequenceNumber);
                        if (ds == null)
                        {
                            helper.CreateProperty(UDC.Label.MESSAGE, "No data returned from database");
                            helper.CreateProperty(UDC.Label.SUCCESS, false);
                        }
                        else
                        {
                            if (ds.Tables.Count > 0)
                            {
                                if (Convert.ToBoolean(ds.Tables[0].Rows[0]["Success"]))
                                {
                                    conferenceRoom = ds.Tables[0].Rows[0]["ConferenceRoom"].ToString();
                                }
                            }
                        }

                        if (isCustomer)
                        {
                            if (conferenceRoom != "")
                            {
                                helper.CreateProperty(UDC.Label.RESPONSEXML, "<Response><Conference callbackUrl='" + outboundCallBackUrl + "?IsCustomer=true&amp;AgentId=" + agentId + "'>" + conferenceRoom + "</Conference></Response>");
                            }
                            else
                            {
                                helper.CreateProperty(UDC.Label.RESPONSEXML, "<Response></Hangup></Response>");
                            }
                        }
                        else
                        {
                            helper.CreateProperty(UDC.Label.RESPONSEXML, "<Response><Conference waitSound='" + voiceClipPath + "AloneWaitClip.mp3' callbackUrl='" + outboundCallBackUrl + "?IsCustomer=false&amp;AgentId=" + agentId + "'>" + httpParameters.CallUUid + "</Conference></Response>");
                        }
                        helper.ParseDataSet(ds);
                    }
                }
                else if (httpParameters.Event == "hangup")
                {
                    callObj.Event             = httpParameters.Event;
                    callObj.Id                = httpParameters.SequenceNumber;
                    callObj.RingTime          = httpParameters.RingTIme;
                    callObj.AnswerTime        = httpParameters.StartTime;
                    callObj.EndTime           = httpParameters.EndTime;
                    callObj.EndReason         = httpParameters.EndReason;
                    callObj.HangupDisposition = httpParameters.HangupDisposition;
                    callObj.IsCustomer        = isCustomer;

                    JObject messageJobj = new JObject();
                    Press3.DataAccessLayer.WebSocketController WSCObj = new Press3.DataAccessLayer.WebSocketController(connectionString);

                    if (!isCustomer)
                    {
                        messageJobj = new JObject(new JProperty("Channel_Name", "Agent_o_" + httpParameters.CallUUid),
                                                  new JProperty("Message", httpParameters.EndReason),
                                                  new JProperty("CallId", httpParameters.SequenceNumber),
                                                  new JProperty("Event", httpParameters.Event));
                        WSCObj.InsertWsNofificationQueue(messageJobj.ToString());
                    }


                    ds = outboundCallObj.UpdateCallDetails(callObj);
                    if (ds == null)
                    {
                        helper.CreateProperty(UDC.Label.MESSAGE, "No data returned from database");
                        helper.CreateProperty(UDC.Label.SUCCESS, false);
                    }
                    else
                    {
                        ds = outboundCallObj.GetAgentConferenceRoom(httpParameters.SequenceNumber);
                        if (ds == null)
                        {
                            helper.CreateProperty(UDC.Label.MESSAGE, "No data returned from database");
                            helper.CreateProperty(UDC.Label.SUCCESS, false);
                        }
                        else
                        {
                            if (ds.Tables.Count > 0)
                            {
                                if (Convert.ToBoolean(ds.Tables[0].Rows[0]["Success"]))
                                {
                                    gatewayURL     = ds.Tables[0].Rows[0]["GatewayURL"].ToString();
                                    conferenceRoom = ds.Tables[0].Rows[0]["ConferenceRoom"].ToString();
                                }
                            }
                        }
                        helper.ParseDataSet(ds);
                    }


                    messageJobj = new JObject(new JProperty("Channel_Name", "Agent_" + agentId),
                                              new JProperty("CallId", httpParameters.SequenceNumber.ToString()),
                                              new JProperty("ConferenceRoom", conferenceRoom),
                                              new JProperty("FromNumber", httpParameters.FromNumber),
                                              new JProperty("IsAgent", true),
                                              new JProperty("CallType", 1),
                                              new JProperty("RequestUUID", httpParameters.RequestUuid),
                                              new JProperty("IsOutbound", 1),
                                              new JProperty("Event", "exit"));
                    WSCObj.InsertWsNofificationQueue(messageJobj.ToString());
                    Logger.Info("WebSocket hangup event");


                    JObject  apiResponseObj                   = new JObject();
                    JObject  apiResponseObjPrivate            = new JObject();
                    Gateways gatewaysObj                      = new Gateways();
                    Press3.DataAccessLayer.Conference confObj = new Press3.DataAccessLayer.Conference(connectionString);
                    apiResponseObj        = gatewaysObj.RestApiRequest("ConferenceName=" + conferenceRoom + "&MemberID=all", gatewayURL + "ConferenceHangup/", "POST");
                    apiResponseObjPrivate = gatewaysObj.RestApiRequest("ConferenceName=private_" + conferenceRoom + "&MemberID=all", gatewayURL + "ConferenceHangup/", "POST");

                    if (isCustomer)
                    {
                        ds = outboundCallObj.UpdateCallBackRequestStatus(callObj);
                        if (ds == null)
                        {
                            helper.CreateProperty(UDC.Label.MESSAGE, "No data returned from database");
                            helper.CreateProperty(UDC.Label.SUCCESS, false);
                        }
                        else
                        {
                            helper.ParseDataSet(ds);
                        }
                    }
                }
                else if (httpParameters.Event == "conference" && httpParameters.ConferenceAction == "enter")
                {
                    callObj.Id               = httpParameters.SequenceNumber;
                    callObj.Event            = httpParameters.Event;
                    callObj.ConferenceAction = httpParameters.ConferenceAction;
                    callObj.RequestUUID      = httpParameters.RequestUuid;
                    callObj.Source           = httpParameters.FromNumber;
                    callObj.Destination      = httpParameters.ToNumber;
                    callObj.FsMemberId       = httpParameters.ConferenceMemberID;
                    callObj.IsCustomer       = isCustomer;
                    callObj.EventTimeStamp   = httpParameters.Eventtimestamp;
                    callObj.ConferenceName   = httpParameters.ConferenceName;
                    callObj.AgentId          = agentId;

                    if (isCustomer)
                    {
                        if (!httpParameters.ConferenceName.StartsWith("private"))
                        {
                            JObject messageJobj = new JObject(new JProperty("Channel_Name", "Agent_" + agentId),
                                                              new JProperty("CallId", httpParameters.SequenceNumber.ToString()),
                                                              new JProperty("ConferenceRoom", httpParameters.ConferenceName),
                                                              new JProperty("FromNumber", httpParameters.FromNumber),
                                                              new JProperty("IsAgent", true),
                                                              new JProperty("CallType", 1),
                                                              new JProperty("RequestUUID", httpParameters.RequestUuid),
                                                              new JProperty("IsOutbound", 1),
                                                              new JProperty("Event", httpParameters.ConferenceAction));
                            Press3.DataAccessLayer.WebSocketController WSCObj = new Press3.DataAccessLayer.WebSocketController(connectionString);
                            WSCObj.InsertWsNofificationQueue(messageJobj.ToString());
                        }
                    }
                    else
                    {
                        JObject messageJobj = new JObject(new JProperty("Channel_Name", "Agent_" + agentId),
                                                          new JProperty("CallId", httpParameters.SequenceNumber.ToString()),
                                                          new JProperty("ConferenceRoom", httpParameters.ConferenceName),
                                                          new JProperty("FromNumber", httpParameters.FromNumber),
                                                          new JProperty("IsAgent", true),
                                                          new JProperty("CallType", 9),
                                                          new JProperty("RequestUUID", httpParameters.RequestUuid),
                                                          new JProperty("IsOutbound", 1),
                                                          new JProperty("ConferenceEvent", httpParameters.ConferenceAction),
                                                          new JProperty("Event", "CustomerOutBound"));
                        Press3.DataAccessLayer.WebSocketController WSCObj = new Press3.DataAccessLayer.WebSocketController(connectionString);
                        WSCObj.InsertWsNofificationQueue(messageJobj.ToString());
                    }

                    ds = outboundCallObj.UpdateOutboundConferenceDetails(callObj);
                    if (ds == null)
                    {
                        helper.CreateProperty(UDC.Label.MESSAGE, "No data returned from database");
                        helper.CreateProperty(UDC.Label.SUCCESS, false);
                    }
                    else
                    {
                        helper.ParseDataSet(ds);
                    }
                }
                else if (httpParameters.Event == "conference" && httpParameters.ConferenceAction == "exit")
                {
                    callObj.Id               = httpParameters.SequenceNumber;
                    callObj.Event            = httpParameters.Event;
                    callObj.ConferenceAction = httpParameters.ConferenceAction;
                    callObj.FsMemberId       = httpParameters.ConferenceMemberID;
                    callObj.EventTimeStamp   = httpParameters.Eventtimestamp;

                    ds = outboundCallObj.UpdateOutboundConferenceDetails(callObj);
                    if (ds == null)
                    {
                        helper.CreateProperty(UDC.Label.MESSAGE, "No data returned from database");
                        helper.CreateProperty(UDC.Label.SUCCESS, false);
                    }
                    else
                    {
                        helper.ParseDataSet(ds);
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Error("Exception in BAL.UpdateCallDetails" + ex.ToString());
            }
            return(helper.GetResponse());
        }