Exemplo n.º 1
0
        public void CreatTask(string portal, string acectok, string otv, string otvzakont, int idcon, int tasktypeid)
        {
            DateTimeOffset td   = DateTimeOffset.Now;
            DateTimeOffset td2  = td.AddHours(1);
            var            data = new[]
            {
                new{
                    text                = "Пропущеный звонок",
                    complete_till       = td2.ToUnixTimeSeconds(),
                    created_at          = td.ToUnixTimeSeconds(),
                    responsible_user_id = Convert.ToInt32(otvzakont),
                    created_by          = Convert.ToInt32(otv),
                    entity_type         = "contacts",
                    entity_id           = idcon,
                    task_type_id        = tasktypeid
                }
            };
            string contentText2 = JsonConvert.SerializeObject(data).ToString();
            string content;

            using (xNet.HttpRequest request = new xNet.HttpRequest())
            {
                request.AddHeader("Authorization", " Bearer " + acectok);
                content = request.Post("https://" + portal + "/api/v4/tasks", contentText2, "application/json").ToString();
            }
        }
Exemplo n.º 2
0
        public string CreatDopFildDeal(string portal, string acectok)
        {
            var data = new[]
            {
                new
                {
                    name  = "Источник-аксател",
                    type  = "select",
                    enums = new[]
                    {
                        new { value = "GoogleAds", sort = 1 },
                        new { value = "Яндекс.Директ", sort = 2 },
                        new { value = "Соц. сети", sort = 3 },
                        new { value = "Бесплатные площадки", sort = 4 },
                        new { value = "Офлайн источники", sort = 5 },
                        new { value = "Прямой трафик", sort = 6 }
                    }
                }
            };
            string contentText2 = JsonConvert.SerializeObject(data).ToString();
            string content;

            using (xNet.HttpRequest request = new xNet.HttpRequest())
            {
                request.AddHeader("Authorization", " Bearer " + acectok);
                content = request.Post("https://" + portal + "/api/v4/leads/custom_fields", contentText2, "application/json").ToString();
            }
            var     converter = new ExpandoObjectConverter();
            dynamic obj       = JsonConvert.DeserializeObject <ExpandoObject>(content, converter);

            return(obj._embedded.custom_fields[0].id.ToString());
        }
Exemplo n.º 3
0
        public string CreatCont(string portal, string acectok, string tel, string userid)
        {
            string content2;

            using (xNet.HttpRequest request = new xNet.HttpRequest())
            {
                request.AddHeader("Authorization", " Bearer " + acectok);
                content2 = request.Get("https://" + portal + "/api/v2/account?with=custom_fields").ToString();
            }
            var     converter = new ExpandoObjectConverter();
            dynamic obj       = JsonConvert.DeserializeObject <ExpandoObject>(content2, converter);
            string  idtelef   = "0";

            foreach (var item in obj._embedded.custom_fields.contacts)
            {
                if (item.Value.name == "Телефон")
                {
                    idtelef = item.Value.id.ToString(); break;
                }
            }

            DateTimeOffset td   = DateTimeOffset.Now;
            var            data = new
            {
                add = new[] {
                    new
                    {
                        name = "Новый контакт",
                        responsible_user_id = userid,
                        created_by          = userid,
                        created_at          = td.ToUnixTimeSeconds(),
                        custom_fields       = new[] {
                            new
                            {
                                id     = idtelef,
                                values = new[]
                                {
                                    new { value = tel, @enum = "WORK" }
                                }
                            }
                        }
                    }
                }
            };
            string contentText2 = JsonConvert.SerializeObject(data).ToString();
            string content;

            using (xNet.HttpRequest request = new xNet.HttpRequest())
            {
                request.AddHeader("Authorization", " Bearer " + acectok);
                content = request.Post("https://" + portal + "/api/v2/contacts", contentText2, "application/json").ToString();
            }
            dynamic obj2   = JsonConvert.DeserializeObject <ExpandoObject>(content, converter);
            string  iduser = obj2._embedded.items[0].id.ToString();

            return(iduser);
        }
