예제 #1
0
        public JObject MakeOutboundCall(string connection, int accountId, int agentId, int customerId, string callUUID, string customerCallUUID, bool isCustomer, string outboundCallBackUrl, int cbrId)
        {
            Press3.DataAccessLayer.Calls callsObject = new Press3.DataAccessLayer.Calls(connection);
            Gateways gatewayObj = new Gateways();
            JObject  resObj     = new JObject();

            try
            {
                DataSet ds = callsObject.MakeOutboundCall(accountId, agentId, customerId, callUUID, customerCallUUID, isCustomer, cbrId);
                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 (ds.Tables[0].TableName == "Calls")
                        {
                            if (isCustomer)
                            {
                                string postData = ""; string originationUrl = "";
                                postData       += "From=" + ds.Tables[0].Rows[0]["FromNumber"] + "&To=" + ds.Tables[0].Rows[0]["ToNumber"] + "";
                                postData       += "&SequenceNumber=" + ds.Tables[0].Rows[0]["CallId"] + "&OriginationUUID=" + ds.Tables[0].Rows[0]["CustomerCallUUID"] + "";
                                postData       += "&Gateways=" + ds.Tables[0].Rows[0]["Gateway"] + "&AnswerUrl=" + outboundCallBackUrl + "?IsCustomer=true" + HttpUtility.UrlEncode("&") + "AgentId=" + agentId + "";
                                postData       += "&HangupUrl=" + outboundCallBackUrl + "?IsCustomer=true" + HttpUtility.UrlEncode("&") + "AgentId=" + agentId + "";
                                originationUrl += ds.Tables[0].Rows[0]["GatewayURL"];
                                resObj          = gatewayObj.RestApiRequest(postData, originationUrl + "Call/", "POST");
                            }
                            else
                            {
                                string postData = ""; string originationUrl = "";
                                postData       += "From=" + ds.Tables[0].Rows[0]["FromNumber"] + "&To=" + ds.Tables[0].Rows[0]["ToNumber"] + "";
                                postData       += "&SequenceNumber=" + ds.Tables[0].Rows[0]["CallId"] + "&OriginationUUID=" + ds.Tables[0].Rows[0]["CallUUID"] + "";
                                postData       += "&Gateways=" + ds.Tables[0].Rows[0]["Gateway"] + "&AnswerUrl=" + outboundCallBackUrl + "?IsCustomer=false" + HttpUtility.UrlEncode("&") + "AgentId=" + agentId + "";
                                postData       += "&HangupUrl=" + outboundCallBackUrl + "?IsCustomer=false" + HttpUtility.UrlEncode("&") + "AgentId=" + agentId + "";;
                                originationUrl += ds.Tables[0].Rows[0]["GatewayURL"];
                                resObj          = gatewayObj.RestApiRequest(postData, originationUrl + "Call/", "POST");
                            }
                            resObj.Add("CallId", ds.Tables[0].Rows[0]["CallId"].ToString());
                        }
                        else
                        {
                            resObj = new JObject(new JProperty("Success", "False"), new JProperty("Message", ds.Tables[0].Rows[0]["Message"]));
                            Logger.Error("Exception In MakeOutboundCall:" + ds.Tables[0].Rows[0]["Message"]);
                        }
                    }
                    else
                    {
                        resObj = new JObject(new JProperty("Success", "False"), new JProperty("Message", "No data returned from database"));
                        Logger.Error("Exception In MakeOutboundCall: No data returned from database");
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Error("Exception In MakeOutboundCall " + ex.ToString());
            }
            return(resObj);
        }
