1
votes

I'm using sample Azure MSGraph Bot Authentication (https://github.com/microsoft/BotBuilder-Samples/blob/master/samples/csharp_dotnetcore/24.bot-authentication-msgraph/Dialogs/MainDialog.cs#L112), without any code changes (only changing APP id's and connection name). Here is the part of code, that works for me wrong:

private async Task<DialogTurnResult> ProcessStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            if (stepContext.Result != null)
            {
                var tokenResponse = stepContext.Result as TokenResponse;

                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);
        }

When I'm typing "me" command, receive my credentials. After that I'm typing another command (for example, "recent"), and bot welcomes me again. I think this can be because of ProcessStepAsync method calls only once, and then dialog returns to first step. But I want bot to return to if/else dialog every time it receives command from me.

In other words, how can I change turn of dialog, so it will back to ProcessStepAsync again, when i'm typing command?

1
Was the problem resolved? Let me know your update. - Md Farid Uddin Kiron
Sure, i'll let you know as soon as i'll try the solution, thanks - Denisov Jr.
That's sounds good, have a great coding time 😀 - Md Farid Uddin Kiron

1 Answers

1
votes

In that case you have to do it while you taking input from user and have to check that input like given format. I would recommend you switch-case rather monotonous if-else block.

Try like this:

 dynamic checkUserInput = turnContext.Activity.Text;

                //Check Each User Input
                switch (checkUserInput.ToLower())
                {
                    case "me":
                        await turnContext.SendActivityAsync(MessageFactory.Text("You have typed me"), cancellationToken);

                        await turnContext.SendActivityAsync(MessageFactory.Text("Once you begin using solution workspace, you'll see checklist that will be help you too:"), cancellationToken);
                        //You can add any additional flow here if needed
                        var overview = OverViewFlow();
                        await turnContext.SendActivityAsync(overview).ConfigureAwait(false);
                        break;
                    case "send":
                          await turnContext.SendActivityAsync(MessageFactory.Text("You have typed send"), cancellationToken);
                         break;
                      default: //When nothing found in user intent
                        await turnContext.SendActivityAsync(MessageFactory.Text("What are you looking for?"), cancellationToken);
                        break;

                }

Though Its not essential but I am showing you how you could make the things done.

 public IMessageActivity OverViewFlow()
        {
            try
            {
                var replyToConversation = Activity.CreateMessageActivity();
                replyToConversation.AttachmentLayout = AttachmentLayoutTypes.Carousel;
                replyToConversation.Attachments = new List<Attachment>();

                Dictionary<string, string> cardContentList = new Dictionary<string, string>();
                cardContentList.Add("Link 1", "https://via.placeholder.com/300.png/09f/fffC/O");
                cardContentList.Add("Link 2", "https://via.placeholder.com/300.png/09f/fffC/O");
                cardContentList.Add("Link 3", "https://via.placeholder.com/300.png/09f/fffC/O");

                foreach (KeyValuePair<string, string> cardContent in cardContentList)
                {
                    List<CardImage> cardImages = new List<CardImage>();
                    cardImages.Add(new CardImage(url: cardContent.Value));

                    List<CardAction> cardButtons = new List<CardAction>();

                    CardAction plButton = new CardAction()
                    {
                        Value = $"",
                        Type = "imBack",
                        Title = "" + cardContent.Key + ""
                    };

                    cardButtons.Add(plButton);

                    HeroCard plCard = new HeroCard()
                    {
                        Title = $"",
                        Subtitle = $"",
                        Images = cardImages,
                        Buttons = cardButtons
                    };

                    Attachment plAttachment = plCard.ToAttachment();
                    replyToConversation.Attachments.Add(plAttachment);
                }

                return replyToConversation;
            }
            catch (Exception ex)
            {
                throw new NotImplementedException(ex.Message, ex.InnerException);
            }
        }

Hope it would help you.