唤醒您在产品问题(对话框)中单击其他按钮时的功能,它会转到主菜单并显示4个选择项

问题描述 投票:1回答:1

我想在单击其他人的自适应卡后从产品问题转到主对话框,例如单击其他按钮后打个招呼,它将进入主对话框并重新启动机器人。当单击其他自适应卡时,其显示静态链接并唤醒msg。但是我无法唤醒它这是我的主对话框:

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

此我的产品问题:

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

    }


 }

}

c# asp.net-mvc click botframework adaptive-cards
1个回答
0
投票

请进行以下更改并测试漫游器:

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

希望它能起作用。

© www.soinside.com 2019 - 2024. All rights reserved.