예제 #2
0
        public string GetXml(HttpContext context, string connectionString)
        {
            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();
            string  conferenceCallBackUrl = System.Web.Configuration.WebConfigurationManager.AppSettings["ConferenceCallBackURL"].ToString();
            Int32   accountId             = 0;
            string  responseXml           = "";
            JObject responseData          = new JObject();
            Helper  helper = new Press3.BusinessRulesLayer.Helper();

            UDC.ReadRestParameters restParameters = new UDC.ReadRestParameters(context);
            try
            {
                Logger.Info("Event:" + restParameters.CallEvent);
                if (restParameters.CallEvent.Equals("getkeys"))
                {
                    DAL.DirectDialExtension dialExtObj = new DAL.DirectDialExtension(connectionString);
                    DataSet ds = new DataSet();
                    if (!string.IsNullOrEmpty(restParameters.Digits))
                    {
                        ds = dialExtObj.DialExtension(restParameters);
                        //if (ds != null)
                        //{
                        //    helper.ParseDataSet(ds);
                        //    responseData = helper.GetResponse();
                        //    responseXml = responseData.SelectToken("ResponseXML").ToString();
                        //    //Make Call to Agent with AnswerXml <Conference>{cutomer_call_request_uuid}</Conference>
                        //    //From,To,AnswerUrl,HangupUrl,AnswerXml
                        //    //AnswerUrl={domain}/DirectDial.ashx HangupUrlSame
                        //    //
                        //    //if (ds.Tables.Count > 1)
                        //    //{
                        //    //    JArray gatewayDetailsObj = (responseData.SelectToken("GatewayDetails") as JArray) as JArray;
                        //    //}
                        //}
                        //else
                        //{
                        //    responseXml = "<Response><Hangup data='No data return from database'/></Response>";
                        //}
                        if (ds != null)
                        {
                            helper.ParseDataSet(ds);
                            responseData = helper.GetResponse();
                            responseXml  = responseData.SelectToken("ResponseXML").ToString();
                            Press3.DataAccessLayer.Conference conferenceObj = new Press3.DataAccessLayer.Conference(connectionString);
                            if (!string.IsNullOrEmpty(Convert.ToString(responseData.SelectToken("AccountId"))))
                            {
                                accountId = Convert.ToInt32(responseData.SelectToken("AccountId").ToString());
                            }
                            //if (accountId > 0)
                            //{
                            //    ManagerDashBoardCounts(connectionString, accountId);
                            //}
                            if (ds.Tables.Count > 1)
                            {
                                JArray   gatewayDetailsObj = (responseData.SelectToken("GatewayDetails") as JArray) as JArray;
                                Gateways gatewaysObj       = new Gateways();
                                string   postingData       = "";
                                JObject  restApiResponse   = new JObject();
                                string   answerXml         = "";
                                foreach (JObject j in gatewayDetailsObj)
                                {
                                    Logger.Info("GatewayDetails loop in direct dial Extension:" + j.ToString());
                                    restApiResponse = new JObject();
                                    string ringUrl     = callBackUrl + "?ChannelName=Agent_" + (j.SelectToken("AgentId")) + "&IsVertoPhone=" + (j.SelectToken("OriginationUrl").ToString().Contains("verto.rtc") ? "true" : "false") + "&IsAgent=true&isTransferToAgent=false&IsRingUrl=true";
                                    string digitsMatch = "digitsMatch='" + j.SelectToken("ConferenceDigits") + "'";

                                    //answerXml = "<Response><Conference stayAlone='true' callbackMethod='GET' callbackUrl='" + callBackUrl + "?ChannelName=Agent_" + (j.SelectToken("AgentId")) + "&#38;IsVertoPhone=" + (j.SelectToken("OriginationUrl").ToString().Contains("verto.rtc") ? "true" : "false") + "&#38;IsAgent=true&#38;isTransferToAgent=false";
                                    answerXml = "<Response><Conference " + digitsMatch + " stayAlone='true' callbackMethod='GET' callbackUrl='" + callBackUrl + "?ChannelName=Agent_" + (j.SelectToken("AgentId")) + "&#38;IsVertoPhone=" + (j.SelectToken("OriginationUrl").ToString().Contains("verto.rtc") ? "true" : "false") + "&#38;IsAgent=true&#38;isTransferToAgent=false";

                                    answerXml += "&#38;GatewayURL=" + j.SelectToken("HttpUrl").ToString() + "' >" + j.SelectToken("Room") + "</Conference></Response>";

                                    //  postingData = "RingUrl=" + HttpUtility.UrlEncode(ringUrl) + "&AnswerXml=" + System.Web.HttpUtility.UrlEncode(answerXml) + "&Priority=H&SequenceNumber=" + j.SelectToken("SequenceNumber") + "&From=";
                                    postingData  = "AnswerXml=" + System.Web.HttpUtility.UrlEncode(answerXml) + "&Priority=H&SequenceNumber=" + j.SelectToken("SequenceNumber") + "&From=";
                                    postingData += j.SelectToken("Source") + "&To=" + j.SelectToken("Number") + "&OriginateSleep=1&AnswerUrl=" + conferenceCallBackUrl + "&Gateways=";
                                    postingData += j.SelectToken("OriginationUrl") + "&HangupUrl=" + hangupUrl + "&ExtraDialString=" + System.Web.HttpUtility.UrlEncode(j.SelectToken("ExtraDialString").ToString());
                                    Logger.Info("call Request Executing to The server in dial extension : " + j.SelectToken("HttpUrl").ToString() + "posting data " + postingData.ToString());
                                    // Logger.Info("httpurl " + j.SelectToken("HttpUrl").ToString());


                                    restApiResponse = gatewaysObj.RestApiRequest(postingData, j.SelectToken("HttpUrl").ToString() + "Call/", "POST");
                                    if (Convert.ToBoolean(restApiResponse.SelectToken("Success").ToString()))
                                    {
                                        Logger.Debug("Call Initiated Response in dial Extension:" + restApiResponse);
                                        var uuid      = restApiResponse.SelectToken("RequestUUID").ToString();
                                        var seqNumber = Convert.ToInt32(j.SelectToken("SequenceNumber").ToString());
                                        conferenceObj.UpdateConferenceRequestUUID(uuid, seqNumber);
                                    }
                                    else
                                    {
                                        Logger.Info("Call Request not Success in dial extension please check Ycom Rest logs for more info payload:" + postingData);
                                        responseXml = "<Response><Hangup data='Issue in connect agent in dial extension'/></Response>";
                                    }
                                }
                            }
                            responseXml = "<Response>" + responseXml + "</Response>";
                        }
                        else
                        {
                            responseXml = "<Response><Hangup data='No data return from database'/></Response>";
                        }
                    }
                }
            }catch (Exception ex) {
                Logger.Error(ex.ToString());
            }
            return(responseXml);
        }
