wake up the functionality on hi on clicking on others in product issue(A dialog) its goes to main dailog and show 4 choice

陌路散爱 提交于 2019-12-14 04:19:50

问题


I want to go to main dialog from product issue after clicking on adaptive card of others, like when say hi after clicking on other it will go main dialog and start the bot again. When click on other adaptive card its shows a static link and wake up msg . but i am not able wake up it on hi This is my main dialog:

namespace Microsoft.BotBuilderSamples
{
public class MainDialog : ComponentDialog
{


    protected readonly ILogger _logger;
    protected readonly string[] _cards =
     {
        Path.Combine(".", "Resources", "ValidationCard.json"),


    };
    public MainDialog(ILogger<MainDialog> logger)
        : base(nameof(MainDialog))
    {
        _logger = logger;


        _logger = logger;
        AddDialog(new ProductIssue($"{nameof(MainDialog)}.fromMain"));
        AddDialog(new ProductIssue($"{nameof(Confirm)}.fromConfirm"));
        AddDialog(new Confirm());
        AddDialog(new ChoicePrompt(nameof(ChoicePrompt)));
        AddDialog(new WaterfallDialog($"{nameof(MainDialog)}.mainFlow", new WaterfallStep[]
        {
            ChoiceCardStepAsync,
            ShowCardStepAsync,
         }));

        AddDialog(new TextPrompt(nameof(TextPrompt)));
        InitialDialogId = $"{nameof(MainDialog)}.mainFlow";
    }


    private async Task<DialogTurnResult> ChoiceCardStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
    {
        if (stepContext.Context.Activity.Text == "no")
        {
            return await stepContext.BeginDialogAsync($"{nameof(MainDialog)}.fromMain", null, cancellationToken);
        }
        else if (stepContext.Context.Activity.Text == "yes")
        {

            return await stepContext.BeginDialogAsync(nameof(Confirm), null, cancellationToken);

        }

        var options = new PromptOptions()
        {

            Prompt = MessageFactory.Text("Welcome user, How can we serve you ? "),
            RetryPrompt = MessageFactory.Text("That was not a valid choice, please select a option between 1 to 4."),
            Choices = GetChoices(),
        };

        return await stepContext.PromptAsync(nameof(ChoicePrompt), options, cancellationToken);
    }


    private async Task<DialogTurnResult> ShowCardStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
    {

        var attachments = new List<Attachment>();
        var reply = MessageFactory.Attachment(attachments);
        switch (((FoundChoice)stepContext.Result).Value)
        {
            case "Product issue":
                reply.Attachments.Add(Cards.CreateAdaptiveCardAttachment3());
                break;

            case "Register Product":

                reply.Attachments.Add(Cards.GetHeroCard1().ToAttachment());
                break;
            case "Online Purchase":

                reply.Attachments.Add(Cards.GetHeroCard2().ToAttachment());
                break;
            case "Customer Grivance":

                reply.Attachments.Add(Cards.GetHeroCard3().ToAttachment());
                break;

            default:
                reply.AttachmentLayout = AttachmentLayoutTypes.Carousel;
                reply.Attachments.Add(Cards.CreateAdaptiveCardAttachment3());
                reply.AttachmentLayout = AttachmentLayoutTypes.Carousel;
                reply.Attachments.Add(Cards.GetHeroCard1().ToAttachment());
                break;
        }


        await stepContext.Context.SendActivityAsync(reply, cancellationToken);
        if (stepContext.Context.Activity.Text == "Register Product" || stepContext.Context.Activity.Text == "Online Purchase" || stepContext.Context.Activity.Text == "Customer Grivance")
        {
            Random r = new Random();
            var validationcard = Cards.CreateAdaptiveCardAttachment2(_cards[r.Next(_cards.Length)]);
            await stepContext.Context.SendActivityAsync(MessageFactory.Attachment(validationcard), cancellationToken);
        }

        return await stepContext.ContinueDialogAsync();
    }



    private IList<Choice> GetChoices()
    {
        var cardOptions = new List<Choice>()
        {

            new Choice() { Value = "Product issue", Synonyms = new List<string>() { "adaptive" } },
            new Choice() { Value = "Register Product", Synonyms = new List<string>() { "hero" } },
            new Choice() { Value = "Online Purchase", Synonyms = new List<string>() { "hero" } },
            new Choice() { Value = "Customer Grivance", Synonyms = new List<string>() { "hero" } },

        };

        return cardOptions;
    }
}
}

This my Product issue:

namespace Microsoft.BotBuilderSamples
{
public class ProductIssue : ComponentDialog
{
    private const string UserInfo = "value-userInfo";
    protected readonly ILogger _logger;
    protected readonly string[] _cards =
     {
        Path.Combine(".", "Resources", "ValidationCard.json"),
     };

