Exemple #1
0
        public async void postToTeams()
        {
            string results;

            List <JSONObjects> jObjects = new List <JSONObjects>();

            jObjects = JSONObjects.userTicketInfo(GetResponse(snowURL + "/incident.do?JSONv2&sysparm_query=assignment_group=aebac70a484e450050b9a061ace9668b^active=true^u_submission_source=self+service^state!=6^ORDERBYDESCnumber").Result);

            if (jObjects.Count > 0)
            {
                foreach (JSONObjects jobject in jObjects)
                {
                    if (tickets.Count > 0)
                    {
                        if (tickets.Contains(jobject.number))
                        {
                            continue;
                        }
                    }

                    string json = new JavaScriptSerializer().Serialize(new
                    {
                        roomId = "<roomId>",
                        text   = "New Ticket From " + JSONObjects.JSONParser(GetResponse(snowURL + "sys_user.do?JSONv2&sysparm_query=sys_id=" + jobject.u_affected_user).Result, "user_name") + "\nTicketNumber: " + jobject.number + "\nDescription: " + jobject.description + "\nAssigned To: " + JSONObjects.JSONParser(GetResponse(snowURL + "sys_user.do?JSONv2&sysparm_query=sys_id=" + jobject.assigned_to).Result, "user_name")
                    });

                    clientTeams = new HttpClient(handler);

                    clientTeams.BaseAddress = new Uri("https://api.ciscospark.com/v1/messages");
                    clientTeams.DefaultRequestHeaders.Accept.Clear();
                    clientTeams.DefaultRequestHeaders.Authorization =
                        new AuthenticationHeaderValue("Bearer", "<bot token>");
                    clientTeams.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                    clientTeams.DefaultRequestHeaders.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36");

                    HttpContent content = new StringContent(json, UnicodeEncoding.UTF8, "application/json");
                    content.Headers.ContentType = new MediaTypeHeaderValue("application/json");

                    using (var result = await clientTeams.PostAsync(clientTeams.BaseAddress, content).ConfigureAwait(false))
                    {
                        //result.EnsureSuccessStatusCode();

                        using (HttpContent contents = result.Content)
                            results = contents.ReadAsStringAsync().Result;
                    }

                    tickets.Add(jobject.number);
                }
            }
        }
Exemple #2
0
        public static List <JSONObjects> userTicketInfo(string json)
        {
            List <JSONObjects> jobject = new List <JSONObjects>();

            try
            {
                JObject result = new JObject();
                result = JObject.Parse(json);

                JArray records = (JArray)result["records"];

                int recentTickets = 0;

                if (records.Count > 5)
                {
                    recentTickets = 5;
                }
                else if (records.Count <= 5)
                {
                    recentTickets = records.Count();
                }

                for (int i = 0; i < recentTickets; i++)
                {
                    JSONObjects placeholder = new JSONObjects();

                    JToken findNumber     = records[i]["number"];
                    JToken findShDesc     = records[i]["affected_user"];
                    JToken findIncSt      = records[i]["description"];
                    JToken findAssignedto = records[i]["assigned_to"];

                    placeholder.number          = findNumber.ToString();
                    placeholder.u_affected_user = findShDesc.ToString();
                    placeholder.description     = findIncSt.ToString();
                    placeholder.assigned_to     = findAssignedto.ToString();

                    jobject.Add(placeholder);
                }
            }
            catch (Newtonsoft.Json.JsonReaderException je)
            {
                return(jobject);
            }


            return(jobject);
        }