Answered by:
Wake up the bot when a adaptive card name other is clicked in my dialog name product issue

Question
-
I have 2 dailog name main dailog and product issue. After displaying the first step of product issue , Four adaptive card are called name inveter , fan , battery and others in 2 step their is a condition
when click on others in adaptive card a static link is displayed with a msg wake me up with hi. But bot throw a error
Here is my code
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;
}
}
}HERE is 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);
}
}
}- Moved by Carey FrischMVP, Editor Friday, November 29, 2019 6:57 PM Relocated
Friday, November 29, 2019 8:43 AM
Answers
-
Might try asking for help over here.
https://stackoverflow.com/questions/tagged/botframework
Regards, Dave Patrick ....
Microsoft Certified Professional
Microsoft MVP [Windows Server] Datacenter Management
Disclaimer: This posting is provided "AS IS" with no warranties or guarantees, and confers no rights.- Proposed as answer by Richard MuellerMVP, Banned Saturday, November 30, 2019 12:58 AM
- Marked as answer by Richard MuellerMVP, Banned Saturday, December 7, 2019 8:57 PM
Saturday, November 30, 2019 12:48 AM