Beispiel #1
0
        public static void Message()
        {
            NpgsqlConnection conn      = Connection.GetConnection();
            XElement         configXml = XElement.Load(System.AppDomain.CurrentDomain.BaseDirectory + @"\config.xml");

            urlligacao = configXml.Element("UrlLigacao").Value.ToString();
            urlservice = configXml.Element("UrlService").Value.ToString();
            token      = configXml.Element("Token").Value.ToString();

            CallModel call       = new CallModel();
            string    call_id    = "";
            string    result     = "";
            string    campanha   = "";
            string    extension  = "";
            int       total_time = 0;
            string    reason     = "";

            try {
                string query = "select callid,REPLACE(REPLACE(REPLACE(data::text,'[',''),']',''),'\"','') as data from cdr where processed = false group by callid";

                NpgsqlCommand    command = new NpgsqlCommand(query, conn);
                NpgsqlDataReader rd      = command.ExecuteReader();

                while (rd.Read())
                {
                    total_time = 0;
                    extension  = "";
                    campanha   = "";
                    reason     = "";

                    string[] lineList = rd["data"].ToString().Split(',');

                    call.CallId    = lineList[0].ToString().Replace("Call", "").Trim();
                    call.HistoryId = lineList[1].ToString();

                    campanha = lineList[2].ToString().ToUpper();

                    call.DtInicioChamada = lineList[4].ToString();
                    call.DtFimChamada    = lineList[5].ToString();

                    if (!lineList[6].Equals(""))
                    {
                        string[] timeList = lineList[6].Split(':');

                        int hour    = Int32.Parse(timeList[0]) * 3600;
                        int minute  = Int32.Parse(timeList[1]) * 60;
                        int seconds = Int32.Parse(timeList[2]);
                        total_time = hour + minute + seconds;
                    }

                    call.TempoConversacao = total_time.ToString();

                    call.ReasonTerminated = lineList[8].ToString();
                    reason          = lineList[8].ToString();;
                    call.DestinoTel = lineList[11].ToString();
                    call.FinalDn    = lineList[14].ToString();
                    extension       = lineList[14].ToString();
                    call.Chain      = lineList[18].ToString();

                    if (!lineList[18].Equals(""))
                    {
                        string[] callList = lineList[18].Split(';');

                        if (callList.Length > 2)
                        {
                            call.Campanha = callList[2].Replace("Ext.", "").Trim();
                        }
                    }

                    call.OrigemTel              = extension;
                    call.DestinationType        = lineList[20].ToString();
                    call.FinalDestinationType   = lineList[21].ToString();
                    call.DestinationDisplayName = lineList[23].ToString();
                    call.SourceDisplayName      = lineList[24].ToString();
                    call.MissedQueueCalls       = lineList[25].ToString();

                    if (campanha.Contains("MAKECALL") && !reason.Equals("LicenseLimit"))
                    {
                        result          = "";
                        call.UrlLigacao = urlligacao + Util.FindDirectory(extension, rd["callid"].ToString());;
                        call.Token      = token;
                        result          = Send(JsonConvert.SerializeObject(call), rd["callid"].ToString());

                        if (result.Equals("OK"))
                        {
                            call_id += rd["callid"] + " ";
                        }
                    }
                    else
                    {
                        call_id += rd["callid"] + " ";
                    }
                }

                rd.Close();

                if (call_id != "")
                {
                    call_id = call_id.Trim().Replace(" ", "','");
                    NpgsqlCommand cmd = new NpgsqlCommand("update cdr set processed = true where callid in ('" + call_id + "')", conn);
                    cmd.ExecuteReader();
                }
            }
            catch (Exception ex) {
                Util.Log(ex.ToString());
            }
            finally {
                if (conn != null)
                {
                    conn.Close();
                }
            }
        }
