From 37ae42f8e62ebcbf2ef53eaae8a10a0efda06610 Mon Sep 17 00:00:00 2001 From: yuesu Date: Wed, 6 Nov 2019 19:37:33 +0800 Subject: [PATCH] add location event support in news skill --- .../newsskill/Dialogs/MainDialog.cs | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/skills/csharp/experimental/newsskill/Dialogs/MainDialog.cs b/skills/csharp/experimental/newsskill/Dialogs/MainDialog.cs index 0ce1e3d1f7..2248c64c5e 100644 --- a/skills/csharp/experimental/newsskill/Dialogs/MainDialog.cs +++ b/skills/csharp/experimental/newsskill/Dialogs/MainDialog.cs @@ -167,6 +167,42 @@ public MainDialog( return result; } + protected override async Task OnEventActivityAsync(DialogContext dc, CancellationToken cancellationToken = default(CancellationToken)) + { + var ev = dc.Context.Activity.AsEventActivity(); + var value = ev.Value?.ToString(); + + var state = await _stateAccessor.GetAsync(dc.Context, () => new NewsSkillState()); + + switch (ev.Name) + { + case Events.Location: + { + // Test trigger with + // /event:{ "Name": "Location", "Value": "34.05222222222222,-118.2427777777777" } + if (!string.IsNullOrEmpty(value)) + { + var coords = value.Split(','); + if (coords.Length == 2) + { + if (double.TryParse(coords[0], out var lat) && double.TryParse(coords[1], out var lng)) + { + state.CurrentCoordinates = value; + } + } + } + + break; + } + + default: + { + await dc.Context.SendActivityAsync(new Activity(type: ActivityTypes.Trace, text: $"Unknown Event '{ev.Name ?? "undefined"}' was received but not processed.")); + break; + } + } + } + private async Task OnCancel(DialogContext dc) { await _responder.ReplyWith(dc.Context, MainResponses.Cancelled); @@ -193,5 +229,10 @@ private async Task PopulateStateFromSemanticAction(ITurnContext context) state.CurrentCoordinates = locationObj; } } + + public class Events + { + public const string Location = "Location"; + } } } \ No newline at end of file