public static async Task <AcademicResult> Interpret(string query)
        {
            var client      = new HttpClient();
            var queryString = HttpUtility.ParseQueryString(string.Empty);

            // Request headers
            client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", "SECRET");

            // Request parameters
            queryString["query"]    = query;
            queryString["model"]    = "latest";
            queryString["count"]    = "10";
            queryString["complete"] = "1";
            var uri = "https://api.projectoxford.ai/academic/v1.0/interpret?" + queryString;

            var response = await client.GetAsync(uri);

            string resp = await response.Content.ReadAsStringAsync();

            AcademicResult result = JsonConvert.DeserializeObject <AcademicResult>(resp);

            return(result);
        }
        public async Task AfterChosenAsync(IDialogContext context, IAwaitable <long> argument)
        {
            var            choice = await argument;
            AcademicResult result = new AcademicResult();

            context.PerUserInConversationData.TryGetValue <AcademicResult>("result", out result);
            string responseMessage = string.Empty;
            string linkMsg         = string.Empty;

            if (result != null)
            {
                if (choice > result.interpretations.Count())
                {
                    await context.PostAsync("Okay! ask me.");
                }
                else
                {
                    EvaluateResult resp = await Utilities.Evaluate(result.interpretations[Convert.ToInt16(choice) - 1].rules[0].output.value);

                    int counter = 1;
                    foreach (var en in resp.entities)
                    {
                        EX ex = JsonConvert.DeserializeObject <EX>(en.E);
                        linkMsg = string.Empty;
                        foreach (var link in ex.S)
                        {
                            switch (link.Ty)
                            {
                            case 1:
                                linkMsg += $" [HTML]({link.U})";
                                break;

                            case 2:
                                linkMsg += $" [TEXT]({link.U})";
                                break;

                            case 3:
                                linkMsg += $" [PDF]({link.U})";
                                break;

                            case 4:
                                linkMsg += $" [DOC]({link.U})";
                                break;

                            case 5:
                                linkMsg += $" [PPT]({link.U})";
                                break;

                            case 6:
                                linkMsg += $" [XLS]({link.U})";
                                break;

                            case 7:
                                linkMsg += $" [PS]({link.U})";
                                break;

                            default:
                                linkMsg += $" [LINK]({link.U})";
                                break;
                            }
                        }

                        responseMessage += $"- {counter} . {ex.DN} {linkMsg} \r\n";
                        counter++;
                    }

                    await context.PostAsync(responseMessage);
                }
            }

            context.Wait(MessageReceivedAsync);
        }
        public async Task MessageReceivedAsync(IDialogContext context, IAwaitable <Message> argument)
        {
            var    message = await argument;
            string name    = string.Empty;

            name = message.GetBotPerUserInConversationData <string>("name");
            if (string.IsNullOrEmpty(name))
            {
                PromptDialog.Text(context, AfterResetAsync, "Hi! What is your name?");
            }
            else
            {
                bool welcome = false;
                context.PerUserInConversationData.TryGetValue <bool>("welcome", out welcome);

                if (!welcome)
                {
                    await context.PostAsync($"Welcome back {name}");

                    context.PerUserInConversationData.SetValue <bool>("welcome", true);
                    context.Wait(MessageReceivedAsync);
                }
                else if ((message.Text.ToLower().Equals("hi")) || (message.Text.ToLower().Equals("hello")))
                {
                    await context.PostAsync("Hello again!");

                    context.Wait(MessageReceivedAsync);
                }
                else
                {
                    //Interpret query
                    AcademicResult resp = await Utilities.Interpret(message.Text.ToLower());

                    if (resp.interpretations.Count == 0)
                    {
                        resp = await Utilities.Interpret(message.Text.ToLower());
                    }

                    //TODO: check resp
                    XmlDocument doc             = new XmlDocument();
                    string      xPath           = "rule/attr";
                    string      responseMessage = string.Empty;
                    string      parse           = string.Empty;

                    if (resp.interpretations.Count == 0)
                    {
                        await context.PostAsync("Sorry i couldn't find anything. Please try again.");

                        context.Wait(MessageReceivedAsync);
                    }
                    else
                    {
                        context.PerUserInConversationData.SetValue <AcademicResult>("result", resp);
                        int        counter = 1;
                        List <int> options = new List <int>();

                        //Get proper text for each interpretations
                        foreach (var interp in resp.interpretations)
                        {
                            //Add to options
                            options.Add(counter);

                            doc.LoadXml(interp.parse);
                            var nodes = doc.SelectNodes(xPath);
                            parse = string.Empty;
                            List <Item> attributes = new List <Item>();


                            foreach (XmlNode node in nodes)
                            {
                                if (node.Attributes.Count == 2)
                                {
                                    if (node.Attributes[1].Name == "canonical")
                                    {
                                        attributes.Add(new Item {
                                            Attribute = node.Attributes[0].Value, Value = node.Attributes[1].Value
                                        });
                                    }
                                    else
                                    {
                                        attributes.Add(new Item {
                                            Attribute = node.Attributes[0].Value, Value = node.Attributes[1].Value
                                        });
                                    }
                                }
                                else
                                {
                                    attributes.Add(new Item {
                                        Attribute = node.Attributes[0].Value, Value = node.InnerText
                                    });
                                }
                            }

                            parse            = "Papers " + ProcessAttribute(attributes);
                            responseMessage += $"- {counter} : {parse} \r\n";
                            counter         += 1;
                        }

                        options.Add(counter);
                        responseMessage += $"- {counter} : Search something else \r\n";

                        //Post reply
                        responseMessage = "Here is what I found. Simply reply with the number of your choice \r\n" + responseMessage;
                        PromptDialog.Number(context, AfterChosenAsync, responseMessage, "Sorry! I did not understand. Please choose from above options.");
                    }
                }
            }
        }