New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Problem: No clear way to combine Adaptive Cards with prompts in dialogs. #614
Comments
Any update of a possible solution ? |
This is my current theory, but I don't know which direction the team is going in with this... It seems like the intention for combining adaptive cards with dialogs is to use the card to collect information that you can use to start the dialog, by passing in values in the call to the dialog context's Begin method. In the first step of the dialog, you would check for any input values and...discard any that don't validate. (There is probably a more elegant way to handle this.) You have the same issue with triggering a dialog from a LUIS result that can return entities. For use of an Adaptive card (or LUIS) from within a dialog, you could add a "sub-dialog" via a dialog container to your dialog set, that you could pass arguments into and use as one of the steps in the "parent" dialog. |
The way Adaptive Cards show in a dialog can lead to undesired results. The user can ignore the adaptive card and continue the conversation. At any given time the user can return in history and click on buttons in the card. The card message is 'out of sequence' sync with the rest of the dialog. @JonathanFingold , as you identified, currently, there is no to 'force' the user to click buttons as the adaptive card have no way to ensure modality. We can think of a new prompt, called Adaptive card prompt that wait for user input from the card. We'll look into this after our current release. |
@yochay - do you know when we can have something like apatite card prompt part of v4? We were looking for similar solution and wanted to check the timeline before implementing effort on something custom. |
Using a |
thanks @v-kydela for reply, but i am getting and exception on line var dc = await Dialogs.CreateContextAsync(turnContext); while returning adaptive card with choice prompt with many buttons. Error is like: Error reading JArray from JsonReader. Current JsonReader item is not an array: StartObject. Path 'DialogState.DialogStack.$values[0].State.dialogs.DialogStack.$values[0].State.options.Prompt.attachments.$values[0].content.body'. i feel it is related to microsoft/AdaptiveCards#2148 but not sure. any solutions? |
Incorrect information corrected below |
This documentation (https://docs.microsoft.com/en-us/healthbot/scenario-authoring/adding-cards#getting-data-from-forms) talks about using adaptive cards in prompts to gather data from forms. Unfortunately, they use some kind of GUI and I can't seem to figure out how to implement the card in a prompt without getting an error message. I use Node. Also, the JSON.parse command the documentation uses doesn't work for me. |
@FRANZKAFKA13 - While Adaptive Cards are great for gathering information and sending it to the bot, the information must be retrieved from the activity's value property and prompts are expecting replies to only come in the form of an activity's text property |
@FRANZKAFKA13 The documentation page you've shared is in reference to authoring adaptive cards in the HealthBot scenario authoring tool. This is different from a bot built using the Bot Builder sdk alone. More about Microsoft Health Bot Service can be found here: https://docs.microsoft.com/en-us/healthbot/index |
@tusharvaja |
Incorrect information corrected below |
Here's an example of how you might use an Adaptive Card with a prompt: private async Task<DialogTurnResult> PromptWithAdaptiveCardAsync(WaterfallStepContext stepContext, CancellationToken token)
{
var choices = new[] { "One", "Two", "Three" };
var card = new AdaptiveCard
{
Version = new AdaptiveSchemaVersion(1, 0),
Body = { new AdaptiveTextBlock("Make your choice") },
Actions = choices.Select(choice => new AdaptiveSubmitAction
{
Title = choice,
//Data = choice, // For imBack behavior
Data = new { choice }, // For postBack behavior
}).ToList<AdaptiveAction>(),
};
return await stepContext.PromptAsync(
CHOICEPROMPT,
new PromptOptions
{
Choices = ChoiceFactory.ToChoices(choices),
Prompt = (Activity)MessageFactory.Attachment(new Attachment
{
ContentType = AdaptiveCard.ContentType,
Content = JsonConvert.DeserializeObject(JsonConvert.SerializeObject(card)),
}),
},
token);
} |
any updates on that? what is the recommended way to make adaptive card as part of the flow in waterfall? |
Once again I need to correct myself (every comment a new revelation). Choice prompts are not "smart enough to look inside the activity's Value property" on their own. It turns out you can change an incoming activity's @Unders0n - When you say combobox I'm guessing you mean an adaptive choice set. Here's a method that can set your activity's private async Task HandleSubmitActionAsync(ITurnContext turnContext)
{
dynamic value = turnContext.Activity.Value;
string text = value["combo"]; // The property will be named after your choice set's ID
text = string.IsNullOrEmpty(text) ? "." : text; // In case the input is empty
turnContext.Activity.Text = text;
var dc = await Dialogs.CreateContextAsync(turnContext);
var result = await dc.ContinueDialogAsync();
} This could be called from var activity = turnContext.Activity;
if (activity.Type == ActivityTypes.Message)
{
if (string.IsNullOrEmpty(activity.Text))
{
await HandleSubmitActionAsync(turnContext);
}
} |
@v-kydela thanks for your clarification, i've managed it to work though have an issue:
i'm being able to set Text from value of selected dropdown as from your example but it looping thought this step of waterfall and not goin further. I've checked your example and it worked correct only if i leave |
@EricDahlvang solutions mentioned in this topic is definitely looking like hacky workarounds, is Microsoft planning to change design on that and give smth like modal adaptive cards with easy and correct way to handle events? Thank you. |
@Unders0n - The choice prompt's I've also made a feature request to bring back cards in prompts and it's been triaged for 4.3. Adaptive cards will never be modal, though. Look into suggested actions because they're meant to serve the purpose of a one-time set of choices. Or if you really want to prevent reuse of cards you can use something like this technique (was written for V3 but can be easily adapted for V4): https://stackoverflow.com/questions/51701003/microsoft-bot-framework-webchat-disable-adaptivecards-submit-buttons-of-previou/51774589#51774589 |
@v-kydela thanks for updates. ListStyle.None is useful for this case. |
@Unders0n - While it may be more difficult to extract the choices using a JSON card than if you generated the card in C#, LINQ's |
I've faced an issue that i can't pass Value along with Title, when i'm creating stepcontext.PromptAsync , Choices in PromptOptions accepts only list of strings. Any solutions to that? |
@Unders0n - I'm not entirely sure what you're asking, but would you mind posting a question on StackOverflow? This thread is getting sort of long |
@v-kydela I followed the above method to combine adaptive card with prompts in waterfall steps.
Calling adaptive card(.json).
The below code will help us to move to previous step. But how do we implement the same with adaptive card. I have raised this issue even in stack overflow. https://stackoverflow.com/questions/56180596/i-am-using-bot-framework-v4-3-i-want-to-retrieve-adaptive-card-submit-values Kindly help me in solving this issue. |
@gagana-hg - I don't see how a |
One problem with cards is that on some channels users can interact with them again, out-of-sync with the current turn. I don't see any obvious way to include an identifier in the activity payload for a card action, but that would be my first inclination. You could then use that identifier to determine which turn the activity should be associated with. |
@v-kydela I tried with |
@gagana-hg - We have no current timeline or estimate for it, but as a customer you should feel free to voice your interest in this, perhaps on this thread: microsoft/botframework-sdk#5396 |
I also require something like AdaptiveCardPrompt for a requirement. |
Any updates on this? |
Hi Team, any updates on this? Or, any workarounds? Currently we are using a custom base prompt class to achieve this. It works fine in all scenarios, except for validations. `using Microsoft.Bot.Builder; namespace CSITBot /// Basic configuration options supported by all prompts. /// /// The type of the . public abstract class CustomPromptBase : Dialog { private const string PersistedOptions = "options"; private const string PersistedState = "state";
}` `using Microsoft.Bot.Builder; namespace CSITBot
}` Usage --> |
Closing as part of R10 triage. The community now has an adaptive card prompt: https://github.com/BotBuilderCommunity/botbuilder-community-dotnet/tree/develop/libraries/Bot.Builder.Community.Dialogs.Prompts |
Setup:
Issue:
Discussion:
The user can use the adaptive card to send a response, or just type in a value. There is no clear way to handle this with existing prompts with writing a new one from the base Prompt class.
The text was updated successfully, but these errors were encountered: