在产品问题(对话框)上单击其他按钮时,唤醒您的功能喜好,并转到主菜单并显示4个选择 [英] wake up the functionality on hi on clicking on others in product issue(A dialog) its goes to main dailog and show 4 choice

查看:72
本文介绍了在产品问题(对话框)上单击其他按钮时,唤醒您的功能喜好,并转到主菜单并显示4个选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

这是我的产品问题:

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

    }


 }

}

推荐答案

请进行以下更改并测试bot:

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

希望它能正常工作.

这篇关于在产品问题(对话框)上单击其他按钮时,唤醒您的功能喜好,并转到主菜单并显示4个选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