// Handles introduction/continuation prompt logic.
        private async Task <DialogTurnResult> IntroStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            if (stepContext.Context.IsSkill())
            {
                // If the bot is in skill mode, skip directly to route and do not prompt
                return(await stepContext.NextAsync(cancellationToken : cancellationToken));
            }
            else
            {
                // If bot is in local mode, prompt with intro or continuation message
                var prompt = stepContext.Options as Activity ?? HeroCardResponses.SendIntroCard(stepContext.Context, _templateManager);
                var state  = await _stateAccessor.GetAsync(stepContext.Context, () => new NewsSkillState(), cancellationToken : cancellationToken);

                var activity = stepContext.Context.Activity;
                if (activity.Type == ActivityTypes.ConversationUpdate)
                {
                    prompt = HeroCardResponses.SendIntroCard(stepContext.Context, _templateManager);
                }

                var promptOptions = new PromptOptions
                {
                    Prompt = (Activity)prompt
                };

                return(await stepContext.PromptAsync(nameof(TextPrompt), promptOptions, cancellationToken));
            }
        }
        // Runs on every turn of the conversation to check if the conversation should be interrupted.
        protected async Task <DialogTurnResult> InterruptDialogAsync(DialogContext innerDc, CancellationToken cancellationToken)
        {
            DialogTurnResult interrupted = null;
            var activity = innerDc.Context.Activity;

            if (activity.Type == ActivityTypes.Message && !string.IsNullOrEmpty(activity.Text))
            {
                // Get connected LUIS result from turn state.
                var generalResult = innerDc.Context.TurnState.Get <General>(StateProperties.GeneralLuisResult);
                (var generalIntent, var generalScore) = generalResult.TopIntent();

                if (generalScore > 0.5)
                {
                    switch (generalIntent)
                    {
                    case General.Intent.Cancel:
                    {
                        await innerDc.Context.SendActivityAsync(_templateManager.GenerateActivityForLocale(MainStrings.CANCELLED), cancellationToken);

                        await innerDc.CancelAllDialogsAsync(cancellationToken);

                        if (innerDc.Context.IsSkill())
                        {
                            var state = await _stateAccessor.GetAsync(innerDc.Context, () => new NewsSkillState(), cancellationToken : cancellationToken);

                            interrupted = await innerDc.EndDialogAsync(state.IsAction?new ActionResult(false) : null, cancellationToken : cancellationToken);
                        }
                        else
                        {
                            interrupted = await innerDc.BeginDialogAsync(InitialDialogId, cancellationToken : cancellationToken);
                        }

                        break;
                    }

                    case General.Intent.Help:
                    {
                        await innerDc.Context.SendActivityAsync(HeroCardResponses.SendHelpCard(innerDc.Context, _templateManager), cancellationToken);

                        await innerDc.RepromptDialogAsync(cancellationToken);

                        interrupted = EndOfTurn;
                        break;
                    }
                    }
                }
            }

            return(interrupted);
        }
        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));
        }
Exemple #4
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));
            }
        }