forked from microsoft/BotBuilder-Samples
-
Notifications
You must be signed in to change notification settings - Fork 1
/
SurveyDialog.cs
51 lines (44 loc) · 1.52 KB
/
SurveyDialog.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
namespace CreateNewConversationBot
{
using System;
using System.Threading.Tasks;
using Microsoft.Bot.Builder.Dialogs;
using Microsoft.Bot.Builder.FormFlow;
[Serializable]
public sealed class SurveyDialog : IDialog<object>
{
public async Task StartAsync(IDialogContext context)
{
var form = new FormDialog<Survey>(new Survey(), BuildSurveyForm, FormOptions.PromptInStart);
context.Call(form, this.OnSurveyCompleted);
}
private static IForm<Survey> BuildSurveyForm()
{
return new FormBuilder<Survey>()
.AddRemainingFields()
.Build();
}
private async Task OnSurveyCompleted(IDialogContext context, IAwaitable<Survey> result)
{
try
{
var survey = await result;
await context.PostAsync($"Got it... {survey.Name} you've been programming for {survey.YearsCoding} years and use {survey.Language}.");
}
catch (FormCanceledException<Survey> e)
{
string reply;
if (e.InnerException == null)
{
reply = "You have canceled the survey";
}
else
{
reply = $"Oops! Something went wrong :( Technical Details: {e.InnerException.Message}";
}
await context.PostAsync(reply);
}
context.Done(string.Empty);
}
}
}