Exemplo n.º 4
0
        public int CreatDeal(string portal, string acectok, int cosht, int idcont, int idotv, string tag, string number, Dictionary <string, string> dicdop)
        {
            Dopdata[] dopdatas = new Dopdata[dicdop.Count];

            int i = 0;

            foreach (var item in dicdop)
            {
                Dopdata dopdata = new Dopdata();
                dopdata.field_id = Convert.ToInt32(item.Key);
                dopdata.values   = new[] { new { value = item.Value.ToString() } };
                dopdatas[i]      = dopdata;
                i++;
            }


            foreach (var item in dicdop)
            {
            }
            var data = new[]
            {
                new
                {
                    name                = "Новая сделка от " + number,
                    created_by          = idotv,
                    responsible_user_id = idotv,
                    price               = cosht,
                    //custom_fields_values = new[]
                    //{
                    //    new {field_id = Convert.ToInt32(iddopfild), values = new[]{ new { value = namedopfild } }  }

                    //},
                    custom_fields_values = dopdatas,
                    _embedded            = new
                    {
                        contacts = new[]
                        {
                            new{ id = idcont }
                        },
                        tags = new[]
                        {
                            new{ name = tag }
                        }
                    }
                }
            };
            string contentText2 = JsonConvert.SerializeObject(data).ToString();
            string content;

            using (xNet.HttpRequest request = new xNet.HttpRequest())
            {
                request.AddHeader("Authorization", " Bearer " + acectok);
                content = request.Post("https://" + portal + "/api/v4/leads", contentText2, "application/json").ToString();
            }
            return(1);
        }
Exemplo n.º 5
0
        public void ShowEvent(string portal, string acectok, string tel, string useid)
        {
            var data = new
            {
                add = new[] {
                    new
                    {
                        type         = "phone_call",
                        phone_number = tel,
                        users        = new[] { useid }
                    }
                }
            };
            string contentText2 = JsonConvert.SerializeObject(data).ToString();
            string content;

            using (xNet.HttpRequest request = new xNet.HttpRequest())
            {
                request.AddHeader("Authorization", " Bearer " + acectok);
                content = request.Post("https://" + portal + "/api/v2/events", contentText2, "application/json").ToString();
            }
        }
Exemplo n.º 6
0
        public ActionResult Index(string Domen, string Hesh)
        {
            List <object[]> nametask = new List <object[]>();
            var             data     = new
            {
                filter = new
                {
                    TAG = "oktell"
                },
                select = new[] { "UF_CRM_TASK", "TITLE", "TAG" }
            };
            string contentText = JsonConvert.SerializeObject(data).ToString();
            string content;

            try
            {
                using (xNet.HttpRequest request = new xNet.HttpRequest())
                {
                    content = request.Post("https://" + Domen + "/rest/" + Hesh + "/tasks.task.list", contentText, "application/json").ToString();
                }
            }
            catch
            {
                nametask = null;
                return(View(nametask));
            }
            var     converter = new ExpandoObjectConverter();
            dynamic obj       = JsonConvert.DeserializeObject <ExpandoObject>(content, converter);

            foreach (var item in obj.result.tasks)
            {
                nametask.Add(new object[] { item.id, item.title });
            }
            ViewBag.Domen = Domen;
            ViewBag.Hesh  = Hesh;

            return(View(nametask));
        }
