forked from microsoft/BotBuilder-Samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRootDialog.cs
68 lines (58 loc) · 2.2 KB
/
RootDialog.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
namespace SimpleTaskAutomationBot.Dialogs
{
using System;
using System.Threading.Tasks;
using Microsoft.Bot.Builder.Dialogs;
using Microsoft.Bot.Connector;
#pragma warning disable 1998
[Serializable]
public class RootDialog : IDialog<object>
{
private const string ChangePasswordOption = "Change Password";
private const string ResetPasswordOption = "Reset Password";
public async Task StartAsync(IDialogContext context)
{
context.Wait(this.MessageReceivedAsync);
}
private async Task MessageReceivedAsync(IDialogContext context, IAwaitable<IMessageActivity> result)
{
PromptDialog.Choice(
context,
this.AfterChoiceSelected,
new[] { ChangePasswordOption, ResetPasswordOption },
"What do you want to do today?",
"I am sorry but I didn't understand that. I need you to select one of the options below",
attempts: 2);
}
private async Task AfterChoiceSelected(IDialogContext context, IAwaitable<string> result)
{
try
{
var selection = await result;
switch (selection)
{
case ChangePasswordOption:
await context.PostAsync("This functionality is not yet implemented! Try resetting your password.");
await this.StartAsync(context);
break;
case ResetPasswordOption:
context.Call(new ResetPasswordDialog(), this.AfterResetPassword);
break;
}
}
catch (TooManyAttemptsException)
{
await this.StartAsync(context);
}
}
private async Task AfterResetPassword(IDialogContext context, IAwaitable<bool> result)
{
var success = await result;
if (!success)
{
await context.PostAsync("Your identity was not verified and your password cannot be reset");
}
await this.StartAsync(context);
}
}
}