예제 #3
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());
        }
        public string GetStudioXml(HttpContext context, string connectionString, bool isQueuedCall = false, bool IsCbrCall = false)
        {
            string  responseXml  = "";
            Int32   accountId    = 0;
            DataSet ds           = new DataSet();
            JObject responseData = new JObject();

            helper = new Press3.BusinessRulesLayer.Helper();


            //    Logger.Info("Connect to Queue GetStudioXml Started is QueuedCall:"+isQueuedCall+",IsCbrCall:"+IsCbrCall);
            try
            {
                Press3.DataAccessLayer.Conference     conferenceObj = new Press3.DataAccessLayer.Conference(connectionString);
                Press3.DataAccessLayer.GetStudioXmlV1 getStudioXml  = new DataAccessLayer.GetStudioXmlV1(connectionString);
                httpParameters.ParseParameters(context);

                Logger.Info("Incoming call received from:" + httpParameters.FromNumber + ",ToNumber:" + httpParameters.ToNumber + ",Queued Call:" + isQueuedCall + ",Is callBackRequest call:" + IsCbrCall);

                if (string.IsNullOrEmpty(httpParameters.CallStatus) || string.IsNullOrEmpty(httpParameters.ToNumber) || string.IsNullOrEmpty(httpParameters.FromNumber) || string.IsNullOrEmpty(httpParameters.Event))
                {
                    Logger.Debug("Mandatory Parameters are Missing from Connecting to Queue Agent:Callstatus:" + httpParameters.CallStatus + ",Tonumber:" + httpParameters.ToNumber + ",FromNumber:" + httpParameters.FromNumber + ",Event:" + httpParameters.Event);
                    responseXml = "<Response><Hangup data='Mandatory Parameter Missing from connect to agent'/></Response>";
                }
                else
                {
                    if (isQueuedCall)
                    {
                        Logger.Info("It is in Queued Call for fetching agent from connect to agent CallUuid:" + httpParameters.CallUUid + ",SequenceNUmber:" + httpParameters.SequenceNumber);
                        ds = getStudioXml.GetAgentQueueXml(httpParameters);
                    }
                    else if (IsCbrCall)
                    {
                        Logger.Info("It is in  callback request Call  processing cbr Queue CallUuid:" + httpParameters.CallUUid + ",SequenceNUmber:" + httpParameters.SequenceNumber);
                        ds = getStudioXml.GetCbrQueueXml(httpParameters);
                    }

                    else
                    {
                        ds = getStudioXml.StudioXml(httpParameters);
                    }

                    if (ds != null)
                    {
                        helper.ParseDataSet(ds);
                        responseData = helper.GetResponse();
                        responseXml  = responseData.SelectToken("ResponseXML").ToString();
                        if (!string.IsNullOrEmpty(Convert.ToString(responseData.SelectToken("AccountId"))))
                        {
                            accountId = Convert.ToInt32(responseData.SelectToken("AccountId").ToString());
                        }
                        Logger.Info("Studio controller: response data before dialing to agent:" + responseData.ToString());
                        if (accountId > 0)
                        {
                            ManagerDashBoardCounts(connectionString, accountId);
                        }
                        if (ds.Tables.Count > 1)
                        {
                            JArray   gatewayDetailsObj = (responseData.SelectToken("GatewayDetails") as JArray) as JArray;
                            Gateways gatewaysObj       = new Gateways();
                            string   postingData       = "";
                            JObject  restApiResponse   = new JObject();
                            string   answerXml         = "";
                            foreach (JObject j in gatewayDetailsObj)
                            {
                                Logger.Info("GatewayDetails loop in Studio Controller:" + j.ToString());
                                restApiResponse = new JObject();
                                string ringUrl     = callBackUrl + "?ChannelName=Agent_" + (j.SelectToken("AgentId")) + "&IsVertoPhone=" + (j.SelectToken("OriginationUrl").ToString().Contains("verto.rtc") ? "true" : "false") + "&IsAgent=true&isTransferToAgent=false&IsRingUrl=true";
                                string digitsMatch = "digitsMatch='" + j.SelectToken("ConferenceDigits") + "'";
                                //Logger.Info("Conference Digits:"+digitsMatch);
                                answerXml  = "<Response><Conference " + digitsMatch + " stayAlone='true' callbackMethod='GET' callbackUrl='" + callBackUrl + "?ChannelName=Agent_" + (j.SelectToken("AgentId")) + "&#38;IsVertoPhone=" + (j.SelectToken("OriginationUrl").ToString().Contains("verto.rtc") ? "true" : "false") + "&#38;IsAgent=true&#38;isTransferToAgent=false";
                                answerXml += "&#38;GatewayURL=" + j.SelectToken("HttpUrl").ToString() + "' >" + j.SelectToken("Room") + "</Conference></Response>";

                                //postingData = "RingUrl=" + HttpUtility.UrlEncode(ringUrl) +
                                postingData = "AnswerXml=" + System.Web.HttpUtility.UrlEncode(answerXml) + "&Source=Agent&Priority=H&SequenceNumber=" + j.SelectToken("SequenceNumber") + "&From=";
                                // postingData = "AnswerXml=" + System.Web.HttpUtility.UrlEncode(answerXml) + "&Priority=H&SequenceNumber=" + j.SelectToken("SequenceNumber") + "&From=";
                                postingData += j.SelectToken("Source") + "&To=" + j.SelectToken("Number") + "&OriginateSleep=1&AnswerUrl=" + conferenceCallBackUrl + "&Gateways=";
                                postingData += j.SelectToken("OriginationUrl") + "&HangupUrl=" + hangupUrl + "&ExtraDialString=" + System.Web.HttpUtility.UrlEncode(j.SelectToken("ExtraDialString").ToString());
                                Logger.Info("call Request Executing to The server : " + j.SelectToken("HttpUrl").ToString() + "posting data " + postingData.ToString());
                                // Logger.Info("httpurl " + j.SelectToken("HttpUrl").ToString());
                                restApiResponse = gatewaysObj.RestApiRequest(postingData, j.SelectToken("HttpUrl").ToString() + "Call/", "POST");
                                if (Convert.ToBoolean(restApiResponse.SelectToken("Success").ToString()))
                                {
                                    Logger.Debug("Studio call process Call Initiated Response:" + restApiResponse);
                                    var uuid      = restApiResponse.SelectToken("RequestUUID").ToString();
                                    var seqNumber = Convert.ToInt32(j.SelectToken("SequenceNumber").ToString());
                                    conferenceObj.UpdateConferenceRequestUUID(uuid, seqNumber);
                                }
                                else
                                {
                                    Logger.Info("Call Request not Success please check Ycom Rest logs for more info payload:" + postingData);
                                    responseXml = "<Response><Hangup data='Issue in connect agent'/></Response>";
                                }
                            }
                        }
                        responseXml = "<Response>" + responseXml + "</Response>";
                    }
                    else
                    {
                        responseXml = "<Response><Speak>No agent available call is getting hangup</Speak><Hangup data='No data return from database'/></Response>";
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Info("Exception in GetStudio Xml: " + ex.ToString());
                responseXml = string.Format("<Response><Hangup data='server error -->{0} '/></Response>", ex.ToString());
            }
            return(responseXml);
        }