Пример #1
0
        private async Task <DialogTurnResult> ProcessStepAsync(WaterfallStepContext step, CancellationToken cancellationToken)
        {
            if (step.Result != null)
            {
                var bot           = step.Context.TurnState.Get <ActivityBotBase>("bot");
                var tokenResponse = step.Result as TokenResponse;

                if (tokenResponse?.Token != null)
                {
                    var parts   = (System.Convert.ToString(step.Values["command"]) ?? string.Empty).ToLowerInvariant().Split(' ');
                    var command = parts[0];

                    if (command == "myprofile")
                    {
                        FitBitApiHelper fitBitApiHelper = new FitBitApiHelper(tokenResponse.Token);
                        UserProfile     userProfile     = await fitBitApiHelper.GetUserProfileAsync();

                        var reply = step.Context.Activity.CreateReply();
                        reply.Attachments = new List <Attachment>()
                        {
                            DialogHelpers.CreateUserProfileAdaptiveCard(userProfile),
                            //DialogHelpers.CreateBotFunctionsCard("What would you like to do next? Select one", bot).ToAttachment()
                        };

                        await step.Context.SendActivityAsync(reply, cancellationToken);
                    }
                    else if (command == "mybadges")
                    {
                        FitBitApiHelper fitBitApiHelper = new FitBitApiHelper(tokenResponse.Token);
                        UserBadges      userBadges      = await fitBitApiHelper.GetUserBadgesAsync();

                        var reply = step.Context.Activity.CreateReply();
                        reply.Attachments = new List <Attachment>()
                        {
                            DialogHelpers.CreateUserBadgesCard(userBadges),
                            //DialogHelpers.CreateBotFunctionsCard("What would you like to do next? Select one", bot).ToAttachment()
                        };

                        await step.Context.SendActivityAsync(reply, cancellationToken);
                    }
                    else if (command == "myactivity")
                    {
                        FitBitApiHelper fitBitApiHelper = new FitBitApiHelper(tokenResponse.Token);
                        var             userBadges      = await fitBitApiHelper.GetUserActivityAsync(DateTime.Now);

                        var str1 = DialogHelpers.SummaryText(userBadges);
                        await step.Context.SendActivityAsync(MessageFactory.Text(str1), cancellationToken);
                    }
                    else if (command == "quit")
                    {
                        await step.Context.SendActivityAsync("Exiting Fitbit dialog.", cancellationToken : cancellationToken);

                        var conversationStateProp = bot.ConversationState.CreateProperty <int>("counter");
                        await conversationStateProp.SetAsync(step.Context, 0);

                        return(await step.EndDialogAsync(cancellationToken : cancellationToken));
                    }
                    else
                    {
                        await step.Context.SendActivityAsync(MessageFactory.Text("I don't recognize that option."), cancellationToken);
                    }

                    //else
                    //{
                    //    var reply = step.Context.Activity.CreateReply();
                    //    reply.Attachments = new List<Attachment>()
                    //    {
                    //        DialogHelpers.CreateBotFunctionsHeroCard("This is what I can do for you.").ToAttachment()
                    //    };

                    //    await step.Context.SendActivityAsync(reply, cancellationToken);
                    //}

                    //else
                    //{
                    //    await step.Context.SendActivityAsync($"Your token is: {tokenResponse.Token}", cancellationToken: cancellationToken);
                    //}
                    return(await step.ReplaceDialogAsync(nameof(WaterfallDialog), cancellationToken : cancellationToken));
                }
            }
            else
            {
                await step.Context.SendActivityAsync(MessageFactory.Text("We couldn't log you in. Please try again later."), cancellationToken);
            }

            return(await step.EndDialogAsync(cancellationToken : cancellationToken));
        }