I'm using Adaptive card version 1.2 and Bot Builder dialog version is 4.5.1 in my Bot. Currently I'm calling adaptive card inside waterfall dialog using TextPrompt
. I have written a validator method to validate values returned from the card. This works fine in Bot Emulator. But when I host it on Azure I'm Getting error.
In the validator method, Adaptive card values are captured in promptContext.Recognized.Value
. But it returns null
when hosted on Azure which results in Object reference not set to an instance of an object exception.
//DialogClass
AddDialog(new WaterfallDialog(nameof(WaterfallDialog), new WaterfallStep[]
{
AdaptiveCardAsync,
}));
AddDialog(new TextPrompt("AdaptiveCard", CardValidator));
private async Task<DialogTurnResult> SelectedOptionAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
{
// Get Adaptive Card
JObject card = AdaptiveCard();
return await stepContext.PromptAsync("AdaptiveCard",
new PromptOptions
{
Prompt = (Activity)MessageFactory.Attachment(new Attachment
{
ContentType = AdaptiveCard.ContentType,
Content = card,
}),
}, cancellationToken);
}
//Calling adaptive card.
public JObject AdaptiveCard()
{
string fileName = "GetValues.json";
// combine path for cross platform support
string[] paths = { ".", "AdaptiveCards", fileName };
string fullPath = Path.Combine(paths);
var adaptiveCard = File.ReadAllText(fullPath);
JObject card = JObject.Parse(adaptiveCard);
}
// To validate values received from adaptive card.
private async Task<bool> CardValidator(PromptValidatorContext<string> promptContext, CancellationToken cancellationToken)
{
var result = JObject.Parse(promptContext.Recognized.Value);
}
//Calling Dialog - DialogExtension.cs
public static class DialogExtension
{
public static async Task Run(this Dialog dialog, ITurnContext turnContext, IStatePropertyAccessor<DialogState> accessor, CancellationToken cancellationToken = default(CancellationToken))
{
try
{
var dialogSet = new DialogSet(accessor);
dialogSet.Add(dialog);
var dialogContext = await dialogSet.CreateContextAsync(turnContext, cancellationToken);
// Ensure that message is a postBack (like a submission from Adaptive Cards)
if (dialogContext.Context.Activity.GetType().GetProperty("ChannelData") != null)
{
var channelData = JObject.Parse(dialogContext.Context.Activity.ChannelData.ToString());
if (channelData.ContainsKey("postBack") || channelData.ContainsKey("postback"))
{
var postbackActivity = dialogContext.Context.Activity;
// Convert the user's Adaptive Card input into the input of a Text Prompt
// Must be sent as a string
postbackActivity.Text = postbackActivity.Value.ToString();
//await dialogContext.Context.SendActivityAsync(postbackActivity);
}
}
var results = await dialogContext.ContinueDialogAsync(cancellationToken);
if (results.Status == DialogTurnStatus.Empty)
{
await dialogContext.BeginDialogAsync(dialog.Id, null, cancellationToken);
}
}
catch(Exception ex)
{
await turnContext.SendActivityAsync(MessageFactory.Text(ex.Message));
}
}
Kindly help me in resolving the issue.
The issue is that both "Test in Web Chat" and the Web Chat iFrame
<embed>
code still uses WebChat V3, which doesn't support Adaptive Cards well. WebChat V4 should be rolling out to both of those in the next couple of weeks.Regarding your LUIS issue, go to:
appsettings.json
file.This will not affect your other V4 bots since each bot should use its own App Service.