In Windows (and most user interface frameworks) we have the concept of message boxes and dialog boxes.
We’ve already seen that we would create an implementation of an IDialog to interact with user input/commands, but the Bot framework also includes the equivalent of a Yes/No message box. For example
public async Task MessageReceivedAsync( IDialogContext context, IAwaitable<IMessageActivity> argument) { PromptDialog.Confirm( context, CalculateAsync, "Do you want to calculate risk?", "Unknown option"); } public async Task CalculateAsync( IDialogContext context, IAwaitable<bool> argument) { var confirm = await argument; await context.PostAsync(confirm ? "Calculated" : "Not Calculated"); context.Wait(MessageReceivedAsync); }
What we have now is a prompt dialog which, when seen in the Bot framework channel emulator will ask the question “Do you want to calculate risk?”. This prompt will also display two buttons Yes & No. The user can press the button or type Y, N, Yes or No. Assuming a valid response is given by the user then the CalculateAsync method is called. If the response is not Y, Yes, N or No (obviously on an English language setup) then the prompt is displayed with the “Unknown option” reply that we specified and the dialog again waits for input (you can set the number of retries if you want the user to have three attempts, for example, to respond correctly to a prompt).
We can remove the Yes/No buttons by using promptStyle: PromptStyle.None, i.e.
PromptDialog.Confirm( context, CalculateAsync, "Do you want to calculate risk?", "Unknown option", promptStyle: PromptStyle.None);