Hi
Following the documentation to create a choiceprompt (example used: Location) : https://docs.microsoft.com/en-us/azure/bot-service/bot-builder-prompts?view=azure-bot-service-4.0&tabs=csharp
I can't seem to correctly cast stepContext.Result from the choice into a string containing the choice.
Instead,
stepContext.Result as string;
results into the object type name : Microsoft.Bot.Builder.Dialogs.Choices.FoundChoices;
I can see stepContext.Result contains the Value property with the selected choice, but I can't access it.
In V3 you had to await the activity to get the string value instead of the object name, but here I can't await stepContext.Result and cast it into a string variable.
What am I doing wrong?
PS: Here's the previous Choice prompt:
`
private static async Task
WaterfallStepContext stepContext,
CancellationToken cancellationToken = default(CancellationToken))
{
return await stepContext.PromptAsync(FAQPrompt,
new PromptOptions
{
Prompt = MessageFactory.Text("What do you want to know?"),
RetryPrompt = MessageFactory.Text("Selected Option not available . Please try again."),
Choices = ChoiceFactory.ToChoices(questions),
},
cancellationToken);
}`
The only way I can make it work is to use SendActivityAsync along with SuggestedActions:
await stepContext.Context.SendActivityAsync(
MessageFactory.SuggestedActions(questions, "What do you want to know?"),
cancellationToken: cancellationToken);
return Dialog.EndOfTurn;
However this defeats the purpose of using the framework in an efficient way, making use of everything at my disposal, like Prompts.
I'm guessing i'm missing something here in order to use the return values of a prompt.
Ok The problem is I'm not sure how to cast if the prompt option was obtained from a list of strings.
Here's the prompt:
public static List<string> questions;
return await stepContext.PromptAsync(FAQPrompt,
new PromptOptions
{
Prompt = MessageFactory.Text("What do you want to know?"),
RetryPrompt = MessageFactory.Text("Selected Option not available . Please try again."),
Choices = ChoiceFactory.ToChoices(questions),
},
cancellationToken);
and here's what crashes the code:
var FAQChoice = (List<string>)stepContext.Result;
What am I doing wrong?
Ok, found the answer, but this should be added to the documentation about prompts and handling the results on the next step
var FAQChoice = ((FoundChoice)stepContext.Result).Value.ToString();
Most helpful comment
Ok, found the answer, but this should be added to the documentation about prompts and handling the results on the next step
var FAQChoice = ((FoundChoice)stepContext.Result).Value.ToString();