Exemplo n.º 1
0
        private async Task <DialogTurnResult> SetFavoritesAsync(WaterfallStepContext sc, CancellationToken cancellationToken)
        {
            var convState = await ConvAccessor.GetAsync(sc.Context, () => new NewsSkillState(), cancellationToken : cancellationToken);

            var userState = await UserAccessor.GetAsync(sc.Context, () => new NewsSkillUserState(), cancellationToken : cancellationToken);

            // if intent is SetFavorites or not set in state yet
            if ((convState.LuisResult != null && convState.LuisResult.TopIntent().intent == Luis.NewsLuis.Intent.SetFavoriteTopics) || userState.Category == null)
            {
                // show card with categories the user can choose
                var categories = new PromptOptions()
                {
                    Choices = new List <Choice>(),
                };

                categories.Choices.Add(new Choice("Business"));
                categories.Choices.Add(new Choice("Entertainment"));
                categories.Choices.Add(new Choice("Health"));
                categories.Choices.Add(new Choice("Politics"));
                categories.Choices.Add(new Choice("World"));
                categories.Choices.Add(new Choice("Sports"));

                return(await sc.PromptAsync(nameof(ChoicePrompt), new PromptOptions()
                {
                    Prompt = TemplateManager.GenerateActivityForLocale(FavoriteTopicsResponses.FavoriteTopicPrompt),
                    Choices = categories.Choices
                },
                                            cancellationToken));
            }

            return(await sc.NextAsync(userState.Category, cancellationToken));
        }
Exemplo n.º 2
0
        private async Task <DialogTurnResult> GetSiteAsync(WaterfallStepContext sc, CancellationToken cancellationToken)
        {
            var convState = await ConvAccessor.GetAsync(sc.Context, () => new NewsSkillState(), cancellationToken : cancellationToken);

            string query = (string)sc.Result;

            if (convState.LuisResult != null && convState.LuisResult.Entities.site != null && convState.LuisResult.Entities.site.Length > 0)
            {
                string site = convState.LuisResult.Entities.site[0].Replace(" ", string.Empty);
                query = string.Concat(query, $" site:{site}");
            }

            return(await sc.NextAsync(query, cancellationToken));
        }
Exemplo n.º 3
0
        private async Task <DialogTurnResult> GetQuery(WaterfallStepContext sc, CancellationToken cancellationToken)
        {
            var convState = await ConvAccessor.GetAsync(sc.Context, () => new NewsSkillState());

            // Let's see if we have a topic
            if (convState.LuisResult.Entities.topic != null && convState.LuisResult.Entities.topic.Length > 0)
            {
                return(await sc.NextAsync(convState.LuisResult.Entities.topic[0]));
            }

            return(await sc.PromptAsync(nameof(TextPrompt), new PromptOptions()
            {
                Prompt = await _responder.RenderTemplate(sc.Context, sc.Context.Activity.Locale, FindArticlesResponses.TopicPrompt)
            }));
        }
        private async Task <DialogTurnResult> ShowArticlesAsync(WaterfallStepContext sc, CancellationToken cancellationToken)
        {
            var userState = await UserAccessor.GetAsync(sc.Context, () => new NewsSkillUserState(), cancellationToken : cancellationToken);

            var articles = await _client.GetTrendingNewsAsync(userState.Market);

            await sc.Context.SendActivityAsync(HeroCardResponses.ShowTrendingCards(sc.Context, TemplateManager, articles), cancellationToken);

            var state = await ConvAccessor.GetAsync(sc.Context, () => new NewsSkillState(), cancellationToken : cancellationToken);

            if (state.IsAction)
            {
                return(await sc.EndDialogAsync(GenerateNewsActionResult(articles, true), cancellationToken));
            }

            return(await sc.EndDialogAsync(cancellationToken : cancellationToken));
        }
Exemplo n.º 5
0
        private async Task <DialogTurnResult> ShowArticlesAsync(WaterfallStepContext sc, CancellationToken cancellationToken)
        {
            var userState = await UserAccessor.GetAsync(sc.Context, () => new NewsSkillUserState(), cancellationToken : cancellationToken);

            userState.Category = (FoundChoice)sc.Result;

            // show favorite articles
            var articles = await _client.GetNewsByCategoryAsync(userState.Category.Value, userState.Market);

            await sc.Context.SendActivityAsync(HeroCardResponses.ShowFindArticleCards(sc.Context, TemplateManager, articles, true));

            var state = await ConvAccessor.GetAsync(sc.Context, () => new NewsSkillState(), cancellationToken : cancellationToken);

            if (state.IsAction)
            {
                return(await sc.EndDialogAsync(GenerateNewsActionResult(articles, true), cancellationToken));
            }

            return(await sc.EndDialogAsync(cancellationToken : cancellationToken));
        }
        private async Task <DialogTurnResult> ShowArticlesAsync(WaterfallStepContext sc, CancellationToken cancellationToken)
        {
            var userState = await UserAccessor.GetAsync(sc.Context, () => new NewsSkillUserState(), cancellationToken : cancellationToken);

            var query = (string)sc.Result;

            using (var client = new NewsClient(Settings.BingNewsEndPoint, _newsKey))
            {
                var articles = await client.GetNewsForTopicAsync(query, userState.Market);

                await sc.Context.SendActivityAsync(HeroCardResponses.ShowFindArticleCards(sc.Context, TemplateManager, articles), cancellationToken);

                var state = await ConvAccessor.GetAsync(sc.Context, () => new NewsSkillState(), cancellationToken : cancellationToken);

                if (state.IsAction)
                {
                    return(await sc.EndDialogAsync(GenerateNewsActionResult(articles, true), cancellationToken));
                }

                return(await sc.EndDialogAsync(cancellationToken : cancellationToken));
            }
        }
Exemplo n.º 7
0
        protected async Task <DialogTurnResult> GetMarketAsync(WaterfallStepContext sc, CancellationToken cancellationToken)
        {
            var userState = await UserAccessor.GetAsync(sc.Context, () => new NewsSkillUserState(), cancellationToken : cancellationToken);

            var convState = await ConvAccessor.GetAsync(sc.Context, () => new NewsSkillState(), cancellationToken : cancellationToken);

            // Check if there's already a location
            if (!string.IsNullOrWhiteSpace(userState.Market))
            {
                return(await sc.NextAsync(userState.Market, cancellationToken));
            }
            else if (!string.IsNullOrWhiteSpace(convState.CurrentCoordinates))
            {
                // make maps service query with location coordinates instead of user input
                return(await sc.NextAsync(convState.CurrentCoordinates, cancellationToken));
            }

            // Prompt user for location
            return(await sc.PromptAsync(nameof(TextPrompt), new PromptOptions()
            {
                Prompt = TemplateManager.GenerateActivityForLocale(MainStrings.MarketPrompt),
                RetryPrompt = TemplateManager.GenerateActivityForLocale(MainStrings.MarketRetryPrompt)
            }));
        }
Exemplo n.º 8
0
        protected override async Task <DialogTurnResult> OnContinueDialogAsync(DialogContext dc, CancellationToken cancellationToken = default(CancellationToken))
        {
            var state = await ConvAccessor.GetAsync(dc.Context, cancellationToken : cancellationToken);

            return(await base.OnContinueDialogAsync(dc, cancellationToken));
        }
        protected override async Task <DialogTurnResult> OnBeginDialogAsync(DialogContext dc, object options, CancellationToken cancellationToken = default(CancellationToken))
        {
            var state = await ConvAccessor.GetAsync(dc.Context);

            return(await base.OnBeginDialogAsync(dc, options, cancellationToken));
        }