Beispiel #2
0
        public static void Message()
        {
            NpgsqlConnection conn      = Connection.GetConnection();
            XElement         configXml = XElement.Load(AppDomain.CurrentDomain.BaseDirectory + @"\config.xml");

            urlligacao      = configXml.Element("UrlLigacao").Value.ToString();
            urlservice      = configXml.Element("UrlService").Value.ToString();
            token           = configXml.Element("Token").Value.ToString();
            domain          = configXml.Element("Domain").Value.ToString();
            company_id      = configXml.Element("CompanyId").Value.ToString();
            extension_start = configXml.Element("ExtensionStart").Value.ToString();
            extension_end   = configXml.Element("ExtensionEnd").Value.ToString();
            extensions      = configXml.Element("Extensions").Value.ToString();

            Regex r = new Regex(@"\[[^\}]+?\]");

            CallModel call        = new CallModel();
            string    call_id     = "";
            string    result      = "";
            string    callfile    = "";
            int       range_start = 0;
            int       range_end   = 0;
            int       extension   = 0;
            int       restriction = 0;
            bool      a           = false;

            string[] extensionsList = null;
            string   ramal          = "";

            try {
                if (!extension_start.Equals("0"))
                {
                    restriction = 1;

                    try {
                        range_start = Int32.Parse(configXml.Element("ExtensionStart").Value.ToString());
                    }
                    catch (Exception) {
                        range_start = 0;
                    }

                    try {
                        range_end = Int32.Parse(configXml.Element("ExtensionEnd").Value.ToString());

                        if (range_end == 0)
                        {
                            range_end = 999999999;
                        }
                    }
                    catch (Exception) {
                        range_end = 999999999;
                    }
                }
                else if (!extensions.Equals("0"))
                {
                    restriction    = 2;
                    extensionsList = extensions.Split(',');
                }

                string query = "select myphone_callhistory_v14.call_id, dnowner, party_name, " +
                               "CASE  " +
                               "WHEN calltype = 2 THEN 'Inbound'  " +
                               "WHEN calltype = 3 THEN 'Outbound'  " +
                               "ELSE 'Invalid' END as calltype, " +
                               "party_callerid, to_char(start_time  - interval '3 hours', 'YYYY-MM-DD HH24:MI:SS') as start_time, " +
                               "to_char(end_time  - interval '3 hours', 'YYYY-MM-DD HH24:MI:SS') as end_time, " +
                               "(date_part('second', end_time - start_time) + (date_part('minute', end_time - start_time) * 60)) as tempo, " +
                               "to_char(established_time, 'YYYYMMDDHH24MISS') as established " +
                               "from myphone_callhistory_v14 " +
                               "inner join crm_integration on myphone_callhistory_v14.call_id = crm_integration.call_id " +
                               "where crm_integration.processed = false";

                NpgsqlCommand    command = new NpgsqlCommand(query, conn);
                NpgsqlDataReader rd      = command.ExecuteReader();

                while (rd.Read())
                {
                    if (restriction.Equals(0))
                    {
                        Util.Log("Filtro: " + restriction);
                        result   = "";
                        callfile = Util.FindRecording(rd["call_id"].ToString());

                        Match m = r.Match(callfile);

                        call.UrlLigacao       = urlligacao + callfile;
                        call.CallName         = m.ToString().Replace("[", "").Replace("]", "");
                        call.TipoChamada      = rd["calltype"].ToString();
                        call.Domain           = domain;
                        call.CompanyId        = company_id;
                        call.Token            = token;
                        call.OrigemTel        = rd["dnowner"].ToString();
                        call.DestinoTel       = rd["party_callerid"].ToString();
                        call.DtInicioChamada  = rd["start_time"].ToString();
                        call.DtFimChamada     = rd["end_time"].ToString();
                        call.TempoConversacao = rd["tempo"].ToString();
                        result = Send(JsonConvert.SerializeObject(call), rd["call_id"].ToString());

                        if (result.Equals("OK"))
                        {
                            call_id += rd["call_id"] + " ";
                        }
                    }
                    else if (restriction.Equals(1))
                    {
                        try {
                            extension = Int32.Parse(rd["dnowner"].ToString());
                        }
                        catch (Exception) {
                            extension = 0;
                        }

                        Util.Log("Filtro: " + restriction + " Ramal: [" + extension + "] Inicio/fim: " + range_start + " " + range_end);

                        if ((extension >= range_start) && (extension <= range_end))
                        {
                            result   = "";
                            callfile = Util.FindRecording(rd["call_id"].ToString());

                            Match m = r.Match(callfile);

                            call.UrlLigacao       = urlligacao + callfile;
                            call.CallName         = m.ToString().Replace("[", "").Replace("]", "");
                            call.TipoChamada      = rd["calltype"].ToString();
                            call.Domain           = domain;
                            call.CompanyId        = company_id;
                            call.Token            = token;
                            call.OrigemTel        = rd["dnowner"].ToString();
                            call.DestinoTel       = rd["party_callerid"].ToString();
                            call.DtInicioChamada  = rd["start_time"].ToString();
                            call.DtFimChamada     = rd["end_time"].ToString();
                            call.TempoConversacao = rd["tempo"].ToString();
                            result = Send(JsonConvert.SerializeObject(call), rd["call_id"].ToString());

                            if (result.Equals("OK"))
                            {
                                call_id += rd["call_id"] + " ";
                            }
                        }
                        else
                        {
                            call_id += rd["call_id"] + " ";
                        }
                    }
                    else if (restriction.Equals(2))
                    {
                        ramal = rd["dnowner"].ToString();
                        a     = Array.Exists(extensionsList, element => element == ramal);

                        Util.Log("Filtro: " + restriction + " Ramal: [" + ramal + "] Teste: " + a);

                        if (a)
                        {
                            result   = "";
                            callfile = Util.FindRecording(rd["call_id"].ToString());

                            Match m = r.Match(callfile);

                            call.UrlLigacao       = urlligacao + callfile;
                            call.CallName         = m.ToString().Replace("[", "").Replace("]", "");
                            call.TipoChamada      = rd["calltype"].ToString();
                            call.Domain           = domain;
                            call.CompanyId        = company_id;
                            call.Token            = token;
                            call.OrigemTel        = rd["dnowner"].ToString();
                            call.DestinoTel       = rd["party_callerid"].ToString();
                            call.DtInicioChamada  = rd["start_time"].ToString();
                            call.DtFimChamada     = rd["end_time"].ToString();
                            call.TempoConversacao = rd["tempo"].ToString();
                            result = Send(JsonConvert.SerializeObject(call), rd["call_id"].ToString());

                            if (result.Equals("OK"))
                            {
                                call_id += rd["call_id"] + " ";
                            }
                        }
                        else
                        {
                            call_id += rd["call_id"] + " ";
                        }
                    }
                }

                rd.Close();

                if (call_id != "")
                {
                    call_id = call_id.Trim().Replace(" ", ",");
                    NpgsqlCommand cmd = new NpgsqlCommand("update crm_integration set processed = true where call_id in (" + call_id + ")", conn);
                    cmd.ExecuteReader();
                }
            }
            catch (Exception ex) {
                Util.Log(ex.ToString());
            }
            finally {
                if (conn != null)
                {
                    conn.Close();
                }
            }
        }
