forked from microsoft/BotBuilder-Samples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRootDialog.cs
More file actions
48 lines (42 loc) · 1.99 KB
/
RootDialog.cs
File metadata and controls
48 lines (42 loc) · 1.99 KB
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
44
45
46
47
48
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Bot.Builder;
using Microsoft.Bot.Builder.Dialogs;
namespace Microsoft.BotBuilderSamples
{
/// <summary>
/// This is an example root dialog. Replace this with your applications.
/// </summary>
public class RootDialog : ComponentDialog
{
public RootDialog()
: base("root")
{
AddDialog(CreateWaterfall());
AddDialog(new NumberPrompt<long>("number"));
}
private static WaterfallDialog CreateWaterfall()
{
return new WaterfallDialog("root-waterfall", new WaterfallStep[] { Step1Async, Step2Async, Step3Async });
}
private static async Task<DialogTurnResult> Step1Async(WaterfallStepContext stepContext, CancellationToken cancellationToken)
{
return await stepContext.PromptAsync("number", new PromptOptions { Prompt = MessageFactory.Text("Enter a number.") }, cancellationToken);
}
private static async Task<DialogTurnResult> Step2Async(WaterfallStepContext stepContext, CancellationToken cancellationToken)
{
var first = (long)stepContext.Result;
stepContext.Values["first"] = first;
return await stepContext.PromptAsync("number", new PromptOptions { Prompt = MessageFactory.Text($"I have {first} now enter another number") }, cancellationToken);
}
private static async Task<DialogTurnResult> Step3Async(WaterfallStepContext stepContext, CancellationToken cancellationToken)
{
var first = (long)stepContext.Values["first"];
var second = (long)stepContext.Result;
await stepContext.Context.SendActivityAsync(MessageFactory.Text($"The result of the first minus the second is {first - second}."), cancellationToken);
return await stepContext.EndDialogAsync(cancellationToken);
}
}
}