Skip to content
This repository has been archived by the owner on Jun 30, 2022. It is now read-only.

[News] support location event #2662

Merged
merged 1 commit into from
Nov 7, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions skills/csharp/experimental/newsskill/Dialogs/MainDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<InterruptionAction> OnCancel(DialogContext dc)
{
await _responder.ReplyWith(dc.Context, MainResponses.Cancelled);
Expand All @@ -193,5 +229,10 @@ private async Task PopulateStateFromSemanticAction(ITurnContext context)
state.CurrentCoordinates = locationObj;
}
}

public class Events
{
public const string Location = "Location";
}
}
}