    public ProductIssue(string dialogId) : base(dialogId)
    {
        AddDialog(new TextPrompt(nameof(TextPrompt)));
        AddDialog(new ChoicePrompt(nameof(ChoicePrompt)));
        if (dialogId == $"{nameof(MainDialog)}.fromMain")
            AddDialog(new WaterfallDialog(nameof(WaterfallDialog), new WaterfallStep[]
    {
           optionAsync,
           InoptionAsync,
           AnyOthersAsync,
           OtpAsync,
          UserauthenticationAsync

            }));
        else
            AddDialog(new WaterfallDialog(nameof(WaterfallDialog), new WaterfallStep[]
            {
                   InoptionAsync,
                   AnyOthersAsync,
                   OtpAsync,
                   UserauthenticationAsync

            }));
        InitialDialogId = nameof(WaterfallDialog);
        AddDialog(new TextPrompt(nameof(TextPrompt)));

    }
    private async Task<DialogTurnResult> optionAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
    {

        var attachments = new List<Attachment>();
        var reply = MessageFactory.Attachment(attachments);
        reply.AttachmentLayout = AttachmentLayoutTypes.Carousel;
        reply.Attachments.Add(Cards.CreateAdaptiveCardAttachment4());
        reply.Attachments.Add(Cards.CreateAdaptiveCardAttachment5());
        reply.Attachments.Add(Cards.CreateAdaptiveCardAttachment6());
        reply.Attachments.Add(Cards.CreateAdaptiveCardAttachment7());
        var promptOptions = new PromptOptions { Prompt = MessageFactory.Text("Please select any option.") };
        await stepContext.Context.SendActivityAsync(reply, cancellationToken);
        return await stepContext.PromptAsync(nameof(TextPrompt), promptOptions, cancellationToken);

    }

    private async Task<DialogTurnResult> InoptionAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
    {
        if (stepContext.Context.Activity.Text == "Inverter" || stepContext.Context.Activity.Text == "Fan" || stepContext.Context.Activity.Text == "Battery" || stepContext.Context.Activity.Text == "Confirm")
        {
            var attachments = new List<Attachment>();
            var reply = MessageFactory.Attachment(attachments);
            reply.AttachmentLayout = AttachmentLayoutTypes.Carousel;
            reply.Attachments.Add(Cards.CreateAdaptiveCardAttachment8());
            await stepContext.Context.SendActivityAsync(reply, cancellationToken);
        }
        else if (stepContext.Context.Activity.Text == "Others")
        {
            var attachments = new List<Attachment>();
            var reply = MessageFactory.Attachment(attachments);
            reply.AttachmentLayout = AttachmentLayoutTypes.Carousel;
            reply.Attachments.Add(Cards.GetHeroCard5().ToAttachment());
            await stepContext.Context.SendActivityAsync(reply, cancellationToken);
            await stepContext.Context.SendActivityAsync(MessageFactory.Text("I will be here if you need me further."), cancellationToken);
          //  await   stepContext.EndDialogAsync(null, cancellationToken);
        }
        var promptOptions = new PromptOptions { Prompt = MessageFactory.Text("") };
        return await stepContext.PromptAsync(nameof(TextPrompt), promptOptions, cancellationToken);
      //  return await stepContext.NextAsync(null, cancellationToken);
    }

    private async Task<DialogTurnResult> AnyOthersAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
    {
        if (stepContext.Context.Activity.Text == "Any Others")
        {
            await stepContext.Context.SendActivityAsync(MessageFactory.Text("We are here to help you."), cancellationToken);
        }
        var prompt = new PromptOptions { Prompt = MessageFactory.Text("Please enter your specific problem") };
        return await stepContext.PromptAsync(nameof(TextPrompt), prompt, cancellationToken);
    }

    private async Task<DialogTurnResult> OtpAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
    {
        stepContext.Values[UserInfo] = new UserInput();
        await stepContext.Context.SendActivityAsync(MessageFactory.Text("To proceed further, we will be verifying your mobile number by sending an OTP."), cancellationToken);
        await stepContext.Context.SendActivityAsync(MessageFactory.Text("We have just sent an OTP to your number"), cancellationToken);
        var num = new PromptOptions
        {
            Prompt = MessageFactory.Text("Kindly enter the OTP sent(6 digit number)")
        };
        return await stepContext.PromptAsync(nameof(TextPrompt), num, cancellationToken);
    }
    private async Task<DialogTurnResult> UserauthenticationAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
    {
        var Otp = (UserInput)stepContext.Values[UserInfo];
        int value;
        var len = (stepContext.Result.ToString()).Length;
        bool success = int.TryParse(stepContext.Result.ToString(), out value);
        if (success == true && len == 6)
        {
            await stepContext.Context.SendActivityAsync(MessageFactory.Text("Thanks. Your OTP is confirmed."), cancellationToken);
            await stepContext.Context.SendActivityAsync(MessageFactory.Text("We are now validating your number against our database. This may take a minute."), cancellationToken);
            await stepContext.Context.SendActivityAsync(MessageFactory.Text("We will be registering you as a user in our system. Please provide a few details."), cancellationToken);
        }
        var attachments = new List<Attachment>();
        var reply = MessageFactory.Attachment(attachments);
        reply.AttachmentLayout = AttachmentLayoutTypes.Carousel;
        reply.Attachments.Add(Cards.CreateAdaptiveCardAttachment9());
        await stepContext.Context.SendActivityAsync(reply, cancellationToken);
        var promptOptions = new PromptOptions { Prompt = MessageFactory.Text("") };
        return await stepContext.PromptAsync(nameof(TextPrompt), promptOptions, cancellationToken);

    }


 }

}


回答1:


Please make the following change and test the bot :

else if (stepContext.Context.Activity.Text == "Others")
    {
        var attachments = new List<Attachment>();
        var reply = MessageFactory.Attachment(attachments);
        reply.AttachmentLayout = AttachmentLayoutTypes.Carousel;
        reply.Attachments.Add(Cards.GetHeroCard5().ToAttachment());
        await stepContext.Context.SendActivityAsync(reply, cancellationToken);
        await stepContext.Context.SendActivityAsync(MessageFactory.Text("I will be here if you need me further."), cancellationToken);
        return await stepContext.EndDialogAsync(null, cancellationToken);
    }

Hope it works then.



来源:https://stackoverflow.com/questions/59100901/wake-up-the-functionality-on-hi-on-clicking-on-others-in-product-issuea-dialog

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!