public async Task ArtistInfo(IDialogContext context, LuisResult result)
        {
            QureyController qc     = new QureyController();
            string          entity = "";
            string          ans    = "";

            qc.PostQuestionOne(result.Query, result.TopScoringIntent.Intent, result.TopScoringIntent.Score.ToString(), "0");

            if (result.Entities != null)
            {
                switch (result.Entities.Count)
                {
                case 1:
                    entity += result.Entities[0].Entity;
                    break;

                case 2:
                    entity += result.Entities[0].Entity + " " + result.Entities[1].Entity;
                    break;

                case 3:
                    entity += result.Entities[0].Entity + " " + result.Entities[1].Entity + " " + result.Entities[2].Entity;
                    break;
                }
            }
            else
            {
                entity = result.Query;
            }

            await context.PostAsync("Here are results i found : ");

            try
            {
                BingSearch bingSearch = new BingSearch();

                bingSearch = BingSearchData.getSearchResult(entity);

                if (bingSearch != null)
                {
                    CardUtil.showBingWikiHeroCard((IMessageActivity)context.Activity, bingSearch);
                    ans = bingSearch.news.readLink;
                }
                else
                {
                    await context.PostAsync($"I couldn't find a artist info :0");
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine($"Error when filtering artists: {e}");
            }
            if (ans == "")
            {
                ans = "";
            }
            qc.PostAnswerOne(ans, result.TopScoringIntent.Intent);
        }
        public async Task WhoIsQuestion(IDialogContext context, IAwaitable <IMessageActivity> activity,
                                        LuisResult result)
        {
            QureyController qc = new QureyController();

            qc.PostQuestionOne(result.Query, result.TopScoringIntent.Intent, result.TopScoringIntent.Score.ToString(), "0");

            if (result.TopScoringIntent.Score > 0.5)
            {
                string entity = result.Query;

                await context.PostAsync("I think it is : ");

                try
                {
                    BingSearch bingSearch = new BingSearch();

                    bingSearch = BingSearchData.getSearchResult(entity);

                    if (bingSearch != null)
                    {
                        CardUtil.showBingWikiHeroCard((IMessageActivity)context.Activity, bingSearch);
                    }
                    else
                    {
                        await context.PostAsync($"I couldn't find any results :( You can try again.");
                    }
                }
                catch (Exception e)
                {
                    Debug.WriteLine($"I couldn't find any results :( You can try again.");
                    Console.WriteLine(e);
                }
            }
            else
            {
                string ans = "";
                ans = qc.GetTrainedAnswer(result.Query);
                qc.PostAnswerOne(ans, result.TopScoringIntent.Intent);
                await context.PostAsync(ans);

                context.Wait(MessageReceived);
            }
        }
Example #3
0
        public virtual async Task MessageReceivedAsync(IDialogContext context, IAwaitable <IMessageActivity> result)
        {
            var message = await result;

            string entity = "";

            if (message.Text.Length > 0)
            {
                entity = message.Text;
            }

            await context.PostAsync("Here are results i found : ");

            try
            {
                BingSearch bingSearch = new BingSearch();

                bingSearch = BingSearchData.getSearchResult(entity);

                if (bingSearch != null)
                {
                    CardUtil.showBingWikiHeroCard((IMessageActivity)context.Activity, bingSearch);
                    QureyController qc = new QureyController();
                    qc.PostAnswerOne(bingSearch.entities.readLink, "BingSearch");
                }
                else
                {
                    await context.PostAsync($"I couldn't find what you asked, you can always try again..");
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine($"Error when filtering by genre: {e}");
            }

            context.Done <object>(null);
        }