Exemplo n.º 7
0
        public ActionResult Test()
        {
            // string text = System.IO.File.ReadAllText(System.Web.Hosting.HostingEnvironment.MapPath("/text.txt"));
            var data = new
            {
                ALFACRM_URL  = "legionsport.s20.online",
                PHONE_NUMBER = "+375(44)719-66-49",                    // номер звонящего в случае входящего звонка, или исходящий номер.
                AXATEL_GUID  = "ceb9906c-0a24-4d7b-a8f4-f6e8f381c355",
                CALL_GUID    = "asd9906c-0ad4-4d7b-ada4-f6e8fasdc353", // постоянный ID звонка во внешней системе
                TYPE         = "in"                                    // направление звонка, может быть либо in либо out;
            };
            string contentText2 = JsonConvert.SerializeObject(data).ToString();
            string content;

            using (xNet.HttpRequest request = new xNet.HttpRequest())
            {
                content = request.Post("http://localhost:62415/method/alfacrm/alert", contentText2, "application/json").ToString();
            }
            var     converter = new ExpandoObjectConverter();
            dynamic obj4      = JsonConvert.DeserializeObject <ExpandoObject>(content, converter);

            return(Content(content));
        }
Exemplo n.º 8
0
        public int CreatRazobrab(string portal, string acectok, int cosht, int idcont, int idotv, string tag, string number, string link, int duration, string iddopfild, string namedopfild)
        {
            var    converter = new ExpandoObjectConverter();
            string content2;

            using (xNet.HttpRequest request2 = new xNet.HttpRequest())
            {
                request2.AddHeader("Authorization", " Bearer " + acectok);
                content2 = request2.Get("https://" + portal + "/api/v4/leads/pipelines").ToString();
            }
            dynamic obj2 = JsonConvert.DeserializeObject <ExpandoObject>(content2, converter);

            var data3 = new[]
            {
                new{ name = tag }
            };
            string contentText3 = JsonConvert.SerializeObject(data3).ToString();
            string content3;

            using (xNet.HttpRequest request3 = new xNet.HttpRequest())
            {
                request3.AddHeader("Authorization", " Bearer " + acectok);
                content3 = request3.Post("https://" + portal + "/api/v4/leads/tags", contentText3, "application/json").ToString();
            }
            dynamic        obj3    = JsonConvert.DeserializeObject <ExpandoObject>(content3, converter);
            int            idtag   = Convert.ToInt32(obj3._embedded.tags[0].id);
            int            idvoron = Convert.ToInt32(obj2._embedded.pipelines[0].id);
            string         guid1   = Guid.NewGuid().ToString();
            DateTimeOffset td      = DateTimeOffset.Now;
            var            data    = new[]
            {
                new
                {
                    request_id  = "123",
                    source_name = "Источник #1",
                    source_uid  = guid1,
                    pipeline_id = idvoron,
                    created_at  = td.ToUnixTimeSeconds(),
                    _embedded   = new
                    {
                        leads = new[]
                        {
                            new{ name  = "Новая сделка",
                                 price = cosht,
                                 custom_fields_values = new[]
                                 {
                                     new { field_id = Convert.ToInt32(iddopfild), values = new[] { new { value = namedopfild } } }
                                 },
                                 _embedded = new{
                                     tags = new[]
                                     {
                                         new{ id = idtag }
                                     }
                                 } }
                        },
                        contacts = new[]
                        {
                            new{ id = idcont }
                        }
                    },
                    metadata = new
                    {
                        is_call_event_needed = true,
                        duration             = duration,
                        uniq         = guid1,
                        service_code = "12345678",
                        link         = link, //"https://service-axatel.ru:8099/content/zapisvobrabotke.mp3",
                        phone        = number,
                        called_at    = td.ToUnixTimeSeconds(),
                        from         = "клиента " + number
                    }
                }
            };
            string contentText2 = JsonConvert.SerializeObject(data).ToString();
            string content;

            using (xNet.HttpRequest request = new xNet.HttpRequest())
            {
                request.AddHeader("Authorization", " Bearer " + acectok);
                content = request.Post("https://" + portal + "/api/v4/leads/unsorted/sip", contentText2, "application/json").ToString();
            }
            dynamic obj = JsonConvert.DeserializeObject <ExpandoObject>(content, converter);

            return(1);
        }