Beispiel #3
0
        public static void Message()
        {
            NpgsqlConnection conn = Connection.GetConnection();

            XElement configXml = XElement.Load(System.AppDomain.CurrentDomain.BaseDirectory + @"\config.xml");

            urlligacao = configXml.Element("UrlLigacao").Value.ToString();
            urlservice = configXml.Element("UrlService").Value.ToString();
            token      = configXml.Element("TokenExact").Value.ToString();

            CallModel call        = new CallModel();
            string    call_id     = "";
            string    result      = "";
            int       range_start = 0;
            int       range_end   = 0;
            int       extension   = 0;

            try {
                try {
                    range_start = Int32.Parse(configXml.Element("ExtensionStart").Value.ToString());
                }
                catch (Exception) {
                    range_start = 0;
                }

                try {
                    range_end = Int32.Parse(configXml.Element("ExtensionEnd").Value.ToString());

                    if (range_end == 0)
                    {
                        range_end = 999999999;
                    }
                }
                catch (Exception) {
                    range_end = 999999999;
                }

                string query = "select myphone_callhistory_v14.call_id, dnowner, " +
                               "party_callerid, to_char(start_time  - interval '3 hours', 'YYYY-MM-DD HH24:MI:SS') as start_time, " +
                               "to_char(end_time  - interval '3 hours', 'YYYY-MM-DD HH24:MI:SS') as end_time, " +
                               "(date_part('second', end_time - start_time) + (date_part('minute', end_time - start_time) * 60)) as tempo, " +
                               "to_char(established_time, 'YYYYMMDDHH24MISS') as established " +
                               "from myphone_callhistory_v14 " +
                               "inner join crm_integration on myphone_callhistory_v14.call_id = crm_integration.call_id " +
                               "where crm_integration.processed = false";

                NpgsqlCommand    command = new NpgsqlCommand(query, conn);
                NpgsqlDataReader rd      = command.ExecuteReader();

                while (rd.Read())
                {
                    try {
                        extension = Int32.Parse(rd["dnowner"].ToString());
                    }
                    catch (Exception) {
                        extension = 0;
                    }

                    if ((extension >= range_start) && (extension <= range_end))
                    {
                        result                = "";
                        call.UrlLigacao       = urlligacao + Util.FindDirectory(rd["dnowner"].ToString(), rd["party_dn"].ToString(), rd["established"].ToString());
                        call.OrigemTel        = rd["dnowner"].ToString();
                        call.DestinoTel       = rd["party_dn"].ToString();
                        call.DtInicioChamada  = rd["start_time"].ToString();
                        call.DtFimChamada     = rd["end_time"].ToString();
                        call.TempoConversacao = rd["tempo"].ToString();
                        result                = Send(JsonConvert.SerializeObject(call), rd["call_id"].ToString());

                        if (result.Equals("OK"))
                        {
                            call_id += rd["call_id"] + " ";
                        }
                    }
                    else
                    {
                        call_id += rd["call_id"] + " ";
                    }
                }

                rd.Close();

                if (call_id != "")
                {
                    call_id = call_id.Trim().Replace(" ", ",");
                    NpgsqlCommand cmd = new NpgsqlCommand("update crm_integration set processed = true where call_id in (" + call_id + ")", conn);
                    cmd.ExecuteReader();
                }
            }
            catch (Exception ex) {
                Util.Log(ex.ToString());
            }
            finally {
                if (conn != null)
                {
                    conn.Close();
                }
            }
        }