Esempio n. 1
0
        public JObject Dial(DataSet dial, string connection, Boolean isWarmTransfer, int toAgentId)
        {
            JObject responseJobj = new JObject();
            string  postData = "", answerXml = "";
            bool    isAgenttransfer = true;
            bool    isVertoPhone    = false;
            string  callBackUrl     = System.Web.Configuration.WebConfigurationManager.AppSettings["CallBackUrl"].ToString();
            string  answerUrl       = System.Web.Configuration.WebConfigurationManager.AppSettings["AnswerUrl"].ToString();
            string  hangupUrl       = System.Web.Configuration.WebConfigurationManager.AppSettings["HangupUrl"].ToString();

            try
            {
                if (isWarmTransfer)
                {
                    isAgenttransfer = false;
                }
                if (dial.Tables[0].Rows[0]["OriginationUrl"].ToString() == "verto.rtc/")
                {
                    isVertoPhone = true;
                }

                Press3.BusinessRulesLayer.Gateways gatewayObj = new Press3.BusinessRulesLayer.Gateways();
                answerXml  = "<Response><Conference callbackMethod='GET'  callbackUrl='" + callBackUrl + "?ChannelName=Agent_" + Convert.ToString(toAgentId) + "&#38;IsVertoPhone=" + isVertoPhone.ToString() + "&#38;IsAgent=true&#38;isTransferToAgent=" + isAgenttransfer.ToString() + "&#38;TalkingAgentRequestUUID=";
                answerXml += dial.Tables[0].Rows[0]["TalkingAgentRequestUUID"].ToString() + "&#38;CallerSequenceNumber=" + dial.Tables[0].Rows[0]["CallerSequenceNumber"].ToString();
                answerXml += "&#38;CallerFsMemberId=" + dial.Tables[0].Rows[0]["CallerFsMemberId"].ToString() + "&#38;IsWarmTransfer=" + isWarmTransfer.ToString();
                answerXml += "&#38;GatewayURL=" + dial.Tables[0].Rows[0]["HttpUrl"].ToString() + "' >" + dial.Tables[0].Rows[0]["ConferenceRoom"].ToString() + "</Conference></Response>";
                Logger.Info("answerXml " + answerXml);
                postData  = "AnswerXml=" + System.Web.HttpUtility.UrlEncode(answerXml) + "&Prioraty=H&SequenceNumber=" + dial.Tables[0].Rows[0]["SequenceNumber"].ToString();
                postData += "&From=" + dial.Tables[0].Rows[0]["Source"].ToString() + "&To=" + dial.Tables[0].Rows[0]["Destination"].ToString();
                postData += "&OriginateSleep=1&AnswerUrl=" + answerUrl + "&Gateways=" + dial.Tables[0].Rows[0]["OriginationUrl"].ToString();
                postData += "&HangupUrl=" + hangupUrl + "&ExtraDialString=" + System.Web.HttpUtility.UrlEncode(dial.Tables[0].Rows[0]["ExtraDialString"].ToString());
                Logger.Info("postData " + postData);
                responseJobj = gatewayObj.RestApiRequest(postData, dial.Tables[0].Rows[0]["HttpUrl"].ToString() + "Call/", "POST");
                Logger.Info("responseJobj " + responseJobj);
                if (Convert.ToBoolean(responseJobj.SelectToken("Success").ToString()))
                {
                    var uuid      = responseJobj.SelectToken("RequestUUID").ToString();
                    var seqNumber = Convert.ToInt32(dial.Tables[0].Rows[0]["SequenceNumber"].ToString());
                    Press3.DataAccessLayer.Conference conferenceObj = new Press3.DataAccessLayer.Conference(connection);
                    conferenceObj.UpdateConferenceRequestUUID(uuid, seqNumber);
                }
                else
                {
                    responseJobj = new JObject(new JProperty("Success", false),
                                               new JProperty("Message", "Can not transfer call right now"));
                    //responseXml = "<Response><Hangup data='Issue in connect agent'/></Response>";
                }
            }
            catch (Exception ex)
            {
                responseJobj = new JObject(new JProperty("Success", false),
                                           new JProperty("Message", "Can not transfer call right now"));
                Logger.Error("Error in Class --> Calls, Method --> Dial, Exception -->" + ex.ToString());
            }

            return(responseJobj);
        }
Esempio 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());
        }