Ejemplo n.º 1
0
        public async Task <List <Attachment> > SearchKB()
        {
            List <Attachment> llist = new List <Attachment>();

            if (MessagesController.ConverastionalUserList != null)
            {
                HttpClient cons = new HttpClient();
                cons.BaseAddress = new Uri("https://crmapikyliebot.azurewebsites.net/");
                cons.DefaultRequestHeaders.Accept.Clear();
                cons.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
                cons.Timeout = TimeSpan.FromMinutes(1);

                List <Models.CRMKnowledgeBaseArticle> crmKBA = new List <Models.CRMKnowledgeBaseArticle>();

                using (cons)
                {
                    HttpResponseMessage res = await cons.GetAsync("CRM/SearchKB/" + MessagesController.ConverastionalUserList[index].searchTerm + "/");

                    if (res.IsSuccessStatusCode)
                    {
                        crmKBA = await res.Content.ReadAsAsync <List <Models.CRMKnowledgeBaseArticle> >();
                    }
                }

                if (crmKBA.Count > 0)
                {
                    foreach (Models.CRMKnowledgeBaseArticle kb in crmKBA)
                    {
                        Attachment a = BotHelper.GetHeroCard(
                            kb.title + " (" + kb.articleNumber + ")",
                            "Published: " + kb.publishedDate.ToShortDateString(),
                            kb.description,
                            new CardImage(url: "https://azurecomcdn.azureedge.net/cvt-5daae9212bb433ad0510fbfbff44121ac7c759adc284d7a43d60dbbf2358a07a/images/page/services/functions/01-develop.png"),
                            new CardAction(ActionTypes.OpenUrl, "Learn more", value: "https://askkylie.microsoftcrmportals.com/knowledgebase/article/" + kb.articleNumber));
                        llist.Add(a);
                    }
                }
            }
            return(llist);
        }