Exemplo n.º 9
0
        public void RegisterCall(string portal, string acectok, string tel, string userid, int status, string type, string link, string CALL_FINISH_DATE = "", int?duration = 0)
        {
            if (status == 6)
            {
                duration = 0; CALL_FINISH_DATE = DateTime.Now.ToString("dd.MM.yyyy HH:mm:ss");
            }
            string result = "";

            if (status == 4)
            {
                result = "Звонок cостоялся";
            }
            else if (status == 1)
            {
                result = "Оставил голосовое сообщение";
            }
            else if (status == 2)
            {
                result = "Перезвонить позже";
            }
            else if (status == 3)
            {
                result = "Нет на месте";
            }
            else if (status == 5)
            {
                result = "Неверный номер";
            }
            else if (status == 7)
            {
                result = "Номер занят";
            }

            // DateTime td = DateTimeю.Parse(CALL_START_DATE);
            //   DateTimeOffset td = DateTimeOffset.Now;
            DateTimeOffset tdn  = DateTimeOffset.Parse(CALL_FINISH_DATE);
            Guid           guid = Guid.NewGuid();
            var            data = new
            {
                add = new[] {
                    new
                    {
                        uniq                = guid.ToString(),
                        phone_number        = tel,
                        source              = ClienID,
                        created_at          = tdn.ToUnixTimeSeconds(),
                        created_by          = userid,
                        duration            = duration,
                        call_status         = status,
                        call_result         = result,
                        direction           = type,
                        link                = link, //"https://service-axatel.ru:8099/content/zapisvobrabotke.mp3",
                        responsible_user_id = userid
                    }
                }
            };
            string contentText2 = JsonConvert.SerializeObject(data).ToString();
            string pach         = System.Web.Hosting.HostingEnvironment.MapPath("/logamo.txt");

            System.IO.StreamWriter myfile = new System.IO.StreamWriter(pach, true);
            myfile.WriteLine(DateTime.Now.ToString() + "--FinishJson--Data:" + contentText2 + "--Portal:" + portal + "\n\n");
            myfile.Close();
            myfile.Dispose();
            string content;

            using (xNet.HttpRequest request = new xNet.HttpRequest())
            {
                request.AddHeader("Authorization", " Bearer " + acectok);

                content = request.Post("https://" + portal + "/api/v2/calls", contentText2, "application/json").ToString();
            }
        }
Exemplo n.º 10
0
        public ApiResult UserQuery(string path, HttpMethod httpMethod, Dictionary <string, string> headers = null, string content = "", bool jsonContent = false)
        {
            xNet.HttpResponse response    = null;
            string            contentType = null;

            path = BaseUri + path;

            if (!(httpMethod == HttpMethod.Get || httpMethod == HttpMethod.Post ||
                  httpMethod == HttpMethod.Delete || httpMethod == HttpMethod.Put))
            {
                throw new ArgumentException("Unsupported http method " + httpMethod);
            }
            if (httpMethod != HttpMethod.Get && content.Length == 0)
            {
                throw new ArgumentException("Empty content.");
            }

            if (headers != null && headers.Count == 0)
            {
                throw new ArgumentException("Empty headers.");
            }

            if (headers != null)
            {
                foreach (var h in headers)
                {
                    _request.AddHeader(h.Key, h.Value);
                }
            }
            if (httpMethod != HttpMethod.Get)
            {
                contentType = jsonContent ? "application/json" : "application/x-www-form-urlencoded";
            }
            lock (_obj)
            {
                try
                {
                    if (httpMethod == HttpMethod.Get)
                    {
                        response = _request.Get(path);
                    }

                    else if (httpMethod == HttpMethod.Post)
                    {
                        response = _request.Post(path, content, contentType);
                    }

                    else if (httpMethod == HttpMethod.Delete)
                    {
                        response = _request.Delete(path, content, contentType);
                    }

                    else if (httpMethod == HttpMethod.Put)
                    {
                        response = _request.Put(path, content, contentType);
                    }
                }
                catch (xNet.HttpException ex)
                {
                    return(new ApiResult((int)ex.HttpStatusCode, ex.InnerMessage));
                }
            }
            content = response.ToString();
            ParseResponseHeaders(response);

            return(new ApiResult((int)response.StatusCode, content));
        }