-
Notifications
You must be signed in to change notification settings - Fork 174
Expand file tree
/
Copy pathLocationDialogSampleBot.cs
More file actions
89 lines (75 loc) · 3.15 KB
/
Copy pathLocationDialogSampleBot.cs
File metadata and controls
89 lines (75 loc) · 3.15 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
using System;
using System.Threading;
using System.Threading.Tasks;
using Bot.Builder.Community.Dialogs.Location;
using Microsoft.Bot.Builder;
using Microsoft.Bot.Builder.Dialogs;
using Microsoft.Bot.Schema;
using Microsoft.Extensions.Logging;
namespace Google_Adapter_Sample
{
public class LocationDialogSampleBot : IBot
{
private ConversationState _conversationState;
private DialogSet Dialogs { get; set; }
public LocationDialogSampleBot(ILoggerFactory loggerFactory, ConversationState conversationState)
{
_conversationState = conversationState ?? throw new ArgumentNullException(nameof(conversationState));
Dialogs = new DialogSet(_conversationState.CreateProperty<DialogState>(nameof(LocationDialogSampleBot)));
Dialogs.Add(new LocationDialog("<BING MAPS OR AZURE MAPS API KEY>",
"Please enter a location",
conversationState,
useAzureMaps: true,
requiredFields: LocationRequiredFields.StreetAddress | LocationRequiredFields.PostalCode,
options: LocationOptions.None
));
Dialogs.Add(new WaterfallDialog("MainDialog", new WaterfallStep[]
{
async (dc, cancellationToken) =>
{
return await dc.BeginDialogAsync(LocationDialog.DefaultLocationDialogId);
},
async (dc, cancellationToken) =>
{
if (dc.Result is Place returnedPlace)
{
await dc.Context.SendActivityAsync($"Location found: {returnedPlace.GetPostalAddress().FormattedAddress}");
}
else
{
await dc.Context.SendActivityAsync($"No location found");
}
return await dc.EndDialogAsync();
}
}));
}
public async Task OnTurnAsync(ITurnContext turnContext, CancellationToken cancellationToken = default(CancellationToken))
{
var dc = await Dialogs.CreateContextAsync(turnContext);
switch (turnContext.Activity.Type)
{
case ActivityTypes.Message:
var dialogResult = await dc.ContinueDialogAsync();
if (!dc.Context.Responded)
{
switch (dialogResult.Status)
{
case DialogTurnStatus.Empty:
await dc.BeginDialogAsync("MainDialog");
break;
case DialogTurnStatus.Waiting:
break;
case DialogTurnStatus.Complete:
await dc.EndDialogAsync();
break;
default:
await dc.CancelAllDialogsAsync();
break;
}
}
break;
}
}
}
}