Ejemplo n.º 1
0
        private async Task <DialogTurnResult> PromptStepAsync(WaterfallStepContext step, CancellationToken cancellationToken)
        {
            var activity = step.Context.Activity;

            if (step.Result.ToString() == "Ver ultimos correos")
            {
                await OAuthHelpers.ListRecentMailAsync(step.Context, step.Result as TokenResponse);
            }
            else if (step.Result.ToString() == "Otro")
            {
                var reply = step.Context.Activity.CreateReply();
                reply.Attachments = new List <Attachment> {
                    CreateHeroCard().ToAttachment()
                };
                reply.Text = "Ingresa la consulta";
                return(await step.BeginDialogAsync("waterfallStepsOtro", cancellationToken : cancellationToken));

                //await step.Context.SendActivityAsync(reply, cancellationToken);
            }
            // Set the context if the message is not the magic code.
            if (activity.Type == ActivityTypes.Message && !Regex.IsMatch(activity.Text, @"(\d{6})"))
            {
                await accessors.CommandState.SetAsync(step.Context, activity.Text, cancellationToken);

                await accessors.UserState.SaveChangesAsync(step.Context, cancellationToken : cancellationToken);
            }

            return(await step.BeginDialogAsync("loginPrompt", cancellationToken : cancellationToken));
        }
Ejemplo n.º 2
0
        private async Task <DialogTurnResult> CorreosStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            // WaterfallStep always finishes with the end of the Waterfall or with another dialog; here it is a Prompt Dialog.
            // Running a prompt here means the next WaterfallStep will be run when the users response is received.

            // return await stepContext.PromptAsync("name", new PromptOptions { Prompt = MessageFactory.Text("Please enter your name.") }, cancellationToken);



            try
            {
                var tokenResponse = (TokenResponse)stepContext.Result;
                if (tokenResponse != null)
                {
                    //throw new InvalidOperationException("xd1");
                    await OAuthHelpers.ListRecentMailAsync(stepContext.Context, stepContext.Result as TokenResponse);

                    return(await stepContext.EndDialogAsync(cancellationToken : cancellationToken));
                }
                else
                {
                    //List.
                    //throw new InvalidOperationException("xd");
                    return(await stepContext.ReplaceDialogAsync(this.Id, null, cancellationToken));
                }
            }
            catch (Exception error)
            {
                //accessors.UserProfile.Name
                return(await stepContext.ReplaceDialogAsync(this.Id, null, cancellationToken));

                throw new InvalidOperationException(error.Message + stepContext.Result);
                //return await stepContext.ReplaceDialogAsync(this.Id, null, cancellationToken);
            }
        }
Ejemplo n.º 3
0
        private async Task <DialogTurnResult> ProcessStep2Async(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            var tokenResponse = (TokenResponse)stepContext.Result;

            if (tokenResponse != null)
            {
                // We do not need to store the token in the bot. When we need the token we can
                // send another prompt. If the token is valid the user will not need to log back in.
                // The token will be available in the Result property of the task.

                // If we have the token use the user is authenticated so we may use it to make API calls.
                if (tokenResponse?.Token != null)
                {
                    var parts = ((string)stepContext.Values["command"] ?? string.Empty).ToLowerInvariant().Split(' ');

                    var command = parts[0];

                    if (command == "me")
                    {
                        await OAuthHelpers.ListMeAsync(stepContext.Context, tokenResponse);
                    }
                    else if (command.StartsWith("send"))
                    {
                        await OAuthHelpers.SendMailAsync(stepContext.Context, tokenResponse, parts[1]);
                    }
                    else if (command.StartsWith("recent"))
                    {
                        await OAuthHelpers.ListRecentMailAsync(stepContext.Context, tokenResponse);
                    }
                    else
                    {
                        await stepContext.Context.SendActivityAsync(MessageFactory.Text($"Your token is: {tokenResponse.Token}"), cancellationToken);
                    }
                }
            }
            else
            {
                await stepContext.Context.SendActivityAsync(MessageFactory.Text("We couldn't log you in. Please try again later."), cancellationToken);
            }

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