| Branch | Status | Recommended NuGet package version |
|---|---|---|
| master |
This is part of the Bot Builder Community Extensions project which contains various pieces of middleware, recognizers and other components for use with the Bot Builder .NET SDK v4.
This package contains additional prompts, beyond those offered out of the box by the Bot Builder v4 .NET SDK.
Currently the following Prompts are available;
| Prompt | Description |
|---|---|
| Number with Unit | Prompt a user for Currency, Temperature, Age, Dimension (distance). |
Available via NuGet package Bot.Builder.Community.Dialogs.Prompts
Install into your project using the following command in the package manager;
PM> Install-Package Bot.Builder.Community.Dialogs.Prompts
Below is example usage for each of the Prompts
The Number with Unit Prompt allows you to prompt for the following types of number;
- Currency
- Temperature
- Age
- Dimension (e.g. miles / meters)
Internally the Prompt uses the Microsoft Text Recognizers NumberWithPrompt recognizer.
To use the Prompt, create a new instance of the Prompt, specifying the type of Prompt (e.g. currency) using the second parameter. Once you have created the instance of your Prompt, you can add it to your list of dialogs (e.g. within a ComponentDialog).
var numberPrompt = new NumberWithUnitPrompt(
"CurrencyPrompt",
NumberWithUnitPromptType.Currency,
defaultLocale: Culture.English);Then, you can call the bot by specifying your PromptOptions and calling PromptAsync.
var options = new PromptOptions
{
Prompt = new Activity { Type = ActivityTypes.Message, Text = "Enter a currency." }
};
await dc.PromptAsync("CurrencyPrompt", options, cancellationToken);The Prompt will return a NumberWithUnitResult object. This object contains a Value (dynamic) and a Unit (string). For example, if a user enters "twenty three dollars" when you are using the Currency prompt type, the resulting NumberWithUnitResult object will have Unit: "Dollar", Value: "23". Below is an example of how you might use this result.
var currencyPromptResult = (NumberWithUnitResult)results.Result;
await turnContext.SendActivityAsync(MessageFactory.Text($"Bot received Value: {currencyPromptResult.Value}, Unit: {currencyPromptResult.Unit}"), cancellationToken);