-
Notifications
You must be signed in to change notification settings - Fork 1
/
SampleNumberPromptProvider.cs
43 lines (40 loc) · 1.33 KB
/
SampleNumberPromptProvider.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
namespace sample.Areas
{
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Bot.Builder.Dialogs;
using Zyin.IntentBot.Prompt;
/// <summary>
/// Sample Number prompt with value validation
/// </summary>
public class SampleNumberPromptProvider : TypedPromptProvider<int?>
{
/// <summary>
/// Get a Prompt/Dialog object prompts and validates
/// </summary>
/// <param name="promptName"></param>
/// <returns>Dialot used to prompt</returns>
public override Dialog GetPrompt(string promptName)
{
return new NumberPrompt<int>(promptName, this.ValidateNumber);
}
/// <summary>
/// number validator
/// </summary>
/// <param name="promptContext"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
private Task<bool> ValidateNumber(PromptValidatorContext<int> promptContext, CancellationToken cancellationToken)
{
if (promptContext.Recognized.Succeeded)
{
var value = promptContext.Recognized.Value;
if (value >= 1 && value <= 10)
{
return Task.FromResult(true);
}
}
return Task.FromResult(false);;
}
}
}